diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GroovyBundle.properties index 76af8e6f251d..3b8f72911cc5 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GroovyBundle.properties +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GroovyBundle.properties @@ -223,6 +223,8 @@ illegal.default.modifier=Modifier 'default' makes sense only in interface's meth illegal.default.modifier.fix=Remove 'default' modifier default.modifier.in.old.versions=Modifier 'default' is available with Groovy 3.0 or later operator.is.not.supported.in=Operator ''{0}'' is not supported in current version +unsupported.negated.in=Negated 'in' is not supported in current version +unsupported.negated.instanceof=Negated 'instanceof' is not supported in current version unsupported.elvis.assignment=Elvis assignment is not supported in current version unsupported.safe.index.access=Safe index access is not supported in current version diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotatorPre30.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotatorPre30.kt index 4b45a8661af5..c690ce04655e 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotatorPre30.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotatorPre30.kt @@ -5,8 +5,10 @@ import com.intellij.lang.annotation.AnnotationHolder import org.jetbrains.plugins.groovy.GroovyBundle.message import org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor +import org.jetbrains.plugins.groovy.lang.psi.api.GrInExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstanceOfExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty internal class GroovyAnnotatorPre30(private val holder: AnnotationHolder) : GroovyElementVisitor() { @@ -20,6 +22,22 @@ internal class GroovyAnnotatorPre30(private val holder: AnnotationHolder) : Groo } } + override fun visitInExpression(expression: GrInExpression) { + super.visitInExpression(expression) + val negation = expression.negationToken + if (negation != null) { + holder.createErrorAnnotation(negation, message("unsupported.negated.in")) + } + } + + override fun visitInstanceofExpression(expression: GrInstanceOfExpression) { + super.visitInstanceofExpression(expression) + val negation = expression.negationToken + if (negation != null) { + holder.createErrorAnnotation(negation, message("unsupported.negated.instanceof")) + } + } + override fun visitAssignmentExpression(expression: GrAssignmentExpression) { super.visitAssignmentExpression(expression) val operator = expression.operationToken diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java index b8d367a8c6a2..f20df822aac0 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/GroovyElementVisitor.java @@ -1,22 +1,9 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.*; +import org.jetbrains.plugins.groovy.lang.psi.api.GrInExpression; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList; @@ -169,6 +156,10 @@ public abstract class GroovyElementVisitor { visitExpression(expression); } + public void visitInExpression(@NotNull GrInExpression expression) { + visitBinaryExpression(expression); + } + public void visitUnaryExpression(@NotNull GrUnaryExpression expression) { visitExpression(expression); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/GrInExpression.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/GrInExpression.java index a1901efe12a7..8cd8554e00b6 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/GrInExpression.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/GrInExpression.java @@ -1,7 +1,12 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi.api; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression; public interface GrInExpression extends GrBinaryExpression { + + @Nullable + PsiElement getNegationToken(); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrInstanceOfExpression.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrInstanceOfExpression.java index 8c2da77fcd4a..e105c43eceea 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrInstanceOfExpression.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrInstanceOfExpression.java @@ -1,32 +1,19 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; -/** - * @author ven - */ public interface GrInstanceOfExpression extends GrExpression { + @Nullable GrTypeElement getTypeElement(); + @Nullable + PsiElement getNegationToken(); + @NotNull GrExpression getOperand(); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrInExpressionImpl.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrInExpressionImpl.kt index 7bf6b2370dca..8f4183ae8477 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrInExpressionImpl.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrInExpressionImpl.kt @@ -2,10 +2,17 @@ package org.jetbrains.plugins.groovy.lang.psi.impl import com.intellij.lang.ASTNode +import com.intellij.psi.PsiElement +import org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_NOT +import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor import org.jetbrains.plugins.groovy.lang.psi.api.GrInExpression import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrBinaryExpressionImpl class GrInExpressionImpl(node: ASTNode) : GrBinaryExpressionImpl(node), GrInExpression { + override fun getNegationToken(): PsiElement? = findChildByType(T_NOT) + + override fun accept(visitor: GroovyElementVisitor): Unit = visitor.visitInExpression(this) + override fun toString(): String = "${javaClass.simpleName}(${node.elementType})" } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrInstanceofExpressionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrInstanceofExpressionImpl.java index 80c02c7c4da7..e0077976b7ec 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrInstanceofExpressionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/types/GrInstanceofExpressionImpl.java @@ -1,23 +1,10 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.types; import com.intellij.lang.ASTNode; import com.intellij.psi.CommonClassNames; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,6 +14,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstan import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.GrExpressionImpl; +import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_NOT; + /** * @author ven */ @@ -56,6 +45,12 @@ public class GrInstanceofExpressionImpl extends GrExpressionImpl implements GrIn return findChildByClass(GrTypeElement.class); } + @Nullable + @Override + public PsiElement getNegationToken() { + return findChildByType(T_NOT); + } + @Override @NotNull public GrExpression getOperand() { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy30HighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy30HighlightingTest.groovy index 3ef9ba660275..55789070b14f 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy30HighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/Groovy30HighlightingTest.groovy @@ -73,4 +73,12 @@ I i = {3} void 'test safe index access'() { fixture.testHighlighting testName + '.groovy' } + + void 'test negated in'() { + fixture.testHighlighting testName + '.groovy' + } + + void 'test negated instanceof'() { + fixture.testHighlighting testName + '.groovy' + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyPre30HighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyPre30HighlightingTest.groovy index eb9f6da29fe3..0e59679d48dd 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyPre30HighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyPre30HighlightingTest.groovy @@ -22,4 +22,12 @@ class GroovyPre30HighlightingTest extends GrHighlightingTestBase { void 'test safe index access'() { fixture.testHighlighting testName + '.groovy' } + + void 'test negated in'() { + fixture.testHighlighting testName + '.groovy' + } + + void 'test negated instanceof'() { + fixture.testHighlighting testName + '.groovy' + } } diff --git a/plugins/groovy/testdata/highlighting/pre30/negatedIn.groovy b/plugins/groovy/testdata/highlighting/pre30/negatedIn.groovy new file mode 100644 index 000000000000..968550ef379f --- /dev/null +++ b/plugins/groovy/testdata/highlighting/pre30/negatedIn.groovy @@ -0,0 +1 @@ +a !in b diff --git a/plugins/groovy/testdata/highlighting/pre30/negatedInstanceof.groovy b/plugins/groovy/testdata/highlighting/pre30/negatedInstanceof.groovy new file mode 100644 index 000000000000..b2e77f39a1fc --- /dev/null +++ b/plugins/groovy/testdata/highlighting/pre30/negatedInstanceof.groovy @@ -0,0 +1 @@ +a !instanceof Object diff --git a/plugins/groovy/testdata/highlighting/v30/negatedIn.groovy b/plugins/groovy/testdata/highlighting/v30/negatedIn.groovy new file mode 100644 index 000000000000..aa976d628ae0 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/v30/negatedIn.groovy @@ -0,0 +1 @@ +a !in b diff --git a/plugins/groovy/testdata/highlighting/v30/negatedInstanceof.groovy b/plugins/groovy/testdata/highlighting/v30/negatedInstanceof.groovy new file mode 100644 index 000000000000..a857755cac08 --- /dev/null +++ b/plugins/groovy/testdata/highlighting/v30/negatedInstanceof.groovy @@ -0,0 +1 @@ +a !instanceof Object