Search in sources :

Example 1 with EntryPoint

use of com.intellij.codeInspection.reference.EntryPoint in project intellij-community by JetBrains.

the class InspectionTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
    myUnusedCodeExtension = new EntryPoint() {

        @NotNull
        @Override
        public String getDisplayName() {
            return "duh";
        }

        @Override
        public boolean isEntryPoint(@NotNull RefElement refElement, @NotNull PsiElement psiElement) {
            return isEntryPoint(psiElement);
        }

        @Override
        public boolean isEntryPoint(@NotNull PsiElement psiElement) {
            return ext_src != null && VfsUtilCore.isAncestor(ext_src, PsiUtilCore.getVirtualFile(psiElement), false);
        }

        @Override
        public boolean isSelected() {
            return true;
        }

        @Override
        public void setSelected(boolean selected) {
        }

        @Override
        public void readExternal(Element element) {
        }

        @Override
        public void writeExternal(Element element) {
        }
    };
    point.registerExtension(myUnusedCodeExtension);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) PsiElement(com.intellij.psi.PsiElement) RefElement(com.intellij.codeInspection.reference.RefElement) Element(org.jdom.Element) EntryPoint(com.intellij.codeInspection.reference.EntryPoint) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement)

Example 2 with EntryPoint

use of com.intellij.codeInspection.reference.EntryPoint 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 3 with EntryPoint

use of com.intellij.codeInspection.reference.EntryPoint 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)

Example 4 with EntryPoint

use of com.intellij.codeInspection.reference.EntryPoint in project android by JetBrains.

the class AndroidInspectionsTest method getAndroidEntryPoint.

@NotNull
private AndroidComponentEntryPoint getAndroidEntryPoint() {
    AndroidComponentEntryPoint result = null;
    for (EntryPoint entryPoint : ((UnusedDeclarationInspection) myUnusedDeclarationToolWrapper.getTool()).getExtensions()) {
        if (entryPoint instanceof AndroidComponentEntryPoint) {
            try {
                result = (AndroidComponentEntryPoint) entryPoint;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    assertNotNull(result);
    return result;
}
Also used : EntryPoint(com.intellij.codeInspection.reference.EntryPoint) UnusedDeclarationInspection(com.intellij.codeInspection.deadCode.UnusedDeclarationInspection) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EntryPoint (com.intellij.codeInspection.reference.EntryPoint)4 NotNull (org.jetbrains.annotations.NotNull)4 RefElement (com.intellij.codeInspection.reference.RefElement)3 Element (org.jdom.Element)3 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)2 PsiElement (com.intellij.psi.PsiElement)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 UnusedDeclarationInspection (com.intellij.codeInspection.deadCode.UnusedDeclarationInspection)1 PsiCompiledElement (com.intellij.psi.PsiCompiledElement)1 IOException (java.io.IOException)1