Skip to content

Commit 453774c

Browse files
committed
Fix YAMLUnquotedColon inspection for IDEA >= 2018.3
1 parent 36b3275 commit 453774c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/YamlUnquotedColon.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.jetbrains.yaml.psi.YAMLCompoundValue;
1313
import org.jetbrains.yaml.psi.YAMLKeyValue;
1414

15+
import static fr.adrienbrault.idea.symfony2plugin.util.VersionUtil.productVersionGreaterThanOrEqual;
16+
1517
/**
1618
* @author Daniel Espendiller <daniel@espendiller.net>
1719
*/
@@ -39,7 +41,7 @@ private static class MyPsiElementVisitor extends PsiElementVisitor {
3941
public void visitElement(PsiElement element) {
4042
// every array element implements this interface
4143
// check for inside "foo: <foo: foo>"
42-
if(!(element instanceof YAMLCompoundValue) || element.getNode().getElementType() != YAMLElementTypes.COMPOUND_VALUE) {
44+
if(!isIllegalColonExpression(element)) {
4345
super.visitElement(element);
4446
return;
4547
}
@@ -67,5 +69,14 @@ public void visitElement(PsiElement element) {
6769

6870
super.visitElement(element);
6971
}
72+
73+
private boolean isIllegalColonExpression(PsiElement element) {
74+
75+
if (productVersionGreaterThanOrEqual(2018, 3)) {
76+
return (element instanceof YAMLCompoundValue) && element.getNode().getElementType() == YAMLElementTypes.MAPPING;
77+
}
78+
79+
return (element instanceof YAMLCompoundValue) && element.getNode().getElementType() == YAMLElementTypes.COMPOUND_VALUE;
80+
}
7081
}
7182
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fr.adrienbrault.idea.symfony2plugin.util;
2+
3+
import com.intellij.openapi.application.ApplicationInfo;
4+
5+
public class VersionUtil {
6+
public static boolean productVersionGreaterThanOrEqual(int major, int minor) {
7+
ApplicationInfo instance = ApplicationInfo.getInstance();
8+
9+
return Integer.valueOf(instance.getMajorVersion()) > major || (Integer.valueOf(instance.getMajorVersion()).equals(major) && Integer.valueOf(instance.getMinorVersionMainPart()) >= minor);
10+
}
11+
}

0 commit comments

Comments
 (0)