Skip to content

Commit

Permalink
encapsulate myTestRootDisposable
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 19, 2016
1 parent 969b831 commit 1996140
Show file tree
Hide file tree
Showing 60 changed files with 279 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -66,7 +66,7 @@ protected void setUpModule() {
@Override
protected void setUp() throws Exception {
super.setUp();
myProject.getMessageBus().connect(myTestRootDisposable).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
myProject.getMessageBus().connect(getTestRootDisposable()).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
@Override
public void rootsChanged(ModuleRootEvent event) {
//todo[nik] projectOpened isn't called in tests so we need to add this listener manually
Expand Down Expand Up @@ -249,7 +249,7 @@ private CompilationLog compile(final ParameterizedRunnable<CompileStatusNotifica
public void fileGenerated(String outputRoot, String relativePath) {
generatedFilePaths.add(relativePath);
}
}, myTestRootDisposable);
}, getTestRootDisposable());
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testTypeAnnotatedField() {
myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target(ElementType.TYPE_USE) public @interface TestNotNull { }");
NullableNotNullManager manager = NullableNotNullManager.getInstance(getProject());
manager.setNotNulls("foo.TestNotNull");
Disposer.register(myTestRootDisposable, manager::setNotNulls);
Disposer.register(getTestRootDisposable(), manager::setNotNulls);
doTest();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/*
* Copyright 2000-2016 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.codeInsight.completion;

import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.template.SmartCompletionContextType;
import com.intellij.codeInsight.template.Template;
Expand All @@ -12,7 +26,6 @@
import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
Expand Down Expand Up @@ -656,7 +669,7 @@ public void testLiveTemplate() throws Throwable {
final SmartCompletionContextType completionContextType =
ContainerUtil.findInstance(TemplateContextType.EP_NAME.getExtensions(), SmartCompletionContextType.class);
((TemplateImpl)template).getTemplateContext().setEnabled(completionContextType, true);
CodeInsightTestUtil.addTemplate(template, myTestRootDisposable);
CodeInsightTestUtil.addTemplate(template, getTestRootDisposable());
doTest();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand All @@ -18,7 +18,6 @@
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.defUse.DefUseInspection;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
Expand Down Expand Up @@ -79,7 +78,7 @@ private void doTestAmbiguous() throws Exception {
//ambiguous method calls
private void doTestAmbiguous(@NotNull JavaSdkVersion javaSdkVersion) throws Exception {
final String name = getTestName(true);
IdeaTestUtil.setTestVersion(javaSdkVersion, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(javaSdkVersion, getModule(), getTestRootDisposable());
doTest(BASE_PATH + name + "/pck/AmbiguousMethodCall.java", BASE_PATH + "/" + name, false, false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -55,7 +55,7 @@ protected Sdk getProjectJDK() {

private void doTest(@NotNull LanguageLevel languageLevel, @NotNull JavaSdkVersion sdkVersion, boolean checkWarnings) {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(languageLevel);
IdeaTestUtil.setTestVersion(sdkVersion, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(sdkVersion, getModule(), getTestRootDisposable());
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false);
}
private void doTest5(boolean checkWarnings) { doTest(LanguageLevel.JDK_1_5, JavaSdkVersion.JDK_1_6, checkWarnings); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -31,7 +31,7 @@ protected void setUp() throws Exception {
super.setUp();
enableInspectionTools(new UnusedDeclarationInspection(), new UncheckedWarningLocalInspection(), new JavacQuirksInspection(), new RedundantCastInspection());
setLanguageLevel(LanguageLevel.JDK_1_6);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_6, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_6, getModule(), getTestRootDisposable());
}

private void doTest(boolean checkWarnings, boolean checkInfos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void setUp() throws Exception {
super.setUp();
enableInspectionTools(new UnusedDeclarationInspection(), new UncheckedWarningLocalInspection(), new JavacQuirksInspection(), new RedundantCastInspection());
setLanguageLevel(LanguageLevel.JDK_1_7);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_7, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_7, getModule(), getTestRootDisposable());
}

private void doTest(boolean checkWarnings, boolean checkInfos, InspectionProfileEntry... inspections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testSillyAssignment() {
public void testUnused() { doTest(true, false); }
public void testQualifierBeforeClassName() { doTest(false, false); }
public void testQualifiedSuper() {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_6, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_6, getModule(), getTestRootDisposable());
doTest(false, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected String getTestDataPath() {
@Override
public void setUp() throws Exception {
super.setUp();
PlatformTestUtil.registerExtension(PsiAugmentProvider.EP_NAME, new TestAugmentProvider(), myTestRootDisposable);
PlatformTestUtil.registerExtension(PsiAugmentProvider.EP_NAME, new TestAugmentProvider(), getTestRootDisposable());
myFixture.addClass("package lombok;\npublic @interface val { }");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -883,7 +886,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull
}
};
LineMarkerProviders.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, provider);
Disposer.register(myTestRootDisposable, () -> LineMarkerProviders.INSTANCE.removeExplicitExtension(JavaLanguage.INSTANCE, provider));
Disposer.register(getTestRootDisposable(), () -> LineMarkerProviders.INSTANCE.removeExplicitExtension(JavaLanguage.INSTANCE, provider));
myDaemonCodeAnalyzer.restart();
try {
TextRange range = FileStatusMap.getDirtyTextRange(getEditor(), Pass.UPDATE_ALL);
Expand Down Expand Up @@ -2194,7 +2197,7 @@ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file
}
};
IntentionManager.getInstance().addAction(longLongUpdate);
Disposer.register(myTestRootDisposable, () -> IntentionManager.getInstance().unregisterIntention(longLongUpdate));
Disposer.register(getTestRootDisposable(), () -> IntentionManager.getInstance().unregisterIntention(longLongUpdate));
configureByText(JavaFileType.INSTANCE, "class X { <caret> }");
makeEditorWindowVisible(new Point(0, 0));
doHighlighting();
Expand All @@ -2221,7 +2224,7 @@ public void testLightBulbIsHiddenWhenFixRangeIsCollapsed() {
((EditorImpl)myEditor).getScrollPane().getViewport().setSize(1000, 1000);

final Set<LightweightHint> visibleHints = ContainerUtil.newIdentityTroveSet();
getProject().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, new EditorHintListener() {
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(EditorHintListener.TOPIC, new EditorHintListener() {
@Override
public void hintShown(final Project project, final LightweightHint hint, final int flags) {
visibleHints.add(hint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -803,7 +803,7 @@ private void doTest() {

private void doTest(boolean warnings) {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTest(BASE_PATH + "/" + getTestName(false) + ".java", warnings, false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -43,7 +43,7 @@ public void _testUnrelatedClassesExtendsTypeParams() throws Exception {

private void doTest() {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), myTestRootDisposable);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -45,7 +45,7 @@ protected String getBasePath() {
@Override
protected void beforeActionStarted(String testName, String contents) {
if (testName.contains("Guava")) {
ReplaceFromOfNullableFixTest.addGuavaOptional(myTestRootDisposable);
ReplaceFromOfNullableFixTest.addGuavaOptional(getTestRootDisposable());
}
super.beforeActionStarted(testName, contents);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2016 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.
*/

/*
* Created by IntelliJ IDEA.
* User: max
Expand All @@ -11,7 +27,6 @@
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
import com.intellij.codeInspection.canBeFinal.CanBeFinalInspection;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiNamedElement;
Expand Down Expand Up @@ -143,7 +158,7 @@ public boolean isImplicitRead(PsiElement element) {
public boolean isImplicitWrite(PsiElement element) {
return element instanceof PsiField && "implicitWrite".equals(((PsiNamedElement)element).getName());
}
}, myTestRootDisposable);
}, getTestRootDisposable());

doTest();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
Expand Down Expand Up @@ -75,7 +75,7 @@ private void setupCustomAnnotations() {
NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject());
nnnManager.setNotNulls("foo.NotNull");
nnnManager.setNullables("foo.Nullable");
Disposer.register(myTestRootDisposable, () -> {
Disposer.register(getTestRootDisposable(), () -> {
nnnManager.setNotNulls();
nnnManager.setNullables();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected String getTestDataPath() {
protected void setUp() throws Exception {
super.setUp();
myFilter = new FileTreeAccessFilter();
PsiManagerEx.getInstanceEx(getProject()).setAssertOnFileLoadingFilter(myFilter, myTestRootDisposable);
PsiManagerEx.getInstanceEx(getProject()).setAssertOnFileLoadingFilter(myFilter, getTestRootDisposable());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2000-2016 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.
*/

/*
* Created by IntelliJ IDEA.
* User: Alexey
Expand Down Expand Up @@ -127,7 +143,7 @@ public void testOverrideCustomDefault() {

final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject());
nnnManager.setNullables("custom.CheckForNull");
Disposer.register(myTestRootDisposable, new Disposable() {
Disposer.register(getTestRootDisposable(), new Disposable() {
@Override
public void dispose() {
nnnManager.setNullables();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
/*
* Copyright 2000-2016 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.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.emptyMethod.EmptyMethodInspection;
import com.intellij.codeInspection.ex.*;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.i18n.I18nInspection;
import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.injected.MyTestInjector;
Expand Down Expand Up @@ -55,7 +72,7 @@ public void testSuppressAll() throws Exception {

public void testInjections() throws Exception {
MyTestInjector testInjector = new MyTestInjector(getPsiManager());
testInjector.injectAll(myTestRootDisposable);
testInjector.injectAll(getTestRootDisposable());

doTest();
}
Expand Down
Loading

0 comments on commit 1996140

Please sign in to comment.