Skip to content

Commit f194bc6

Browse files
committed
Fix faulty error highlighting for route parameters
Closes: #50
1 parent e3f3948 commit f194bc6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/com/cedricziel/idea/typo3/annotation/RouteAnnotator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.util.TextRange;
1010
import com.intellij.psi.PsiElement;
1111
import com.intellij.psi.util.PsiTreeUtil;
12+
import com.jetbrains.php.lang.psi.elements.ArrayCreationExpression;
1213
import com.jetbrains.php.lang.psi.elements.MethodReference;
1314
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1415
import org.jetbrains.annotations.NotNull;
@@ -29,14 +30,21 @@ public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder a
2930
}
3031

3132
PsiElement methodReference = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
32-
if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl")) {
33+
if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getAjaxUrl") && !hasArrayCreationParent(psiElement)) {
3334
annotateAjaxRoutes(psiElement, annotationHolder, value);
3435
}
35-
if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute")) {
36+
if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "buildUriFromRoute") && !hasArrayCreationParent(psiElement)) {
3637
annotateRoutes(psiElement, annotationHolder, value);
3738
}
3839
}
3940

41+
private boolean hasArrayCreationParent(@NotNull PsiElement psiElement) {
42+
if (psiElement.getParent() == null) {
43+
return false;
44+
}
45+
return psiElement.getParent().getParent() instanceof ArrayCreationExpression;
46+
}
47+
4048
private void annotateAjaxRoutes(PsiElement psiElement, AnnotationHolder annotationHolder, String value) {
4149
RouteProvider routeProvider = new RouteProvider();
4250
routeProvider.collect(psiElement.getProject());
@@ -56,7 +64,7 @@ private void annotateRoute(PsiElement psiElement, AnnotationHolder annotationHol
5664
if (routeProvider.has(value, routeType)) {
5765
TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset());
5866
Annotation annotation = annotationHolder.createInfoAnnotation(range, null);
59-
annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
67+
annotation.setTextAttributes(DefaultLanguageHighlighterColors.STRING);
6068
} else {
6169
TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset());
6270
annotationHolder.createErrorAnnotation(range, "Unresolved route");

0 commit comments

Comments
 (0)