instantiate UnusedDeclarationInspection properly in tests; got rid of setters

This commit is contained in:
Alexey Kudravtsev
2014-11-12 13:59:57 +03:00
parent 902b0c03c7
commit 18365be5d0
5 changed files with 40 additions and 35 deletions

View File

@@ -24,6 +24,7 @@ import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspectionBase;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.ui.components.JBTabbedPane;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.awt.*;
@@ -31,6 +32,14 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class UnusedDeclarationInspection extends UnusedDeclarationInspectionBase {
@TestOnly
public UnusedDeclarationInspection(boolean enabledInEditor) {
super(enabledInEditor);
}
public UnusedDeclarationInspection() {
}
@Override
protected UnusedSymbolLocalInspectionBase createUnusedSymbolLocalInspection() {
return new UnusedSymbolLocalInspection();

View File

@@ -77,11 +77,15 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
myUnusedDeclarationInspection = new UnusedDeclarationInspection();
myUnusedDeclarationInspection = new UnusedDeclarationInspection(isUnusedInspectionRequired());
enableInspectionTool(myUnusedDeclarationInspection);
setLanguageLevel(LanguageLevel.JDK_1_4);
}
private boolean isUnusedInspectionRequired() {
return getTestName(false).contains("UnusedInspection");
}
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
@@ -226,14 +230,8 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
}
}
public void testUnusedNonPrivateMembers() {
try {
myUnusedDeclarationInspection.setEnabledInEditor(true);
doTest(true, false);
}
finally {
myUnusedDeclarationInspection.setEnabledInEditor(false);
}
public void testUnusedInspectionNonPrivateMembers() {
doTest(true, false);
}
public void testUnusedNonPrivateMembers2() {
@@ -281,33 +279,27 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
myUnusedDeclarationInspection = new UnusedDeclarationInspectionBase();
}
}
public void testUnusedNonPrivateMembersReferencedFromText() {
try {
myUnusedDeclarationInspection.setEnabledInEditor(true);
doTest(true, false);
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
PsiDirectory directory = myFile.getParent();
assertNotNull(myFile.toString(), directory);
PsiFile txt = directory.createFile("x.txt");
VirtualFile vFile = txt.getVirtualFile();
assertNotNull(txt.toString(), vFile);
try {
VfsUtil.saveText(vFile, "XXX");
}
catch (IOException e) {
throw new RuntimeException(e);
}
public void testUnusedInspectionNonPrivateMembersReferencedFromText() {
doTest(true, false);
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
PsiDirectory directory = myFile.getParent();
assertNotNull(myFile.toString(), directory);
PsiFile txt = directory.createFile("x.txt");
VirtualFile vFile = txt.getVirtualFile();
assertNotNull(txt.toString(), vFile);
try {
VfsUtil.saveText(vFile, "XXX");
}
});
catch (IOException e) {
throw new RuntimeException(e);
}
}
});
List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
assertEmpty(infos);
}
finally {
myUnusedDeclarationInspection.setEnabledInEditor(false);
}
List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
assertEmpty(infos);
}
public void testNamesHighlighting() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,10 @@ public class GlobalInspectionToolWrapper extends InspectionToolWrapper<GlobalIns
super(globalInspectionTool);
}
public GlobalInspectionToolWrapper(@NotNull GlobalInspectionTool tool, @NotNull InspectionEP ep) {
super(tool, ep);
}
public GlobalInspectionToolWrapper(@NotNull InspectionEP ep) {
super(ep);
}