diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy index 7f181760e1ea..6703d1b2064d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy @@ -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 */ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 07bae515ea7d..1a89cefdcff8 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -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 infos = doHighlighting(HighlightSeverity.WARNING); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt index daad966dcf81..cbeddb5ee4f5 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt @@ -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() diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index 3758b36c198b..24254bc97b39 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -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.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 result = new ArrayList(); + final ArrayList 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 filter(@NotNull List infos, @NotNull HighlightSeverity minSeverity) { - ArrayList result = new ArrayList(); + ArrayList 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 availableActions = new ArrayList(); + final List availableActions = new ArrayList<>(); for (HighlightInfo info :infos) { if (info.quickFixActionRanges != null) { diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java index ab439829ce9a..32d906a217d0 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java @@ -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); diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java b/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java index a7d9ca133c03..5aec1c33928d 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java @@ -60,12 +60,12 @@ public abstract class InspectionToolWrapper 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()); } } diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolsRegistrarCore.java b/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolsRegistrarCore.java index b9b617ec0121..5acd410b3dd2 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolsRegistrarCore.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolsRegistrarCore.java @@ -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 instantiateTool(@NotNull Class toolClass) { try { return ReflectionUtil.newInstance(toolClass); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index 1e4731e28d29..5eaef5f6bfc6 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -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 computable = extension == null ? new Computable.PredefinedValueComputable(toolWrapper.getDisplayName()) : extension::getDisplayName; + Computable 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 initAndDo(@NotNull Computable runnable) { + public static T initAndDo(@NotNull Supplier runnable) { boolean old = INIT_INSPECTIONS; try { INIT_INSPECTIONS = true; - return runnable.compute(); + return runnable.get(); } finally { INIT_INSPECTIONS = old; diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java index 3851c6112d25..4eb039b464d9 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java @@ -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> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList(); + private final List> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList(); - private boolean myInspectionComponentsLoaded = false; + private boolean myInspectionComponentsLoaded; private synchronized void ensureInitialized() { - if (!myInspectionComponentsLoaded) { - myInspectionComponentsLoaded = true; - Set providers = new THashSet(); - //noinspection unchecked - providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class))); - ContainerUtil.addAll(providers, Extensions.getExtensions(InspectionToolProvider.EXTENSION_POINT_NAME)); - List> factories = new ArrayList>(); - 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 providers = new THashSet<>(); + //noinspection deprecation + providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class))); + ContainerUtil.addAll(providers, InspectionToolProvider.EXTENSION_POINT_NAME.getExtensions()); + List> 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 providers, - @NotNull List> factories) { + @NotNull List> factories) { for (InspectionToolProvider provider : providers) { - for (Class aClass : provider.getInspectionClasses()) { - factories.add(() -> wrapTool((InspectionProfileEntry)InspectionToolsRegistrarCore.instantiateTool(aClass))); + //noinspection unchecked + for (Class 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 createTools() { ensureInitialized(); - final List tools = new ArrayList(myInspectionToolFactories.size()); - for (final Factory factory : myInspectionToolFactories) { + List tools = new ArrayList<>(myInspectionToolFactories.size()); + for (Supplier factory : myInspectionToolFactories) { ProgressManager.checkCanceled(); - final InspectionToolWrapper toolWrapper = factory.create(); + InspectionToolWrapper toolWrapper = factory.get(); if (toolWrapper != null && checkTool(toolWrapper) == null) { tools.add(toolWrapper); } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java index 5d4f19afba29..1cca5efb7499 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java @@ -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 compute() { - HashMap map = new HashMap(); - for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) { + Map map = new THashMap<>(); + for (LocalInspectionEP ep : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) { map.put(ep.getShortName(), ep); } return map; diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 73e49df03f6c..893bb90e3a46 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -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 once on Java 7 - protected void enableInspectionTools(@NotNull Class... classes) { + protected void enableInspectionTools(@NotNull Class[] classes) { final InspectionProfileEntry[] tools = new InspectionProfileEntry[classes.length]; final List 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 errors = ContainerUtil.newSmartList(); - Function, ?> runSafe = c -> { + List errors = new SmartList<>(); + Consumer> 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(); } } 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 daba1ab3e726..d5ae70685463 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -187,7 +187,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig List renderers = result.get(offset); if (renderers == null) { - result.put(offset, renderers = new SmartList()); + 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(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 result = new ArrayList(); + List result = new ArrayList<>(); IntentionListStep intentionListStep = new IntentionListStep(null, intentions, editor, file, file.getProject()); for (Map.Entry> 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> inspections) { - List tools = new ArrayList(); + public void enableInspections(@NotNull Collection> inspections) { + List tools = new SmartList<>(); for (Class 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 tools = new ArrayList(); + List 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 files = new ArrayList(); + final ArrayList 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 infos = doHighlighting(); - ArrayList actions = new ArrayList(); + ArrayList actions = new ArrayList<>(); for (HighlightInfo info : infos) { if (info.quickFixActionRanges != null) { for (Pair pair : info.quickFixActionRanges) { @@ -671,7 +665,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig List 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 processor = new CommonProcessors.CollectProcessor(); + final CommonProcessors.CollectProcessor 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 processor = new CommonProcessors.FindFirstProcessor(); + CommonProcessors.FindFirstProcessor processor = new CommonProcessors.FindFirstProcessor<>(); findGutters(processor); return processor.getFoundValue(); } @@ -1009,9 +1005,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull @Override public List findGuttersAtCaret() { - CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor(); + CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor<>(); findGutters(processor); - return new ArrayList(processor.getResults()); + return new ArrayList<>(processor.getResults()); } private void findGutters(Processor processor) { @@ -1048,7 +1044,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull public List findAllGutters() { final Project project = getProject(); - final SortedMap> result = new TreeMap>(); + final SortedMap> result = new TreeMap<>(); List infos = doHighlighting(); for (HighlightInfo info : infos) { @@ -1160,7 +1156,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final CaretModel caretModel = myEditor.getCaretModel(); final List carets = caretModel.getAllCarets(); - final List originalOffsets = new ArrayList(carets.size()); + final List 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 result = new ArrayList(); + final List 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 borders = new LinkedList(); + final List 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 highlighting, @NotNull String tagName, boolean withColor) { - final List borders = new LinkedList(); + final List borders = new LinkedList<>(); for (HighlightInfo region : highlighting) { TextAttributes attributes = region.getTextAttributes(null, null); borders.add(new Border(Border.LEFT, region.getStartOffset(), diff --git a/platform/util/src/com/intellij/openapi/util/Factory.java b/platform/util/src/com/intellij/openapi/util/Factory.java index a258f19ec82a..3b474f720ce8 100644 --- a/platform/util/src/com/intellij/openapi/util/Factory.java +++ b/platform/util/src/com/intellij/openapi/util/Factory.java @@ -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 { - Factory NULL_FACTORY = new Factory() { - @Override - public Object create() { - return null; - } - }; - T create(); }