diff --git a/java/java-tests/testData/inspection/globalContext/Foo.java b/java/java-tests/testData/inspection/globalContext/Foo.java new file mode 100644 index 000000000000..4a2b44daf653 --- /dev/null +++ b/java/java-tests/testData/inspection/globalContext/Foo.java @@ -0,0 +1 @@ +public class Foo {} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java new file mode 100644 index 000000000000..809f49672384 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/GlobalInspectionContextTest.java @@ -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/"; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java index bb012a5b2665..94c1e9100a8c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfileTest.java @@ -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(), new ArrayList(), new ArrayList()); - Map tools = context.getTools(); - assertEquals(1, tools.size()); } private static LocalInspectionToolWrapper createTool(String s) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 7a7c661e3dcd..87e76ffe3409 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -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 getUsedTools() { - InspectionProfileImpl profile = (InspectionProfileImpl)getCurrentProfile(); + InspectionProfileImpl profile = new InspectionProfileImpl((InspectionProfileImpl)getCurrentProfile()); List tools = profile.getAllEnabledInspectionTools(myProject); THashSet set = null; for (ToolsImpl tool : tools) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index a9698f2f37a9..f42c5b62f97e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -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;