Search in sources :

Example 1 with AnySupers

use of org.jetbrains.plugins.groovy.refactoring.util.AnySupers in project intellij-community by JetBrains.

the class GrIntroduceClosureParameterProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (!mySettings.generateDelegate()) {
        detectAccessibilityConflicts(usagesIn, conflicts);
    }
    final GrExpression expression = mySettings.getExpression();
    if (expression != null && toSearchFor instanceof PsiMember) {
        final AnySupers anySupers = new AnySupers();
        expression.accept(anySupers);
        if (anySupers.containsSupers()) {
            final PsiElement containingClass = PsiUtil.getFileOrClassContext(toReplaceIn);
            for (UsageInfo usageInfo : usagesIn) {
                if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
                    if (!PsiTreeUtil.isAncestor(containingClass, usageInfo.getElement(), false)) {
                        conflicts.putValue(expression, RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
                        break;
                    }
                }
            }
        }
    }
    return showConflicts(conflicts, usagesIn);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ExternalUsageInfo(com.intellij.refactoring.introduceParameter.ExternalUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo) AnySupers(org.jetbrains.plugins.groovy.refactoring.util.AnySupers) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo)

Example 2 with AnySupers

use of org.jetbrains.plugins.groovy.refactoring.util.AnySupers in project intellij-community by JetBrains.

the class ExtractClosureFromMethodProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final GrStatement[] statements = myHelper.getStatements();
    for (GrStatement statement : statements) {
        GroovyIntroduceParameterUtil.detectAccessibilityConflicts(statement, usagesIn, conflicts, false, myProject);
    }
    for (UsageInfo info : usagesIn) {
        if (info instanceof OtherLanguageUsageInfo) {
            final String lang = CommonRefactoringUtil.htmlEmphasize(info.getElement().getLanguage().getDisplayName());
            conflicts.putValue(info.getElement(), GroovyRefactoringBundle.message("cannot.process.usage.in.language.{0}", lang));
        }
    }
    if (!myMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
        final AnySupers anySupers = new AnySupers();
        for (GrStatement statement : statements) {
            statement.accept(anySupers);
        }
        if (anySupers.containsSupers()) {
            for (UsageInfo usageInfo : usagesIn) {
                if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
                    if (!PsiTreeUtil.isAncestor(myMethod.getContainingClass(), usageInfo.getElement(), false)) {
                        conflicts.putValue(statements[0], RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
                        break;
                    }
                }
            }
        }
    }
    if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) {
        throw new ConflictsInTestsException(conflicts.values());
    }
    if (!conflicts.isEmpty()) {
        final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usagesIn);
        if (!conflictsDialog.showAndGet()) {
            if (conflictsDialog.isShowConflicts())
                prepareSuccessful();
            return false;
        }
    }
    prepareSuccessful();
    return true;
}
Also used : GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) AnySupers(org.jetbrains.plugins.groovy.refactoring.util.AnySupers)

Example 3 with AnySupers

use of org.jetbrains.plugins.groovy.refactoring.util.AnySupers in project intellij-community by JetBrains.

the class GrIntroduceParameterProcessor method preprocessUsages.

@Override
protected boolean preprocessUsages(@NotNull Ref<UsageInfo[]> refUsages) {
    UsageInfo[] usagesIn = refUsages.get();
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (!mySettings.generateDelegate()) {
        GroovyIntroduceParameterUtil.detectAccessibilityConflicts(mySettings.getExpression(), usagesIn, conflicts, mySettings.replaceFieldsWithGetters() != IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_NONE, myProject);
    }
    final GrMethod toReplaceIn = (GrMethod) mySettings.getToReplaceIn();
    if (mySettings.getExpression() != null && !toReplaceIn.hasModifierProperty(PsiModifier.PRIVATE)) {
        final AnySupers anySupers = new AnySupers();
        mySettings.getExpression().accept(anySupers);
        if (anySupers.containsSupers()) {
            for (UsageInfo usageInfo : usagesIn) {
                if (!(usageInfo.getElement() instanceof PsiMethod) && !(usageInfo instanceof InternalUsageInfo)) {
                    if (!PsiTreeUtil.isAncestor(toReplaceIn.getContainingClass(), usageInfo.getElement(), false)) {
                        conflicts.putValue(mySettings.getExpression(), RefactoringBundle.message("parameter.initializer.contains.0.but.not.all.calls.to.method.are.in.its.class", CommonRefactoringUtil.htmlEmphasize(PsiKeyword.SUPER)));
                        break;
                    }
                }
            }
        }
    }
    for (IntroduceParameterMethodUsagesProcessor processor : IntroduceParameterMethodUsagesProcessor.EP_NAME.getExtensions()) {
        processor.findConflicts(this, refUsages.get(), conflicts);
    }
    return showConflicts(conflicts, usagesIn);
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) UsageInfo(com.intellij.usageView.UsageInfo) NoConstructorClassUsageInfo(com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo) DefaultConstructorImplicitUsageInfo(com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo) AnySupers(org.jetbrains.plugins.groovy.refactoring.util.AnySupers)

Example 4 with AnySupers

use of org.jetbrains.plugins.groovy.refactoring.util.AnySupers in project intellij-community by JetBrains.

the class GroovyMethodInliner method collectConflicts.

@NotNull
private static MultiMap<PsiElement, String> collectConflicts(@NotNull GrCallExpression call, @NotNull Collection<GroovyInlineMethodUtil.ReferenceExpressionInfo> infos) {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    for (GroovyInlineMethodUtil.ReferenceExpressionInfo info : infos) {
        if (!PsiUtil.isAccessible(call, info.declaration)) {
            if (info.declaration instanceof PsiMethod) {
                String className = info.containingClass.getName();
                String signature = GroovyRefactoringUtil.getMethodSignature((PsiMethod) info.declaration);
                String name = CommonRefactoringUtil.htmlEmphasize(className + "." + signature);
                conflicts.putValue(info.declaration, GroovyRefactoringBundle.message("method.is.not.accessible.form.context.0", name));
            } else if (info.declaration instanceof PsiField) {
                if (!(info.declaration instanceof GrField && ((GrField) info.declaration).getGetters().length > 0)) {
                    // conflict if field doesn't have implicit getters
                    String className = info.containingClass.getName();
                    String name = CommonRefactoringUtil.htmlEmphasize(className + "." + info.getPresentation());
                    conflicts.putValue(info.declaration, GroovyRefactoringBundle.message("field.is.not.accessible.form.context.0", name));
                }
            }
        }
        AnySupers visitor = new AnySupers();
        info.expression.accept(visitor);
        if (visitor.containsSupers()) {
            conflicts.putValue(info.expression, GroovyRefactoringBundle.message("super.reference.is.used"));
        }
    }
    return conflicts;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) AnySupers(org.jetbrains.plugins.groovy.refactoring.util.AnySupers) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)4 AnySupers (org.jetbrains.plugins.groovy.refactoring.util.AnySupers)4 UsageInfo (com.intellij.usageView.UsageInfo)3 DefaultConstructorImplicitUsageInfo (com.intellij.refactoring.util.usageInfo.DefaultConstructorImplicitUsageInfo)2 NoConstructorClassUsageInfo (com.intellij.refactoring.util.usageInfo.NoConstructorClassUsageInfo)2 ExternalUsageInfo (com.intellij.refactoring.introduceParameter.ExternalUsageInfo)1 InternalUsageInfo (com.intellij.refactoring.introduceParameter.InternalUsageInfo)1 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)1 NotNull (org.jetbrains.annotations.NotNull)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)1 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1