From 6d9e69af663ef214a4a94c2c981ca93fb76e85e1 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Fri, 21 Apr 2017 17:34:43 +0300 Subject: [PATCH] [groovy] tuple expressions cannot have types, as well as they cannot be a subject for introducing variable or parameter. --- ...dAssignmentOfMemberOfRawTypeInspection.java | 4 +++- .../confusing/GroovyGStringKeyInspection.java | 5 ++--- .../expressions/GrTupleExpressionImpl.java | 18 ++++++++++-------- .../introduce/GrIntroduceHandlerBase.java | 3 ++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java index 5452407838ab..5ec0a275e9fc 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/assignment/GroovyUncheckedAssignmentOfMemberOfRawTypeInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -36,6 +36,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnState import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTupleExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; @@ -143,6 +144,7 @@ public class GroovyUncheckedAssignmentOfMemberOfRawTypeInspection extends BaseIn super.visitAssignmentExpression(assignment); GrExpression lValue = assignment.getLValue(); + if (lValue instanceof GrTupleExpression) return; if (!PsiUtil.mightBeLValue(lValue)) return; IElementType opToken = assignment.getOperationTokenType(); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyGStringKeyInspection.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyGStringKeyInspection.java index b0292c9ca6dd..76c58df8baa8 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyGStringKeyInspection.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/confusing/GroovyGStringKeyInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -65,8 +65,6 @@ public class GroovyGStringKeyInspection extends BaseInspection { @Override public void visitExpression(@NotNull GrExpression grExpression) { - if (!isGStringType(grExpression)) return; - final PsiElement gstringParent = grExpression.getParent(); if (gstringParent == null || !(gstringParent instanceof GrArgumentList)) return; @@ -78,6 +76,7 @@ public class GroovyGStringKeyInspection extends BaseInspection { return; } + if (!isGStringType(grExpression)) return; if (!isMapPutMethod((GrMethodCall)grandparent)) return; registerError(grExpression); diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrTupleExpressionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrTupleExpressionImpl.java index a400d3c9eb43..88fe3189f8c8 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrTupleExpressionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrTupleExpressionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * 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. @@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions; import com.intellij.lang.ASTNode; -import com.intellij.psi.CommonClassNames; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiType; import com.intellij.util.ArrayUtilRt; @@ -31,18 +30,16 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTupleE */ public class GrTupleExpressionImpl extends GrExpressionImpl implements GrTupleExpression { - @Override - public String toString() { - return "Tuple Assignment Expression"; - } - public GrTupleExpressionImpl(@NotNull ASTNode node) { super(node); } @Override public PsiType getType() { - return getTypeByFQName(CommonClassNames.JAVA_UTIL_LIST); + // The reason this method exists is that tuple expression can appear in the left side of an assignment. + // LHS should probably have its own interface with implementations: GrReferenceExpression, GrIndexProperty, GrTupleExpression, + // while GrTupleExpression will just implement it, but not an GrExpression. + throw new UnsupportedOperationException("Tuple expressions cannot have type"); } @Override @@ -61,4 +58,9 @@ public class GrTupleExpressionImpl extends GrExpressionImpl implements GrTupleEx public void accept(GroovyElementVisitor visitor) { visitor.visitTupleExpression(this); } + + @Override + public String toString() { + return "Tuple Assignment Expression"; + } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java index c9f5b5258e74..a45c18ff8f54 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/GrIntroduceHandlerBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * 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. @@ -218,6 +218,7 @@ public abstract class GrIntroduceHandlerBase