disable inspection on tearDown, cleanup

This commit is contained in:
Vladimir Krivosheev
2016-07-12 15:30:59 +02:00
parent 1efbe3b775
commit 367d3705af
13 changed files with 144 additions and 126 deletions
@@ -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.
@@ -14,19 +14,19 @@
* limitations under the License.
*/
package com.intellij.codeInsight
import com.intellij.codeInsight.generation.ClassMember
import com.intellij.codeInsight.generation.GenerateGetterHandler
import com.intellij.codeInsight.generation.GenerateSetterHandler
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.JavaCodeStyleManager
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.ui.UIUtil
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
import org.jetbrains.annotations.Nullable
/**
* @author peter
*/
@@ -104,8 +104,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
@Override public String[] getIgnoreAnnotations() { return new String[]{"MyAnno"}; }
};
UnusedDeclarationInspectionBase deadCodeInspection = new UnusedDeclarationInspectionBase(true);
enableInspectionTool(deadCodeInspection);
enableInspectionTool(new UnusedDeclarationInspectionBase(true));
doTest(true, false);
List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
@@ -17,7 +17,6 @@ package com.intellij.codeInspection.ex
import com.intellij.configurationStore.SchemeManagerFactoryBase
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.Computable
import com.intellij.testFramework.InMemoryFsRule
import com.intellij.testFramework.ProjectRule
import com.intellij.util.readText
@@ -57,7 +56,7 @@ internal class InspectionSchemeTest {
val scheme = profileManager.profiles.first() as InspectionProfileImpl
assertThat(scheme.name).isEqualTo("Bar")
InspectionProfileImpl.initAndDo(Computable { scheme.initInspectionTools(null) })
InspectionProfileImpl.initAndDo { scheme.initInspectionTools(null) }
schemeManagerFactory.save()
@@ -30,7 +30,6 @@ import com.intellij.codeInspection.InspectionToolProvider;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.ide.startup.StartupManagerEx;
import com.intellij.ide.startup.impl.StartupManagerImpl;
@@ -93,7 +92,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
final LocalInspectionTool[] tools = configureLocalInspectionTools();
CodeInsightTestFixtureImpl.configureInspections(tools, getProject(), Collections.<String>emptyList(),
CodeInsightTestFixtureImpl.configureInspections(tools, getProject(), Collections.emptyList(),
getTestRootDisposable());
DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
@@ -137,8 +136,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
}
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
InspectionToolWrapper toolWrapper = InspectionToolRegistrar.wrapTool(tool);
LightPlatformTestCase.enableInspectionTool(getProject(), toolWrapper);
LightPlatformTestCase.enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(tool), getTestRootDisposable());
}
protected void enableInspectionTools(@NotNull InspectionProfileEntry... tools) {
@@ -170,7 +168,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
}
protected static LocalInspectionTool[] createLocalInspectionTools(final InspectionToolProvider... provider) {
final ArrayList<LocalInspectionTool> result = new ArrayList<LocalInspectionTool>();
final ArrayList<LocalInspectionTool> result = new ArrayList<>();
for (InspectionToolProvider toolProvider : provider) {
for (Class aClass : toolProvider.getInspectionClasses()) {
try {
@@ -342,7 +340,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
@NotNull
public static List<HighlightInfo> filter(@NotNull List<HighlightInfo> infos, @NotNull HighlightSeverity minSeverity) {
ArrayList<HighlightInfo> result = new ArrayList<HighlightInfo>();
ArrayList<HighlightInfo> result = new ArrayList<>();
for (final HighlightInfo info : infos) {
if (info.getSeverity().compareTo(minSeverity) >= 0) result.add(info);
}
@@ -376,7 +374,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
if (intentionAction == null) {
final List<IntentionAction> availableActions = new ArrayList<IntentionAction>();
final List<IntentionAction> availableActions = new ArrayList<>();
for (HighlightInfo info :infos) {
if (info.quickFixActionRanges != null) {
@@ -53,9 +53,14 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
@Override
protected void tearDown() throws Exception {
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest();
super.tearDown();
try {
// return default value to avoid unnecessary save
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest();
}
finally {
super.tearDown();
}
}
@Override
@@ -108,6 +113,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
data.init();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
//noinspection ResultOfMethodCallIgnored
getFile().getText(); //to load text
myJavaFilesFilter.allowTreeAccessForFile(getVFile());
PsiManagerEx.getInstanceEx(getProject()).setAssertOnFileLoadingFilter(myJavaFilesFilter, myTestRootDisposable);
@@ -60,12 +60,12 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
protected InspectionToolWrapper(@NotNull InspectionToolWrapper<T, E> other) {
myEP = other.myEP;
// we need to create a copy for buffering
if (other.myTool != null) {
//noinspection unchecked
myTool = myEP != null ? (T)myEP.instantiateTool() : (T)InspectionToolsRegistrarCore.instantiateTool(other.myTool.getClass());
if (other.myTool == null) {
myTool = null;
}
else {
myTool = null;
//noinspection unchecked
myTool = (T)(myEP == null ? InspectionToolsRegistrarCore.instantiateTool(other.myTool.getClass()) : myEP.instantiateTool());
}
}
@@ -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.
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
public class InspectionToolsRegistrarCore {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolsRegistrarCore");
static Object instantiateTool(@NotNull Class<?> toolClass) {
static <T> T instantiateTool(@NotNull Class<T> toolClass) {
try {
return ReflectionUtil.newInstance(toolClass);
}
@@ -57,6 +57,7 @@ import org.jetbrains.annotations.TestOnly;
import java.io.IOException;
import java.util.*;
import java.util.function.Supplier;
/**
* @author max
@@ -148,7 +149,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
};
final InspectionProfileImpl profile = new InspectionProfileImpl(name, registrar, InspectionProfileManager.getInstance());
initAndDo((Computable)() -> {
initAndDo(() -> {
profile.initInspectionTools(project);
return null;
});
@@ -615,7 +616,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
final InspectionEP extension = toolWrapper.getExtension();
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<String>(toolWrapper.getDisplayName()) : extension::getDisplayName;
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName()) : extension::getDisplayName;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
key = HighlightDisplayKey.register(shortName, computable, toolWrapper.getID(),
((LocalInspectionToolWrapper)toolWrapper).getAlternativeID());
@@ -1015,11 +1016,11 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@SuppressWarnings("TestOnlyProblems")
public static <T> T initAndDo(@NotNull Computable<T> runnable) {
public static <T> T initAndDo(@NotNull Supplier<T> runnable) {
boolean old = INIT_INSPECTIONS;
try {
INIT_INSPECTIONS = true;
return runnable.compute();
return runnable.get();
}
finally {
INIT_INSPECTIONS = old;
@@ -21,9 +21,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.ex.ComponentManagerEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.util.Factory;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
@@ -32,6 +30,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
/**
* @author max
@@ -39,35 +38,44 @@ import java.util.Set;
public class InspectionToolRegistrar {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolRegistrar");
private final List<Factory<InspectionToolWrapper>> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList();
private final List<Supplier<InspectionToolWrapper>> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList();
private boolean myInspectionComponentsLoaded = false;
private boolean myInspectionComponentsLoaded;
private synchronized void ensureInitialized() {
if (!myInspectionComponentsLoaded) {
myInspectionComponentsLoaded = true;
Set<InspectionToolProvider> providers = new THashSet<InspectionToolProvider>();
//noinspection unchecked
providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class)));
ContainerUtil.addAll(providers, Extensions.getExtensions(InspectionToolProvider.EXTENSION_POINT_NAME));
List<Factory<InspectionToolWrapper>> factories = new ArrayList<Factory<InspectionToolWrapper>>();
registerTools(providers, factories);
final boolean isInternal = ApplicationManager.getApplication().isInternal();
for (final LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
if (!isInternal && ep.isInternal) continue;
factories.add(() -> new LocalInspectionToolWrapper(ep));
}
for (final InspectionEP ep : Extensions.getExtensions(InspectionEP.GLOBAL_INSPECTION)) {
if (!isInternal && ep.isInternal) continue;
factories.add(() -> new GlobalInspectionToolWrapper(ep));
}
myInspectionToolFactories.addAll(factories);
if (myInspectionComponentsLoaded) {
return;
}
myInspectionComponentsLoaded = true;
Set<InspectionToolProvider> providers = new THashSet<>();
//noinspection deprecation
providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class)));
ContainerUtil.addAll(providers, InspectionToolProvider.EXTENSION_POINT_NAME.getExtensions());
List<Supplier<InspectionToolWrapper>> factories = new ArrayList<>();
registerTools(providers, factories);
boolean isInternal = ApplicationManager.getApplication().isInternal();
for (LocalInspectionEP ep : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
if (!isInternal && ep.isInternal) {
continue;
}
factories.add(() -> new LocalInspectionToolWrapper(ep));
}
for (InspectionEP ep : InspectionEP.GLOBAL_INSPECTION.getExtensions()) {
if (!isInternal && ep.isInternal) {
continue;
}
factories.add(() -> new GlobalInspectionToolWrapper(ep));
}
myInspectionToolFactories.addAll(factories);
}
@NotNull
public static InspectionToolWrapper wrapTool(@NotNull InspectionProfileEntry profileEntry) {
if (profileEntry instanceof LocalInspectionTool) {
//noinspection TestOnlyProblems
return new LocalInspectionToolWrapper((LocalInspectionTool)profileEntry);
}
if (profileEntry instanceof GlobalInspectionTool) {
@@ -77,10 +85,14 @@ public class InspectionToolRegistrar {
}
private static void registerTools(@NotNull Collection<InspectionToolProvider> providers,
@NotNull List<Factory<InspectionToolWrapper>> factories) {
@NotNull List<Supplier<InspectionToolWrapper>> factories) {
for (InspectionToolProvider provider : providers) {
for (Class aClass : provider.getInspectionClasses()) {
factories.add(() -> wrapTool((InspectionProfileEntry)InspectionToolsRegistrarCore.instantiateTool(aClass)));
//noinspection unchecked
for (Class<InspectionProfileEntry> aClass : provider.getInspectionClasses()) {
factories.add(() -> {
InspectionProfileEntry entry = InspectionToolsRegistrarCore.instantiateTool(aClass);
return entry == null ? null : wrapTool(entry);
});
}
}
}
@@ -93,10 +105,10 @@ public class InspectionToolRegistrar {
public List<InspectionToolWrapper> createTools() {
ensureInitialized();
final List<InspectionToolWrapper> tools = new ArrayList<InspectionToolWrapper>(myInspectionToolFactories.size());
for (final Factory<InspectionToolWrapper> factory : myInspectionToolFactories) {
List<InspectionToolWrapper> tools = new ArrayList<>(myInspectionToolFactories.size());
for (Supplier<InspectionToolWrapper> factory : myInspectionToolFactories) {
ProgressManager.checkCanceled();
final InspectionToolWrapper toolWrapper = factory.create();
InspectionToolWrapper toolWrapper = factory.get();
if (toolWrapper != null && checkTool(toolWrapper) == null) {
tools.add(toolWrapper);
}
@@ -20,16 +20,15 @@ import com.intellij.codeInspection.GlobalInspectionContext;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.LocalInspectionEP;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiElement;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.util.HashMap;
import java.util.Map;
/**
@@ -62,7 +61,6 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
return context.getStdJobDescriptors().LOCAL_ANALYSIS_ARRAY;
}
public boolean isUnfair() {
return myEP == null ? getTool() instanceof UnfairLocalInspectionTool : myEP.unfair;
}
@@ -85,8 +83,8 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
@NotNull
@Override
protected Map<String, LocalInspectionEP> compute() {
HashMap<String, LocalInspectionEP> map = new HashMap<String, LocalInspectionEP>();
for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
Map<String, LocalInspectionEP> map = new THashMap<>();
for (LocalInspectionEP ep : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
map.put(ep.getShortName(), ep);
}
return map;
@@ -21,7 +21,10 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.hint.HintManager;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.InspectionEP;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalInspectionEP;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
@@ -65,7 +68,6 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.io.FileUtil;
@@ -115,6 +117,7 @@ import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
/**
* @author yole
@@ -125,6 +128,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
@NonNls private static final String LIGHT_PROJECT_MARK = "Light project: ";
private static IdeaTestApplication ourApplication;
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
protected static Project ourProject;
private static Module ourModule;
private static PsiManager ourPsiManager;
@@ -223,9 +227,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
if (ourProject != null) {
closeAndDeleteProject();
}
ApplicationManager.getApplication().runWriteAction(() -> {
cleanPersistedVFSContent();
});
ApplicationManager.getApplication().runWriteAction(LightPlatformTestCase::cleanPersistedVFSContent);
final File projectFile = FileUtil.createTempFile(ProjectImpl.LIGHT_PROJECT_NAME, ProjectFileType.DOT_DEFAULT_EXTENSION);
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile);
@@ -342,8 +344,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue();
}
// todo: use Class<? extends InspectionProfileEntry> once on Java 7
protected void enableInspectionTools(@NotNull Class<?>... classes) {
protected void enableInspectionTools(@NotNull Class<? extends InspectionProfileEntry>[] classes) {
final InspectionProfileEntry[] tools = new InspectionProfileEntry[classes.length];
final List<InspectionEP> eps = ContainerUtil.newArrayList();
@@ -371,27 +372,36 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
protected void enableInspectionTool(@NotNull InspectionToolWrapper toolWrapper) {
enableInspectionTool(getProject(), toolWrapper);
}
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
InspectionToolWrapper toolWrapper = InspectionToolRegistrar.wrapTool(tool);
enableInspectionTool(getProject(), toolWrapper);
enableInspectionTool(getProject(), toolWrapper, myTestRootDisposable);
}
public static void enableInspectionTool(@NotNull final Project project, @NotNull final InspectionToolWrapper toolWrapper) {
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(tool), myTestRootDisposable);
}
public static void enableInspectionTool(@NotNull Project project, @NotNull InspectionToolWrapper toolWrapper, @Nullable Disposable disposable) {
InspectionProfileImpl profile = (InspectionProfileImpl)InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
final String shortName = toolWrapper.getShortName();
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), toolWrapper.getID());
}
InspectionProfileImpl.initAndDo((Computable)() -> {
InspectionProfileImpl impl = (InspectionProfileImpl)profile;
InspectionToolWrapper existingWrapper = impl.getInspectionTool(shortName, project);
InspectionProfileImpl.initAndDo(() -> {
InspectionToolWrapper existingWrapper = profile.getInspectionTool(shortName, project);
if (existingWrapper == null || existingWrapper.isInitialized() != toolWrapper.isInitialized() || toolWrapper.isInitialized() && toolWrapper.getTool() != existingWrapper.getTool()) {
impl.addTool(project, toolWrapper, new THashMap<>());
profile.addTool(project, toolWrapper, new THashMap<>());
}
profile.enableTool(shortName, project);
if (disposable != null) {
Disposer.register(disposable, new Disposable() {
@Override
public void dispose() {
profile.disableTool(shortName, project);
}
});
}
impl.enableTool(shortName, project);
return null;
});
}
@@ -401,27 +411,27 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
return LocalInspectionTool.EMPTY_ARRAY;
}
@SuppressWarnings("TearDownDoesntCallSuperTearDown")
@Override
protected void tearDown() throws Exception {
Project project = getProject();
CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
List<Throwable> errors = ContainerUtil.newSmartList();
Function<ThrowableRunnable<?>, ?> runSafe = c -> {
List<Throwable> errors = new SmartList<>();
Consumer<ThrowableRunnable<?>> runSafe = c -> {
try {
c.run();
}
catch (Throwable e) {
errors.add(e);
}
return true;
};
try {
runSafe.fun(() -> checkForSettingsDamage(errors));
runSafe.fun(() -> doTearDown(project, ourApplication, true, errors));
runSafe.fun(super::tearDown);
runSafe.fun(() -> myThreadTracker.checkLeak());
runSafe.fun(() -> InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project));
runSafe.fun(() -> ((VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance()).assertPointersAreDisposed());
runSafe.accept(() -> CodeStyleSettingsManager.getInstance(project).dropTemporarySettings());
runSafe.accept(() -> checkForSettingsDamage(errors));
runSafe.accept(() -> doTearDown(project, ourApplication, true, errors));
runSafe.accept(super::tearDown);
runSafe.accept(() -> myThreadTracker.checkLeak());
runSafe.accept(() -> InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project));
runSafe.accept(() -> ((VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance()).assertPointersAreDisposed());
}
catch (Throwable e) {
errors.add(e);
@@ -559,6 +569,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
}
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Override
public final void runBare() throws Throwable {
if (!shouldRunTest()) {
@@ -581,6 +592,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
resetAllFields();
}
catch (Throwable e) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
}
}
@@ -594,6 +606,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
}
@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
private void startRunAndTear() throws Throwable {
setUp();
try {
@@ -696,6 +709,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
if (!ourProject.isDisposed()) {
@SuppressWarnings("ConstantConditions")
File ioFile = new File(ourProject.getProjectFilePath());
Disposer.dispose(ourProject);
if (ioFile.exists()) {
@@ -715,7 +729,9 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
if (ourPathToKeep != null) {
File parent = new File(ourPathToKeep).getParentFile();
if (parent.getName().startsWith(UsefulTestCase.TEMP_DIR_MARKER)) {
parent.delete(); // delete only empty folders
// delete only empty folders
//noinspection ResultOfMethodCallIgnored
parent.delete();
}
}
@@ -187,7 +187,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
List<GutterMark> renderers = result.get(offset);
if (renderers == null) {
result.put(offset, renderers = new SmartList<GutterMark>());
result.put(offset, renderers = new SmartList<>());
}
renderers.add(renderer);
}
@@ -199,7 +199,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
InspectionToolWrapper[] wrapped = ContainerUtil.map2Array(tools, InspectionToolWrapper.class, InspectionToolRegistrar::wrapTool);
final InspectionProfileImpl profile = InspectionProfileImpl.createSimple(LightPlatformTestCase.PROFILE, project, wrapped);
profile.disableToolByDefault(new ArrayList<String>(disabledInspections), project);
profile.disableToolByDefault(new ArrayList<>(disabledInspections), project);
final ApplicationInspectionProfileManager inspectionProfileManager = ApplicationInspectionProfileManager.getInstanceImpl();
final Profile oldRootProfile = inspectionProfileManager.getCurrentProfile();
@@ -213,7 +213,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
});
inspectionProfileManager.setRootProfile(profile.getName());
InspectionProfileImpl.initAndDo((Computable)() -> {
InspectionProfileImpl.initAndDo(() -> {
InspectionProjectProfileManager.getInstance(project).updateProfile(profile);
ProjectInspectionProfileManager.getInstanceImpl(project).setRootProfile(profile.getName());
return null;
@@ -297,7 +297,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
List<IntentionAction> result = new ArrayList<IntentionAction>();
List<IntentionAction> result = new ArrayList<>();
IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject());
for (Map.Entry<IntentionAction, List<IntentionAction>> entry : intentionListStep.getActionsWithSubActions().entrySet()) {
result.add(entry.getKey());
@@ -401,7 +401,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
public void enableInspections(@NotNull InspectionProfileEntry... inspections) {
assertInitialized();
for (InspectionProfileEntry inspection : inspections) {
LightPlatformTestCase.enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(inspection));
LightPlatformTestCase.enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(inspection), getTestRootDisposable());
}
}
@@ -411,16 +411,10 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Override
public void enableInspections(@NotNull final Collection<Class<? extends LocalInspectionTool>> inspections) {
List<LocalInspectionTool> tools = new ArrayList<LocalInspectionTool>();
public void enableInspections(@NotNull Collection<Class<? extends LocalInspectionTool>> inspections) {
List<LocalInspectionTool> tools = new SmartList<>();
for (Class<? extends LocalInspectionTool> clazz : inspections) {
try {
LocalInspectionTool inspection = clazz.getConstructor().newInstance();
tools.add(inspection);
}
catch (Exception e) {
throw new RuntimeException("Cannot instantiate " + clazz);
}
tools.add(ReflectionUtil.newInstance(clazz));
}
enableInspections(tools.toArray(new LocalInspectionTool[tools.size()]));
}
@@ -435,7 +429,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@Override
public void enableInspections(@NotNull InspectionToolProvider... providers) {
List<LocalInspectionTool> tools = new ArrayList<LocalInspectionTool>();
List<LocalInspectionTool> tools = new ArrayList<>();
for (InspectionToolProvider provider : providers) {
for (Class<?> clazz : provider.getInspectionClasses()) {
try {
@@ -474,7 +468,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final boolean checkInfos,
final boolean checkWeakWarnings,
@NotNull final String... filePaths) {
final ArrayList<VirtualFile> files = new ArrayList<VirtualFile>();
final ArrayList<VirtualFile> files = new ArrayList<>();
for (String path : filePaths) {
files.add(copyFileToProject(path));
}
@@ -622,7 +616,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
configureByFilesInner(filePaths);
}
List<HighlightInfo> infos = doHighlighting();
ArrayList<IntentionAction> actions = new ArrayList<IntentionAction>();
ArrayList<IntentionAction> actions = new ArrayList<>();
for (HighlightInfo info : infos) {
if (info.quickFixActionRanges != null) {
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
@@ -671,7 +665,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
List<IntentionAction> intentions = getAvailableIntentions(filePaths);
IntentionAction action = CodeInsightTestUtil.findIntentionByText(intentions, intentionName);
if (action == null) {
System.out.println(intentionName + " not found among " + StringUtil.join(intentions, action1 -> action1.getText(), ","));
//noinspection UseOfSystemOutOrSystemErr
System.out.println(intentionName + " not found among " + StringUtil.join(intentions, IntentionAction::getText, ","));
}
return action;
}
@@ -697,6 +692,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
checkResultByFile(fileAfter);
}
catch (RuntimeException e) {
//noinspection UseOfSystemOutOrSystemErr
System.out.println("LookupElementStrings = " + getLookupElementStrings());
throw e;
}
@@ -743,7 +739,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final LookupElement[] elements = getLookupElements();
if (elements == null) return null;
return ContainerUtil.map(elements, lookupItem -> lookupItem.getLookupString());
return ContainerUtil.map(elements, LookupElement::getLookupString);
}
@Override
@@ -961,7 +957,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final FindUsagesHandler handler =
((FindManagerImpl)FindManager.getInstance(project)).getFindUsagesManager().getFindUsagesHandler(targetElement, false);
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
Assert.assertNotNull("Cannot find handler for: " + targetElement, handler);
final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
final FindUsagesOptions options = handler.getFindUsagesOptions(null);
@@ -1001,7 +997,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@Nullable
public GutterMark findGutter(@NotNull final String filePath) {
configureByFilesInner(filePath);
CommonProcessors.FindFirstProcessor<GutterMark> processor = new CommonProcessors.FindFirstProcessor<GutterMark>();
CommonProcessors.FindFirstProcessor<GutterMark> processor = new CommonProcessors.FindFirstProcessor<>();
findGutters(processor);
return processor.getFoundValue();
}
@@ -1009,9 +1005,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@NotNull
@Override
public List<GutterMark> findGuttersAtCaret() {
CommonProcessors.CollectProcessor<GutterMark> processor = new CommonProcessors.CollectProcessor<GutterMark>();
CommonProcessors.CollectProcessor<GutterMark> processor = new CommonProcessors.CollectProcessor<>();
findGutters(processor);
return new ArrayList<GutterMark>(processor.getResults());
return new ArrayList<>(processor.getResults());
}
private void findGutters(Processor<GutterMark> processor) {
@@ -1048,7 +1044,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@NotNull
public List<GutterMark> findAllGutters() {
final Project project = getProject();
final SortedMap<Integer, List<GutterMark>> result = new TreeMap<Integer, List<GutterMark>>();
final SortedMap<Integer, List<GutterMark>> result = new TreeMap<>();
List<HighlightInfo> infos = doHighlighting();
for (HighlightInfo info : infos) {
@@ -1160,7 +1156,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final CaretModel caretModel = myEditor.getCaretModel();
final List<Caret> carets = caretModel.getAllCarets();
final List<Integer> originalOffsets = new ArrayList<Integer>(carets.size());
final List<Integer> originalOffsets = new ArrayList<>(carets.size());
for (final Caret caret : carets) {
originalOffsets.add(caret.getOffset());
@@ -1170,7 +1166,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
// We do it in reverse order because completions would affect offsets
// i.e.: when you complete "spa" to "spam", next caret offset increased by 1
Collections.reverse(originalOffsets);
final List<LookupElement> result = new ArrayList<LookupElement>();
final List<LookupElement> result = new ArrayList<>();
for (final int originalOffset : originalOffsets) {
caretModel.moveToOffset(originalOffset);
final LookupElement[] lookupElements = completeBasic();
@@ -1728,7 +1724,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
final FoldingModel model = myEditor.getFoldingModel();
final FoldRegion[] foldingRegions = model.getAllFoldRegions();
final List<Border> borders = new LinkedList<Border>();
final List<Border> borders = new LinkedList<>();
for (FoldRegion region : foldingRegions) {
borders.add(new Border(Border.LEFT, region.getStartOffset(), region.getPlaceholderText(), region.isExpanded()));
@@ -1750,7 +1746,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@NotNull
public String getHighlightingDescription(@NotNull List<HighlightInfo> highlighting, @NotNull String tagName, boolean withColor) {
final List<Border> borders = new LinkedList<Border>();
final List<Border> borders = new LinkedList<>();
for (HighlightInfo region : highlighting) {
TextAttributes attributes = region.getTextAttributes(null, null);
borders.add(new Border(Border.LEFT, region.getStartOffset(),
@@ -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.
@@ -19,12 +19,5 @@ package com.intellij.openapi.util;
* @author dsl
*/
public interface Factory<T> {
Factory NULL_FACTORY = new Factory() {
@Override
public Object create() {
return null;
}
};
T create();
}