Search in sources :

Example 11 with RefElement

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

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

the class InitializationDependencyUtils method tabulateInitializationDependentClasses.

@SuppressWarnings({ "MethodWithMultipleLoops" })
private static void tabulateInitializationDependentClasses(RefElement element, Set<RefClass> dependents) {
    final Collection<RefElement> references = element.getInReferences();
    final RefJavaUtil refUtil = RefJavaUtil.getInstance();
    for (RefElement reference : references) {
        final RefClass refClass = refUtil.getTopLevelClass(reference);
        if (refClass != null) {
            dependents.add(refClass);
        }
    }
    final List<RefEntity> children = element.getChildren();
    for (RefEntity child : children) {
        if (child instanceof RefElement) {
            tabulateInitializationDependentClasses((RefElement) child, dependents);
        }
    }
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) RefClass(com.intellij.codeInspection.reference.RefClass) RefEntity(com.intellij.codeInspection.reference.RefEntity) RefJavaUtil(com.intellij.codeInspection.reference.RefJavaUtil)

Example 13 with RefElement

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

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

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

the class SuppressableInspectionTreeNode method getSuppressContent.

@NotNull
public final Pair<PsiElement, CommonProblemDescriptor> getSuppressContent() {
    RefEntity refElement = getElement();
    CommonProblemDescriptor descriptor = getDescriptor();
    PsiElement element = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor) descriptor).getPsiElement() : refElement instanceof RefElement ? ((RefElement) refElement).getElement() : null;
    return Pair.create(element, descriptor);
}
Also used : RefElement(com.intellij.codeInspection.reference.RefElement) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) RefEntity(com.intellij.codeInspection.reference.RefEntity) CommonProblemDescriptor(com.intellij.codeInspection.CommonProblemDescriptor) ProblemDescriptor(com.intellij.codeInspection.ProblemDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RefElement (com.intellij.codeInspection.reference.RefElement)25 RefEntity (com.intellij.codeInspection.reference.RefEntity)16 PsiElement (com.intellij.psi.PsiElement)11 NotNull (org.jetbrains.annotations.NotNull)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Nullable (org.jetbrains.annotations.Nullable)4 EntryPoint (com.intellij.codeInspection.reference.EntryPoint)3 PsiFile (com.intellij.psi.PsiFile)3 Element (org.jdom.Element)3 UnusedDeclarationInspectionBase (com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase)2 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)2 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)2 RefClass (com.intellij.codeInspection.reference.RefClass)2 RefJavaUtil (com.intellij.codeInspection.reference.RefJavaUtil)2 RefManagerImpl (com.intellij.codeInspection.reference.RefManagerImpl)2 Project (com.intellij.openapi.project.Project)2 Navigatable (com.intellij.pom.Navigatable)2 SearchScope (com.intellij.psi.search.SearchScope)2 HashSet (com.intellij.util.containers.HashSet)2 THashSet (gnu.trove.THashSet)2