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);
}
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);
}
}
}
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);
}
}
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();
}
}
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);
}
Aggregations