boolean (@NotNull final Ref<UsageInfo[]> refUsages) { MultiMap<PsiElement, String> conflicts = new MultiMap<>(); PsiClass existingClass = JavaPsiFacade.getInstance(myProject).findClass(myQualifiedName, GlobalSearchScope.allScope(myProject)); if (myUseExistingClass) { if (existingClass == null) { conflicts.putValue(null, JavaRareRefactoringsBundle.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()); final PsiCodeBlock methodBody = myMethod.getBody(); if (methodBody != null) { methodBody.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReturnStatement(final @NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression returnValue = statement.getReturnValue(); if (returnValue != null) { returnTypes.add(returnValue.getType()); } } @Override public void visitClass(@NotNull PsiClass aClass) {} @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) {} }); } final PsiMethod[] constructors = existingClass.getConstructors(); constr: for (PsiMethod constructor : constructors) { final PsiParameter[] parameters = constructor.getParameterList().getParameters(); if (parameters.length == 1) { final PsiParameter parameter = parameters[0]; final PsiType parameterType = parameter.getType(); for (PsiType returnType : returnTypes) { if (getInferredType(parameterType, returnType, existingClass, myMethod) == null && !TypeConversionUtil.isAssignable(parameterType, returnType)) { continue constr; } } if (!PsiUtil.isAccessible(constructor, myMethod, null)) { continue constr; } final PsiCodeBlock body = constructor.getBody(); if (body == null) continue constr; final boolean[] found = new boolean[1]; body.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitAssignmentExpression(final @NotNull PsiAssignmentExpression expression) { super.visitAssignmentExpression(expression); final PsiExpression lExpression = expression.getLExpression(); if (lExpression instanceof PsiReferenceExpression && myDelegateField.isEquivalentTo(((PsiReferenceExpression)lExpression).resolve())) { found[0] = true; } } }); if (found[0]) { foundConstructor = true; break; } } } if (!foundConstructor) { conflicts.putValue(existingClass, JavaBundle.message("wrap.return.value.existing.class.does.not.have.appropriate.constructor.conflict")); } } if (myUnwrapMethodName.length() == 0) { conflicts.putValue(existingClass, JavaBundle.message("wrap.return.value.existing.class.does.not.have.getter.conflict")); } } else { if (existingClass != null) { conflicts.putValue(existingClass, JavaRareRefactoringsBundle.message("there.already.exists.a.class.with.the.selected.name")); } if (myMoveDestination != null && !myMoveDestination.isTargetAccessible(myProject, myMethod.getContainingFile().getVirtualFile())) { conflicts.putValue(myMethod, JavaBundle.message("wrap.return.value.created.class.not.accessible.conflict")); } } return showConflicts(conflicts, refUsages.get()); }