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);
}
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;
}
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);
}
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;
}
Aggregations