Search in sources :

Example 6 with UnusedDeclarationInspectionBase

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);
}
Also used : UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 7 with UnusedDeclarationInspectionBase

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);
}
Also used : UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 8 with UnusedDeclarationInspectionBase

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));
}
Also used : UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) UnusedSymbolLocalInspectionBase(com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase)

Example 9 with UnusedDeclarationInspectionBase

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);
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) PsiElement(com.intellij.psi.PsiElement) RefElement(com.intellij.codeInspection.reference.RefElement) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) Element(org.jdom.Element) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) EntryPoint(com.intellij.codeInspection.reference.EntryPoint) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 10 with UnusedDeclarationInspectionBase

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();
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) UnusedDeclarationInspectionBase(com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase) RefElement(com.intellij.codeInspection.reference.RefElement) Element(org.jdom.Element) EntryPoint(com.intellij.codeInspection.reference.EntryPoint) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)3 HighlightDisplayKey (com.intellij.codeInsight.daemon.HighlightDisplayKey)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)2 InspectionProfile (com.intellij.codeInspection.InspectionProfile)2 EntryPoint (com.intellij.codeInspection.reference.EntryPoint)2 RefElement (com.intellij.codeInspection.reference.RefElement)2 UnusedSymbolLocalInspectionBase (com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase)2 Project (com.intellij.openapi.project.Project)2 Element (org.jdom.Element)2 com.intellij.codeHighlighting (com.intellij.codeHighlighting)1 EditorInfo (com.intellij.codeInsight.EditorInfo)1 CompletionContributor (com.intellij.codeInsight.completion.CompletionContributor)1 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 DeleteCatchFix (com.intellij.codeInsight.daemon.impl.quickfix.DeleteCatchFix)1 LightQuickFixTestCase (com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase)1 CodeFoldingManager (com.intellij.codeInsight.folding.CodeFoldingManager)1 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1