use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase 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.deadCode.UnusedDeclarationInspectionBase in project android by JetBrains.
the class AndroidJavaHighlightingTest method testInjectResourceAnnotation.
public void testInjectResourceAnnotation() throws Exception {
myFixture.enableInspections(new UnusedDeclarationInspectionBase());
myFixture.copyFileToProject(BASE_PATH + "values.xml", "res/values/values.xml");
myFixture.copyFileToProject(BASE_PATH + "InjectResource.java", "src/p1/p2/InjectResource.java");
myFixture.copyFileToProject(BASE_PATH + "SomeAnnotation.java", "src/p1/p2/SomeAnnotation.java");
myFixture.copyFileToProject(BASE_PATH + "R1.java", "src/p1/p2/R1.java");
myFixture.copyFileToProject("R.java", "src/p1/p2/R.java");
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".java", "src/p1/p2/MyActivity.java");
myFixture.configureFromExistingVirtualFile(f);
myFixture.checkHighlighting(true, false, true);
}
use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase in project android by JetBrains.
the class AndroidJavaHighlightingTest method testParcelable.
public void testParcelable() throws Exception {
myFixture.enableInspections(new UnusedDeclarationInspectionBase(true));
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + getTestName(false) + ".java", "src/p1/p2/MyParcelable.java");
myFixture.configureFromExistingVirtualFile(f);
myFixture.checkHighlighting(true, false, true);
}
use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase in project intellij-community by JetBrains.
the class RefJavaManagerImpl method getDeadCodeTool.
private UnusedDeclarationInspectionBase getDeadCodeTool(PsiFile file) {
Tools tools = ((GlobalInspectionContextBase) myRefManager.getContext()).getTools().get(UnusedDeclarationInspectionBase.SHORT_NAME);
InspectionToolWrapper toolWrapper = tools == null ? null : tools.getEnabledTool(file);
InspectionProfileEntry tool = toolWrapper == null ? null : toolWrapper.getTool();
return tool instanceof UnusedDeclarationInspectionBase ? (UnusedDeclarationInspectionBase) tool : null;
}
use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase in project intellij-community by JetBrains.
the class QuickFixFactoryImpl method registerFixesForUnusedParameter.
@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
Project myProject = parameter.getProject();
InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
UnusedDeclarationInspectionBase unusedParametersInspection = (UnusedDeclarationInspectionBase) profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.SHORT_NAME, parameter);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
List<IntentionAction> options = new ArrayList<>();
HighlightDisplayKey myUnusedSymbolKey = HighlightDisplayKey.find(UnusedSymbolLocalInspectionBase.SHORT_NAME);
options.addAll(IntentionManager.getInstance().getStandardIntentionOptions(myUnusedSymbolKey, parameter));
if (unusedParametersInspection != null) {
SuppressQuickFix[] batchSuppressActions = unusedParametersInspection.getBatchSuppressActions(parameter);
Collections.addAll(options, SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(batchSuppressActions));
}
//need suppress from Unused Parameters but settings from Unused Symbol
QuickFixAction.registerQuickFixAction((HighlightInfo) highlightInfo, new SafeDeleteFix(parameter), options, HighlightDisplayKey.getDisplayNameByKey(myUnusedSymbolKey));
}
Aggregations