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 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));
}
use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase in project intellij-community by JetBrains.
the class LightAdvHighlightingJdk7Test method testDynamicallyAddIgnoredAnnotations.
public void testDynamicallyAddIgnoredAnnotations() {
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
EntryPoint extension = new EntryPoint() {
@NotNull
@Override
public String getDisplayName() {
return "duh";
}
@Override
public boolean isEntryPoint(@NotNull RefElement refElement, @NotNull PsiElement psiElement) {
return false;
}
@Override
public boolean isEntryPoint(@NotNull PsiElement psiElement) {
return false;
}
@Override
public boolean isSelected() {
return false;
}
@Override
public void setSelected(boolean selected) {
}
@Override
public void readExternal(Element element) {
}
@Override
public void writeExternal(Element element) {
}
@Override
public String[] getIgnoreAnnotations() {
return new String[] { "MyAnno" };
}
};
enableInspectionTool(new UnusedDeclarationInspectionBase(true));
doTest(true, false);
List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
// unused class and unused method
assertEquals(2, infos.size());
try {
point.registerExtension(extension);
infos = doHighlighting(HighlightSeverity.WARNING);
HighlightInfo info = assertOneElement(infos);
assertEquals("Class 'WithMain' is never used", info.getDescription());
} finally {
point.unregisterExtension(extension);
}
}
use of com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase in project intellij-community by JetBrains.
the class LightAdvHighlightingTest method testUnusedNonPrivateMembers2.
public void testUnusedNonPrivateMembers2() {
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
EntryPoint extension = new EntryPoint() {
@NotNull
@Override
public String getDisplayName() {
return "duh";
}
@Override
public boolean isEntryPoint(@NotNull RefElement refElement, @NotNull PsiElement psiElement) {
return false;
}
@Override
public boolean isEntryPoint(@NotNull PsiElement psiElement) {
return psiElement instanceof PsiMethod && ((PsiMethod) psiElement).getName().equals("myTestMethod");
}
@Override
public boolean isSelected() {
return false;
}
@Override
public void setSelected(boolean selected) {
}
@Override
public void readExternal(Element element) {
}
@Override
public void writeExternal(Element element) {
}
};
point.registerExtension(extension);
try {
myUnusedDeclarationInspection = new UnusedDeclarationInspectionBase(true);
doTest(true);
} finally {
point.unregisterExtension(extension);
myUnusedDeclarationInspection = new UnusedDeclarationInspectionBase();
}
}
Aggregations