[groovy] highlight negated in and instanceof in <3.0 (IDEA-188424)

This commit is contained in:
Daniil Ovchinnikov
2018-05-28 18:21:02 +03:00
parent 5fc6874352
commit 410cabfa2d
13 changed files with 74 additions and 49 deletions
@@ -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
@@ -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
@@ -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);
}
@@ -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();
}
@@ -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();
}
@@ -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})"
}
@@ -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() {
@@ -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'
}
}
@@ -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'
}
}
@@ -0,0 +1 @@
a <error descr="Negated 'in' is not supported in current version">!</error>in b
@@ -0,0 +1 @@
a <error descr="Negated 'instanceof' is not supported in current version">!</error>instanceof Object
@@ -0,0 +1 @@
a !in b
@@ -0,0 +1 @@
a !instanceof Object