void (@NotNull Project project, @Nullable Collection<? extends PsiElement> scopes, UsageInfo[] usages, @NotNull VirtualFile vFile, @NotNull MultiMap<PsiElement, @DialogMessage String> conflicts) { if (scopes == null) return; for (final PsiElement scope : scopes) { if (scope instanceof PsiPackage) return; } final Module targetModule = ModuleUtilCore.findModuleForFile(vFile, project); if (targetModule == null) return; final GlobalSearchScope resolveScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(targetModule); final HashSet<PsiElement> reported = new HashSet<>(); Consumer<PsiJavaCodeReferenceElement> processor = new Consumer<>() { @Override public void accept(PsiJavaCodeReferenceElement reference) { final PsiElement resolved = reference.resolve(); if (resolved != null && !reported.contains(resolved) && !CommonRefactoringUtil.isAncestor(resolved, scopes) && !(resolved instanceof LightElement) && resolved.isPhysical() && !haveElementInScope(resolved)) { if (resolved instanceof PsiMethod) { for (PsiMethod superMethod : ((PsiMethod)resolved).findDeepestSuperMethods()) { if (haveElementInScope(superMethod)) return; } } final String scopeDescription = RefactoringUIUtil.getDescription(ConflictsUtil.getContainer(reference), true); final String message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.in.module.2", RefactoringUIUtil.getDescription(resolved, true), scopeDescription, CommonRefactoringUtil.htmlEmphasize(targetModule.getName())); conflicts.putValue(reference, StringUtil.capitalize(message)); reported.add(resolved); } } private boolean haveElementInScope(PsiElement resolved) { if (PsiSearchScopeUtil.isInScope(resolveScope, resolved)) { return true; } if (!resolved.getManager().isInProject(resolved)) { if (resolved instanceof PsiMember) { final PsiClass containingClass = ((PsiMember)resolved).getContainingClass(); if (containingClass != null) { final String fqn = containingClass.getQualifiedName(); if (fqn != null) { final PsiClass classFromTarget = JavaPsiFacade.getInstance(project).findClass(fqn, resolveScope); if (classFromTarget != null) { if (resolved instanceof PsiMethod) { return classFromTarget.findMethodsBySignature((PsiMethod)resolved, true).length > 0; } if (resolved instanceof PsiField) { return classFromTarget.findFieldByName(((PsiField)resolved).getName(), false) != null; } if (resolved instanceof PsiClass) { return classFromTarget.findInnerClassByName(((PsiClass)resolved).getName(), false) != null; } } } } } if (resolved instanceof PsiClass) { final String fqn = ((PsiClass)resolved).getQualifiedName(); return fqn != null && JavaPsiFacade.getInstance(project).findClass(fqn, resolveScope) != null; } } return false; } }; for (final PsiElement scope : scopes) { JavaElementVisitor visitor; if (scope instanceof PsiCompiledElement) { // For compiled element walking visitor should not be used: see PsiWalkingState#elementStarted visitor = new JavaRecursiveElementVisitor() { @Override public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) { super.visitReferenceElement(reference); processor.accept(reference); } }; } else { visitor = new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) { super.visitReferenceElement(reference); processor.accept(reference); } }; } ProgressManager.progress( JavaRefactoringBundle.message("processing.progress.text", SymbolPresentationUtil.getSymbolPresentableText(scope))); scope.accept(visitor); } boolean isInTestSources = ModuleRootManager.getInstance(targetModule).getFileIndex().isInTestSourceContent(vFile); NextUsage: for (UsageInfo usage : usages) { final PsiElement element = usage.getElement(); if (element != null && PsiTreeUtil.getParentOfType(element, PsiImportStatement.class, false) == null) { for (PsiElement scope : scopes) { if (PsiTreeUtil.isAncestor(scope, element, false)) continue NextUsage; } final GlobalSearchScope resolveScope1 = element.getResolveScope(); if (!resolveScope1.isSearchInModuleContent(targetModule, isInTestSources)) { final PsiFile usageFile = element.getContainingFile(); PsiElement container; if (usageFile instanceof PsiJavaFile) { container = ConflictsUtil.getContainer(element); } else { container = usageFile; } final String scopeDescription = RefactoringUIUtil.getDescription(container, true); final VirtualFile usageVFile = usageFile.getVirtualFile(); if (usageVFile != null) { Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(usageVFile); if (module != null) { final String message; final PsiElement referencedElement; if (usage instanceof MoveRenameUsageInfo) { referencedElement = ((MoveRenameUsageInfo)usage).getReferencedElement(); } else { referencedElement = usage.getElement(); } assert referencedElement != null : usage; if (module == targetModule && isInTestSources) { message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.production.of.module.2", RefactoringUIUtil.getDescription(referencedElement, true), scopeDescription, CommonRefactoringUtil.htmlEmphasize(module.getName())); } else { message = RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.module.2", RefactoringUIUtil.getDescription(referencedElement, true), scopeDescription, CommonRefactoringUtil.htmlEmphasize(module.getName())); } conflicts.putValue(element, StringUtil.capitalize(message)); } } } } } }