Commit 5042b9f5 authored by Anna.Kozlova's avatar Anna.Kozlova
Browse files

wrap return value: check accessibility & navigational elements

IDEA-189391
parent ff83d64f
Branches unavailable Tags unavailable
No related merge requests found
Showing with 11 additions and 7 deletions
+11 -7
......@@ -183,12 +183,16 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
@Override
protected boolean preprocessUsages(@NotNull final Ref<UsageInfo[]> refUsages) {
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, GlobalSearchScope.allScope(myProject));
PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, GlobalSearchScope.allScope(myProject));
if (myUseExistingClass) {
if (existingClass == null) {
conflicts.putValue(null, RefactorJBundle.message("could.not.find.selected.wrapping.class"));
}
else {
PsiElement navigationElement = existingClass.getNavigationElement();
if (navigationElement instanceof PsiClass) {
existingClass = (PsiClass)navigationElement;
}
boolean foundConstructor = false;
final Set<PsiType> returnTypes = new HashSet<>();
returnTypes.add(myMethod.getReturnType());
......@@ -222,19 +226,19 @@ public class WrapReturnValueProcessor extends FixableUsagesRefactoringProcessor
continue constr;
}
}
if (!PsiUtil.isAccessible(constructor, myMethod, null)) {
continue constr;
}
final PsiCodeBlock body = constructor.getBody();
LOG.assertTrue(body != null);
if (body == null) continue constr;
final boolean[] found = new boolean[1];
body.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitAssignmentExpression(final PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
final PsiExpression lExpression = expression.getLExpression();
if (lExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)lExpression).resolve() == myDelegateField) {
final PsiExpression rExpression = expression.getRExpression();
if (rExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)rExpression).resolve() == parameter) {
found[0] = true;
}
if (lExpression instanceof PsiReferenceExpression && myDelegateField.isEquivalentTo(((PsiReferenceExpression)lExpression).resolve())) {
found[0] = true;
}
}
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment