private boolean checkAccessibility(final PsiClass aClass) { // We don't care about accessibility in javadoc if (JavaResolveUtil.isInJavaDoc(myPlace)) { return true; } if (PsiImplUtil.isInServerPage(aClass.getContainingFile())) { PsiFile file = FileContextUtil.getContextFile(myPlace); if (PsiImplUtil.isInServerPage(file)) { return true; } } boolean accessible = true; if (aClass instanceof PsiTypeParameter) { accessible = !myStaticContext; } PsiManager manager = aClass.getManager(); if (aClass.hasModifierProperty(PsiModifier.PRIVATE)) { PsiElement parent = aClass.getParent(); while (true) { PsiElement parentScope = parent.getParent(); if (parentScope instanceof PsiJavaFile) break; parent = parentScope; if (!(parentScope instanceof PsiClass)) break; } if (parent instanceof PsiDeclarationStatement) { parent = parent.getParent(); } accessible = false; for (PsiElement placeParent = myPlace; placeParent != null; placeParent = placeParent.getContext()) { if (manager.areElementsEquivalent(placeParent, parent)) accessible = true; } } final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); if (aClass.hasModifierProperty(PsiModifier.PROTECTED)) { accessible = false; if (myPlace != null && facade.arePackagesTheSame(aClass, myPlace)) { accessible = true; } else { if (aClass.getContainingClass() != null) { accessible = myAccessClass == null || myPlace != null && facade.getResolveHelper().isAccessible(aClass, myPlace, myAccessClass); } } } if (aClass.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) { if (myPlace == null || !facade.arePackagesTheSame(aClass, myPlace)) { accessible = false; } } return accessible; }
private boolean isOnDemand(PsiElement fileContext, PsiClass psiClass) { if (isImported(fileContext)) { return ((PsiImportStatementBase) fileContext).isOnDemand(); } String fqn = psiClass.getQualifiedName(); if (fqn == null) return false; PsiFile file = myPlace == null ? null : FileContextUtil.getContextFile(myPlace); String[] defaultPackages = file instanceof PsiJavaFile ? ((PsiJavaFile) file).getImplicitlyImportedPackages() : DEFAULT_PACKAGES; String packageName = StringUtil.getPackageName(fqn); for (String defaultPackage : defaultPackages) { if (defaultPackage.equals(packageName)) return true; } // class from my package imported implicitly return file instanceof PsiJavaFile && ((PsiJavaFile) file).getPackageName().equals(packageName); }