IDEA-86380 Batch inspections: previous results are not cleared

This commit is contained in:
Dmitry Avdeev
2012-05-25 13:56:21 +04:00
parent 2f9deb86eb
commit d3f7325610
5 changed files with 83 additions and 12 deletions
@@ -0,0 +1 @@
public class Foo {}
@@ -0,0 +1,69 @@
/*
* Copyright 2000-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.CodeInsightTestCase;
import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.visibility.VisibilityInspection;
/**
* @author Dmitry Avdeev
* Date: 5/24/12
*/
public class GlobalInspectionContextTest extends CodeInsightTestCase {
public void testProblemDuplication() throws Exception {
String shortName = new VisibilityInspection().getShortName();
InspectionProfileImpl profile = new InspectionProfileImpl("Foo");
profile.disableAllTools();
profile.enableTool(shortName);
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
context.setExternalProfile(profile);
configureByFile("Foo.java");
AnalysisScope scope = new AnalysisScope(getFile());
context.doInspections(scope, InspectionManager.getInstance(getProject()));
Tools tools = context.getTools().get(shortName);
GlobalInspectionToolWrapper tool = (GlobalInspectionToolWrapper)tools.getTool();
assertEquals(1, tool.getProblemDescriptors().size());
context.doInspections(scope, InspectionManager.getInstance(getProject()));
tools = context.getTools().get(shortName);
tool = (GlobalInspectionToolWrapper)tools.getTool();
assertEquals(1, tool.getProblemDescriptors().size());
}
@Override
public void setUp() throws Exception {
super.setUp();
InspectionProfileImpl.INIT_INSPECTIONS = true;
}
@Override
public void tearDown() throws Exception {
InspectionProfileImpl.INIT_INSPECTIONS = false;
super.tearDown();
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath() + "/inspection/globalContext/";
}
}
@@ -28,7 +28,6 @@ import org.jdom.JDOMException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual;
@@ -221,8 +220,6 @@ public class InspectionProfileTest extends LightIdeaTestCase {
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
context.setExternalProfile(profile);
context.initializeTools(new ArrayList<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
Map<String,Tools> tools = context.getTools();
assertEquals(1, tools.size());
}
private static LocalInspectionToolWrapper createTool(String s) {
@@ -33,10 +33,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PathMacroManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.progress.*;
import com.intellij.openapi.progress.impl.ProgressManagerImpl;
import com.intellij.openapi.progress.util.ProgressWrapper;
import com.intellij.openapi.project.DumbService;
@@ -271,12 +268,19 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
getContentManager().removeContent(myContent, true);
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
Runnable runnable = new Runnable() {
public void run() {
myCurrentScope = scope;
launchInspections(scope, manager);
}
});
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
}
else {
ApplicationManager.getApplication().invokeLater(runnable);
}
}
@@ -483,7 +487,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
public void performInspectionsWithProgress(@NotNull final AnalysisScope scope, @NotNull final InspectionManager manager) {
final PsiManager psiManager = PsiManager.getInstance(myProject);
myProgressIndicator = ProgressManager.getInstance().getProgressIndicator();
myProgressIndicator = ApplicationManager.getApplication().isUnitTestMode() ? new EmptyProgressIndicator() : ProgressManager.getInstance().getProgressIndicator();
//init manager in read action
RefManagerImpl refManager = (RefManagerImpl)getRefManager();
try {
@@ -714,7 +718,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G
}
protected List<ToolsImpl> getUsedTools() {
InspectionProfileImpl profile = (InspectionProfileImpl)getCurrentProfile();
InspectionProfileImpl profile = new InspectionProfileImpl((InspectionProfileImpl)getCurrentProfile());
List<ToolsImpl> tools = profile.getAllEnabledInspectionTools(myProject);
THashSet<ToolsImpl> set = null;
for (ToolsImpl tool : tools) {
@@ -92,7 +92,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private boolean myModified = false;
private volatile boolean myInitialized;
private InspectionProfileImpl(@NotNull InspectionProfileImpl inspectionProfile) {
InspectionProfileImpl(@NotNull InspectionProfileImpl inspectionProfile) {
super(inspectionProfile.getName());
myRegistrar = inspectionProfile.myRegistrar;