diff --git a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java index ba0c559dbad2..7a05b5f2ace2 100644 --- a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java @@ -42,6 +42,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.psi.util.PsiUtilCore; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests; import com.intellij.util.ArrayUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -145,7 +146,7 @@ public abstract class InspectionTestCase extends PsiTestCase { InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject()); InspectionToolWrapper[] toolWrappers = runDeadCodeFirst ? new InspectionToolWrapper []{getUnusedDeclarationWrapper(), toolWrapper} : new InspectionToolWrapper []{toolWrapper}; toolWrappers = ArrayUtil.mergeArrays(toolWrappers, additional); - final GlobalInspectionContextImpl globalContext = + final GlobalInspectionContextForTests globalContext = CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrappers); InspectionTestUtil.runTool(toolWrapper, scope, globalContext); diff --git a/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java index 798732e6f597..46318b9ca89d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/InspectionTestUtil.java @@ -22,7 +22,7 @@ import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ui.InspectionToolPresentation; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.JDOMUtil; -import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests; import com.intellij.util.ui.UIUtil; import org.jdom.Document; import org.jdom.Element; @@ -153,7 +153,7 @@ expected: public static void runTool(@NotNull InspectionToolWrapper toolWrapper, @NotNull final AnalysisScope scope, - @NotNull final GlobalInspectionContextImpl globalContext) { + @NotNull final GlobalInspectionContextForTests globalContext) { final String shortName = toolWrapper.getShortName(); final HighlightDisplayKey key = HighlightDisplayKey.find(shortName); if (key == null){ @@ -164,6 +164,6 @@ expected: do { UIUtil.dispatchAllInvocationEvents(); } - while (!CodeInsightTestFixtureImpl.isInspectionsFinished(globalContext)); + while (!globalContext.isFinished()); } } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 9e30febbdb9a..d46a400510f6 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -462,19 +462,19 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig scope.invalidate(); InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject()); - GlobalInspectionContextImpl globalContext = createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper); + GlobalInspectionContextForTests globalContext = createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrapper); InspectionTestUtil.runTool(toolWrapper, scope, globalContext); InspectionTestUtil.compareToolResults(globalContext, toolWrapper, false, new File(getTestDataPath(), testDir).getPath()); } @NotNull - public static GlobalInspectionContextImpl createGlobalContextForTool(@NotNull AnalysisScope scope, + public static GlobalInspectionContextForTests createGlobalContextForTool(@NotNull AnalysisScope scope, @NotNull final Project project, @NotNull InspectionManagerEx inspectionManager, @NotNull final InspectionToolWrapper ... toolWrappers) { final InspectionProfileImpl profile = InspectionProfileImpl.createSimple("test", project, toolWrappers); - GlobalInspectionContextImpl context = new GlobalInspectionContextImpl(project, inspectionManager.getContentManager()) { + GlobalInspectionContextForTests context = new GlobalInspectionContextForTests(project, inspectionManager.getContentManager()) { @Override protected List getUsedTools() { try { @@ -488,21 +488,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig InspectionProfileImpl.INIT_INSPECTIONS = false; } } - - @Override - protected void notifyInspectionsFinished() { - super.notifyInspectionsFinished(); - putUserData(FINISHED, true); - } }; context.setCurrentScope(scope); return context; } - private static final Key FINISHED = Key.create("Inspections finished"); - public static boolean isInspectionsFinished(@NotNull GlobalInspectionContext context) { - return context.getUserData(FINISHED) == Boolean.TRUE; - } @Override @Nullable diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/GlobalInspectionContextForTests.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/GlobalInspectionContextForTests.java new file mode 100644 index 000000000000..4ec7ce1251e2 --- /dev/null +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/GlobalInspectionContextForTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2015 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.testFramework.fixtures.impl; + +import com.intellij.codeInspection.ex.GlobalInspectionContextImpl; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.ui.content.ContentManager; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public class GlobalInspectionContextForTests extends GlobalInspectionContextImpl { + private volatile boolean myFinished; + + public GlobalInspectionContextForTests(@NotNull Project project, @NotNull NotNullLazyValue contentManager) { + super(project, contentManager); + } + + @Override + protected void notifyInspectionsFinished() { + super.notifyInspectionsFinished(); + myFinished = true; + } + + public boolean isFinished() { + return myFinished; + } +}