use of com.intellij.codeInspection.ex.EntryPointsManager in project intellij-community by JetBrains.
the class UnusedDeclarationInspectionBase method isEntryPoint.
public boolean isEntryPoint(@NotNull PsiElement element) {
final Project project = element.getProject();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
if (element instanceof PsiMethod && isAddMainsEnabled() && PsiClassImplUtil.isMainOrPremainMethod((PsiMethod) element)) {
return true;
}
if (element instanceof PsiClass) {
PsiClass aClass = (PsiClass) element;
final PsiClass applet = psiFacade.findClass("java.applet.Applet", GlobalSearchScope.allScope(project));
if (isAddAppletEnabled() && applet != null && aClass.isInheritor(applet, true)) {
return true;
}
final PsiClass servlet = psiFacade.findClass("javax.servlet.Servlet", GlobalSearchScope.allScope(project));
if (isAddServletEnabled() && servlet != null && aClass.isInheritor(servlet, true)) {
return true;
}
if (isAddMainsEnabled() && PsiMethodUtil.hasMainMethod(aClass))
return true;
}
if (element instanceof PsiModifierListOwner) {
final EntryPointsManager entryPointsManager = EntryPointsManager.getInstance(project);
if (entryPointsManager.isEntryPoint(element))
return true;
}
for (EntryPoint extension : myExtensions) {
if (extension.isSelected() && extension.isEntryPoint(element)) {
return true;
}
}
return isImplicitUsage(element);
}
use of com.intellij.codeInspection.ex.EntryPointsManager in project intellij-community by JetBrains.
the class VisibilityInspection method queryExternalUsagesRequests.
@Override
protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, @NotNull final ProblemDescriptionsProcessor processor) {
final EntryPointsManager entryPointsManager = globalContext.getEntryPointsManager(manager);
for (RefElement entryPoint : entryPointsManager.getEntryPoints()) {
ignoreElement(processor, entryPoint);
}
ExtensionPoint<VisibilityExtension> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.VISIBLITY_TOOL);
for (VisibilityExtension addin : point.getExtensions()) {
addin.fillIgnoreList(manager, processor);
}
manager.iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull final RefEntity refEntity) {
if (!(refEntity instanceof RefElement))
return;
if (processor.getDescriptions(refEntity) == null)
return;
refEntity.accept(new RefJavaVisitor() {
@Override
public void visitField(@NotNull final RefField refField) {
if (refField.getAccessModifier() != PsiModifier.PRIVATE) {
globalContext.enqueueFieldUsagesProcessor(refField, psiReference -> {
ignoreElement(processor, refField);
return false;
});
}
}
@Override
public void visitMethod(@NotNull final RefMethod refMethod) {
if (!refMethod.isExternalOverride() && refMethod.getAccessModifier() != PsiModifier.PRIVATE && !(refMethod instanceof RefImplicitConstructor)) {
globalContext.enqueueDerivedMethodsProcessor(refMethod, derivedMethod -> {
ignoreElement(processor, refMethod);
return false;
});
globalContext.enqueueMethodUsagesProcessor(refMethod, psiReference -> {
ignoreElement(processor, refMethod);
return false;
});
}
}
@Override
public void visitClass(@NotNull final RefClass refClass) {
if (!refClass.isAnonymous()) {
globalContext.enqueueDerivedClassesProcessor(refClass, inheritor -> {
ignoreElement(processor, refClass);
return false;
});
globalContext.enqueueClassUsagesProcessor(refClass, psiReference -> {
ignoreElement(processor, refClass);
return false;
});
final RefMethod defaultConstructor = refClass.getDefaultConstructor();
if (entryPointsManager.isAddNonJavaEntries() && defaultConstructor != null) {
final PsiClass psiClass = refClass.getElement();
String qualifiedName = psiClass != null ? psiClass.getQualifiedName() : null;
if (qualifiedName != null) {
final Project project = manager.getProject();
PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(qualifiedName, (file, startOffset, endOffset) -> {
entryPointsManager.addEntryPoint(defaultConstructor, false);
ignoreElement(processor, defaultConstructor);
return false;
}, GlobalSearchScope.projectScope(project));
}
}
}
}
});
}
});
return false;
}
Aggregations