mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix SingleInspectionProfilePanelTest
This commit is contained in:
@@ -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.
|
||||
@@ -19,7 +19,6 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.psi.JavaElementVisitor;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
@@ -32,7 +31,7 @@ public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
|
||||
public void testErrorLikeUnusedSymbol() throws Exception {
|
||||
enableInspectionTool(new LocalInspectionToolWrapper(new LocalInspectionTool() {
|
||||
enableInspectionTool(new LocalInspectionTool() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getShortName() {
|
||||
@@ -73,7 +72,7 @@ public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase {
|
||||
public String getGroupDisplayName() {
|
||||
return getDisplayName();
|
||||
}
|
||||
}));
|
||||
});
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -23,8 +23,10 @@ import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
|
||||
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel
|
||||
import com.intellij.testFramework.LightIdeaTestCase
|
||||
import com.intellij.testFramework.configureInspections
|
||||
import com.intellij.testFramework.createProfile
|
||||
import junit.framework.TestCase
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
|
||||
class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
|
||||
private val myInspection = JavaDocLocalInspection()
|
||||
@@ -32,11 +34,10 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
|
||||
// see IDEA-85700
|
||||
fun testSettingsModification() {
|
||||
val project = ProjectManager.getInstance().defaultProject
|
||||
val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
|
||||
val profile = profileManager.currentProfile
|
||||
val profile = configureInspections(arrayOf(myInspection), project, myTestRootDisposable)
|
||||
|
||||
val model = profile.modifiableModel
|
||||
val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile)
|
||||
val panel = SingleInspectionProfilePanel(ProjectInspectionProfileManager.getInstanceImpl(project), profile.name, model, profile)
|
||||
panel.isVisible = true
|
||||
panel.reset()
|
||||
|
||||
@@ -45,9 +46,9 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
|
||||
tool.myAdditionalJavadocTags = "foo"
|
||||
model.setModified(true)
|
||||
panel.apply()
|
||||
TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
|
||||
assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
|
||||
|
||||
assertEquals("foo", getInspection(profile).myAdditionalJavadocTags)
|
||||
assertThat(getInspection(profile).myAdditionalJavadocTags).isEqualTo("foo")
|
||||
panel.disposeUI()
|
||||
}
|
||||
|
||||
@@ -73,7 +74,7 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
|
||||
|
||||
model.setModified(true)
|
||||
panel.apply()
|
||||
TestCase.assertEquals(1, InspectionProfileTest.countInitializedTools(model))
|
||||
assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
|
||||
|
||||
assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
|
||||
panel.disposeUI()
|
||||
@@ -86,7 +87,7 @@ class SingleInspectionProfilePanelTest : LightIdeaTestCase() {
|
||||
profile.initInspectionTools(project)
|
||||
|
||||
val originalTool = getInspection(profile)
|
||||
TestCase.assertEquals("", originalTool.myAdditionalJavadocTags)
|
||||
assertThat(originalTool.myAdditionalJavadocTags).isEmpty()
|
||||
|
||||
val model = profile.modifiableModel
|
||||
val copyTool = getInspection(model)
|
||||
|
||||
@@ -33,12 +33,14 @@ import com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import com.intellij.util.JdomKt;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.profile.ProfileEx.serializeProfile;
|
||||
@@ -574,21 +576,24 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
assertEquals(test, JDOMUtil.writeElement(serializeProfile(foo)));
|
||||
}
|
||||
|
||||
public static int countInitializedTools(Profile foo) {
|
||||
return getInitializedTools(foo).size();
|
||||
public static int countInitializedTools(@NotNull Profile foo) {
|
||||
return getInitializedTools((InspectionProfileImpl)foo).size();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<InspectionToolWrapper> getInitializedTools(@NotNull Profile foo) {
|
||||
List<InspectionToolWrapper> initialized = new ArrayList<>();
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)foo).getAllTools(getProject());
|
||||
public static List<InspectionToolWrapper> getInitializedTools(@NotNull InspectionProfileImpl foo) {
|
||||
List<InspectionToolWrapper> initialized = null;
|
||||
List<ScopeToolState> tools = foo.getAllTools(getProject());
|
||||
for (ScopeToolState tool : tools) {
|
||||
InspectionToolWrapper toolWrapper = tool.getTool();
|
||||
if (toolWrapper.isInitialized()) {
|
||||
if (initialized == null) {
|
||||
initialized = new SmartList<>();
|
||||
}
|
||||
initialized.add(toolWrapper);
|
||||
}
|
||||
}
|
||||
return initialized;
|
||||
return initialized == null ? Collections.emptyList() : initialized;
|
||||
}
|
||||
|
||||
private static LocalInspectionToolWrapper createTool(String s, boolean enabled) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.configurationStore.SchemeManagerFactoryBase
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.testFramework.InMemoryFsRule
|
||||
import com.intellij.testFramework.ProjectRule
|
||||
import com.intellij.testFramework.runInInitMode
|
||||
import com.intellij.util.readText
|
||||
import com.intellij.util.write
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@@ -56,7 +57,7 @@ internal class InspectionSchemeTest {
|
||||
val scheme = profileManager.profiles.first() as InspectionProfileImpl
|
||||
assertThat(scheme.name).isEqualTo("Bar")
|
||||
|
||||
InspectionProfileImpl.initAndDo { scheme.initInspectionTools(null) }
|
||||
runInInitMode { scheme.initInspectionTools(null) }
|
||||
|
||||
schemeManagerFactory.save()
|
||||
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import com.intellij.testFramework.Assertions.assertThat
|
||||
import com.intellij.testFramework.ProjectRule
|
||||
import com.intellij.testFramework.RuleChain
|
||||
import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.testFramework.runInInitMode
|
||||
import com.intellij.util.delete
|
||||
import com.intellij.util.readText
|
||||
import com.intellij.util.write
|
||||
@@ -106,7 +107,7 @@ internal class ProjectInspectionManagerTest {
|
||||
assertThat(projectInspectionProfileManager.state).isEmpty()
|
||||
|
||||
// cause to use app profile
|
||||
InspectionProfileImpl.initAndDo {
|
||||
runInInitMode {
|
||||
val currentProfile = projectInspectionProfileManager.currentProfile
|
||||
assertThat(currentProfile.isProjectLevel).isTrue()
|
||||
currentProfile.disableTool("Convert2Diamond", project)
|
||||
@@ -137,7 +138,7 @@ internal class ProjectInspectionManagerTest {
|
||||
|
||||
project.baseDir.refresh(false, true)
|
||||
(ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
|
||||
InspectionProfileImpl.initAndDo {
|
||||
runInInitMode {
|
||||
assertThat(projectInspectionProfileManager.currentProfile.getToolDefaultState("Convert2Diamond", project).level).isEqualTo(HighlightDisplayLevel.ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
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.ide.highlighter.JavaFileType;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
@@ -59,7 +58,10 @@ import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.search.IndexPatternBuilder;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.psi.xml.XmlFileNSInfoProvider;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.testFramework.ExpectedHighlightingData;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.HighlightTestInfo;
|
||||
import com.intellij.testFramework.InspectionsKt;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -131,7 +133,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
|
||||
LightPlatformTestCase.enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(tool), getTestRootDisposable());
|
||||
InspectionsKt.enableInspectionTool(getProject(), tool, getTestRootDisposable());
|
||||
}
|
||||
|
||||
protected void enableInspectionTools(@NotNull InspectionProfileEntry... tools) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
@@ -28,7 +28,7 @@ import java.util.List;
|
||||
|
||||
public interface Tools {
|
||||
@NotNull
|
||||
InspectionToolWrapper getInspectionTool(PsiElement element);
|
||||
InspectionToolWrapper getInspectionTool(@Nullable PsiElement element);
|
||||
|
||||
@NotNull
|
||||
String getShortName();
|
||||
@@ -39,6 +39,8 @@ public interface Tools {
|
||||
@NotNull
|
||||
List<ScopeToolState> getTools();
|
||||
|
||||
void collectTools(@NotNull List<ScopeToolState> result);
|
||||
|
||||
@NotNull
|
||||
ScopeToolState getDefaultState();
|
||||
|
||||
|
||||
+8
-8
@@ -69,16 +69,16 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
private AnalysisScope myCurrentScope;
|
||||
@NotNull
|
||||
private final Project myProject;
|
||||
private final List<JobDescriptor> myJobDescriptors = new ArrayList<JobDescriptor>();
|
||||
private final List<JobDescriptor> myJobDescriptors = new ArrayList<>();
|
||||
|
||||
private final StdJobDescriptors myStdJobDescriptors = new StdJobDescriptors();
|
||||
protected ProgressIndicator myProgressIndicator = new EmptyProgressIndicator();
|
||||
|
||||
private InspectionProfile myExternalProfile;
|
||||
|
||||
protected final Map<Key, GlobalInspectionContextExtension> myExtensions = new HashMap<Key, GlobalInspectionContextExtension>();
|
||||
protected final Map<Key, GlobalInspectionContextExtension> myExtensions = new HashMap<>();
|
||||
|
||||
protected final Map<String, Tools> myTools = new THashMap<String, Tools>();
|
||||
protected final Map<String, Tools> myTools = new THashMap<>();
|
||||
|
||||
@NonNls public static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool";
|
||||
|
||||
@@ -328,7 +328,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
protected List<Tools> getUsedTools() {
|
||||
InspectionProfileImpl profile = (InspectionProfileImpl)getCurrentProfile();
|
||||
List<Tools> tools = profile.getAllEnabledInspectionTools(myProject);
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<InspectionToolWrapper>();
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<>();
|
||||
for (Tools tool : tools) {
|
||||
profile.collectDependentInspections(tool.getTool(), dependentTools, getProject());
|
||||
}
|
||||
@@ -336,9 +336,9 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
if (dependentTools.isEmpty()) {
|
||||
return tools;
|
||||
}
|
||||
Set<Tools> set = new THashSet<Tools>(tools, TOOLS_HASHING_STRATEGY);
|
||||
Set<Tools> set = new THashSet<>(tools, TOOLS_HASHING_STRATEGY);
|
||||
set.addAll(ContainerUtil.map(dependentTools, toolWrapper -> new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true, true)));
|
||||
return new ArrayList<Tools>(set);
|
||||
return new ArrayList<>(set);
|
||||
}
|
||||
|
||||
private static void classifyTool(@NotNull List<Tools> outGlobalTools,
|
||||
@@ -390,7 +390,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
}
|
||||
|
||||
public static void cleanupElements(@NotNull final Project project, @Nullable final Runnable runnable, @NotNull PsiElement... scope) {
|
||||
final List<SmartPsiElementPointer<PsiElement>> elements = new ArrayList<SmartPsiElementPointer<PsiElement>>();
|
||||
final List<SmartPsiElementPointer<PsiElement>> elements = new ArrayList<>();
|
||||
final SmartPointerManager manager = SmartPointerManager.getInstance(project);
|
||||
for (PsiElement element : scope) {
|
||||
elements.add(manager.createSmartPsiElementPointer(element));
|
||||
@@ -403,7 +403,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
@Nullable final Runnable runnable,
|
||||
final List<SmartPsiElementPointer<PsiElement>> elements) {
|
||||
Runnable cleanupRunnable = () -> {
|
||||
final List<PsiElement> psiElements = new ArrayList<PsiElement>();
|
||||
final List<PsiElement> psiElements = new ArrayList<>();
|
||||
for (SmartPsiElementPointer<PsiElement> element : elements) {
|
||||
PsiElement psiElement = element.getElement();
|
||||
if (psiElement != null && psiElement.isPhysical()) {
|
||||
|
||||
+6
-21
@@ -49,6 +49,7 @@ import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -56,7 +57,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -147,10 +147,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
return toolWrappers;
|
||||
}
|
||||
}, InspectionProfileManager.getInstance());
|
||||
initAndDo(() -> {
|
||||
profile.initInspectionTools(project);
|
||||
return null;
|
||||
});
|
||||
for (InspectionToolWrapper toolWrapper : toolWrappers) {
|
||||
profile.enableTool(toolWrapper.getShortName(), project);
|
||||
}
|
||||
@@ -261,7 +257,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
@NotNull
|
||||
public Set<HighlightSeverity> getUsedSeverities() {
|
||||
LOG.assertTrue(myInitialized);
|
||||
final Set<HighlightSeverity> result = new HashSet<>();
|
||||
Set<HighlightSeverity> result = new THashSet<>();
|
||||
for (Tools tools : myTools.values()) {
|
||||
for (ScopeToolState state : tools.getTools()) {
|
||||
result.add(state.getLevel().getSeverity());
|
||||
@@ -882,11 +878,12 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ScopeToolState> getAllTools(Project project) {
|
||||
public List<ScopeToolState> getAllTools(@Nullable Project project) {
|
||||
initInspectionTools(project);
|
||||
final List<ScopeToolState> result = new ArrayList<>();
|
||||
|
||||
List<ScopeToolState> result = new ArrayList<>();
|
||||
for (Tools tools : myTools.values()) {
|
||||
result.addAll(tools.getTools());
|
||||
tools.collectTools(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1008,16 +1005,4 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
private static class InspectionProfileImplHolder {
|
||||
private static final InspectionProfileImpl DEFAULT_PROFILE = new InspectionProfileImpl(DEFAULT_PROFILE_NAME);
|
||||
}
|
||||
|
||||
@SuppressWarnings("TestOnlyProblems")
|
||||
public static <T> T initAndDo(@NotNull Supplier<T> runnable) {
|
||||
boolean old = INIT_INSPECTIONS;
|
||||
try {
|
||||
INIT_INSPECTIONS = true;
|
||||
return runnable.get();
|
||||
}
|
||||
finally {
|
||||
INIT_INSPECTIONS = old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ToolsImpl implements Tools {
|
||||
@NotNull
|
||||
private ScopeToolState insertTool(@NotNull final ScopeToolState scopeToolState, final int idx) {
|
||||
if (myTools == null) {
|
||||
myTools = new ArrayList<ScopeToolState>();
|
||||
myTools = new ArrayList<>();
|
||||
if (scopeToolState.isEnabled()) {
|
||||
setEnabled(true);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class ToolsImpl implements Tools {
|
||||
|
||||
@NotNull
|
||||
public List<InspectionToolWrapper> getAllTools() {
|
||||
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
|
||||
List<InspectionToolWrapper> result = new ArrayList<>();
|
||||
for (ScopeToolState state : getTools()) {
|
||||
result.add(state.getTool());
|
||||
}
|
||||
@@ -179,7 +179,7 @@ public class ToolsImpl implements Tools {
|
||||
final InspectionToolWrapper toolWrapper = myDefaultState.getTool();
|
||||
|
||||
final List<Element> scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
|
||||
final List<String> scopeNames = new ArrayList<String>();
|
||||
final List<String> scopeNames = new ArrayList<>();
|
||||
for (Element scopeElement : scopeElements) {
|
||||
final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
|
||||
if (scopeName == null) {
|
||||
@@ -216,7 +216,7 @@ public class ToolsImpl implements Tools {
|
||||
String scopeName = scopeNames.get(i);
|
||||
List<String> order = dependencies.get(scopeName);
|
||||
if (order == null) {
|
||||
order = new ArrayList<String>();
|
||||
order = new ArrayList<>();
|
||||
dependencies.put(scopeName, order);
|
||||
}
|
||||
for (int j = i + 1; j < scopeNames.size(); j++) {
|
||||
@@ -242,12 +242,23 @@ public class ToolsImpl implements Tools {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<ScopeToolState> getTools() {
|
||||
if (myTools == null) return Collections.singletonList(myDefaultState);
|
||||
List<ScopeToolState> result = new ArrayList<ScopeToolState>(myTools);
|
||||
if (myTools == null) {
|
||||
return Collections.singletonList(myDefaultState);
|
||||
}
|
||||
|
||||
List<ScopeToolState> result = new ArrayList<>(myTools);
|
||||
result.add(myDefaultState);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectTools(@NotNull List<ScopeToolState> result) {
|
||||
if (myTools != null) {
|
||||
result.addAll(myTools);
|
||||
}
|
||||
result.add(myDefaultState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ScopeToolState getDefaultState() {
|
||||
@@ -325,8 +336,6 @@ public class ToolsImpl implements Tools {
|
||||
return myDefaultState.getLevel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public HighlightDisplayLevel getLevel() {
|
||||
return myDefaultState.getLevel();
|
||||
}
|
||||
@@ -406,7 +415,6 @@ public class ToolsImpl implements Tools {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void disableTool(@NotNull PsiElement element) {
|
||||
final Project project = element.getProject();
|
||||
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(project);
|
||||
|
||||
+8
-7
@@ -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.
|
||||
@@ -280,7 +280,8 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
final boolean enabled = state.isEnabled();
|
||||
if (isPreviousEnabled == null) {
|
||||
isPreviousEnabled = enabled;
|
||||
} else if (!isPreviousEnabled.equals(enabled)) {
|
||||
}
|
||||
else if (!isPreviousEnabled.equals(enabled)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -313,8 +314,8 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
LOG.assertTrue(myTreeTable != null);
|
||||
|
||||
Boolean state = null;
|
||||
final HashSet<HighlightDisplayKey> tools = new HashSet<HighlightDisplayKey>();
|
||||
final List<InspectionConfigTreeNode> nodes = new ArrayList<InspectionConfigTreeNode>();
|
||||
final HashSet<HighlightDisplayKey> tools = new HashSet<>();
|
||||
final List<InspectionConfigTreeNode> nodes = new ArrayList<>();
|
||||
|
||||
for (TreePath selectionPath : myTreeTable.getTree().getSelectionPaths()) {
|
||||
final InspectionConfigTreeNode node = (InspectionConfigTreeNode)selectionPath.getLastPathComponent();
|
||||
@@ -396,7 +397,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
|
||||
private static class SeverityAndOccurrences {
|
||||
private HighlightSeverity myPrimarySeverity;
|
||||
private final Map<String, HighlightSeverity> myOccurrences = new HashMap<String, HighlightSeverity>();
|
||||
private final Map<String, HighlightSeverity> myOccurrences = new HashMap<>();
|
||||
|
||||
public void setSeverityToMixed() {
|
||||
myPrimarySeverity = ScopesAndSeveritiesTable.MIXED_FAKE_SEVERITY;
|
||||
@@ -428,7 +429,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
private static class MultiColoredHighlightSeverityIconSink {
|
||||
|
||||
|
||||
private final Map<String, SeverityAndOccurrences> myScopeToAverageSeverityMap = new HashMap<String, SeverityAndOccurrences>();
|
||||
private final Map<String, SeverityAndOccurrences> myScopeToAverageSeverityMap = new HashMap<>();
|
||||
|
||||
private String myDefaultScopeName;
|
||||
|
||||
@@ -456,7 +457,7 @@ public class InspectionsConfigTreeTable extends TreeTable {
|
||||
if (myScopeToAverageSeverityMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Map<String, HighlightSeverity> result = new HashMap<String, HighlightSeverity>();
|
||||
final Map<String, HighlightSeverity> result = new HashMap<>();
|
||||
final Map.Entry<String, SeverityAndOccurrences> entry = ContainerUtil.getFirstItem(myScopeToAverageSeverityMap.entrySet());
|
||||
result.put(entry.getKey(), entry.getValue().getPrimarySeverity());
|
||||
if (myScopeToAverageSeverityMap.size() == 1) {
|
||||
|
||||
@@ -17,17 +17,11 @@ package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
|
||||
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.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;
|
||||
import com.intellij.ide.highlighter.ProjectFileType;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
@@ -78,7 +72,6 @@ import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl;
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl;
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
@@ -97,7 +90,6 @@ import com.intellij.util.indexing.UnindexedFilesUpdater;
|
||||
import com.intellij.util.lang.CompoundRuntimeException;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashMap;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -341,26 +333,11 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue();
|
||||
}
|
||||
|
||||
protected void enableInspectionTools(@NotNull Class<? extends InspectionProfileEntry>[] classes) {
|
||||
final InspectionProfileEntry[] tools = new InspectionProfileEntry[classes.length];
|
||||
|
||||
final List<InspectionEP> eps = ContainerUtil.newArrayList();
|
||||
ContainerUtil.addAll(eps, Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION));
|
||||
ContainerUtil.addAll(eps, Extensions.getExtensions(InspectionEP.GLOBAL_INSPECTION));
|
||||
|
||||
next:
|
||||
for (int i = 0; i < classes.length; i++) {
|
||||
for (InspectionEP ep : eps) {
|
||||
if (classes[i].getName().equals(ep.implementationClass)) {
|
||||
tools[i] = ep.instantiateTool();
|
||||
continue next;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unable to find extension point for " + classes[i].getName());
|
||||
}
|
||||
|
||||
enableInspectionTools(tools);
|
||||
}
|
||||
//protected void enableInspectionTools(@NotNull Class<? extends InspectionProfileEntry>[] classes) {
|
||||
// for (InspectionProfileEntry tool : InspectionTestUtil.instantiateTools(Arrays.asList(classes))) {
|
||||
// enableInspectionTool(tool);
|
||||
// }
|
||||
//}
|
||||
|
||||
protected void enableInspectionTools(@NotNull InspectionProfileEntry... tools) {
|
||||
for (InspectionProfileEntry tool : tools) {
|
||||
@@ -368,37 +345,12 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableInspectionTool(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
enableInspectionTool(getProject(), toolWrapper, myTestRootDisposable);
|
||||
}
|
||||
//protected void enableInspectionTool(@NotNull InspectionToolWrapper toolWrapper) {
|
||||
// InspectionsKt.enableInspectionTool(getProject(), toolWrapper, myTestRootDisposable);
|
||||
//}
|
||||
|
||||
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
|
||||
enableInspectionTool(getProject(), InspectionToolRegistrar.wrapTool(tool), myTestRootDisposable);
|
||||
}
|
||||
|
||||
public static void enableInspectionTool(@NotNull Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull 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(() -> {
|
||||
InspectionToolWrapper existingWrapper = profile.getInspectionTool(shortName, project);
|
||||
if (existingWrapper == null || existingWrapper.isInitialized() != toolWrapper.isInitialized() || toolWrapper.isInitialized() && toolWrapper.getTool() != existingWrapper.getTool()) {
|
||||
profile.addTool(project, toolWrapper, new THashMap<>());
|
||||
}
|
||||
profile.enableTool(shortName, project);
|
||||
|
||||
Disposer.register(disposable, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
profile.disableTool(shortName, project);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
});
|
||||
InspectionsKt.enableInspectionTool(getProject(), tool, myTestRootDisposable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+10
-23
@@ -38,7 +38,6 @@ import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
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.facet.Facet;
|
||||
import com.intellij.facet.FacetManager;
|
||||
@@ -338,7 +337,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), getTestRootDisposable());
|
||||
InspectionsKt.enableInspectionTool(getProject(), inspection, getTestRootDisposable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,10 +348,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
|
||||
@Override
|
||||
public void enableInspections(@NotNull Collection<Class<? extends LocalInspectionTool>> inspections) {
|
||||
List<LocalInspectionTool> tools = new SmartList<>();
|
||||
for (Class<? extends LocalInspectionTool> clazz : inspections) {
|
||||
tools.add(ReflectionUtil.newInstance(clazz));
|
||||
}
|
||||
List<InspectionProfileEntry> tools = InspectionTestUtil.instantiateTools(inspections);
|
||||
enableInspections(tools.toArray(new LocalInspectionTool[tools.size()]));
|
||||
}
|
||||
|
||||
@@ -365,24 +361,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableInspections(@NotNull InspectionToolProvider... providers) {
|
||||
List<LocalInspectionTool> tools = new ArrayList<>();
|
||||
for (InspectionToolProvider provider : providers) {
|
||||
for (Class<?> clazz : provider.getInspectionClasses()) {
|
||||
try {
|
||||
Object o = clazz.getConstructor().newInstance();
|
||||
if (o instanceof LocalInspectionTool) {
|
||||
LocalInspectionTool inspection = (LocalInspectionTool)o;
|
||||
tools.add(inspection);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Cannot instantiate " + clazz, e);
|
||||
}
|
||||
}
|
||||
public void enableInspections(@NotNull InspectionToolProvider... providers) {
|
||||
List<Class<? extends LocalInspectionTool>> classes = JBIterable.of(providers)
|
||||
.flatten((o) -> Arrays.asList(o.getInspectionClasses()))
|
||||
.transform((Function<Class, Class<? extends LocalInspectionTool>>)o ->
|
||||
LocalInspectionTool.class.isAssignableFrom(o) ? (Class<? extends LocalInspectionTool>) o : null)
|
||||
.filter(Conditions.notNull())
|
||||
.toList();
|
||||
enableInspections(classes);
|
||||
}
|
||||
enableInspections(tools.toArray(new LocalInspectionTool[tools.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long testHighlighting(final boolean checkWarnings,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.testFramework
|
||||
|
||||
import com.intellij.analysis.AnalysisScope
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.codeInspection.LocalInspectionTool
|
||||
import com.intellij.codeInspection.ex.*
|
||||
@@ -25,6 +26,7 @@ import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
|
||||
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests
|
||||
import com.intellij.util.ReflectionUtil
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.util.*
|
||||
|
||||
@@ -32,24 +34,19 @@ fun configureInspections(tools: Array<InspectionProfileEntry>,
|
||||
project: Project,
|
||||
parentDisposable: Disposable): InspectionProfileImpl {
|
||||
val profile = InspectionProfileImpl.createSimple(UUID.randomUUID().toString(), project, tools.map { InspectionToolRegistrar.wrapTool(it) })
|
||||
// profile.disableToolByDefault(disabledInspections, project)
|
||||
|
||||
val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
|
||||
|
||||
val oldRootProfile = profileManager.currentProfile
|
||||
// we don't restore old project profile because in tests it must be in any case null - app default profile
|
||||
Disposer.register(parentDisposable, Disposable {
|
||||
profileManager.deleteProfile(profile)
|
||||
profileManager.setCurrentProfile(oldRootProfile)
|
||||
clearAllToolsIn(InspectionProfileImpl.getDefaultProfile(), project)
|
||||
profileManager.setCurrentProfile(null)
|
||||
clearAllToolsIn(InspectionProfileImpl.getDefaultProfile())
|
||||
})
|
||||
|
||||
profileManager.setRootProfile(profile.name)
|
||||
InspectionProfileImpl.initAndDo<Any>({
|
||||
profileManager.addProfile(profile)
|
||||
profile.initInspectionTools(project)
|
||||
profileManager.setCurrentProfile(profile)
|
||||
null
|
||||
})
|
||||
runInInitMode {
|
||||
profileManager.addProfile(profile)
|
||||
profile.initInspectionTools(project)
|
||||
profileManager.setCurrentProfile(profile)
|
||||
}
|
||||
return profile
|
||||
}
|
||||
|
||||
@@ -58,23 +55,27 @@ fun configureInspections(tools: Array<InspectionProfileEntry>,
|
||||
fun createGlobalContextForTool(scope: AnalysisScope,
|
||||
project: Project,
|
||||
toolWrappers: List<InspectionToolWrapper<*, *>> = emptyList()): GlobalInspectionContextForTests {
|
||||
val profile = InspectionProfileImpl.createSimple("test", project, toolWrappers)
|
||||
val context = object : GlobalInspectionContextForTests(project, (InspectionManagerEx.getInstance(project) as InspectionManagerEx).contentManager) {
|
||||
override fun getUsedTools(): List<Tools> {
|
||||
return InspectionProfileImpl.initAndDo {
|
||||
runInInitMode {
|
||||
val profile = InspectionProfileImpl.createSimple("test", project, toolWrappers)
|
||||
val context = object : GlobalInspectionContextForTests(project, (InspectionManagerEx.getInstance(project) as InspectionManagerEx).contentManager) {
|
||||
override fun getUsedTools(): List<Tools> {
|
||||
for (tool in toolWrappers) {
|
||||
profile.enableTool(tool.shortName, project)
|
||||
}
|
||||
profile.getAllEnabledInspectionTools(project)
|
||||
return profile.getAllEnabledInspectionTools(project)
|
||||
}
|
||||
}
|
||||
context.currentScope = scope
|
||||
return context
|
||||
}
|
||||
context.currentScope = scope
|
||||
return context
|
||||
}
|
||||
|
||||
private fun clearAllToolsIn(profile: InspectionProfileImpl, project: Project) {
|
||||
for (state in profile.getAllTools(project)) {
|
||||
private fun clearAllToolsIn(profile: InspectionProfileImpl) {
|
||||
if (!profile.wasInitialized()) {
|
||||
return
|
||||
}
|
||||
|
||||
for (state in profile.getAllTools(null)) {
|
||||
val wrapper = state.tool
|
||||
if (wrapper.extension != null) {
|
||||
// make it not initialized
|
||||
@@ -85,4 +86,36 @@ private fun clearAllToolsIn(profile: InspectionProfileImpl, project: Project) {
|
||||
|
||||
fun ProjectInspectionProfileManager.createProfile(localInspectionTool: LocalInspectionTool, disposable: Disposable): InspectionProfileImpl {
|
||||
return configureInspections(arrayOf(localInspectionTool), project, disposable)
|
||||
}
|
||||
|
||||
fun enableInspectionTool(project: Project, tool: InspectionProfileEntry, disposable: Disposable) = enableInspectionTool(project, InspectionToolRegistrar.wrapTool(tool), disposable)
|
||||
|
||||
private fun enableInspectionTool(project: Project, toolWrapper: InspectionToolWrapper<*, *>, disposable: Disposable) {
|
||||
val profile = ProjectInspectionProfileManager.getInstanceImpl(project).currentProfile
|
||||
val shortName = toolWrapper.shortName
|
||||
val key = HighlightDisplayKey.find(shortName)
|
||||
if (key == null) {
|
||||
HighlightDisplayKey.register(shortName, toolWrapper.displayName, toolWrapper.id)
|
||||
}
|
||||
|
||||
runInInitMode {
|
||||
val existingWrapper = profile.getInspectionTool(shortName, project)
|
||||
if (existingWrapper == null || existingWrapper.isInitialized != toolWrapper.isInitialized || toolWrapper.isInitialized && toolWrapper.tool !== existingWrapper.tool) {
|
||||
profile.addTool(project, toolWrapper, THashMap<String, List<String>>())
|
||||
}
|
||||
profile.enableTool(shortName, project)
|
||||
|
||||
Disposer.register(disposable, Disposable { profile.disableTool(shortName, project) })
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> runInInitMode(runnable: () -> T): T {
|
||||
val old = InspectionProfileImpl.INIT_INSPECTIONS
|
||||
try {
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = true
|
||||
return runnable()
|
||||
}
|
||||
finally {
|
||||
InspectionProfileImpl.INIT_INSPECTIONS = old
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user