use of com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase in project intellij-community by JetBrains.
the class InspectionProfileTest method testMergeUnusedDeclarationAndUnusedSymbol.
public void testMergeUnusedDeclarationAndUnusedSymbol() throws Exception {
//no specific settings
final Element element = JdomKt.loadElement("<profile version=\"1.0\">\n" + " <option name=\"myName\" value=\"" + PROFILE + "\" />\n" + "</profile>");
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(element);
profile.getModifiableModel().commit();
assertThat(profile.writeScheme()).isEqualTo(element);
//settings to merge
final Element unusedProfile = JdomKt.loadElement("<profile version=\"1.0\">\n" + " <option name=\"myName\" value=\"" + PROFILE + "\" />\n" + " <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" + " <option name=\"FIELD\" value=\"true\" />\n" + " <option name=\"METHOD\" value=\"true\" />\n" + " <option name=\"CLASS\" value=\"true\" />\n" + " <option name=\"PARAMETER\" value=\"true\" />\n" + " <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"false\" />\n" + " </inspection_tool>\n" + " <inspection_tool class=\"UnusedDeclaration\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" + " </inspection_tool>\n" + "</profile>");
profile.readExternal(unusedProfile);
profile.getModifiableModel().commit();
assertEquals("<profile version=\"1.0\">\n" + " <option name=\"myName\" value=\"ToConvert\" />\n" + " <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" + " <option name=\"FIELD\" value=\"true\" />\n" + " <option name=\"METHOD\" value=\"true\" />\n" + " <option name=\"CLASS\" value=\"true\" />\n" + " <option name=\"PARAMETER\" value=\"true\" />\n" + " <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"false\" />\n" + " </inspection_tool>\n" + " <inspection_tool class=\"UnusedDeclaration\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" + " </inspection_tool>\n" + "</profile>", serialize(profile));
//make them default
profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(unusedProfile);
profile.modifyProfile(it -> {
InspectionToolWrapper toolWrapper = it.getInspectionTool("unused", getProject());
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase) toolWrapper.getTool();
tool.ADD_NONJAVA_TO_ENTRIES = true;
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
inspectionTool.setParameterVisibility(PsiModifier.PUBLIC);
});
String mergedText = "<profile version=\"1.0\">\n" + " <option name=\"myName\" value=\"ToConvert\" />\n" + " <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" + " <option name=\"FIELD\" value=\"true\" />\n" + " <option name=\"METHOD\" value=\"true\" />\n" + " <option name=\"CLASS\" value=\"true\" />\n" + " <option name=\"PARAMETER\" value=\"true\" />\n" + " <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"false\" />\n" + " </inspection_tool>\n" + " <inspection_tool class=\"UnusedDeclaration\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" + " <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" + " </inspection_tool>\n" + " <inspection_tool class=\"unusedMerged\" />\n" + "</profile>";
assertEquals(mergedText, serialize(profile));
Element toImportElement = profile.writeScheme();
final InspectionProfileImpl importedProfile = InspectionToolsConfigurable.importInspectionProfile(toImportElement, getApplicationProfileManager(), getProject());
//check merged
Element mergedElement = JdomKt.loadElement(mergedText);
profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(mergedElement);
profile.getModifiableModel().commit();
assertThat(profile.writeScheme()).isEqualTo(mergedElement);
assertThat(importedProfile.writeScheme()).isEqualTo(mergedElement);
}
use of com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase in project intellij-community by JetBrains.
the class UnusedDeclarationPresentation method updateContent.
@Override
public void updateContent() {
getTool().checkForReachableRefs(getContext());
myContents.clear();
final UnusedSymbolLocalInspectionBase localInspectionTool = getTool().getSharedLocalInspectionTool();
getContext().getRefManager().iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull RefEntity refEntity) {
//dead code doesn't work with refModule | refPackage
if (!(refEntity instanceof RefJavaElement))
return;
RefJavaElement refElement = (RefJavaElement) refEntity;
if (!compareVisibilities(refElement, localInspectionTool))
return;
if (!(getContext().getUIOptions().FILTER_RESOLVED_ITEMS && getIgnoredRefElements().contains(refElement)) && refElement.isValid() && getFilter().accepts(refElement)) {
if (skipEntryPoints(refElement))
return;
registerContentEntry(refEntity, RefJavaUtil.getInstance().getPackageName(refEntity));
}
}
});
updateProblemElements();
}
use of com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase in project intellij-community by JetBrains.
the class LightAdvHighlightingTest method testUnusedParamsOfPublicMethodDisabled.
public void testUnusedParamsOfPublicMethodDisabled() {
UnusedSymbolLocalInspectionBase tool = myUnusedDeclarationInspection.getSharedLocalInspectionTool();
assertNotNull(tool);
String oldVal = tool.getParameterVisibility();
try {
tool.setParameterVisibility(PsiModifier.PRIVATE);
doTest(true);
} finally {
tool.setParameterVisibility(oldVal);
}
}
use of com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase in project intellij-community by JetBrains.
the class InspectionProfileTest method testStoredMemberVisibility.
public void testStoredMemberVisibility() throws Exception {
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(JdomKt.loadElement("<profile version=\"1.0\">\n" + " <inspection_tool class=\"unused\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" + " <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" + " <option name=\"FIELD\" value=\"true\" />\n" + " <option name=\"METHOD\" value=\"true\" />\n" + " <option name=\"CLASS\" value=\"true\" />\n" + " <option name=\"PARAMETER\" value=\"true\" />\n" + " <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"true\" />\n" + " <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" + " </inspection_tool>\n" + "</profile>"));
profile.modifyProfile(it -> {
InspectionToolWrapper toolWrapper = it.getInspectionTool("unused", getProject());
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase) toolWrapper.getTool();
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
inspectionTool.setClassVisibility(PsiModifier.PUBLIC);
inspectionTool.CLASS = false;
});
String mergedText = "<profile version=\"1.0\">\n" + " <option name=\"myName\" value=\"ToConvert\" />\n" + " <inspection_tool class=\"unused\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" + " <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" + " <option name=\"FIELD\" value=\"true\" />\n" + " <option name=\"METHOD\" value=\"true\" />\n" + " <option name=\"CLASS\" value=\"false\" />\n" + " <option name=\"PARAMETER\" value=\"true\" />\n" + " <option name=\"REPORT_PARAMETER_FOR_PUBLIC_METHODS\" value=\"true\" />\n" + " <option name=\"ADD_MAINS_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_APPLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" + " <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" + " </inspection_tool>\n" + "</profile>";
assertEquals(mergedText, serialize(profile));
}
Aggregations