Skip to content

Commit 4e8e07b

Browse files
committed
Scope TCA inspections to column definitions
1 parent f75ae01 commit 4e8e07b

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/main/java/com/cedricziel/idea/typo3/codeInspection/MissingColumnTypeInspection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.jetbrains.annotations.NotNull;
1414

1515
import static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
16+
import static com.cedricziel.idea.typo3.util.TCAUtil.insideTCAColumnDefinition;
1617

1718
public class MissingColumnTypeInspection extends PhpInspection {
1819
@Nls
@@ -40,7 +41,7 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, bo
4041
public void visitPhpElement(PhpPsiElement element) {
4142

4243
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
43-
if (!isArrayStringValue) {
44+
if (!isArrayStringValue || !insideTCAColumnDefinition(element)) {
4445
return;
4546
}
4647

src/main/java/com/cedricziel/idea/typo3/codeInspection/MissingRenderTypeInspection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jetbrains.annotations.NotNull;
1515

1616
import static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
17+
import static com.cedricziel.idea.typo3.util.TCAUtil.insideTCAColumnDefinition;
1718

1819
public class MissingRenderTypeInspection extends PhpInspection {
1920
@Nls
@@ -41,7 +42,7 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, bo
4142
public void visitPhpElement(PhpPsiElement element) {
4243

4344
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
44-
if (!isArrayStringValue) {
45+
if (!isArrayStringValue || !insideTCAColumnDefinition(element)) {
4546
return;
4647
}
4748

src/main/java/com/cedricziel/idea/typo3/codeInspection/MissingTableInspection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.jetbrains.annotations.NotNull;
1414

1515
import static com.cedricziel.idea.typo3.util.TCAUtil.arrayIndexIsTCATableNameField;
16+
import static com.cedricziel.idea.typo3.util.TCAUtil.insideTCAColumnDefinition;
1617

1718
public class MissingTableInspection extends PhpInspection {
1819
@Nls
@@ -40,7 +41,7 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, bo
4041
public void visitPhpElement(PhpPsiElement element) {
4142

4243
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
43-
if (!isArrayStringValue) {
44+
if (!isArrayStringValue || !insideTCAColumnDefinition(element)) {
4445
return;
4546
}
4647

src/main/java/com/cedricziel/idea/typo3/tca/codeInspection/InvalidQuantityInspection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Arrays;
1616

1717
import static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
18+
import static com.cedricziel.idea.typo3.util.TCAUtil.insideTCAColumnDefinition;
1819

1920
public class InvalidQuantityInspection extends PhpInspection {
2021
@Nls
@@ -37,7 +38,7 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, bo
3738
public void visitPhpElement(PhpPsiElement element) {
3839

3940
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
40-
if (!isArrayStringValue) {
41+
if (!isArrayStringValue || !insideTCAColumnDefinition(element)) {
4142
return;
4243
}
4344

src/main/java/com/cedricziel/idea/typo3/util/TCAUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,17 @@ private static Set<PsiElement> findAvailableRenderTypes(Project project) {
142142

143143
return elements;
144144
}
145+
146+
public static boolean insideTCAColumnDefinition(PsiElement element) {
147+
return PlatformPatterns.psiElement()
148+
.withAncestor(
149+
11,
150+
PlatformPatterns
151+
.psiElement(PhpElementTypes.HASH_ARRAY_ELEMENT)
152+
.withChild(
153+
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText("'columns'")
154+
)
155+
)
156+
.accepts(element);
157+
}
145158
}

0 commit comments

Comments
 (0)