diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java index 0893d05fac1d..8d1965e605b0 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/PsiUtil.java @@ -123,13 +123,6 @@ public class PsiUtil { return false; } - public static boolean isLValueOfOperatorAssignment(@NotNull GrReferenceExpression element) { - PsiElement parent = PsiTreeUtil.skipParentsOfType(element, GrParenthesizedExpression.class); - return parent instanceof GrAssignmentExpression - && ((GrAssignmentExpression)parent).isOperatorAssignment() - && PsiTreeUtil.isAncestor(((GrAssignmentExpression)parent).getLValue(), element, false); - } - public static boolean isApplicable(@Nullable PsiType[] argumentTypes, @NotNull PsiMethod method, PsiSubstitutor substitutor, @@ -372,11 +365,11 @@ public class PsiUtil { @Override public Iterator iterator() { return new Iterator() { - TIntStack indices = new TIntStack(); - Stack superTypesStack = new Stack<>(); + final TIntStack indices = new TIntStack(); + final Stack superTypesStack = new Stack<>(); + final Set visited = new HashSet<>(); PsiClass current; boolean nextObtained; - Set visited = new HashSet<>(); { if (includeSelf) { @@ -849,7 +842,11 @@ public class PsiUtil { public static boolean isUsedInIncOrDec(GrExpression expr) { PsiElement parent = PsiTreeUtil.skipParentsOfType(expr, GrParenthesizedExpression.class); + return isPlusPlusOrMinusMinus(parent); + } + @Contract("null -> false") + public static boolean isPlusPlusOrMinusMinus(@Nullable PsiElement parent) { if (parent instanceof GrUnaryExpression) { IElementType tokenType = ((GrUnaryExpression)parent).getOperationTokenType(); return tokenType == GroovyTokenTypes.mINC || tokenType == GroovyTokenTypes.mDEC; @@ -857,32 +854,30 @@ public class PsiUtil { return false; } - public static GrReferenceExpression qualifyMemberReference(GrReferenceExpression refExpr, PsiMember member, String name) { + public static void qualifyMemberReference(@NotNull GrReferenceExpression refExpr, @NotNull PsiMember member, String name) { assert refExpr.getQualifierExpression() == null; final PsiClass clazz = member.getContainingClass(); assert clazz != null; - final PsiElement replaced; if (member.hasModifierProperty(PsiModifier.STATIC)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getQualifiedName() + "." + name); - replaced = refExpr.replace(newRefExpr); + refExpr.replace(newRefExpr); } else { final PsiClass containingClass = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); if (member.getManager().areElementsEquivalent(containingClass, clazz)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText("this." + name); - replaced = refExpr.replace(newRefExpr); + refExpr.replace(newRefExpr); } else { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getName() + ".this." + name); - replaced = refExpr.replace(newRefExpr); + refExpr.replace(newRefExpr); } } - return (GrReferenceExpression)replaced; } public static GroovyResolveResult[] getConstructorCandidates(PsiClassType classType, PsiType[] argTypes, GroovyPsiElement context) { @@ -907,14 +902,13 @@ public class PsiUtil { while ((parent = element.getParent()) instanceof GrParenthesizedExpression) { element = parent; } - return element; } else { while (element instanceof GrParenthesizedExpression) { element = ((GrParenthesizedExpression)element).getOperand(); } - return element; } + return element; } @NotNull @@ -961,6 +955,7 @@ public class PsiUtil { private static final String[] visibilityModifiers = new String[]{PsiModifier.PRIVATE, PsiModifier.PROTECTED, PsiModifier.PUBLIC}; + @SuppressWarnings("Duplicates") public static void escalateVisibility(PsiMember owner, PsiElement place) { PsiModifierList modifierList = owner.getModifierList(); LOG.assertTrue(modifierList != null); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java index 5c361ba43962..750e72c3e31b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/GroovyRefactoringUtil.java @@ -54,6 +54,8 @@ import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils; import java.util.*; +import static org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isPlusPlusOrMinusMinus; + /** * @author ilyas */ @@ -426,14 +428,6 @@ public abstract class GroovyRefactoringUtil { return result; } - public static boolean isPlusPlusOrMinusMinus(PsiElement element) { - if (element instanceof GrUnaryExpression) { - IElementType operandSign = ((GrUnaryExpression)element).getOperationTokenType(); - return operandSign == GroovyTokenTypes.mDEC || operandSign == GroovyTokenTypes.mINC; - } - return false; - } - public static boolean isCorrectReferenceName(String newName, Project project) { if (newName.startsWith("'''") || newName.startsWith("\"\"\"")) { if (newName.length() < 6 || !newName.endsWith("'''")) {