dynamically add dead code extension

This commit is contained in:
Alexey Kudravtsev
2010-10-07 17:09:33 +04:00
parent f43854de7a
commit e2f12d5e29
5 changed files with 131 additions and 10 deletions

View File

@@ -1,6 +1,21 @@
package com.intellij.codeInsight.daemon;
import com.intellij.ExtensionPoints;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.reference.EntryPoint;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.extensions.ExtensionPoint;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.PsiElement;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* This class is for "lightweight" tests only, i.e. those which can run inside default light project set up
@@ -13,12 +28,17 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos);
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()};
}
public void testDuplicateAnnotations() throws Exception {
doTest(false, false);
}
public void testSwitchByString() throws Exception {
doTest(true, false);
doTest(false, false);
}
public void testDiamondPos1() throws Exception {
@@ -56,4 +76,69 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
public void testDiamondNeg5() throws Exception {
doTest(false, false);
}
public void testDynamicallyAddIgnoredAnnotations() throws Exception {
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL);
EntryPoint extension = new EntryPoint() {
@NotNull
@Override
public String getDisplayName() {
return "duh";
}
@Override
public boolean isEntryPoint(RefElement refElement, PsiElement psiElement) {
return false;
}
@Override
public boolean isEntryPoint(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"};
}
};
UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection();
enableInspectionTool(deadCodeInspection);
doTest(true, false);
List<HighlightInfo> infos = DaemonAnalyzerTestCase.filter(doHighlighting(), HighlightSeverity.WARNING);
assertEquals(2, infos.size()); // unused class and unused method
try {
point.registerExtension(extension);
infos = DaemonAnalyzerTestCase.filter(doHighlighting(), HighlightSeverity.WARNING);
HighlightInfo info = assertOneElement(infos);
assertEquals("Class 'WithMain' is never used", info.description);
}
finally {
point.unregisterExtension(extension);
}
}
}