use of com.intellij.codeInspection.util.RefFilter in project intellij-community by JetBrains.
the class UnusedDeclarationInspectionBase method queryExternalUsagesRequests.
@Override
public boolean queryExternalUsagesRequests(@NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
checkForReachableRefs(globalContext);
final RefFilter filter = myPhase == 1 ? new StrictUnreferencedFilter(this, globalContext) : new RefUnreachableFilter(this, globalContext);
LOG.assertTrue(myProcessedSuspicious != null, "phase: " + myPhase);
final boolean[] requestAdded = { false };
globalContext.getRefManager().iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull RefEntity refEntity) {
if (!(refEntity instanceof RefJavaElement))
return;
if (refEntity instanceof RefClass && ((RefClass) refEntity).isAnonymous())
return;
RefJavaElement refElement = (RefJavaElement) refEntity;
if (filter.accepts(refElement) && !myProcessedSuspicious.contains(refElement)) {
refEntity.accept(new RefJavaVisitor() {
@Override
public void visitField(@NotNull final RefField refField) {
myProcessedSuspicious.add(refField);
PsiField psiField = refField.getElement();
if (psiField != null && isSerializationImplicitlyUsedField(psiField)) {
getEntryPointsManager(globalContext).addEntryPoint(refField, false);
} else {
globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueFieldUsagesProcessor(refField, psiReference -> {
getEntryPointsManager(globalContext).addEntryPoint(refField, false);
return false;
});
requestAdded[0] = true;
}
}
@Override
public void visitMethod(@NotNull final RefMethod refMethod) {
myProcessedSuspicious.add(refMethod);
if (refMethod instanceof RefImplicitConstructor) {
visitClass(refMethod.getOwnerClass());
} else {
PsiMethod psiMethod = (PsiMethod) refMethod.getElement();
if (psiMethod != null && isSerializablePatternMethod(psiMethod, refMethod.getOwnerClass())) {
getEntryPointsManager(globalContext).addEntryPoint(refMethod, false);
} else if (!refMethod.isExternalOverride() && !PsiModifier.PRIVATE.equals(refMethod.getAccessModifier())) {
for (final RefMethod derivedMethod : refMethod.getDerivedMethods()) {
myProcessedSuspicious.add(derivedMethod);
}
enqueueMethodUsages(globalContext, refMethod);
requestAdded[0] = true;
}
}
}
@Override
public void visitClass(@NotNull final RefClass refClass) {
myProcessedSuspicious.add(refClass);
if (!refClass.isAnonymous()) {
globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueDerivedClassesProcessor(refClass, inheritor -> {
getEntryPointsManager(globalContext).addEntryPoint(refClass, false);
return false;
});
globalContext.getExtension(GlobalJavaInspectionContext.CONTEXT).enqueueClassUsagesProcessor(refClass, psiReference -> {
getEntryPointsManager(globalContext).addEntryPoint(refClass, false);
return false;
});
requestAdded[0] = true;
}
}
});
}
}
});
if (!requestAdded[0]) {
if (myPhase == 2) {
myProcessedSuspicious = null;
return false;
} else {
myPhase = 2;
}
}
return true;
}
use of com.intellij.codeInspection.util.RefFilter in project intellij-community by JetBrains.
the class UnusedDeclarationPresentation method exportResults.
@Override
public void exportResults(@NotNull final Element parentNode, @NotNull RefEntity refEntity, @NotNull Predicate<CommonProblemDescriptor> excludedDescriptions) {
if (!(refEntity instanceof RefJavaElement))
return;
final RefFilter filter = getFilter();
if (!getIgnoredRefElements().contains(refEntity) && filter.accepts((RefJavaElement) refEntity)) {
refEntity = getRefManager().getRefinedElement(refEntity);
if (!refEntity.isValid())
return;
RefJavaElement refElement = (RefJavaElement) refEntity;
if (!compareVisibilities(refElement, getTool().getSharedLocalInspectionTool()))
return;
if (skipEntryPoints(refElement))
return;
Element element = refEntity.getRefManager().export(refEntity, parentNode, -1);
if (element == null)
return;
@NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
final HighlightSeverity severity = getSeverity(refElement);
final String attributeKey = getTextAttributeKey(refElement.getRefManager().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
problemClassElement.setAttribute("severity", severity.myName);
problemClassElement.setAttribute("attribute_key", attributeKey);
problemClassElement.addContent(InspectionsBundle.message("inspection.export.results.dead.code"));
element.addContent(problemClassElement);
@NonNls Element hintsElement = new Element("hints");
for (UnusedDeclarationHint hint : UnusedDeclarationHint.values()) {
@NonNls Element hintElement = new Element("hint");
hintElement.setAttribute("value", hint.toString().toLowerCase());
hintsElement.addContent(hintElement);
}
element.addContent(hintsElement);
Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
StringBuffer buf = new StringBuffer();
DeadHTMLComposer.appendProblemSynopsis((RefElement) refEntity, buf);
descriptionElement.addContent(buf.toString());
element.addContent(descriptionElement);
}
super.exportResults(parentNode, refEntity, excludedDescriptions);
}
Aggregations