diff --git a/.idea/libraries/memoryfilesystem.xml b/.idea/libraries/memoryfilesystem.xml
new file mode 100644
index 000000000000..343101b9af73
--- /dev/null
+++ b/.idea/libraries/memoryfilesystem.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build/order.txt b/build/order.txt
index d1730e8a0780..75cfa9c4af0d 100644
--- a/build/order.txt
+++ b/build/order.txt
@@ -1143,7 +1143,7 @@ com/intellij/ide/ui/LafManagerImpl$IdeaLaf.class:/lib/idea.jar
com/intellij/ide/ui/LafManagerImpl$1.class:/lib/idea.jar
com/intellij/ide/ui/LafManagerImpl$2.class:/lib/idea.jar
com/intellij/diagnostic/PerformanceWatcher.class:/lib/idea.jar
-com/intellij/openapi/options/SchemesManagerFactory.class:/lib/openapi.jar
+com/intellij/openapi/options/SchemeManagerFactory.class:/lib/openapi.jar
com/intellij/openapi/components/SettingsSavingComponent.class:/lib/openapi.jar
com/intellij/openapi/options/SchemesManager.class:/lib/openapi.jar
com/intellij/ide/XmlRpcServer.class:/lib/openapi.jar
diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java
index 4d8bd26f32ee..5185e48d5dfb 100644
--- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java
+++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java
@@ -70,15 +70,14 @@ import org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfig
import java.io.File;
import java.util.*;
+import static org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfigurationSerializer.DEFAULT_WILDCARD_PATTERNS;
+
@State(name = "CompilerConfiguration", storages = @Storage("compiler.xml"))
public class CompilerConfigurationImpl extends CompilerConfiguration implements PersistentStateComponent, ProjectComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.CompilerConfiguration");
public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home";
public static final int DEFAULT_BUILD_PROCESS_HEAP_SIZE = 700;
- private static final List DEFAULT_WILDCARD_PATTERNS =
- Arrays.asList("!?*.java", "!?*.form", "!?*.class", "!?*.groovy", "!?*.scala", "!?*.flex", "!?*.kt", "!?*.clj", "!?*.aj");
-
private BackendCompiler myDefaultJavaCompiler;
private State myState = new State();
@@ -139,7 +138,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
@Override
public Element getState() {
- final boolean savingStateInNewFormatAllowed = Registry.is("saving.state.in.new.format.is.allowed", false);
+ final boolean savingStateInNewFormatAllowed = Registry.is("saving.state.in.new.format.is.allowed", true);
Element state = new Element("state");
XmlSerializer.serializeInto(myState, state, new SkipDefaultValuesSerializationFilters() {
diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java
index de244d3c0800..7388509bd104 100644
--- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java
+++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.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.
@@ -620,10 +620,6 @@ public class CompilerTask extends Task.Backgroundable {
return !myUserAcceptedCancel && !myIsApplicationExitingOrProjectClosing && myIndicator.isRunning();
}
- @Override
- public void projectOpened(Project project) {
- }
-
@Override
public void projectClosed(Project project) {
if (project.equals(myProject) && myContent != null) {
@@ -652,4 +648,3 @@ public class CompilerTask extends Task.Backgroundable {
}
}
}
-
\ No newline at end of file
diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java
index 0c9bec8c2cf8..b55549968d90 100644
--- a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java
+++ b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java
@@ -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.
@@ -232,7 +232,7 @@ public class InspectionValidatorWrapper implements Validator {
}
- final InspectionProfile inspectionProfile = myProfileManager.getInspectionProfile();
+ final InspectionProfile inspectionProfile = myProfileManager.getCurrentProfile();
for (final LocalInspectionTool inspectionTool : inspections) {
if (!checkUnderReadAction(item, context, () -> {
final PsiFile file = item.getPsiFile();
diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
index a3a350eae34c..3dec80734559 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java
@@ -123,7 +123,7 @@ class PostHighlightingVisitor {
ApplicationManager.getApplication().assertReadAccessAllowed();
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME);
@@ -141,7 +141,7 @@ class PostHighlightingVisitor {
void collectHighlights(@NotNull HighlightInfoHolder result, @NotNull ProgressIndicator progress) {
DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
FileStatusMap fileStatusMap = daemonCodeAnalyzer.getFileStatusMap();
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
boolean unusedSymbolEnabled = profile.isToolEnabled(myDeadCodeKey, myFile);
GlobalUsageHelper globalUsageHelper = myRefCountHolder.getGlobalUsageHelper(myFile, myDeadCodeInspection, unusedSymbolEnabled);
@@ -194,7 +194,7 @@ class PostHighlightingVisitor {
}
private boolean isUnusedImportEnabled(HighlightDisplayKey unusedImportKey) {
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
if (profile.isToolEnabled(unusedImportKey, myFile) &&
myFile instanceof PsiJavaFile &&
HighlightingLevelManager.getInstance(myProject).shouldHighlight(myFile)) {
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java
index 45692e9006b7..3c2ff0ef3ea3 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java
@@ -19,11 +19,13 @@ import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInsight.daemon.impl.RemoveSuppressWarningAction;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase;
-import com.intellij.codeInspection.ex.*;
+import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
+import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
+import com.intellij.codeInspection.ex.InspectionToolWrapper;
+import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.reference.*;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
@@ -88,7 +90,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
globalContext.getRefManager().iterate(new RefJavaVisitor() {
@Override public void visitClass(@NotNull RefClass refClass) {
if (!globalContext.shouldCheck(refClass, RedundantSuppressInspectionBase.this)) return;
- CommonProblemDescriptor[] descriptors = checkElement(refClass, manager, globalContext.getProject());
+ CommonProblemDescriptor[] descriptors = checkElement(refClass, manager);
if (descriptors != null) {
for (CommonProblemDescriptor descriptor : descriptors) {
if (descriptor instanceof ProblemDescriptor) {
@@ -108,13 +110,13 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
}
@Nullable
- private CommonProblemDescriptor[] checkElement(@NotNull RefClass refEntity, @NotNull InspectionManager manager, @NotNull Project project) {
+ private CommonProblemDescriptor[] checkElement(@NotNull RefClass refEntity, @NotNull InspectionManager manager) {
final PsiClass psiClass = refEntity.getElement();
if (psiClass == null) return null;
- return checkElement(psiClass, manager, project);
+ return checkElement(psiClass, manager);
}
- public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull final InspectionManager manager, @NotNull Project project) {
+ public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull final InspectionManager manager) {
final Map> suppressedScopes = new THashMap>();
psiElement.accept(new JavaRecursiveElementWalkingVisitor() {
@Override public void visitModifierList(PsiModifierList list) {
@@ -159,14 +161,14 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
});
if (suppressedScopes.values().isEmpty()) return null;
- // have to visit all file from scratch since inspections can be written in any perversive way including checkFile() overriding
+ // have to visit all file from scratch since inspections can be written in any pervasive way including checkFile() overriding
Map suppressedTools = new THashMap();
InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager);
for (Collection ids : suppressedScopes.values()) {
for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) {
final String shortName = iterator.next().trim();
for (InspectionToolWrapper toolWrapper : toolWrappers) {
- if (toolWrapper instanceof LocalInspectionToolWrapper &&
+ if (toolWrapper instanceof LocalInspectionToolWrapper &&
(((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName) ||
shortName.equals(((LocalInspectionToolWrapper)toolWrapper).getTool().getAlternativeID()))) {
if (((LocalInspectionToolWrapper)toolWrapper).isUnfair()) {
@@ -179,7 +181,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
}
else if (toolWrapper.getShortName().equals(shortName)) {
//ignore global unused as it won't be checked anyway
- if (toolWrapper instanceof LocalInspectionToolWrapper ||
+ if (toolWrapper instanceof LocalInspectionToolWrapper ||
toolWrapper instanceof GlobalInspectionToolWrapper && !isGlobalInspectionRunCustomly(toolWrapper.getTool())) {
suppressedTools.put(toolWrapper, shortName);
}
@@ -222,29 +224,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
descriptors = new ArrayList();
globalContext.getRefManager().iterate(new RefVisitor() {
@Override public void visitElement(@NotNull RefEntity refEntity) {
- CommonProblemDescriptor[]
- descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() {
- @Nullable
- @Override
- public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
- return CommonProblemDescriptor.EMPTY_ARRAY;
- }
-
- @Override
- public void ignoreElement(@NotNull RefEntity refEntity) {
-
- }
-
- @Override
- public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
- int i =0;
- }
-
- @Override
- public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
- return null;
- }
- });
+ CommonProblemDescriptor[] descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() {});
if (descriptors1 != null) {
ContainerUtil.addAll(descriptors, descriptors1);
}
@@ -330,14 +310,10 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
}
protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) {
- ModifiableModel model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel();
- InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile)model);
- profile.init(manager.getProject());
-
- return profile.getInspectionTools(psiElement);
+ return InspectionProjectProfileManager.getInstance(manager.getProject()).getCurrentProfile().getModifiableModel()
+ .getInspectionTools(psiElement);
}
-
@Override
@Nullable
public QuickFix getQuickFix(final String hint) {
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java
index 28768a4e9aff..692761d7d9da 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java
@@ -84,7 +84,7 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen
protected final Project myProject;
private long myLastModificationCount = -1;
- public EntryPointsManagerBase(final Project project) {
+ public EntryPointsManagerBase(@NotNull Project project) {
myProject = project;
myTemporaryEntryPoints = new HashSet();
myPersistentEntryPoints = new LinkedHashMap(); // To keep the order between readExternal to writeExternal
@@ -100,11 +100,13 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen
if (ADDITIONAL_ANNOS != null) {
ADDITIONAL_ANNOS = null;
UIUtil.invokeLaterIfNeeded(() -> {
- if (ApplicationManager.getApplication().isDisposed()) return;
- InspectionProfileManager.getInstance().fireProfileChanged(null);
+ if (!ApplicationManager.getApplication().isDisposed()) {
+ InspectionProfileManager.getInstance().fireProfileChanged(null);
+ }
});
}
- DaemonCodeAnalyzer.getInstance(project).restart(); // annotations changed
+ // annotations changed
+ DaemonCodeAnalyzer.getInstance(myProject).restart();
}
}, false, this);
}
@@ -246,8 +248,8 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen
}
else if (refConstructors.size() > 1) {
// Many constructors here. Need to ask user which ones are used
- for (int i = 0; i < refConstructors.size(); i++) {
- addEntryPoint(refConstructors.get(i), isPersistent);
+ for (RefMethod refConstructor : refConstructors) {
+ addEntryPoint(refConstructor, isPersistent);
}
}
}
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java
index ebe8490b90a2..dff7bdb91b7d 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.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.
@@ -63,7 +63,7 @@ public class SpecialAnnotationsUtilBase {
static void doQuickFixInternal(@NotNull Project project, @NotNull List targetList, @NotNull String qualifiedName) {
targetList.add(qualifiedName);
Collections.sort(targetList);
- final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
//correct save settings
//TODO lesya
diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java
index 884aa6684388..17aed5039e96 100644
--- a/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java
+++ b/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java
@@ -83,7 +83,7 @@ class AccessCanBeTightenedInspection extends BaseJavaBatchLocalInspectionTool {
public MyVisitor(@NotNull ProblemsHolder holder) {
myHolder = holder;
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(holder.getProject()).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(holder.getProject()).getCurrentProfile();
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, holder.getFile());
myDeadCodeInspection = tool == null ? new UnusedDeclarationInspectionBase() : tool;
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java
index 12a96c284555..661a1ca45cf7 100644
--- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java
+++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java
@@ -46,7 +46,6 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ProcessingContext;
-import com.intellij.util.Processor;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CharArrayUtil;
@@ -312,7 +311,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
}
InspectionProfile inspectionProfile =
- InspectionProjectProfileManager.getInstance(position.getProject()).getInspectionProfile();
+ InspectionProjectProfileManager.getInstance(position.getProject()).getCurrentProfile();
JavaDocLocalInspection inspection =
(JavaDocLocalInspection)inspectionProfile.getUnwrappedTool(JavaDocLocalInspectionBase.SHORT_NAME, position);
if (inspection != null) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
index d7b001b5d122..ecdea37b6e68 100644
--- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
+++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java
@@ -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.
@@ -112,7 +112,7 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa
parent.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
false, HighlightInfoProcessor.getEmpty());
final InspectionProfile inspectionProfile =
- InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
for (PsiLiteralExpression target : targets) {
final Object value = target.getValue();
if (!(value instanceof String)) {
diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java
index 9859acba2f17..17ee364092fe 100644
--- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java
+++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.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.
@@ -654,7 +654,7 @@ public class QuickFixFactoryImpl extends QuickFixFactory {
@Override
public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) {
Project myProject = parameter.getProject();
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
UnusedParametersInspection unusedParametersInspection =
(UnusedParametersInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME, parameter);
LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null);
diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
index 6a749173e3ed..19483d3ba301 100644
--- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
+++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java
@@ -10,7 +10,6 @@ import com.intellij.codeInspection.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Condition;
import com.intellij.pom.Navigatable;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
@@ -398,7 +397,7 @@ public class JavaDocLocalInspection extends JavaDocLocalInspectionBase {
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
myInspection.registerAdditionalTag(myTag);
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
InspectionProfileManager.getInstance().fireProfileChanged(profile);
}
diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt
index 1f3a138fea47..3252c3e6e8b9 100644
--- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt
+++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt
@@ -118,7 +118,7 @@ class JavadocHtmlLintAnnotator(private val manual: Boolean = false) :
file.virtualFile != null && ProjectFileIndex.SERVICE.getInstance(file.project).isInSourceContent(file.virtualFile)
private fun isToolEnabled(file: PsiFile) =
- manual || InspectionProjectProfileManager.getInstance(file.project).inspectionProfile.isToolEnabled(key.value, file)
+ manual || InspectionProjectProfileManager.getInstance(file.project).currentProfile.isToolEnabled(key.value, file)
private fun createTempFile(bytes: ByteArray): File {
val tempFile = FileUtil.createTempFile(File(PathManager.getTempPath()), "javadocHtmlLint", ".java")
diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java
index 76ef138fa2da..21f6ebcaa1c1 100644
--- a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java
+++ b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java
@@ -54,7 +54,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten
private void readExternal(final Element element) {
String level = element.getAttributeValue(LANGUAGE_LEVEL);
if (level == null) {
- myLanguageLevel = Registry.is("saving.state.in.new.format.is.allowed", false) ? null : migrateFromIdea7(element);
+ myLanguageLevel = Registry.is("saving.state.in.new.format.is.allowed", true) ? null : migrateFromIdea7(element);
}
else {
myLanguageLevel = LanguageLevel.valueOf(level);
@@ -86,7 +86,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten
element.setAttribute(DEFAULT_ATTRIBUTE, Boolean.toString(aBoolean));
}
- if (!Registry.is("saving.state.in.new.format.is.allowed", false)) {
+ if (!Registry.is("saving.state.in.new.format.is.allowed", true)) {
writeAttributesForIdea7(element);
}
}
diff --git a/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java b/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java
index 927f464b6e64..bee53a8a5070 100644
--- a/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java
+++ b/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java
@@ -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.
@@ -22,16 +22,16 @@ package com.intellij.profile.codeInspection;
import com.intellij.codeInsight.daemon.InspectionProfileConvertor;
import com.intellij.codeInsight.daemon.JavaAwareInspectionProfileCoverter;
-import com.intellij.codeInspection.ex.InspectionProfileManagerImpl;
+import com.intellij.codeInspection.ex.ApplicationInspectionProfileManager;
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
-import com.intellij.openapi.options.SchemesManagerFactory;
+import com.intellij.openapi.options.SchemeManagerFactory;
import com.intellij.util.messages.MessageBus;
-public class JavaAwareInspectionProfileManager extends InspectionProfileManagerImpl {
+public class JavaAwareInspectionProfileManager extends ApplicationInspectionProfileManager {
public JavaAwareInspectionProfileManager(InspectionToolRegistrar registrar,
- SchemesManagerFactory schemesManagerFactory,
+ SchemeManagerFactory schemeManagerFactory,
MessageBus messageBus) {
- super(registrar, schemesManagerFactory, messageBus);
+ super(registrar, schemeManagerFactory, messageBus);
}
@Override
diff --git a/java/java-tests/java-tests.iml b/java/java-tests/java-tests.iml
index 1008e1276345..3edaf9d0e1fc 100644
--- a/java/java-tests/java-tests.iml
+++ b/java/java-tests/java-tests.iml
@@ -53,5 +53,8 @@
+
+
+
\ No newline at end of file
diff --git a/java/java-tests/testData/inspection/converter/options/options.after.xml b/java/java-tests/testData/inspection/converter/options/options.after.xml
deleted file mode 100644
index 321bff7d639f..000000000000
--- a/java/java-tests/testData/inspection/converter/options/options.after.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
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/HighlightSeverityTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java
index b1a8368ec333..f70060746615 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java
@@ -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);
}
}
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 9f94acbbdd8e..def1ddf09142 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java
@@ -114,8 +114,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/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java
index d88664a0cbd5..b1949d5b722f 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java
@@ -1278,8 +1278,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
public void testDaemonIgnoresFrameDeactivation() throws Throwable {
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save
- final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance();
- inspectionProfileManager.setRootProfile(InspectionProfileImpl.getDefaultProfile().getName()); // reset to default profile from the custom one to avoid unnecessary save
+ InspectionProfileManager.getInstance().setRootProfile(InspectionProfileImpl.getDefaultProfile().getName()); // reset to default profile from the custom one to avoid unnecessary save
String text = "class S { ArrayListXXX x;}";
configureByText(StdFileTypes.JAVA, text);
@@ -1773,7 +1772,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
PsiFile use = createFile("Use.java", "public class Use { { X.ffffffffffffff(); } }");
configureByExistingFile(use.getVirtualFile());
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
HighlightDisplayKey myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME);
if (myDeadCodeKey == null) {
myDeadCodeKey = HighlightDisplayKey.register(UnusedDeclarationInspectionBase.SHORT_NAME, UnusedDeclarationInspectionBase.DISPLAY_NAME);
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java
index 80b5f6256dd4..3f4f6f80be99 100644
--- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2011 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.
@@ -82,7 +82,7 @@ public class RemoveRedundantUncheckedSuppressionTest extends LightQuickFixParame
private void checkMember(PsiMember member, RedundantSuppressInspection inspection, ProblemsHolder holder) {
final ProblemDescriptor[] problemDescriptors =
- (ProblemDescriptor[])inspection.checkElement(member, InspectionManager.getInstance(getProject()), getProject());
+ (ProblemDescriptor[])inspection.checkElement(member, InspectionManager.getInstance(getProject()));
if (problemDescriptors != null) {
for (ProblemDescriptor problemDescriptor : problemDescriptors) {
holder.registerProblem(problemDescriptor);
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
deleted file mode 100644
index c8710e6e290c..000000000000
--- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2000-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.codeInspection;
-
-import com.intellij.JavaTestUtil;
-import com.intellij.codeInspection.ex.InspectionProfileImpl;
-import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.JDOMUtil;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
-import com.intellij.testFramework.LightIdeaTestCase;
-import com.intellij.testFramework.PlatformTestUtil;
-import org.jdom.Element;
-
-import java.io.File;
-
-/**
- * @author anna
- * Date: 13-Apr-2009
- */
-public class InspectionProfilesConverterTest extends LightIdeaTestCase {
- public void testOptions() throws Exception {
- doTest("options");
- }
-
- public void testScope() throws Exception {
- doTest("scope");
- }
-
- private static void doTest(final String dirName) throws Exception {
- InspectionProfileImpl.INIT_INSPECTIONS = true;
- try {
- final String relativePath = "/inspection/converter/";
- final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr");
- for (Element element : JDOMUtil.load(projectFile).getChildren("component")) {
- if (Comparing.strEqual(element.getAttributeValue("name"), "InspectionProjectProfileManager")) {
- final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject());
- profileManager.loadState(element);
-
- Element configElement = profileManager.getState();
- final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml");
- PlatformTestUtil.assertElementsEqual(JDOMUtil.load(file), configElement);
- break;
- }
- }
- }
- finally {
- InspectionProfileImpl.INIT_INSPECTIONS = false;
- }
- }
-}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java
index d350cbb28ecd..87f0012eaeba 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java
@@ -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.
@@ -44,6 +44,7 @@ import com.intellij.util.ui.tree.TreeUtil;
import com.siyeh.ig.bugs.EqualsWithItselfInspection;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
@@ -71,8 +72,8 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
final InspectionProfileImpl profile = new InspectionProfileImpl("test") {
@Override
- public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
- return Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME);
+ public boolean isToolEnabled(@Nullable final HighlightDisplayKey key, PsiElement element) {
+ return key != null && Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME);
}
@Override
@@ -83,7 +84,7 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
@Override
@NotNull
- public ModifiableModel getModifiableModel() {
+ public InspectionProfileImpl getModifiableModel() {
return new InspectionProfileImpl("test") {
@Override
@NotNull
@@ -92,8 +93,8 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
}
@Override
- public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
- return Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME);
+ public boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element) {
+ return key != null && Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME);
}
};
}
@@ -113,7 +114,7 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
private Map>> parse() throws IOException {
final String moduleName = getModule().getName();
- final Map>> map = new HashMap>>();
+ final Map>> map = new HashMap<>();
final File res = new File(PathManagerEx.getTestDataPath(), getTestPath() + File.separator + "res");
final File[] files = res.listFiles();
assert files != null;
@@ -133,11 +134,15 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase {
@Override
protected void tearDown() throws Exception {
- Disposer.dispose(myView);
- myView = null;
- myUnusedToolWrapper = null;
- myDataFlowToolWrapper = null;
- super.tearDown();
+ try {
+ Disposer.dispose(myView);
+ myView = null;
+ myUnusedToolWrapper = null;
+ myDataFlowToolWrapper = null;
+ }
+ finally {
+ super.tearDown();
+ }
}
public void testOfflineWithInvalid() throws Exception {
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java
deleted file mode 100644
index f1ebda035c50..000000000000
--- a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.codeInspection;
-
-import com.intellij.codeInspection.ex.InspectionProfileImpl;
-import com.intellij.codeInspection.ex.InspectionProfileTest;
-import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
-import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.project.ProjectManager;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
-import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
-import com.intellij.testFramework.LightIdeaTestCase;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author Dmitry Avdeev
- * Date: 5/10/12
- */
-public class SingleInspectionProfilePanelTest extends LightIdeaTestCase {
- // see IDEA-85700
- public void testSettingsModification() throws Exception {
- Project project = ProjectManager.getInstance().getDefaultProject();
- InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project);
- InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE);
- profile.initInspectionTools(project);
-
- InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
- SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(profileManager, PROFILE, model, profile);
- panel.setVisible(true);
- panel.reset();
-
- JavaDocLocalInspection tool = getInspection(model);
- assertEquals("", tool.myAdditionalJavadocTags);
- tool.myAdditionalJavadocTags = "foo";
- model.setModified(true);
- panel.apply();
- assertEquals(1, InspectionProfileTest.countInitializedTools(model));
-
- assertEquals("foo", getInspection(profile).myAdditionalJavadocTags);
- panel.disposeUI();
- }
-
- public void testModifyInstantiatedTool() throws Exception {
- Project project = ProjectManager.getInstance().getDefaultProject();
- InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project);
- InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE);
- profile.initInspectionTools(project);
-
- JavaDocLocalInspection originalTool = getInspection(profile);
- originalTool.myAdditionalJavadocTags = "foo";
-
- InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
-
- SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(profileManager, PROFILE, model, profile);
- panel.setVisible(true);
- panel.reset();
- assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1, InspectionProfileTest.countInitializedTools(model));
-
- JavaDocLocalInspection copyTool = getInspection(model);
- copyTool.myAdditionalJavadocTags = "bar";
-
- model.setModified(true);
- panel.apply();
- assertEquals(1, InspectionProfileTest.countInitializedTools(model));
-
- assertEquals("bar", getInspection(profile).myAdditionalJavadocTags);
- panel.disposeUI();
- }
-
- public void testDoNotChangeSettingsOnCancel() throws Exception {
- Project project = ProjectManager.getInstance().getDefaultProject();
- InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project);
- InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE);
- profile.initInspectionTools(project);
-
- JavaDocLocalInspection originalTool = getInspection(profile);
- assertEquals("", originalTool.myAdditionalJavadocTags);
-
- InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
- JavaDocLocalInspection copyTool = getInspection(model);
- copyTool.myAdditionalJavadocTags = "foo";
- // this change IS NOT COMMITTED
-
- assertEquals("", getInspection(profile).myAdditionalJavadocTags);
- }
-
- private JavaDocLocalInspection getInspection(InspectionProfileImpl profile) {
- LocalInspectionToolWrapper original = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName(), getProject());
- assert original != null;
- return (JavaDocLocalInspection)original.getTool();
- }
-
- @Override
- public void setUp() throws Exception {
- InspectionProfileImpl.INIT_INSPECTIONS = true;
- super.setUp();
- }
-
- @Override
- public void tearDown() throws Exception {
- InspectionProfileImpl.INIT_INSPECTIONS = false;
- super.tearDown();
- }
-
- private final JavaDocLocalInspection myInspection = new JavaDocLocalInspection();
-
- @NotNull
- @Override
- protected LocalInspectionTool[] configureLocalInspectionTools() {
- return new LocalInspectionTool[] {myInspection};
- }
-}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt
new file mode 100644
index 000000000000..5471f2a1d872
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInspection
+
+import com.intellij.codeInspection.ex.InspectionProfileImpl
+import com.intellij.codeInspection.ex.InspectionProfileTest
+import com.intellij.codeInspection.ex.LocalInspectionToolWrapper
+import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection
+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()
+
+ // see IDEA-85700
+ fun testSettingsModification() {
+ val project = ProjectManager.getInstance().defaultProject
+ val profile = configureInspections(arrayOf(myInspection), project, testRootDisposable)
+
+ val model = profile.modifiableModel
+ val panel = SingleInspectionProfilePanel(ProjectInspectionProfileManager.getInstanceImpl(project), profile.name, model, profile)
+ panel.isVisible = true
+ panel.reset()
+
+ val tool = getInspection(model)
+ assertEquals("", tool.myAdditionalJavadocTags)
+ tool.myAdditionalJavadocTags = "foo"
+ model.setModified(true)
+ panel.apply()
+ assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
+
+ assertThat(getInspection(profile).myAdditionalJavadocTags).isEqualTo("foo")
+ panel.disposeUI()
+ }
+
+ fun testModifyInstantiatedTool() {
+ val project = ProjectManager.getInstance().defaultProject
+ val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+ val profile = profileManager.createProfile(myInspection, testRootDisposable)
+ profile.initInspectionTools(project)
+
+ val originalTool = getInspection(profile)
+ originalTool.myAdditionalJavadocTags = "foo"
+
+ val model = profile.modifiableModel
+
+ val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile)
+ panel.isVisible = true
+ panel.reset()
+ TestCase.assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1,
+ InspectionProfileTest.countInitializedTools(model))
+
+ val copyTool = getInspection(model)
+ copyTool.myAdditionalJavadocTags = "bar"
+
+ model.setModified(true)
+ panel.apply()
+ assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1)
+
+ assertEquals("bar", getInspection(profile).myAdditionalJavadocTags)
+ panel.disposeUI()
+ }
+
+ fun testDoNotChangeSettingsOnCancel() {
+ val project = ProjectManager.getInstance().defaultProject
+ val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+ val profile = profileManager.createProfile(myInspection, testRootDisposable)
+ profile.initInspectionTools(project)
+
+ val originalTool = getInspection(profile)
+ assertThat(originalTool.myAdditionalJavadocTags).isEmpty()
+
+ val model = profile.modifiableModel
+ val copyTool = getInspection(model)
+ copyTool.myAdditionalJavadocTags = "foo"
+ // this change IS NOT COMMITTED
+
+ assertEquals("", getInspection(profile).myAdditionalJavadocTags)
+ }
+
+ private fun getInspection(profile: InspectionProfileImpl): JavaDocLocalInspection {
+ return (profile.getInspectionTool(myInspection.shortName, getProject()) as LocalInspectionToolWrapper?)!!.tool as JavaDocLocalInspection
+ }
+
+ override fun setUp() {
+ InspectionProfileImpl.INIT_INSPECTIONS = true
+ super.setUp()
+ }
+
+ override fun tearDown() {
+ InspectionProfileImpl.INIT_INSPECTIONS = false
+ super.tearDown()
+ }
+
+ override fun configureLocalInspectionTools() = arrayOf(myInspection)
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
index f3ee0565b991..d538376f91c2 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
@@ -28,17 +28,22 @@ import com.intellij.openapi.util.WriteExternalException;
import com.intellij.profile.Profile;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
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;
import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual;
/**
@@ -58,10 +63,15 @@ public class InspectionProfileTest extends LightIdeaTestCase {
@Override
protected void tearDown() throws Exception {
- super.tearDown();
- //noinspection AssignmentToStaticFieldFromInstanceMethod
- InspectionProfileImpl.INIT_INSPECTIONS = false;
- InspectionProfileManager.getInstance().deleteProfile(PROFILE);
+ try {
+ //noinspection SuperTearDownInFinally
+ super.tearDown();
+ }
+ finally {
+ //noinspection AssignmentToStaticFieldFromInstanceMethod
+ InspectionProfileImpl.INIT_INSPECTIONS = false;
+ InspectionProfileManager.getInstance().deleteProfile(PROFILE);
+ }
}
public void testCopyProjectProfile() throws Exception {
@@ -70,16 +80,14 @@ public class InspectionProfileTest extends LightIdeaTestCase {
profile.readExternal(element);
final ModifiableModel model = profile.getModifiableModel();
model.commit();
- final Element copy = new Element("inspections");
- profile.writeExternal(copy);
- assertElementsEqual(element, copy);
+ assertElementsEqual(element, serializeProfile(profile));
}
private static InspectionProfileImpl createProfile() {
- return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile());
+ return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile(), null);
}
private static InspectionProfileImpl createProfile(@NotNull InspectionProfileImpl base) {
- return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), base);
+ return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), base, null);
}
public void testSameNameSharedProfile() throws Exception {
@@ -87,16 +95,16 @@ public class InspectionProfileTest extends LightIdeaTestCase {
InspectionProfileImpl localProfile = createProfile();
profileManager.updateProfile(localProfile);
- InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(getProject());
+ ProjectInspectionProfileManager projectProfileManager = ProjectInspectionProfileManager.getInstanceImpl(getProject());
try {
//normally on open project profile wrappers are init for both managers
profileManager.updateProfile(localProfile);
InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), projectProfileManager,
- InspectionProfileImpl.getDefaultProfile());
+ InspectionProfileImpl.getDefaultProfile(), null);
projectProfileManager.updateProfile(profile);
- projectProfileManager.setProjectProfile(profile.getName());
+ projectProfileManager.setRootProfile(profile.getName());
- assertTrue(projectProfileManager.getInspectionProfile() == profile);
+ assertTrue(projectProfileManager.getCurrentProfile() == profile);
}
finally {
projectProfileManager.deleteProfile(PROFILE);
@@ -142,49 +150,47 @@ public class InspectionProfileTest extends LightIdeaTestCase {
ModifiableModel model = profile.getModifiableModel();
model.commit();
- Element copy = new Element("inspections");
- profile.writeExternal(copy);
- assertElementsEqual(loadProfile(), copy);
+ assertElementsEqual(loadProfile(), serializeProfile(profile));
}
private static Element loadProfile() throws IOException, JDOMException {
- return JDOMUtil.loadDocument("\n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" + " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " \n" +
- " ").getRootElement();
+ return JdomKt.loadElement("\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" + " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " ");
}
public void testReloadProfileWithUnknownScopes() throws Exception {
- final Element element = JDOMUtil.loadDocument("\n" +
+ final Element element = JdomKt.loadElement("\n" +
" \n" +
" \n" +
" \n" +
@@ -195,32 +201,28 @@ public class InspectionProfileTest extends LightIdeaTestCase {
" \n" +
" \n" +
" \n" +
- " ").getRootElement();
+ "");
final InspectionProfileImpl profile = createProfile();
profile.readExternal(element);
final ModifiableModel model = profile.getModifiableModel();
model.commit();
- final Element copy = new Element("inspections");
- profile.writeExternal(copy);
- assertElementsEqual(element, copy);
+ assertElementsEqual(element, serializeProfile(profile));
}
public void testMergeUnusedDeclarationAndUnusedSymbol() throws Exception {
//no specific settings
- final Element element = JDOMUtil.loadDocument("\n" +
+ final Element element = JdomKt.loadElement("\n" +
" \n" +
- " ").getRootElement();
+ "");
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(element);
ModifiableModel model = profile.getModifiableModel();
model.commit();
- final Element copy = new Element("inspections");
- profile.writeExternal(copy);
- assertElementsEqual(element, copy);
+ assertElementsEqual(element, serializeProfile(profile));
//settings to merge
- final Element unusedProfile = JDOMUtil.loadDocument("\n" +
+ final Element unusedProfile = JdomKt.loadElement("\n" +
" \n" +
" \n" +
" \n" +
@@ -236,7 +238,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
" \n" +
" \n" +
" \n" +
- " ").getRootElement();
+ "");
profile.readExternal(unusedProfile);
model = profile.getModifiableModel();
model.commit();
@@ -288,8 +290,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
"";
assertEquals(mergedText, serialize(profile));
- Element toImportElement = new Element("profile");
- profile.writeExternal(toImportElement);
+ Element toImportElement = serializeProfile(profile);
final InspectionProfileImpl importedProfile =
InspectionToolsConfigurable.importInspectionProfile(toImportElement, InspectionProfileManager.getInstance(), getProject(), null);
@@ -299,13 +300,9 @@ public class InspectionProfileTest extends LightIdeaTestCase {
profile.readExternal(mergedElement);
model = profile.getModifiableModel();
model.commit();
- Element copyMerged = new Element("profile");
- profile.writeExternal(copyMerged);
- assertElementsEqual(mergedElement, copyMerged);
+ assertElementsEqual(mergedElement, serializeProfile(profile));
- Element imported = new Element("profile");
- importedProfile.writeExternal(imported);
- assertElementsEqual(mergedElement, imported);
+ assertElementsEqual(mergedElement, serializeProfile(importedProfile));
}
public void testStoredMemberVisibility() throws Exception {
@@ -324,7 +321,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
" \n" +
" \n" +
"").getRootElement());
- InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
+ InspectionProfileImpl model = profile.getModifiableModel();
InspectionToolWrapper toolWrapper = model.getInspectionTool("unused", getProject());
UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)toolWrapper.getTool();
UnusedSymbolLocalInspectionBase inspectionTool = tool.getSharedLocalInspectionTool();
@@ -444,7 +441,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
"");
}
- private void checkMergedNoChanges(String initialText) throws Exception {
+ private static void checkMergedNoChanges(String initialText) throws Exception {
final Element element = JDOMUtil.loadDocument(initialText).getRootElement();
InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
profile.readExternal(element);
@@ -454,7 +451,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
}
public void testLockProfile() throws Exception {
- final List list = new ArrayList();
+ final List list = new ArrayList<>();
list.add(createTool("foo", true));
InspectionToolRegistrar registrar = new InspectionToolRegistrar() {
@@ -472,7 +469,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
assertTrue(profile.isToolEnabled(HighlightDisplayKey.find("foo")));
assertTrue(profile.getToolDefaultState("foo", getProject()).isEnabled());
- InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel();
+ InspectionProfileImpl model = profile.getModifiableModel();
model.lockProfile(true);
model.initInspectionTools(getProject()); // todo commit should take care of initialization
model.commit();
@@ -483,8 +480,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
"",
serialize(profile));
- Element element = new Element("element");
- profile.writeExternal(element);
+ Element element = serializeProfile(profile);
list.add(createTool("bar", true));
list.add(createTool("disabled", false));
@@ -511,14 +507,12 @@ public class InspectionProfileTest extends LightIdeaTestCase {
}
private static String serialize(InspectionProfileImpl profile) throws WriteExternalException {
- Element element = new Element("profile");
- profile.writeExternal(element);
- return JDOMUtil.writeElement(element);
+ return JDOMUtil.writeElement(serializeProfile(profile));
}
- private static InspectionProfileImpl createProfile(InspectionToolRegistrar registrar) {
- InspectionProfileImpl base = new InspectionProfileImpl("Base", registrar, InspectionProfileManager.getInstance(), null);
- return new InspectionProfileImpl("Foo", registrar, InspectionProfileManager.getInstance(), base);
+ private static InspectionProfileImpl createProfile(@NotNull InspectionToolRegistrar registrar) {
+ InspectionProfileImpl base = new InspectionProfileImpl("Base", registrar, InspectionProfileManager.getInstance(), null, null);
+ return new InspectionProfileImpl("Foo", registrar, InspectionProfileManager.getInstance(), base, null);
}
public void testGlobalInspectionContext() throws Exception {
@@ -528,7 +522,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
context.setExternalProfile(profile);
- context.initializeTools(new ArrayList(), new ArrayList(), new ArrayList());
+ context.initializeTools(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
}
public void testInspectionsInitialization() throws Exception {
@@ -557,7 +551,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
}
public void testDoNotInstantiateOnSave() throws Exception {
- InspectionProfileImpl profile = new InspectionProfileImpl("profile", InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile());
+ InspectionProfileImpl profile = new InspectionProfileImpl("profile", InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile(), null);
assertEquals(0, countInitializedTools(profile));
InspectionToolWrapper[] toolWrappers = profile.getInspectionTools(null);
assertTrue(toolWrappers.length > 0);
@@ -572,7 +566,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
profile.enableTool(id, getProject());
}
assertEquals(0, countInitializedTools(profile));
- profile.writeExternal(new Element("profile"));
+ serializeProfile(profile);
List initializedTools = getInitializedTools(profile);
if (initializedTools.size() > 0) {
for (InspectionToolWrapper initializedTool : initializedTools) {
@@ -607,26 +601,27 @@ public class InspectionProfileTest extends LightIdeaTestCase {
"";
foo.readExternal(JDOMUtil.loadDocument(test).getRootElement());
foo.initInspectionTools(getProject());
- Element serialized = new Element("profile");
- foo.writeExternal(serialized);
- assertEquals(test, JDOMUtil.writeElement(serialized));
+ 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 getInitializedTools(@NotNull Profile foo) {
- List initialized = new ArrayList();
- List tools = ((InspectionProfileImpl)foo).getAllTools(getProject());
+ public static List getInitializedTools(@NotNull InspectionProfileImpl foo) {
+ List initialized = null;
+ List 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) {
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt
new file mode 100644
index 000000000000..1b4d285ea749
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInspection.ex
+
+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
+import org.junit.ClassRule
+import org.junit.Rule
+import org.junit.Test
+
+internal class InspectionSchemeTest {
+ companion object {
+ @JvmField
+ @ClassRule
+ val projectRule = ProjectRule()
+ }
+
+ @JvmField
+ @Rule
+ val fsRule = InMemoryFsRule()
+
+ @Test fun loadSchemes() {
+ val schemeFile = fsRule.fs.getPath("inspection/Bar.xml")
+ val schemeData = """
+
+
+
+ " """.trimIndent()
+ schemeFile.write(schemeData)
+ val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(fsRule.fs.getPath(""))
+ val profileManager = ApplicationInspectionProfileManager(InspectionToolRegistrar.getInstance(),
+ schemeManagerFactory,
+ ApplicationManager.getApplication().messageBus)
+ profileManager.forceInitProfiles(true)
+ profileManager.initProfiles()
+
+ assertThat(profileManager.profiles).hasSize(1)
+ val scheme = profileManager.profiles.first() as InspectionProfileImpl
+ assertThat(scheme.name).isEqualTo("Bar")
+
+ runInInitMode { scheme.initInspectionTools(null) }
+
+ schemeManagerFactory.save()
+
+ assertThat(schemeFile.readText()).isEqualTo(schemeData)
+ profileManager.profiles
+ }
+}
diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt
new file mode 100644
index 000000000000..bc0bc995b292
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/ProjectInspectionManagerTest.kt
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInspection.ex
+
+import com.intellij.codeHighlighting.HighlightDisplayLevel
+import com.intellij.configurationStore.PROJECT_CONFIG_DIR
+import com.intellij.configurationStore.StoreAwareProjectManager
+import com.intellij.configurationStore.loadAndUseProject
+import com.intellij.configurationStore.saveStore
+import com.intellij.openapi.components.stateStore
+import com.intellij.openapi.project.ProjectManager
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManager
+import com.intellij.testFramework.Assertions.assertThat
+import com.intellij.testFramework.InitInspectionRule
+import com.intellij.testFramework.ProjectRule
+import com.intellij.testFramework.RuleChain
+import com.intellij.testFramework.TemporaryDirectory
+import com.intellij.util.delete
+import com.intellij.util.readText
+import com.intellij.util.write
+import org.junit.ClassRule
+import org.junit.Rule
+import org.junit.Test
+import java.nio.file.Paths
+
+internal class ProjectInspectionManagerTest {
+ companion object {
+ @JvmField
+ @ClassRule
+ val projectRule = ProjectRule()
+ }
+
+ val tempDirManager = TemporaryDirectory()
+
+ @Rule
+ @JvmField
+ val ruleChain = RuleChain(tempDirManager, InitInspectionRule())
+
+ @Test fun `component`() {
+ loadAndUseProject(tempDirManager, {
+ it.path
+ }) { project ->
+ val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ projectInspectionProfileManager.currentProfile
+
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ // cause to use app profile
+ projectInspectionProfileManager.setRootProfile(null)
+ val doNotUseProjectProfileState = """
+
+
+
+
+
+ """.trimIndent()
+ assertThat(projectInspectionProfileManager.state).isEqualTo(doNotUseProjectProfileState)
+
+ val inspectionDir = Paths.get(project.stateStore.stateStorageManager.expandMacros(PROJECT_CONFIG_DIR), "inspectionProfiles")
+ val file = inspectionDir.resolve("profiles_settings.xml")
+ project.saveStore()
+ assertThat(file).exists()
+ val doNotUseProjectProfileData = """
+
+
+
+
+
+ """.trimIndent()
+ assertThat(file.readText()).isEqualTo(doNotUseProjectProfileData)
+
+ // test load
+ file.delete()
+
+ project.baseDir.refresh(false, true)
+ (ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ file.write(doNotUseProjectProfileData)
+ project.baseDir.refresh(false, true)
+ (ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
+ assertThat(projectInspectionProfileManager.state).isEqualTo(doNotUseProjectProfileState)
+ }
+ }
+
+ @Test fun `do not save default project profile`() {
+ loadAndUseProject(tempDirManager, {
+ it.path
+ }) { project ->
+ val inspectionDir = Paths.get(project.stateStore.stateStorageManager.expandMacros(PROJECT_CONFIG_DIR), "inspectionProfiles")
+ val profileFile = inspectionDir.resolve("Project_Default.xml")
+ assertThat(profileFile).doesNotExist()
+
+ val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ projectInspectionProfileManager.currentProfile
+
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ project.saveStore()
+
+ assertThat(profileFile).doesNotExist()
+ }
+ }
+
+ @Test fun `profiles`() {
+ loadAndUseProject(tempDirManager, {
+ it.path
+ }) { project ->
+ val projectInspectionProfileManager = ProjectInspectionProfileManager.getInstanceImpl(project)
+ projectInspectionProfileManager.forceLoadSchemes()
+
+ assertThat(projectInspectionProfileManager.state).isEmpty()
+
+ // cause to use app profile
+ val currentProfile = projectInspectionProfileManager.currentProfile
+ assertThat(currentProfile.isProjectLevel).isTrue()
+ currentProfile.disableTool("Convert2Diamond", project)
+
+ project.saveStore()
+
+ val inspectionDir = Paths.get(project.stateStore.stateStorageManager.expandMacros(PROJECT_CONFIG_DIR), "inspectionProfiles")
+ val file = inspectionDir.resolve("profiles_settings.xml")
+
+ assertThat(file).doesNotExist()
+ val profileFile = inspectionDir.resolve("Project_Default.xml")
+ assertThat(profileFile.readText()).isEqualTo("""
+
+
+
+
+
+ """.trimIndent())
+
+ profileFile.write("""
+
+
+
+
+
+ """.trimIndent())
+
+ project.baseDir.refresh(false, true)
+ (ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
+ assertThat(projectInspectionProfileManager.currentProfile.getToolDefaultState("Convert2Diamond", project).level).isEqualTo(HighlightDisplayLevel.ERROR)
+ }
+ }
+}
\ No newline at end of file
diff --git a/java/jdkAnnotations/org/jdom/annotations.xml b/java/jdkAnnotations/org/jdom/annotations.xml
index d22b99b867ce..02739c14c0c0 100644
--- a/java/jdkAnnotations/org/jdom/annotations.xml
+++ b/java/jdkAnnotations/org/jdom/annotations.xml
@@ -48,6 +48,12 @@
-
+ -
+
+
+ -
+
+
-
diff --git a/java/manifest/src/org/jetbrains/lang/manifest/highlighting/MisspelledHeaderInspection.java b/java/manifest/src/org/jetbrains/lang/manifest/highlighting/MisspelledHeaderInspection.java
index 98065392b352..e84d1310c6da 100644
--- a/java/manifest/src/org/jetbrains/lang/manifest/highlighting/MisspelledHeaderInspection.java
+++ b/java/manifest/src/org/jetbrains/lang/manifest/highlighting/MisspelledHeaderInspection.java
@@ -184,7 +184,7 @@ public class MisspelledHeaderInspection extends LocalInspectionTool {
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
myHeaders.add(myHeaderName);
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
InspectionProfileManager.getInstance().fireProfileChanged(profile);
}
}
diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
index b5be6dd83c7f..228830479ba0 100644
--- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
+++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java
@@ -29,8 +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.codeInspection.ex.InspectionToolWrapper;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.ide.startup.StartupManagerEx;
import com.intellij.ide.startup.impl.StartupManagerImpl;
@@ -63,7 +61,7 @@ import com.intellij.psi.xml.XmlFileNSInfoProvider;
import com.intellij.testFramework.ExpectedHighlightingData;
import com.intellij.testFramework.FileTreeAccessFilter;
import com.intellij.testFramework.HighlightTestInfo;
-import com.intellij.testFramework.LightPlatformTestCase;
+import com.intellij.testFramework.InspectionsKt;
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
@@ -81,7 +79,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
@@ -93,8 +90,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
final LocalInspectionTool[] tools = configureLocalInspectionTools();
- CodeInsightTestFixtureImpl.configureInspections(tools, getProject(), Collections.emptyList(),
- getTestRootDisposable());
+ InspectionsKt.configureInspections(tools, getProject(), getTestRootDisposable());
DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
daemonCodeAnalyzer.prepareForTest();
@@ -137,14 +133,11 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
}
protected void enableInspectionTool(@NotNull InspectionProfileEntry tool) {
- InspectionToolWrapper toolWrapper = InspectionToolRegistrar.wrapTool(tool);
- LightPlatformTestCase.enableInspectionTool(getProject(), toolWrapper);
+ InspectionsKt.enableInspectionTool(getProject(), tool, getTestRootDisposable());
}
protected void enableInspectionTools(@NotNull InspectionProfileEntry... tools) {
- for (InspectionProfileEntry tool : tools) {
- enableInspectionTool(tool);
- }
+ InspectionsKt.enableInspectionTools(getProject(), getTestRootDisposable(), tools);
}
protected void enableInspectionToolsFromProvider(InspectionToolProvider toolProvider){
@@ -159,7 +152,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
}
protected void disableInspectionTool(@NotNull String shortName){
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(getProject()).getCurrentProfile();
if (profile.getInspectionTool(shortName, getProject()) != null) {
((InspectionProfileImpl)profile).disableTool(shortName, getProject());
}
@@ -170,7 +163,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 +335,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 +369,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 6545648813f3..334cfce73835 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, getTestRootDisposable());
diff --git a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java
index 08eb0e5fdc73..3538efac6322 100644
--- a/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java
+++ b/java/testFramework/src/com/intellij/testFramework/InspectionTestCase.java
@@ -41,14 +41,15 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiUtilCore;
-import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests;
-import com.intellij.util.ArrayUtil;
+import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author max
@@ -141,11 +142,13 @@ public abstract class InspectionTestCase extends PsiTestCase {
VirtualFile projectDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir));
AnalysisScope scope = createAnalysisScope(sourceDir[0].equals(projectDir) ? projectDir : sourceDir[0].getParent());
- InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject());
- InspectionToolWrapper[] toolWrappers = runDeadCodeFirst ? new InspectionToolWrapper []{getUnusedDeclarationWrapper(), toolWrapper} : new InspectionToolWrapper []{toolWrapper};
- toolWrappers = ArrayUtil.mergeArrays(toolWrappers, additional);
- final GlobalInspectionContextForTests globalContext =
- CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, toolWrappers);
+ List> toolWrappers = new ArrayList<>();
+ if (runDeadCodeFirst) {
+ toolWrappers.add(getUnusedDeclarationWrapper());
+ }
+ toolWrappers.add(toolWrapper);
+ ContainerUtil.addAll(toolWrappers, additional);
+ GlobalInspectionContextForTests globalContext = InspectionsKt.createGlobalContextForTool(scope, getProject(), toolWrappers);
InspectionTestUtil.runTool(toolWrapper, scope, globalContext);
return globalContext;
@@ -222,11 +225,15 @@ public abstract class InspectionTestCase extends PsiTestCase {
@Override
protected void tearDown() throws Exception {
- ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
- point.unregisterExtension(myUnusedCodeExtension);
- myUnusedCodeExtension = null;
- ext_src = null;
- super.tearDown();
+ try {
+ ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
+ point.unregisterExtension(myUnusedCodeExtension);
+ myUnusedCodeExtension = null;
+ ext_src = null;
+ }
+ finally {
+ super.tearDown();
+ }
}
@Override
diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java
index d4b94d3db6ac..e4125584eaa0 100644
--- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java
+++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java
@@ -104,7 +104,7 @@ public class AnnotationProcessorProfileSerializer {
public static void writeExternal(@NotNull ProcessorConfigProfile profile, @NotNull Element element) {
element.setAttribute(NAME, profile.getName());
- if (!Registry.is("saving.state.in.new.format.is.allowed", false) || profile.isEnabled()) {
+ if (!Registry.is("saving.state.in.new.format.is.allowed", true) || profile.isEnabled()) {
element.setAttribute(ENABLED, Boolean.toString(profile.isEnabled()));
}
@@ -141,7 +141,7 @@ public class AnnotationProcessorProfileSerializer {
Element pathElement = null;
- if (!Registry.is("saving.state.in.new.format.is.allowed", false) || !profile.isObtainProcessorsFromClasspath()) {
+ if (!Registry.is("saving.state.in.new.format.is.allowed", true) || !profile.isObtainProcessorsFromClasspath()) {
pathElement = addChild(element, "processorPath");
pathElement.setAttribute("useClasspath", Boolean.toString(profile.isObtainProcessorsFromClasspath()));
}
diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java
index d1f6d058ad2d..b3ad53b84d8a 100644
--- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java
+++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/JpsJavaCompilerConfigurationSerializer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration;
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
+import java.util.Arrays;
import java.util.List;
/**
@@ -44,6 +45,9 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS
public static final String MODULE = "module";
public static final String TARGET_ATTRIBUTE = "target";
+ public static final List DEFAULT_WILDCARD_PATTERNS =
+ Arrays.asList("!?*.java", "!?*.form", "!?*.class", "!?*.groovy", "!?*.scala", "!?*.flex", "!?*.kt", "!?*.clj", "!?*.aj");
+
public JpsJavaCompilerConfigurationSerializer() {
super("compiler.xml", "CompilerConfiguration");
}
@@ -59,12 +63,19 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS
readExcludes(componentTag.getChild(EXCLUDE_FROM_COMPILE), configuration.getCompilerExcludes());
Element resourcePatternsTag = componentTag.getChild(WILDCARD_RESOURCE_PATTERNS);
- for (Element entry : JDOMUtil.getChildren(resourcePatternsTag, ENTRY)) {
- String pattern = entry.getAttributeValue(NAME);
- if (!StringUtil.isEmpty(pattern)) {
+ if (resourcePatternsTag == null) {
+ for (String pattern : DEFAULT_WILDCARD_PATTERNS) {
configuration.addResourcePattern(pattern);
}
}
+ else {
+ for (Element entry : resourcePatternsTag.getChildren(ENTRY)) {
+ String pattern = entry.getAttributeValue(NAME);
+ if (!StringUtil.isEmpty(pattern)) {
+ configuration.addResourcePattern(pattern);
+ }
+ }
+ }
Element annotationProcessingTag = componentTag.getChild(ANNOTATION_PROCESSING);
if (annotationProcessingTag != null) {
@@ -97,6 +108,14 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS
}
}
+ @Override
+ public void loadExtensionWithDefaultSettings(@NotNull JpsProject project) {
+ JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
+ for (String pattern : DEFAULT_WILDCARD_PATTERNS) {
+ configuration.addResourcePattern(pattern);
+ }
+ }
+
public static void readExcludes(Element excludeFromCompileTag, JpsCompilerExcludes excludes) {
if (excludeFromCompileTag != null) {
for (Element fileTag : JDOMUtil.getChildren(excludeFromCompileTag, "file")) {
diff --git a/json/src/com/jetbrains/jsonSchema/JsonSchemaFileTypeManager.java b/json/src/com/jetbrains/jsonSchema/JsonSchemaFileTypeManager.java
index 765518d346e4..f7656c77ee3c 100644
--- a/json/src/com/jetbrains/jsonSchema/JsonSchemaFileTypeManager.java
+++ b/json/src/com/jetbrains/jsonSchema/JsonSchemaFileTypeManager.java
@@ -70,17 +70,8 @@ public class JsonSchemaFileTypeManager implements ProjectManagerListener {
ensureInitialized();
}
- @Override
- public boolean canCloseProject(Project project) {
- return true;
- }
-
@Override
public void projectClosed(Project project) {
reset();
}
-
- @Override
- public void projectClosing(Project project) {
- }
}
diff --git a/lib/annotations/jdk/java/util/concurrent/annotations.xml b/lib/annotations/jdk/java/util/concurrent/annotations.xml
new file mode 100644
index 000000000000..b0e4e822ed3f
--- /dev/null
+++ b/lib/annotations/jdk/java/util/concurrent/annotations.xml
@@ -0,0 +1,6 @@
+
+ -
+
+
+
\ No newline at end of file
diff --git a/lib/dev/memoryfilesystem-0.8.0-sources.jar b/lib/dev/memoryfilesystem-0.8.0-sources.jar
new file mode 100644
index 000000000000..34e7c3f22c4b
Binary files /dev/null and b/lib/dev/memoryfilesystem-0.8.0-sources.jar differ
diff --git a/lib/dev/memoryfilesystem-0.8.0.jar b/lib/dev/memoryfilesystem-0.8.0.jar
new file mode 100644
index 000000000000..c121e4ad9d61
Binary files /dev/null and b/lib/dev/memoryfilesystem-0.8.0.jar differ
diff --git a/platform/analysis-api/src/com/intellij/codeInsight/daemon/HighlightDisplayKey.java b/platform/analysis-api/src/com/intellij/codeInsight/daemon/HighlightDisplayKey.java
index 10316c545e94..254ae4303cec 100644
--- a/platform/analysis-api/src/com/intellij/codeInsight/daemon/HighlightDisplayKey.java
+++ b/platform/analysis-api/src/com/intellij/codeInsight/daemon/HighlightDisplayKey.java
@@ -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,10 +28,10 @@ import java.util.Map;
public class HighlightDisplayKey {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.HighlightDisplayKey");
- private static final Map ourNameToKeyMap = new THashMap();
- private static final Map ourIdToKeyMap = new THashMap();
- private static final Map> ourKeyToDisplayNameMap = new THashMap>();
- private static final Map ourKeyToAlternativeIDMap = new THashMap();
+ private static final Map ourNameToKeyMap = new THashMap<>();
+ private static final Map ourIdToKeyMap = new THashMap<>();
+ private static final Map> ourKeyToDisplayNameMap = new THashMap<>();
+ private static final Map ourKeyToAlternativeIDMap = new THashMap<>();
private final String myName;
private final String myID;
@@ -80,7 +80,7 @@ public class HighlightDisplayKey {
public static HighlightDisplayKey register(@NonNls @NotNull final String name,
@NotNull final String displayName,
@NotNull @NonNls final String id) {
- return register(name, new Computable.PredefinedValueComputable(displayName), id);
+ return register(name, new Computable.PredefinedValueComputable<>(displayName), id);
}
@Nullable
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java
index 8696d3e04a65..b30d399074cb 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfile.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2011 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.
@@ -82,9 +82,9 @@ public interface InspectionProfile extends Profile {
@NotNull
ModifiableModel getModifiableModel();
- boolean isToolEnabled(HighlightDisplayKey key, PsiElement element);
+ boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element);
- boolean isToolEnabled(HighlightDisplayKey key);
+ boolean isToolEnabled(@Nullable HighlightDisplayKey key);
boolean isExecutable(Project project);
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java
index c37f23c03d38..9fd1730cc08e 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java
@@ -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.
@@ -20,7 +20,6 @@ import com.intellij.codeInspection.ex.InspectionElementsMerger;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
@@ -128,7 +127,7 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
return o1.getName().equals(o2.getName());
}
});
-
+
Set suppressors = getSuppressors(element);
final PsiLanguageInjectionHost injectionHost = InjectedLanguageManager.getInstance(element.getProject()).getInjectionHost(element);
if (injectionHost != null) {
@@ -190,11 +189,10 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
}
return elementLanguageSuppressor != null
? Collections.singleton(elementLanguageSuppressor)
- : Collections.emptySet();
+ : Collections.emptySet();
}
public void cleanup(@NotNull Project project) {
-
}
interface DefaultNameProvider {
@@ -403,24 +401,6 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool {
return DEFAULT_FILTER;
}
- /**
- * Initialize inspection with project. Is called on project opened for all profiles as well as on profile creation.
- *
- * @param project to be associated with this entry
- * @deprecated this won't work for inspections configured via {@link InspectionEP}
- */
- public void projectOpened(@NotNull Project project) {
- }
-
- /**
- * Cleanup inspection settings corresponding to the project. Is called on project closed for all profiles as well as on profile deletion.
- *
- * @param project to be disassociated from this entry
- * @deprecated this won't work for inspections configured via {@link InspectionEP}
- */
- public void projectClosed(@NotNull Project project) {
- }
-
/**
* Override this method to return a html inspection description. Otherwise it will be loaded from resources using ID.
*
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionToolsFactory.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionToolsFactory.java
deleted file mode 100644
index 9234a9b53581..000000000000
--- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionToolsFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * User: anna
- * Date: 28-May-2009
- */
-package com.intellij.codeInspection;
-
-import com.intellij.openapi.extensions.ExtensionPointName;
-
-/**
- * This will be removed in future versions.
- * Please use {@link InspectionEP} for inspection registration
- */
-@Deprecated
-public interface InspectionToolsFactory {
- ExtensionPointName EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.inspectionToolsFactory");
-
- InspectionProfileEntry[] createTools();
-}
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java b/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java
index 302ee306b9a2..3803693fb258 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/ModifiableModel.java
@@ -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.
@@ -36,12 +36,6 @@ public interface ModifiableModel extends Profile {
InspectionProfile getParentProfile();
- @Nullable
- String getBaseProfileName();
-
- @Deprecated // use corresponding constructor instead
- void setBaseProfile(InspectionProfile profile);
-
void enableTool(@NotNull String inspectionTool, NamedScope namedScope, Project project);
void disableTool(@NotNull String inspectionTool, NamedScope namedScope, @NotNull Project project);
@@ -52,9 +46,9 @@ public interface ModifiableModel extends Profile {
boolean isToolEnabled(HighlightDisplayKey key);
- boolean isToolEnabled(HighlightDisplayKey key, PsiElement element);
+ boolean isToolEnabled(@Nullable HighlightDisplayKey key, @Nullable PsiElement element);
- void commit() throws IOException;
+ void commit();
boolean isChanged();
@@ -76,8 +70,6 @@ public interface ModifiableModel extends Profile {
InspectionToolWrapper[] getInspectionTools(PsiElement element);
- void copyFrom(@NotNull InspectionProfile profile);
-
/**
* @see InspectionProfile#getSingleTool()
*/
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java b/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java
index 47c14d950f68..ceb0ca61b996 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java
@@ -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.
@@ -34,14 +34,17 @@ public interface ProblemDescriptionsProcessor {
* @return the problems found for the specified node.
*/
@Nullable
- CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity);
+ default CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
+ return CommonProblemDescriptor.EMPTY_ARRAY;
+ }
/**
* Drops all problems which have been collected for the specified reference graph node.
*
* @param refEntity the reference graph node.
*/
- void ignoreElement(@NotNull RefEntity refEntity);
+ default void ignoreElement(@NotNull RefEntity refEntity) {
+ }
/**
* Registers a problem or several problems, with optional quickfixes, for the specified
@@ -50,7 +53,10 @@ public interface ProblemDescriptionsProcessor {
* @param refEntity the reference graph node.
* @param commonProblemDescriptors the descriptors for the problems to register.
*/
- void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors);
+ default void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) {
+ }
- RefEntity getElement(@NotNull CommonProblemDescriptor descriptor);
+ default RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
+ return null;
+ }
}
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 d6df865c7130..5aec1c33928d 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/ex/InspectionToolWrapper.java
@@ -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.
@@ -60,17 +60,16 @@ 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());
}
}
public void initialize(@NotNull GlobalInspectionContext context) {
- projectOpened(context.getProject());
}
@NotNull
@@ -166,18 +165,6 @@ public abstract class InspectionToolWrapper toolClass) {
+ static T instantiateTool(@NotNull Class toolClass) {
try {
return ReflectionUtil.newInstance(toolClass);
}
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ex/ScopeToolState.java b/platform/analysis-api/src/com/intellij/codeInspection/ex/ScopeToolState.java
index 187350f69e36..77f4e2fbd859 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/ex/ScopeToolState.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/ex/ScopeToolState.java
@@ -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.
@@ -64,7 +64,7 @@ public class ScopeToolState {
}
@Nullable
- public NamedScope getScope(Project project) {
+ public NamedScope getScope(@Nullable Project project) {
if (myScope == null && project != null) {
myScope = NamedScopesHolder.getScope(project, myScopeName);
}
diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ex/Tools.java b/platform/analysis-api/src/com/intellij/codeInspection/ex/Tools.java
index 8fde087c1b75..d1f43756d2ab 100644
--- a/platform/analysis-api/src/com/intellij/codeInspection/ex/Tools.java
+++ b/platform/analysis-api/src/com/intellij/codeInspection/ex/Tools.java
@@ -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 getTools();
+ void collectTools(@NotNull List result);
+
@NotNull
ScopeToolState getDefaultState();
diff --git a/platform/analysis-api/src/com/intellij/profile/ApplicationProfileManager.java b/platform/analysis-api/src/com/intellij/profile/ApplicationProfileManager.java
deleted file mode 100644
index 71231a71ddf3..000000000000
--- a/platform/analysis-api/src/com/intellij/profile/ApplicationProfileManager.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.profile;
-
-import com.intellij.openapi.Disposable;
-import com.intellij.psi.search.scope.packageSet.NamedScope;
-import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * User: anna
- * Date: 29-Nov-2005
- */
-public abstract class ApplicationProfileManager implements ProfileManager{
- public abstract Profile createProfile();
-
- public abstract void addProfileChangeListener(@NotNull ProfileChangeAdapter listener);
-
- public abstract void addProfileChangeListener(@NotNull ProfileChangeAdapter listener, @NotNull Disposable parentDisposable);
-
- public abstract void removeProfileChangeListener(@NotNull ProfileChangeAdapter listener);
-
- public abstract void fireProfileChanged(Profile profile);
-
- public abstract void fireProfileChanged(Profile oldProfile, Profile profile, @Nullable NamedScope scope);
-
- public abstract void setRootProfile(@Nullable String profileName);
-
- @NotNull
- public abstract Profile getRootProfile();
-
- public abstract void addProfile(@NotNull Profile profile);
-
- @Override
- public NamedScopesHolder getScopesManager() {
- return null;
- }
-}
diff --git a/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java b/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java
deleted file mode 100644
index 275fea67cc81..000000000000
--- a/platform/analysis-api/src/com/intellij/profile/DefaultProjectProfileManager.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright 2000-2015 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.profile;
-
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.components.MainConfigurationStateSplitter;
-import com.intellij.openapi.components.PersistentStateComponent;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.packageDependencies.DependencyValidationManager;
-import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.xmlb.XmlSerializer;
-import com.intellij.util.xmlb.annotations.OptionTag;
-import gnu.trove.THashMap;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.*;
-
-/**
- * User: anna
- * Date: 30-Nov-2005
- */
-public abstract class DefaultProjectProfileManager extends ProjectProfileManager implements PersistentStateComponent {
- protected static final Logger LOG = Logger.getInstance("#com.intellij.profile.DefaultProjectProfileManager");
-
- @NonNls public static final String SCOPES = "scopes";
- @NonNls protected static final String SCOPE = "scope";
- @NonNls public static final String PROFILE = "profile";
- @NonNls protected static final String NAME = "name";
-
- private static final String VERSION = "1.0";
-
- @NotNull
- protected final Project myProject;
-
- private String myProjectProfile;
-
- @OptionTag("USE_PROJECT_PROFILE")
- private boolean useProjectProfile = true;
-
- private final ApplicationProfileManager myApplicationProfileManager;
-
- private final Map myProfiles = new THashMap();
- protected final DependencyValidationManager myHolder;
- private final List myProfilesListener = ContainerUtil.createLockFreeCopyOnWriteList();
- @NonNls private static final String PROJECT_DEFAULT_PROFILE_NAME = "Project Default";
-
- public DefaultProjectProfileManager(@NotNull final Project project,
- @NotNull ApplicationProfileManager applicationProfileManager,
- @NotNull DependencyValidationManager holder) {
- myProject = project;
- myHolder = holder;
- myApplicationProfileManager = applicationProfileManager;
- }
-
- @NotNull
- public Project getProject() {
- return myProject;
- }
-
- @Override
- public synchronized Profile getProfile(@NotNull String name, boolean returnRootProfileIfNamedIsAbsent) {
- return myProfiles.containsKey(name) ? myProfiles.get(name) : myApplicationProfileManager.getProfile(name, returnRootProfileIfNamedIsAbsent);
- }
-
- @Override
- public synchronized void updateProfile(@NotNull Profile profile) {
- myProfiles.put(profile.getName(), profile);
- for (ProfileChangeAdapter profileChangeAdapter : myProfilesListener) {
- profileChangeAdapter.profileChanged(profile);
- }
- }
-
- @Nullable
- @Override
- public synchronized Element getState() {
- Element state = new Element("settings");
-
- String[] sortedProfiles = myProfiles.keySet().toArray(new String[myProfiles.size()]);
- Arrays.sort(sortedProfiles);
- for (String profile : sortedProfiles) {
- final Profile projectProfile = myProfiles.get(profile);
- if (projectProfile != null) {
- Element profileElement = new Element(PROFILE);
- projectProfile.writeExternal(profileElement);
- boolean hasSmthToSave = sortedProfiles.length > 1 || isCustomProfileUsed();
- if (!hasSmthToSave) {
- for (Element child : profileElement.getChildren()) {
- if (!child.getName().equals("option")) {
- hasSmthToSave = true;
- break;
- }
- }
- }
- if (hasSmthToSave) {
- state.addContent(profileElement);
- }
- }
- }
-
- if (!state.getChildren().isEmpty() || isCustomProfileUsed()) {
- XmlSerializer.serializeInto(this, state);
- state.addContent(new Element("version").setAttribute("value", VERSION));
- }
- return state;
- }
-
- @Override
- public synchronized void loadState(Element state) {
- final Set profileKeys = new HashSet();
- profileKeys.addAll(myProfiles.keySet());
- myProfiles.clear();
- XmlSerializer.deserializeInto(this, state);
- for (Element o : state.getChildren(PROFILE)) {
- Profile profile = myApplicationProfileManager.createProfile();
- profile.setProfileManager(this);
- profile.readExternal(o);
- profile.setProjectLevel(true);
- if (profileKeys.contains(profile.getName())) {
- updateProfile(profile);
- }
- else {
- myProfiles.put(profile.getName(), profile);
- }
- }
- if (state.getChild("version") == null || !Comparing.strEqual(state.getChild("version").getAttributeValue("value"), VERSION)) {
- boolean toConvert = true;
- for (Element o : state.getChildren("option")) {
- if (Comparing.strEqual(o.getAttributeValue("name"), "USE_PROJECT_LEVEL_SETTINGS")) {
- toConvert = Boolean.parseBoolean(o.getAttributeValue("value"));
- break;
- }
- }
- if (toConvert) {
- convert(state);
- }
- }
- }
-
- protected void convert(Element element) {
- }
-
- private boolean isCustomProfileUsed() {
- return myProjectProfile != null && !Comparing.strEqual(myProjectProfile, PROJECT_DEFAULT_PROFILE_NAME);
- }
-
- @NotNull
- @Override
- public NamedScopesHolder getScopesManager() {
- return myHolder;
- }
-
- @NotNull
- @Override
- public synchronized Collection getProfiles() {
- getProjectProfileImpl();
- return myProfiles.values();
- }
-
- @NotNull
- @Override
- public synchronized String[] getAvailableProfileNames() {
- return ArrayUtil.toStringArray(myProfiles.keySet());
- }
-
- @Override
- public synchronized void deleteProfile(@NotNull String name) {
- myProfiles.remove(name);
- }
-
- @Override
- @OptionTag("PROJECT_PROFILE")
- public synchronized String getProjectProfile() {
- return myProjectProfile;
- }
-
- @Override
- public synchronized void setProjectProfile(@Nullable String newProfile) {
- if (Comparing.strEqual(newProfile, myProjectProfile)) {
- return;
- }
-
- String oldProfile = myProjectProfile;
- myProjectProfile = newProfile;
- useProjectProfile = newProfile != null;
- if (oldProfile != null) {
- for (ProfileChangeAdapter adapter : myProfilesListener) {
- adapter.profileActivated(getProfile(oldProfile), newProfile != null ? getProfile(newProfile) : null);
- }
- }
- }
-
- @NotNull
- public synchronized Profile getProjectProfileImpl(){
- if (!useProjectProfile) {
- return myApplicationProfileManager.getRootProfile();
- }
- if (myProjectProfile == null || myProfiles.isEmpty()){
- setProjectProfile(PROJECT_DEFAULT_PROFILE_NAME);
- final Profile projectProfile = myApplicationProfileManager.createProfile();
- projectProfile.copyFrom(myApplicationProfileManager.getRootProfile());
- projectProfile.setProjectLevel(true);
- projectProfile.setName(PROJECT_DEFAULT_PROFILE_NAME);
- myProfiles.put(PROJECT_DEFAULT_PROFILE_NAME, projectProfile);
- }
- else if (!myProfiles.containsKey(myProjectProfile)){
- setProjectProfile(myProfiles.keySet().iterator().next());
- }
- final Profile profile = myProfiles.get(myProjectProfile);
- if (profile.isProjectLevel()) {
- profile.setProfileManager(this);
- }
- return profile;
- }
-
- public void addProfilesListener(@NotNull final ProfileChangeAdapter profilesListener, @NotNull Disposable parent) {
- myProfilesListener.add(profilesListener);
- Disposer.register(parent, new Disposable() {
- @Override
- public void dispose() {
- myProfilesListener.remove(profilesListener);
- }
- });
- }
-
- public static class ProfileStateSplitter extends MainConfigurationStateSplitter {
- @NotNull
- @Override
- protected String getComponentStateFileName() {
- return "profiles_settings";
- }
-
- @NotNull
- @Override
- protected String getSubStateTagName() {
- return PROFILE;
- }
- }
-
- protected void fireProfilesInitialized() {
- for (ProfileChangeAdapter profileChangeAdapter : myProfilesListener) {
- profileChangeAdapter.profilesInitialized();
- }
- }
- protected void fireProfilesShutdown() {
- for (ProfileChangeAdapter profileChangeAdapter : myProfilesListener) {
- profileChangeAdapter.profilesShutdown();
- }
- }
-}
diff --git a/platform/analysis-api/src/com/intellij/profile/Profile.java b/platform/analysis-api/src/com/intellij/profile/Profile.java
index e9945762ebc0..08e65fc15cc3 100644
--- a/platform/analysis-api/src/com/intellij/profile/Profile.java
+++ b/platform/analysis-api/src/com/intellij/profile/Profile.java
@@ -16,6 +16,7 @@
package com.intellij.profile;
import com.intellij.openapi.options.Scheme;
+import com.intellij.util.xmlb.annotations.Transient;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
@@ -26,14 +27,7 @@ import org.jetbrains.annotations.NotNull;
public interface Profile extends Comparable, Scheme {
void copyFrom(@NotNull Profile profile);
- void setLocal(boolean isLocal);
-
- /**
- * @deprecated Use !{@link #isProjectLevel()}
- */
- @Deprecated
- boolean isLocal();
-
+ @Transient
boolean isProjectLevel();
void setProjectLevel(boolean isProjectLevel);
diff --git a/platform/analysis-api/src/com/intellij/profile/ProfileChangeAdapter.java b/platform/analysis-api/src/com/intellij/profile/ProfileChangeAdapter.java
index 514c18766d40..e45fe64fdd0e 100644
--- a/platform/analysis-api/src/com/intellij/profile/ProfileChangeAdapter.java
+++ b/platform/analysis-api/src/com/intellij/profile/ProfileChangeAdapter.java
@@ -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.
@@ -15,15 +15,18 @@
*/
package com.intellij.profile;
-import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-/**
- * User: anna
- * Date: 20-Nov-2005
- */
-public abstract class ProfileChangeAdapter {
- public void profileChanged(Profile profile){}
- public void profileActivated(Profile oldProfile, Profile profile){}
- public void profilesInitialized() {}
- public void profilesShutdown(){}
+public interface ProfileChangeAdapter {
+ default void profileChanged(@Nullable Profile profile) {
+ }
+
+ default void profileActivated(@Nullable Profile oldProfile, @Nullable Profile profile) {
+ }
+
+ default void profilesInitialized() {
+ }
+
+ default void profilesShutdown() {
+ }
}
diff --git a/platform/analysis-api/src/com/intellij/profile/ProfileManager.java b/platform/analysis-api/src/com/intellij/profile/ProfileManager.java
index 3ae699aac843..6a982cbb7ea8 100644
--- a/platform/analysis-api/src/com/intellij/profile/ProfileManager.java
+++ b/platform/analysis-api/src/com/intellij/profile/ProfileManager.java
@@ -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.
@@ -15,6 +15,8 @@
*/
package com.intellij.profile;
+import com.intellij.codeInspection.InspectionProfile;
+import com.intellij.openapi.Disposable;
import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
import org.jetbrains.annotations.NotNull;
@@ -25,14 +27,18 @@ import java.util.Collection;
* Date: 09-Dec-2005
*/
public interface ProfileManager {
- NamedScopesHolder getScopesManager();
+ default NamedScopesHolder getScopesManager() {
+ return null;
+ }
@NotNull
Collection getProfiles();
Profile getProfile(@NotNull String name, boolean returnRootProfileIfNamedIsAbsent);
- Profile getProfile(@NotNull String name);
+ default Profile getProfile(@NotNull String name) {
+ return getProfile(name, true);
+ }
void updateProfile(@NotNull Profile profile);
@@ -40,4 +46,9 @@ public interface ProfileManager {
String[] getAvailableProfileNames();
void deleteProfile(@NotNull String name);
+
+ void addProfileChangeListener(@NotNull ProfileChangeAdapter listener, @NotNull Disposable parent);
+
+ @NotNull
+ InspectionProfile getCurrentProfile();
}
diff --git a/platform/analysis-api/src/com/intellij/profile/ProjectProfileManager.java b/platform/analysis-api/src/com/intellij/profile/ProjectProfileManager.java
deleted file mode 100644
index 584ec3bd90e5..000000000000
--- a/platform/analysis-api/src/com/intellij/profile/ProjectProfileManager.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.profile;
-
-import org.jetbrains.annotations.Nullable;
-
-/**
- * User: anna
- * Date: 30-Nov-2005
- */
-public abstract class ProjectProfileManager implements ProfileManager {
- public abstract String getProfileName();
-
- public abstract String getProjectProfile();
-
- public abstract void setProjectProfile(@Nullable String projectProfile);
-}
diff --git a/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java b/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java
index af943460bbe4..4b94254b636a 100644
--- a/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.java
+++ b/platform/analysis-api/src/com/intellij/psi/search/scope/packageSet/NamedScopesHolder.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.
@@ -102,8 +102,7 @@ public abstract class NamedScopesHolder implements PersistentStateComponent
+
-
-
+
\ No newline at end of file
diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java
index eff520643483..900ce415bedf 100644
--- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java
+++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.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.
@@ -25,6 +25,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.profile.codeInspection.InspectionProfileManager;
+import com.intellij.profile.codeInspection.SeverityProvider;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -33,16 +34,16 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
-import java.io.FileFilter;
import java.io.IOException;
import java.util.HashMap;
+import java.util.Map;
/**
* User: anna
* Date: Dec 20, 2004
*/
public class InspectionProfileConvertor {
- private final HashMap myDisplayLevelMap = new HashMap();
+ private final Map myDisplayLevelMap = new HashMap<>();
@NonNls public static final String OLD_HIGHTLIGHTING_SETTINGS_PROFILE = "EditorHighlightingSettings";
@NonNls public static final String OLD_DEFAUL_PROFILE = "OldDefaultProfile";
@@ -60,17 +61,16 @@ public class InspectionProfileConvertor {
@NonNls private static final String DEFAULT_XML = "Default.xml";
@NonNls private static final String XML_EXTENSION = ".xml";
@NonNls public static final String LEVEL_ATT = "level";
- private final InspectionProfileManager myManager;
+ private final SeverityProvider myManager;
- public InspectionProfileConvertor(InspectionProfileManager manager) {
+ public InspectionProfileConvertor(@NotNull SeverityProvider manager) {
myManager = manager;
renameOldDefaultsProfile();
}
private boolean retrieveOldSettings(@NotNull Element element) {
boolean hasOldSettings = false;
- for (final Object obj : element.getChildren(OPTION_TAG)) {
- Element option = (Element)obj;
+ for (Element option : element.getChildren(OPTION_TAG)) {
final String name = option.getAttributeValue(NAME_ATT);
if (name != null) {
hasOldSettings |= processElement(option, name);
@@ -81,9 +81,7 @@ public class InspectionProfileConvertor {
protected boolean processElement(final Element option, final String name) {
if (name.equals(DISPLAY_LEVEL_MAP_OPTION)) {
- final Element levelMap = option.getChild(VALUE_ATT);
- for (final Object o : levelMap.getChildren()) {
- Element e = (Element)o;
+ for (Element e : option.getChild(VALUE_ATT).getChildren()) {
String key = e.getName();
String levelName = e.getAttributeValue(LEVEL_ATT);
HighlightSeverity severity = myManager.getSeverityRegistrar().getSeverity(levelName);
@@ -98,16 +96,9 @@ public class InspectionProfileConvertor {
public void storeEditorHighlightingProfile(@NotNull Element element, @NotNull InspectionProfile editorProfile) {
if (retrieveOldSettings(element)) {
-
- final ModifiableModel editorProfileModel = editorProfile.getModifiableModel();
-
+ ModifiableModel editorProfileModel = editorProfile.getModifiableModel();
fillErrorLevels(editorProfileModel);
- try {
- editorProfileModel.commit();
- }
- catch (IOException e) {
- LOG.error(e);
- }
+ editorProfileModel.commit();
}
}
@@ -180,7 +171,6 @@ public class InspectionProfileConvertor {
}
}
-
@Nullable
private static String convertToShortName(String displayName, InspectionToolWrapper[] tools) {
if (displayName == null) return null;
@@ -191,5 +181,4 @@ public class InspectionProfileConvertor {
}
return null;
}
-
}
diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java
index e8c8343bdd53..dcda2fe53c66 100644
--- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java
+++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java
@@ -747,7 +747,7 @@ public class HighlightInfo implements Segment {
boolean canCleanup(@NotNull PsiElement element) {
if (myCanCleanup == null) {
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getCurrentProfile();
final HighlightDisplayKey key = myKey;
if (key == null) {
myCanCleanup = false;
@@ -778,7 +778,7 @@ public class HighlightInfo implements Segment {
}
IntentionManager intentionManager = IntentionManager.getInstance();
List newOptions = intentionManager.getStandardIntentionOptions(key, element);
- InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
+ InspectionProfile profile = InspectionProjectProfileManager.getInstance(element.getProject()).getCurrentProfile();
InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java
index fa3f75da526a..d8f3856156be 100644
--- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java
+++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoType.java
@@ -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.
@@ -68,168 +68,168 @@ public interface HighlightInfoType {
HighlightSeverity SYMBOL_TYPE_SEVERITY = new HighlightSeverity("SYMBOL_TYPE_SEVERITY", HighlightSeverity.INFORMATION.myVal-2);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.LOCAL_VARIABLE or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.LOCAL_VARIABLE or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType LOCAL_VARIABLE = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.INSTANCE_FIELD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.INSTANCE_FIELD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType INSTANCE_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.INSTANCE_FINAL_FIELD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.INSTANCE_FINAL_FIELD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType INSTANCE_FINAL_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INSTANCE_FINAL_FIELD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.STATIC_FIELD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.STATIC_FIELD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType STATIC_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_FIELD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.STATIC_FINAL_FIELD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.STATIC_FINAL_FIELD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType STATIC_FINAL_FIELD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_FINAL_FIELD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.PARAMETER or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.PARAMETER or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType PARAMETER = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.PARAMETER_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.METHOD_CALL or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.METHOD_CALL or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType METHOD_CALL = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.METHOD_CALL_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.METHOD_DECLARATION or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.METHOD_DECLARATION or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType METHOD_DECLARATION = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.METHOD_DECLARATION_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.CONSTRUCTOR_CALL or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.CONSTRUCTOR_CALL or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType CONSTRUCTOR_CALL = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CONSTRUCTOR_CALL_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.CONSTRUCTOR_DECLARATION or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.CONSTRUCTOR_DECLARATION or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType CONSTRUCTOR_DECLARATION = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.STATIC_METHOD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.STATIC_METHOD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType STATIC_METHOD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.STATIC_METHOD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ABSTRACT_METHOD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ABSTRACT_METHOD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ABSTRACT_METHOD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ABSTRACT_METHOD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.INHERITED_METHOD or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.INHERITED_METHOD or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType INHERITED_METHOD = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INHERITED_METHOD_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.CLASS_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.CLASS_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.CLASS_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ANONYMOUS_CLASS_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ANONYMOUS_CLASS_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ANONYMOUS_CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANONYMOUS_CLASS_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.INTERFACE_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.INTERFACE_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings("deprecation")
@Deprecated
HighlightInfoType INTERFACE_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ENUM_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ENUM_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ENUM_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ENUM_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.TYPE_PARAMETER_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.TYPE_PARAMETER_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType TYPE_PARAMETER_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.TYPE_PARAMETER_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ABSTRACT_CLASS_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ABSTRACT_CLASS_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ABSTRACT_CLASS_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ABSTRACT_CLASS_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ANNOTATION_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ANNOTATION_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ANNOTATION_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.ANNOTATION_ATTRIBUTE_NAME or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.ANNOTATION_ATTRIBUTE_NAME or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType ANNOTATION_ATTRIBUTE_NAME = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.REASSIGNED_LOCAL_VARIABLE or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.REASSIGNED_LOCAL_VARIABLE or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType REASSIGNED_LOCAL_VARIABLE = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.REASSIGNED_PARAMETER or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.REASSIGNED_PARAMETER or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@Deprecated
HighlightInfoType REASSIGNED_PARAMETER = new HighlightInfoTypeImpl(SYMBOL_TYPE_SEVERITY, CodeInsightColors.REASSIGNED_PARAMETER_ATTRIBUTES);
/**
- * @deprecated For Java use JavaHighlightInfoTypes.IMPLICIT_ANONYMOUS_CLASS_PARAMETER or create a language-specific HighlightInfoType.
+ * @deprecated For Java use JavaHighlightInfoTypes.IMPLICIT_ANONYMOUS_CLASS_PARAMETER or create a language-specific HighlightInfoType.
* The field will be removed in version 17.
*/
@SuppressWarnings({"deprecation", "unused"})
@@ -266,7 +266,7 @@ public interface HighlightInfoType {
public HighlightInfoTypeImpl(@NotNull HighlightSeverity severity, TextAttributesKey attributesKey) {
this(severity, attributesKey, true);
}
-
+
public HighlightInfoTypeImpl(@NotNull HighlightSeverity severity, TextAttributesKey attributesKey, boolean needsUpdateOnTyping) {
mySeverity = severity;
myAttributesKey = attributesKey;
@@ -361,7 +361,7 @@ public interface HighlightInfoType {
return myToolKey;
}
}
-
+
interface Iconable {
Icon getIcon();
}
diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/SeverityRegistrar.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/SeverityRegistrar.java
index 208a58e76a60..63b654e97a81 100644
--- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/SeverityRegistrar.java
+++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/SeverityRegistrar.java
@@ -24,7 +24,6 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.JDOMExternalizableStringList;
import com.intellij.profile.codeInspection.InspectionProfileManager;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.concurrency.AtomicFieldUpdater;
import com.intellij.util.containers.ContainerUtil;
@@ -84,7 +83,7 @@ public class SeverityRegistrar implements Comparator {
public static SeverityRegistrar getSeverityRegistrar(@Nullable Project project) {
return project == null
? InspectionProfileManager.getInstance().getSeverityRegistrar()
- : InspectionProjectProfileManager.getInstance(project).getSeverityRegistrar();
+ : InspectionProfileManager.getInstance(project).getSeverityRegistrar();
}
public void registerSeverity(@NotNull SeverityBasedTextAttributes info, Color renderColor) {
@@ -135,7 +134,7 @@ public class SeverityRegistrar implements Comparator {
}
- public void readExternal(Element element) {
+ public void readExternal(@NotNull Element element) {
myMap.clear();
myRendererColors.clear();
for (Element infoElement : element.getChildren(INFO_TAG)) {
@@ -151,8 +150,9 @@ public class SeverityRegistrar implements Comparator {
final List knownSeverities = getDefaultOrder();
for (String name : myReadOrder) {
HighlightSeverity severity = getSeverity(name);
- if (severity == null || !knownSeverities.contains(severity)) continue;
- read.add(severity);
+ if (severity != null && knownSeverities.contains(severity)) {
+ read.add(severity);
+ }
}
OrderMap orderMap = fromList(read);
if (orderMap.isEmpty()) {
@@ -293,7 +293,6 @@ public class SeverityRegistrar implements Comparator {
return o1 - o2;
}
-
@NotNull
private OrderMap getOrderMap() {
OrderMap orderMap;
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionManagerBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionManagerBase.java
index 4eee9c29edc3..28ae2302dbef 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionManagerBase.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionManagerBase.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.
@@ -18,7 +18,7 @@ package com.intellij.codeInspection;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.profile.codeInspection.InspectionProfileManager;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -175,10 +175,9 @@ public abstract class InspectionManagerBase extends InspectionManager {
public String getCurrentProfile() {
if (myCurrentProfileName == null) {
- final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject());
- myCurrentProfileName = profileManager.getProjectProfile();
+ myCurrentProfileName = ProjectInspectionProfileManager.getInstanceImpl(getProject()).getProjectProfile();
if (myCurrentProfileName == null) {
- myCurrentProfileName = InspectionProfileManager.getInstance().getRootProfile().getName();
+ myCurrentProfileName = InspectionProfileManager.getInstance().getCurrentProfile().getName();
}
}
return myCurrentProfileName;
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java b/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java
index dce11df2124c..32a275314206 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.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,6 @@ import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.LowPriorityAction;
import com.intellij.codeInspection.InspectionManager;
-import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
import com.intellij.openapi.editor.Editor;
@@ -55,8 +54,7 @@ public abstract class CleanupIntention implements IntentionAction, LowPriorityAc
final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false);
final AnalysisScope scope = getScope(project, file);
if (scope != null) {
- final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
- globalContext.codeCleanup(scope, profile, getText(), null, false);
+ globalContext.codeCleanup(scope, InspectionProjectProfileManager.getInstance(project).getCurrentProfile(), getText(), null, false);
}
}
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java
index d2fc4a61fe52..2f11113986ef 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java
@@ -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.
@@ -69,16 +69,16 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
private AnalysisScope myCurrentScope;
@NotNull
private final Project myProject;
- private final List myJobDescriptors = new ArrayList();
+ private final List myJobDescriptors = new ArrayList<>();
private final StdJobDescriptors myStdJobDescriptors = new StdJobDescriptors();
protected ProgressIndicator myProgressIndicator = new EmptyProgressIndicator();
private InspectionProfile myExternalProfile;
- protected final Map myExtensions = new HashMap();
+ protected final Map myExtensions = new HashMap<>();
- protected final Map myTools = new THashMap();
+ protected final Map myTools = new THashMap<>();
@NonNls public static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool";
@@ -109,8 +109,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
public InspectionProfile getCurrentProfile() {
if (myExternalProfile != null) return myExternalProfile;
- InspectionManagerBase managerEx = (InspectionManagerBase)InspectionManager.getInstance(myProject);
- String currentProfile = managerEx.getCurrentProfile();
+ String currentProfile = ((InspectionManagerBase)InspectionManager.getInstance(myProject)).getCurrentProfile();
final InspectionProjectProfileManager inspectionProfileManager = InspectionProjectProfileManager.getInstance(myProject);
Profile profile = inspectionProfileManager.getProfile(currentProfile, false);
if (profile == null) {
@@ -329,7 +328,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
protected List getUsedTools() {
InspectionProfileImpl profile = (InspectionProfileImpl)getCurrentProfile();
List tools = profile.getAllEnabledInspectionTools(myProject);
- Set dependentTools = new LinkedHashSet();
+ Set dependentTools = new LinkedHashSet<>();
for (Tools tool : tools) {
profile.collectDependentInspections(tool.getTool(), dependentTools, getProject());
}
@@ -337,9 +336,9 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
if (dependentTools.isEmpty()) {
return tools;
}
- Set set = new THashSet(tools, TOOLS_HASHING_STRATEGY);
+ Set set = new THashSet<>(tools, TOOLS_HASHING_STRATEGY);
set.addAll(ContainerUtil.map(dependentTools, toolWrapper -> new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true, true)));
- return new ArrayList(set);
+ return new ArrayList<>(set);
}
private static void classifyTool(@NotNull List outGlobalTools,
@@ -386,12 +385,12 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
public static void codeCleanup(@NotNull Project project, @NotNull AnalysisScope scope, @Nullable Runnable runnable) {
GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false);
- final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
globalContext.codeCleanup(scope, profile, null, runnable, false);
}
public static void cleanupElements(@NotNull final Project project, @Nullable final Runnable runnable, @NotNull PsiElement... scope) {
- final List> elements = new ArrayList>();
+ final List> elements = new ArrayList<>();
final SmartPointerManager manager = SmartPointerManager.getInstance(project);
for (PsiElement element : scope) {
elements.add(manager.createSmartPsiElementPointer(element));
@@ -404,7 +403,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
@Nullable final Runnable runnable,
final List> elements) {
Runnable cleanupRunnable = () -> {
- final List psiElements = new ArrayList();
+ final List psiElements = new ArrayList<>();
for (SmartPsiElementPointer element : elements) {
PsiElement psiElement = element.getElement();
if (psiElement != null && psiElement.isPhysical()) {
@@ -415,7 +414,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
return;
}
GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false);
- final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
+ final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
AnalysisScope analysisScope = new AnalysisScope(new LocalSearchScope(psiElements.toArray(new PsiElement[psiElements.size()])), project);
globalContext.codeCleanup(analysisScope, profile, null, runnable, true);
};
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 6c8ab275e5a9..02b77c327c3a 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java
@@ -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.
@@ -22,26 +22,25 @@ import com.intellij.codeInspection.InspectionEP;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ModifiableModel;
+import com.intellij.configurationStore.SchemeDataHolder;
+import com.intellij.configurationStore.SerializableScheme;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.options.ExternalizableScheme;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
-import com.intellij.profile.DefaultProjectProfileManager;
import com.intellij.profile.ProfileEx;
import com.intellij.profile.ProfileManager;
import com.intellij.profile.codeInspection.InspectionProfileManager;
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerKt;
import com.intellij.profile.codeInspection.SeverityProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.scope.packageSet.NamedScope;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
-import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.StringInterner;
import com.intellij.util.graph.CachingSemiGraph;
import com.intellij.util.graph.DFSTBuilder;
import com.intellij.util.graph.GraphGenerator;
@@ -49,19 +48,20 @@ 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;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
-import java.io.IOException;
import java.util.*;
/**
* @author max
*/
-public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme {
+public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, InspectionProfile, ExternalizableScheme,
+ SerializableScheme {
@NonNls static final String INSPECTION_TOOL_TAG = "inspection_tool";
@NonNls static final String CLASS_TAG = "class";
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionProfileImpl");
@@ -73,9 +73,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
public static boolean INIT_INSPECTIONS = false;
private final InspectionToolRegistrar myRegistrar;
@NotNull
- private final Map myUninstalledInspectionsSettings;
+ private final Map myUninitializedSettings = new TreeMap<>();
protected InspectionProfileImpl mySource;
- private Map myTools = new THashMap();
+ private Map myTools = new THashMap<>();
private volatile Map myDisplayLevelMap;
@Attribute("is_locked")
private boolean myLockedProfile;
@@ -88,9 +88,11 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private final Object myLock = new Object();
+ private SchemeDataHolder super InspectionProfileImpl> myDataHolder;
+
InspectionProfileImpl(@NotNull InspectionProfileImpl inspectionProfile) {
- this(inspectionProfile.getName(), inspectionProfile.myRegistrar, inspectionProfile.getProfileManager(), inspectionProfile.myBaseProfile);
- myUninstalledInspectionsSettings.putAll(inspectionProfile.myUninstalledInspectionsSettings);
+ this(inspectionProfile.getName(), inspectionProfile.myRegistrar, inspectionProfile.getProfileManager(), inspectionProfile.myBaseProfile, null);
+ myUninitializedSettings.putAll(inspectionProfile.myUninitializedSettings);
setProjectLevel(inspectionProfile.isProjectLevel());
myLockedProfile = inspectionProfile.myLockedProfile;
@@ -98,43 +100,40 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
copyFrom(inspectionProfile);
}
- public InspectionProfileImpl(@NotNull final String profileName,
+ public InspectionProfileImpl(@NotNull String profileName,
@NotNull InspectionToolRegistrar registrar,
- @NotNull final ProfileManager profileManager) {
- this(profileName, registrar, profileManager, getDefaultProfile());
+ @NotNull ProfileManager profileManager) {
+ this(profileName, registrar, profileManager, getDefaultProfile(), null);
}
public InspectionProfileImpl(@NotNull @NonNls String profileName) {
- this(profileName, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), null);
+ this(profileName, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), null, null);
}
- InspectionProfileImpl(@NotNull final String profileName,
- @NotNull InspectionToolRegistrar registrar,
- @NotNull final ProfileManager profileManager,
- InspectionProfileImpl baseProfile) {
+ public InspectionProfileImpl(@NotNull String profileName,
+ @NotNull InspectionToolRegistrar registrar,
+ @NotNull ProfileManager profileManager,
+ @Nullable InspectionProfileImpl baseProfile,
+ @Nullable SchemeDataHolder super InspectionProfileImpl> dataHolder) {
super(profileName);
+
myRegistrar = registrar;
myBaseProfile = baseProfile;
- setProfileManager(profileManager);
- myUninstalledInspectionsSettings = new TreeMap();
+ myDataHolder = dataHolder;
+ myProfileManager = profileManager;
}
@NotNull
public static InspectionProfileImpl createSimple(@NotNull String name,
- @NotNull final Project project,
- @NotNull final InspectionToolWrapper... toolWrappers) {
- InspectionToolRegistrar registrar = new InspectionToolRegistrar() {
+ @NotNull Project project,
+ @NotNull List toolWrappers) {
+ InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar() {
@NotNull
@Override
public List createTools() {
- return Arrays.asList(toolWrappers);
+ return toolWrappers;
}
- };
- final InspectionProfileImpl profile = new InspectionProfileImpl(name, registrar, InspectionProfileManager.getInstance());
- initAndDo((Computable)() -> {
- profile.initInspectionTools(project);
- return null;
- });
+ }, InspectionProfileManager.getInstance());
for (InspectionToolWrapper toolWrapper : toolWrappers) {
profile.enableTool(toolWrapper.getShortName(), project);
}
@@ -176,18 +175,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return mySource;
}
- @Override
- public String getBaseProfileName() {
- if (myBaseProfile == null) return null;
- return myBaseProfile.getName();
- }
-
- @Override
- @Deprecated // use corresponding constructor instead
- public void setBaseProfile(InspectionProfile profile) {
- throw new IncorrectOperationException();
- }
-
@Override
@SuppressWarnings({"SimplifiableIfStatement"})
public boolean isChanged() {
@@ -249,19 +236,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
((SeverityProvider)getProfileManager()).getOwnSeverityRegistrar().readExternal(highlightElement);
}
- StringInterner interner = new StringInterner();
for (Element toolElement : element.getChildren(INSPECTION_TOOL_TAG)) {
- // make clone to avoid retaining memory via o.parent pointers
- toolElement = toolElement.clone();
- JDOMUtil.internElement(toolElement, interner);
- myUninstalledInspectionsSettings.put(toolElement.getAttributeValue(CLASS_TAG), toolElement);
+ myUninitializedSettings.put(toolElement.getAttributeValue(CLASS_TAG), toolElement.clone());
}
}
@NotNull
public Set getUsedSeverities() {
LOG.assertTrue(myInitialized);
- final Set result = new HashSet();
+ Set result = new THashSet<>();
for (Tools tools : myTools.values()) {
for (ScopeToolState state : tools.getTools()) {
result.add(state.getLevel().getSeverity());
@@ -270,6 +253,21 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return result;
}
+ @NotNull
+ public Element writeScheme() {
+ if (myDataHolder != null) {
+ return myDataHolder.read();
+ }
+
+ Element result = isProjectLevel() ? new Element("profile").setAttribute("version", "1.0") : new Element("inspections").setAttribute("profile_name", getName());
+ serializeInto(result, false);
+
+ if (isProjectLevel()) {
+ return new Element("component").setAttribute("name", "InspectionProjectProfileManager").addContent(result);
+ }
+ return result;
+ }
+
@Override
public void serializeInto(@NotNull Element element, boolean preserveCompatibility) {
// must be first - compatibility
@@ -279,7 +277,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
synchronized (myLock) {
if (!myInitialized) {
- for (Element el : myUninstalledInspectionsSettings.values()) {
+ for (Element el : myUninitializedSettings.values()) {
element.addContent(el.clone());
}
return;
@@ -287,49 +285,51 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
Map diffMap = getDisplayLevelMap();
- if (diffMap != null) {
- diffMap = new TreeMap(diffMap);
- for (String toolName : myUninstalledInspectionsSettings.keySet()) {
- diffMap.put(toolName, false);
+ if (diffMap == null) {
+ return;
+ }
+
+ diffMap = new TreeMap<>(diffMap);
+ for (String toolName : myUninitializedSettings.keySet()) {
+ diffMap.put(toolName, false);
+ }
+
+ for (String toolName : diffMap.keySet()) {
+ if (!myLockedProfile && diffMap.get(toolName).booleanValue()) {
+ markSettingsMerged(toolName, element);
+ continue;
}
- for (String toolName : diffMap.keySet()) {
- if (!myLockedProfile && diffMap.get(toolName).booleanValue()) {
- markSettingsMerged(toolName, element);
+ Element toolElement = myUninitializedSettings.get(toolName);
+ if (toolElement == null) {
+ ToolsImpl toolList = myTools.get(toolName);
+ LOG.assertTrue(toolList != null);
+ Element inspectionElement = new Element(INSPECTION_TOOL_TAG);
+ inspectionElement.setAttribute(CLASS_TAG, toolName);
+ try {
+ toolList.writeExternal(inspectionElement);
+ }
+ catch (WriteExternalException e) {
+ LOG.error(e);
continue;
}
- Element toolElement = myUninstalledInspectionsSettings.get(toolName);
- if (toolElement == null) {
- ToolsImpl toolList = myTools.get(toolName);
- LOG.assertTrue(toolList != null);
- Element inspectionElement = new Element(INSPECTION_TOOL_TAG);
- inspectionElement.setAttribute(CLASS_TAG, toolName);
- try {
- toolList.writeExternal(inspectionElement);
- }
- catch (WriteExternalException e) {
- LOG.error(e);
- continue;
- }
-
- if (!areSettingsMerged(toolName, inspectionElement)) {
- element.addContent(inspectionElement);
- }
- }
- else {
- element.addContent(toolElement.clone());
+ if (!areSettingsMerged(toolName, inspectionElement)) {
+ element.addContent(inspectionElement);
}
}
+ else {
+ element.addContent(toolElement.clone());
+ }
}
}
- private void markSettingsMerged(String toolName, Element element) {
+ private void markSettingsMerged(@NotNull String toolName, @NotNull Element element) {
//add marker if already merged but result is now default (-> empty node)
final String mergedName = InspectionElementsMergerBase.getMergedMarkerName(toolName);
- if (!myUninstalledInspectionsSettings.containsKey(mergedName)) {
+ if (!myUninitializedSettings.containsKey(mergedName)) {
final InspectionElementsMergerBase merger = getMerger(toolName);
- if (merger != null && merger.markSettingsMerged(myUninstalledInspectionsSettings)) {
+ if (merger != null && merger.markSettingsMerged(myUninitializedSettings)) {
element.addContent(new Element(INSPECTION_TOOL_TAG).setAttribute(CLASS_TAG, mergedName));
}
}
@@ -338,7 +338,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private boolean areSettingsMerged(String toolName, Element inspectionElement) {
//skip merged settings as they could be restored from already provided data
final InspectionElementsMergerBase merger = getMerger(toolName);
- return merger != null && merger.areSettingsMerged(myUninstalledInspectionsSettings, inspectionElement);
+ return merger != null && merger.areSettingsMerged(myUninitializedSettings, inspectionElement);
}
public void collectDependentInspections(@NotNull InspectionToolWrapper toolWrapper,
@@ -383,12 +383,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
public void modifyProfile(@NotNull Consumer modelConsumer) {
ModifiableModel model = getModifiableModel();
modelConsumer.consume(model);
- try {
- model.commit();
- }
- catch (IOException e) {
- LOG.error(e);
- }
+ model.commit();
}
@Override
@@ -426,7 +421,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
final InspectionToolWrapper tool = toolList.getInspectionTool(element);
if (id.equals(tool.getID())) {
if (result == null) {
- result = new ArrayList();
+ result = new ArrayList<>();
}
result.add(tool);
}
@@ -435,7 +430,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
- public void save() throws IOException {
+ public void save() {
InspectionProfileManager.getInstance().fireProfileChanged(this);
}
@@ -479,7 +474,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@NotNull
public InspectionToolWrapper[] getInspectionTools(@Nullable PsiElement element) {
initInspectionTools(element == null ? null : element.getProject());
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (Tools toolList : myTools.values()) {
result.add(toolList.getInspectionTool(element));
}
@@ -490,7 +485,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@NotNull
public List getAllEnabledInspectionTools(Project project) {
initInspectionTools(project);
- List result = new ArrayList();
+ List result = new ArrayList<>();
for (final ToolsImpl toolList : myTools.values()) {
if (toolList.isEnabled()) {
result.add(toolList);
@@ -504,14 +499,14 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
getTools(toolId, element.getProject()).disableTool(element);
}
- public void disableToolByDefault(@NotNull List toolIds, Project project) {
- for (final String toolId : toolIds) {
+ public void disableToolByDefault(@NotNull Collection toolIds, @Nullable Project project) {
+ for (String toolId : toolIds) {
getToolDefaultState(toolId, project).setEnabled(false);
}
}
@NotNull
- public ScopeToolState getToolDefaultState(@NotNull String toolId, Project project) {
+ public ScopeToolState getToolDefaultState(@NotNull String toolId, @Nullable Project project) {
return getTools(toolId, project).getDefaultState();
}
@@ -526,15 +521,30 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
public void initInspectionTools(@Nullable Project project) {
- if (ApplicationManager.getApplication().isUnitTestMode() && !INIT_INSPECTIONS) return;
- if (myInitialized) return;
+ //noinspection TestOnlyProblems
+ if (myInitialized || (ApplicationManager.getApplication().isUnitTestMode() && !INIT_INSPECTIONS)) {
+ return;
+ }
+
synchronized (myLock) {
- if (myInitialized) return;
- myInitialized = initialize(project);
+ if (!myInitialized) {
+ initialize(project);
+ }
}
}
- private boolean initialize(@Nullable Project project) {
+ private void initialize(@Nullable Project project) {
+ SchemeDataHolder super InspectionProfileImpl> dataHolder = myDataHolder;
+ if (dataHolder != null) {
+ myDataHolder = null;
+ Element element = dataHolder.read();
+ if (element.getName().equals("component")) {
+ element = element.getChild("profile");
+ }
+ assert element != null;
+ readExternal(element);
+ }
+
if (myBaseProfile != null) {
myBaseProfile.initInspectionTools(project);
}
@@ -544,13 +554,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
tools = createTools(project);
}
catch (ProcessCanceledException ignored) {
- return false;
+ return;
}
- final Map> dependencies = new HashMap>();
+
+ final Map> dependencies = new THashMap<>();
for (InspectionToolWrapper toolWrapper : tools) {
addTool(project, toolWrapper, dependencies);
}
- final GraphGenerator graphGenerator = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph() {
+
+ DFSTBuilder builder = new DFSTBuilder<>(GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph() {
@Override
public Collection getNodes() {
return dependencies.keySet();
@@ -560,22 +572,20 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
public Iterator getIn(String n) {
return dependencies.get(n).iterator();
}
- }));
-
- DFSTBuilder builder = new DFSTBuilder(graphGenerator);
+ })));
if (builder.isAcyclic()) {
- final List scopes = builder.getSortedNodes();
- myScopesOrder = ArrayUtil.toStringArray(scopes);
+ myScopesOrder = ArrayUtil.toStringArray(builder.getSortedNodes());
}
if (mySource != null) {
copyToolsConfigurations(mySource, project);
}
- return true;
- }
- public void removeTool(@NotNull InspectionToolWrapper toolWrapper) {
- myTools.remove(toolWrapper.getShortName());
+ myInitialized = true;
+ if (dataHolder != null) {
+ // should be only after set myInitialized
+ dataHolder.updateDigest(this);
+ }
}
public void addTool(@Nullable Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull Map> dependencies) {
@@ -583,7 +593,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()) : (Computable)() -> 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());
@@ -593,7 +603,11 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
}
- LOG.assertTrue(key != null, shortName + " ; number of initialized tools: " + myTools.size());
+ if (key == null) {
+ LOG.error(shortName + " ; number of initialized tools: " + myTools.size());
+ return;
+ }
+
HighlightDisplayLevel baseLevel = myBaseProfile != null && myBaseProfile.getTools(shortName, project) != null
? myBaseProfile.getErrorLevel(key, project)
: HighlightDisplayLevel.DO_NOT_SHOW;
@@ -602,15 +616,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
//HighlightDisplayLevel level = myBaseProfile != null && myBaseProfile.getTools(shortName, project) != null ? myBaseProfile.getErrorLevel(key, project) : toolWrapper.getDefaultLevel();
boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault();
final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled);
- final Element element = myUninstalledInspectionsSettings.remove(shortName);
+ final Element element = myUninitializedSettings.remove(shortName);
try {
if (element != null) {
toolsList.readExternal(element, this, dependencies);
}
- else if (!myUninstalledInspectionsSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
+ else if (!myUninitializedSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
final InspectionElementsMergerBase merger = getMerger(shortName);
if (merger != null) {
- final Element merged = merger.merge(myUninstalledInspectionsSettings);
+ final Element merged = merger.merge(myUninitializedSettings);
if (merged != null) {
toolsList.readExternal(merged, this, dependencies);
}
@@ -653,14 +667,14 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@NotNull
- private List createTools(Project project) {
+ private List createTools(@Nullable Project project) {
if (mySource != null) {
- return ContainerUtil.map(mySource.getDefaultStates(project), state -> state.getTool());
+ return ContainerUtil.map(mySource.getDefaultStates(project), ScopeToolState::getTool);
}
return myRegistrar.createTools();
}
- private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, Project project) {
+ private HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, @Nullable Project project) {
final ToolsImpl tools = getTools(key.toString(), project);
LOG.assertTrue(tools != null, "profile name: " + myName + " base profile: " + (myBaseProfile != null ? myBaseProfile.getName() : "-") + " key: " + key);
return tools.getLevel();
@@ -668,15 +682,10 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
@NotNull
- public ModifiableModel getModifiableModel() {
+ public InspectionProfileImpl getModifiableModel() {
return new InspectionProfileImpl(this);
}
- @Override
- public void copyFrom(@NotNull InspectionProfile profile) {
- super.copyFrom(profile);
- }
-
private void copyToolsConfigurations(@NotNull InspectionProfileImpl profile, @Nullable Project project) {
try {
for (ToolsImpl toolList : profile.myTools.values()) {
@@ -710,12 +719,13 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@Override
public void cleanup(@NotNull Project project) {
- for (final ToolsImpl toolList : myTools.values()) {
+ if (!myInitialized) {
+ return;
+ }
+
+ for (ToolsImpl toolList : myTools.values()) {
if (toolList.isEnabled()) {
- for (InspectionToolWrapper toolWrapper : toolList.getAllTools()) {
- toolWrapper.projectClosed(project);
- toolWrapper.cleanup(project);
- }
+ toolList.cleanupTools(project);
}
}
}
@@ -765,7 +775,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
- public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
+ public boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element) {
if (key == null) {
return false;
}
@@ -774,7 +784,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@Override
- public boolean isToolEnabled(HighlightDisplayKey key) {
+ public boolean isToolEnabled(@Nullable HighlightDisplayKey key) {
return isToolEnabled(key, null);
}
@@ -789,7 +799,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
//invoke when isChanged() == true
@Override
- public void commit() throws IOException {
+ public void commit() {
LOG.assertTrue(mySource != null);
mySource.commit(this);
getProfileManager().updateProfile(mySource);
@@ -817,17 +827,16 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
myDescription = description;
}
- @Override
public void convert(@NotNull Element element, @NotNull Project project) {
- initInspectionTools(project);
- final Element scopes = element.getChild(DefaultProjectProfileManager.SCOPES);
+ final Element scopes = element.getChild("scopes");
if (scopes == null) {
return;
}
- final List children = scopes.getChildren(SCOPE);
- for (Object s : children) {
- Element scopeElement = (Element)s;
- final String profile = scopeElement.getAttributeValue(DefaultProjectProfileManager.PROFILE);
+
+ initInspectionTools(project);
+
+ for (Element scopeElement : scopes.getChildren(SCOPE)) {
+ final String profile = scopeElement.getAttributeValue(ProjectInspectionProfileManagerKt.PROFILE);
if (profile != null) {
final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile);
if (inspectionProfile != null) {
@@ -873,19 +882,20 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
@NotNull
- public List getAllTools(Project project) {
+ public List getAllTools(@Nullable Project project) {
initInspectionTools(project);
- final List result = new ArrayList();
+
+ List result = new ArrayList<>();
for (Tools tools : myTools.values()) {
- result.addAll(tools.getTools());
+ tools.collectTools(result);
}
return result;
}
@NotNull
- public List getDefaultStates(Project project) {
+ public List getDefaultStates(@Nullable Project project) {
initInspectionTools(project);
- final List result = new ArrayList();
+ final List result = new ArrayList<>();
for (Tools tools : myTools.values()) {
result.add(tools.getDefaultState());
}
@@ -894,7 +904,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
@NotNull
public List getNonDefaultTools(@NotNull String shortName, Project project) {
- final List result = new ArrayList();
+ final List result = new ArrayList<>();
final List nonDefaultTools = getTools(shortName, project).getNonDefaultTools();
if (nonDefaultTools != null) {
result.addAll(nonDefaultTools);
@@ -906,11 +916,6 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return getTools(key.toString(), project).isEnabled(namedScope,project);
}
- @Deprecated
- public void removeScope(@NotNull String toolId, int scopeIdx, Project project) {
- getTools(toolId, project).removeScope(scopeIdx);
- }
-
public void removeScope(@NotNull String toolId, @NotNull String scopeName, Project project) {
getTools(toolId, project).removeScope(scopeName);
}
@@ -928,12 +933,12 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private Map getDisplayLevelMap() {
if (myBaseProfile == null) return null;
if (myDisplayLevelMap == null) {
- // Synchronizing on myExternalInfo as initInspectionTools() synchronizes on it internally.
synchronized (myLock) {
if (myDisplayLevelMap == null) {
initInspectionTools(null);
- TreeMap map = new TreeMap();
- for (String toolId : myTools.keySet()) {
+ Set names = myTools.keySet();
+ Map map = new THashMap<>(names.size());
+ for (String toolId : names) {
map.put(toolId, toolSettingsAreEqual(toolId, myBaseProfile, this));
}
myDisplayLevelMap = map;
@@ -944,11 +949,10 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
return myDisplayLevelMap;
}
- @Override
public void profileChanged() {
myDisplayLevelMap = null;
}
-
+
@NotNull
@Transient
public HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey key, NamedScope scope, Project project) {
@@ -974,7 +978,7 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
}
}
- public ToolsImpl getTools(@NotNull String toolId, Project project) {
+ public ToolsImpl getTools(@NotNull String toolId, @Nullable Project project) {
initInspectionTools(project);
return myTools.get(toolId);
}
@@ -1005,15 +1009,4 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
private static class InspectionProfileImplHolder {
private static final InspectionProfileImpl DEFAULT_PROFILE = new InspectionProfileImpl(DEFAULT_PROFILE_NAME);
}
-
- public static T initAndDo(@NotNull Computable runnable) {
- boolean old = INIT_INSPECTIONS;
- try {
- INIT_INSPECTIONS = true;
- return runnable.compute();
- }
- finally {
- INIT_INSPECTIONS = old;
- }
- }
}
diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java
index a81aba306715..9a5d61d6693f 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java
@@ -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.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.codeInspection.ex;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
@@ -25,12 +24,11 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.psi.PsiElement;
-import com.intellij.util.NotNullFunction;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
-import java.util.List;
import java.util.Set;
+import java.util.function.Function;
/**
* User: anna
@@ -45,36 +43,32 @@ public class InspectionProfileWrapper {
* I.e. given strategy (if any) receives {@link InspectionProfileWrapper} object that is going to be used so far and returns
* {@link InspectionProfileWrapper} object that should be used later.
*/
- public static final Key> CUSTOMIZATION_KEY = Key.create("Inspection Profile Wrapper Customization");
+ public static final Key> CUSTOMIZATION_KEY = Key.create("Inspection Profile Wrapper Customization");
+
+ // check whether some inspection got registered twice by accident. 've bit once.
+ private static boolean alreadyChecked;
+
protected final InspectionProfile myProfile;
public InspectionProfileWrapper(@NotNull InspectionProfile profile) {
myProfile = profile;
}
- @NotNull
- public InspectionToolWrapper[] getInspectionTools(PsiElement element){
- return myProfile.getInspectionTools(element);
- }
-
- // check whether some inspection got registered twice by accident. 've bit once.
- private static boolean alreadyChecked;
public static void checkInspectionsDuplicates(@NotNull InspectionToolWrapper[] toolWrappers) {
- if (alreadyChecked) return;
+ if (alreadyChecked) {
+ return;
+ }
+
alreadyChecked = true;
- Set uniqTools = new THashSet(toolWrappers.length);
+ Set uniqueTools = new THashSet<>(toolWrappers.length);
for (InspectionToolWrapper toolWrapper : toolWrappers) {
ProgressManager.checkCanceled();
- if (!uniqTools.add(toolWrapper.getTool())) {
+ if (!uniqueTools.add(toolWrapper.getTool())) {
LOG.error("Inspection " + toolWrapper.getDisplayName() + " (" + toolWrapper.getTool().getClass() + ") already registered");
}
}
}
- public String getName() {
- return myProfile.getName();
- }
-
public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
return myProfile.isToolEnabled(key, element);
}
@@ -88,16 +82,7 @@ public class InspectionProfileWrapper {
return myProfile.getInspectionTool(shortName, element);
}
- public void init(@NotNull Project project) {
- final List profileEntries = myProfile.getAllEnabledInspectionTools(project);
- for (Tools profileEntry : profileEntries) {
- for (ScopeToolState toolState : profileEntry.getTools()) {
- toolState.getTool().projectOpened(project);
- }
- }
- }
-
- public void cleanup(@NotNull Project project){
+ public void cleanup(@NotNull Project project) {
myProfile.cleanup(project);
}
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 b1612bdc4ff6..4eb039b464d9 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionToolRegistrar.java
@@ -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.
@@ -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,40 +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));
- }
- for (InspectionToolsFactory factory : Extensions.getExtensions(InspectionToolsFactory.EXTENSION_POINT_NAME)) {
- for (final InspectionProfileEntry profileEntry : factory.createTools()) {
- factories.add(() -> wrapTool(profileEntry));
- }
- }
- 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) {
@@ -82,13 +85,14 @@ public class InspectionToolRegistrar {
}
private static void registerTools(@NotNull Collection providers,
- @NotNull List> factories) {
+ @NotNull List> factories) {
for (InspectionToolProvider provider : providers) {
- Class[] classes = provider.getInspectionClasses();
- for (final Class aClass : classes) {
- Factory factory =
- () -> wrapTool((InspectionProfileEntry)InspectionToolsRegistrarCore.instantiateTool(aClass));
- factories.add(factory);
+ //noinspection unchecked
+ for (Class aClass : provider.getInspectionClasses()) {
+ factories.add(() -> {
+ InspectionProfileEntry entry = InspectionToolsRegistrarCore.instantiateTool(aClass);
+ return entry == null ? null : wrapTool(entry);
+ });
}
}
}
@@ -101,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 21564c250ab1..1cca5efb7499 100644
--- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java
+++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/LocalInspectionToolWrapper.java
@@ -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.
@@ -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;
@@ -95,7 +93,7 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper();
+ myTools = new ArrayList<>();
if (scopeToolState.isEnabled()) {
setEnabled(true);
}
@@ -101,7 +101,7 @@ public class ToolsImpl implements Tools {
@NotNull
@Override
- public InspectionToolWrapper getInspectionTool(PsiElement element) {
+ public InspectionToolWrapper getInspectionTool(@Nullable PsiElement element) {
if (myTools != null) {
final PsiFile containingFile = element == null ? null : element.getContainingFile();
final Project project = containingFile == null ? null : containingFile.getProject();
@@ -130,14 +130,10 @@ public class ToolsImpl implements Tools {
return myShortName;
}
- @NotNull
- public List getAllTools() {
- List result = new ArrayList();
+ public void cleanupTools(@NotNull Project project) {
for (ScopeToolState state : getTools()) {
- InspectionToolWrapper toolWrapper = state.getTool();
- result.add(toolWrapper);
+ state.getTool().cleanup(project);
}
- return result;
}
public void writeExternal(@NotNull Element inspectionElement) throws WriteExternalException {
@@ -179,10 +175,9 @@ public class ToolsImpl implements Tools {
myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
final InspectionToolWrapper toolWrapper = myDefaultState.getTool();
- final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
- final List scopeNames = new ArrayList();
- for (Object sO : scopeElements) {
- final Element scopeElement = (Element)sO;
+ final List scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
+ final List scopeNames = new ArrayList<>();
+ for (Element scopeElement : scopeElements) {
final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
if (scopeName == null) {
continue;
@@ -218,7 +213,7 @@ public class ToolsImpl implements Tools {
String scopeName = scopeNames.get(i);
List order = dependencies.get(scopeName);
if (order == null) {
- order = new ArrayList();
+ order = new ArrayList<>();
dependencies.put(scopeName, order);
}
for (int j = i + 1; j < scopeNames.size(); j++) {
@@ -244,12 +239,23 @@ public class ToolsImpl implements Tools {
@Override
@NotNull
public List getTools() {
- if (myTools == null) return Collections.singletonList(myDefaultState);
- List result = new ArrayList(myTools);
+ if (myTools == null) {
+ return Collections.singletonList(myDefaultState);
+ }
+
+ List result = new ArrayList<>(myTools);
result.add(myDefaultState);
return result;
}
+ @Override
+ public void collectTools(@NotNull List result) {
+ if (myTools != null) {
+ result.addAll(myTools);
+ }
+ result.add(myDefaultState);
+ }
+
@Override
@NotNull
public ScopeToolState getDefaultState() {
@@ -327,8 +333,6 @@ public class ToolsImpl implements Tools {
return myDefaultState.getLevel();
}
-
-
public HighlightDisplayLevel getLevel() {
return myDefaultState.getLevel();
}
@@ -408,7 +412,6 @@ public class ToolsImpl implements Tools {
}
}
-
public void disableTool(@NotNull PsiElement element) {
final Project project = element.getProject();
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(project);
diff --git a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java
index 388a3c8eac12..df378e3c6c38 100644
--- a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java
+++ b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java
@@ -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.
@@ -15,7 +15,7 @@
*/
package com.intellij.profile;
-import com.intellij.openapi.project.Project;
+import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerKt;
import com.intellij.util.xmlb.SmartSerializer;
import com.intellij.util.xmlb.annotations.OptionTag;
import com.intellij.util.xmlb.annotations.Transient;
@@ -61,19 +61,6 @@ public abstract class ProfileEx implements Profile {
return myName;
}
- @Override
- public void copyFrom(@NotNull Profile profile) {
- Element config = new Element("config");
- profile.writeExternal(config);
- readExternal(config);
- }
-
- @Override
- @Transient
- public boolean isLocal() {
- return !myIsProjectLevel;
- }
-
@Override
@Transient
public boolean isProjectLevel() {
@@ -85,11 +72,6 @@ public abstract class ProfileEx implements Profile {
myIsProjectLevel = isProjectLevel;
}
- @Override
- public void setLocal(boolean isLocal) {
- myIsProjectLevel = !isLocal;
- }
-
@Override
public void setName(@NotNull String name) {
myName = name;
@@ -117,13 +99,10 @@ public abstract class ProfileEx implements Profile {
}
@Override
- public void writeExternal(Element element) {
+ public final void writeExternal(Element element) {
serializeInto(element, true);
}
- public void profileChanged() {
- }
-
public boolean equals(Object o) {
return this == o || o instanceof ProfileEx && myName.equals(((ProfileEx)o).myName);
}
@@ -140,6 +119,15 @@ public abstract class ProfileEx implements Profile {
return 0;
}
- public void convert(@NotNull Element element, @NotNull Project project) {
+ @Override
+ public final void copyFrom(@NotNull Profile profile) {
+ readExternal(serializeProfile(profile));
+ }
+
+ @NotNull
+ public static Element serializeProfile(@NotNull Profile profile) {
+ Element result = new Element(ProjectInspectionProfileManagerKt.PROFILE);
+ profile.writeExternal(result);
+ return result;
}
}
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt
new file mode 100644
index 000000000000..e3e0f9201f3c
--- /dev/null
+++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/BaseInspectionProfileManager.kt
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.profile.codeInspection
+
+import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
+import com.intellij.codeInspection.InspectionProfile
+import com.intellij.codeInspection.ex.InspectionProfileImpl
+import com.intellij.configurationStore.LazySchemeProcessor
+import com.intellij.openapi.Disposable
+import com.intellij.openapi.diagnostic.Logger
+import com.intellij.openapi.options.SchemeManager
+import com.intellij.openapi.options.SchemeState
+import com.intellij.openapi.project.Project
+import com.intellij.profile.Profile
+import com.intellij.profile.ProfileChangeAdapter
+import com.intellij.util.containers.ContainerUtil
+import com.intellij.util.messages.MessageBus
+
+@JvmField
+internal val LOG = Logger.getInstance(BaseInspectionProfileManager::class.java)
+
+abstract class BaseInspectionProfileManager(messageBus: MessageBus) : InspectionProjectProfileManager() {
+ protected abstract val schemeManager: SchemeManager
+
+ protected val profileListeners: MutableList = ContainerUtil.createLockFreeCopyOnWriteList()
+ private val severityRegistrar = SeverityRegistrar(messageBus)
+
+ override final fun getSeverityRegistrar() = severityRegistrar
+
+ override final fun getOwnSeverityRegistrar() = severityRegistrar
+
+ override final fun addProfileChangeListener(listener: ProfileChangeAdapter, parentDisposable: Disposable) {
+ ContainerUtil.add(listener, profileListeners, parentDisposable)
+ }
+
+ @Suppress("OverridingDeprecatedMember")
+ override final fun addProfileChangeListener(listener: ProfileChangeAdapter) {
+ profileListeners.add(listener)
+ }
+
+ @Suppress("OverridingDeprecatedMember")
+ override final fun removeProfileChangeListener(listener: ProfileChangeAdapter) {
+ profileListeners.remove(listener)
+ }
+
+ internal fun cleanupSchemes(project: Project) {
+ for (profile in schemeManager.allSchemes) {
+ profile.cleanup(project)
+ }
+ }
+
+ override final fun fireProfileChanged(profile: Profile?) {
+ if (profile is InspectionProfileImpl) {
+ profile.profileChanged()
+ }
+ for (adapter in profileListeners) {
+ adapter.profileChanged(profile)
+ }
+ }
+
+ override final fun fireProfileChanged(oldProfile: Profile?, profile: Profile) {
+ for (adapter in profileListeners) {
+ adapter.profileActivated(oldProfile, profile)
+ }
+ }
+
+ fun addProfile(profile: InspectionProfileImpl) {
+ schemeManager.addScheme(profile)
+ }
+
+ override final fun deleteProfile(name: String) {
+ schemeManager.removeScheme(name)?.let {
+ schemeRemoved(it)
+ }
+ }
+
+ fun deleteProfile(profile: InspectionProfileImpl) {
+ schemeManager.removeScheme(profile)
+ schemeRemoved(profile)
+ }
+
+ open protected fun schemeRemoved(scheme: InspectionProfile) {
+ }
+
+ override fun updateProfile(profile: Profile) {
+ schemeManager.addScheme(profile as InspectionProfileImpl)
+ fireProfileChanged(profile)
+ }
+}
+
+abstract class InspectionProfileProcessor : LazySchemeProcessor() {
+ override fun getState(scheme: InspectionProfileImpl): SchemeState {
+ return if (scheme.wasInitialized()) SchemeState.POSSIBLY_CHANGED else SchemeState.UNCHANGED
+ }
+}
\ No newline at end of file
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java
index 83c06dc51f20..b1b299f94891 100644
--- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java
+++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileLoadUtil.java
@@ -32,7 +32,7 @@ import java.io.File;
import java.io.IOException;
public class InspectionProfileLoadUtil {
- @NonNls private static final String PROFILE_NAME_TAG = "profile_name";
+ @NonNls public static final String PROFILE_NAME_TAG = "profile_name";
@NonNls public static final String PROFILE_TAG = "profile";
private static String getProfileName(@NotNull File file, @NotNull Element element) {
@@ -40,20 +40,9 @@ public class InspectionProfileLoadUtil {
return name != null ? name : FileUtil.getNameWithoutExtension(file);
}
- private static String getRootElementAttribute(@NotNull Element element, @NonNls String name) {
- return element.getAttributeValue(name);
- }
-
@Nullable
private static String getRootElementAttribute(@NonNls String name, @NotNull Element element) {
- return getRootElementAttribute(element, name);
- }
-
- @NotNull
- public static String getProfileName(@NotNull Element element) {
- String name = getRootElementAttribute(element, PROFILE_NAME_TAG);
- if (name != null) return name;
- return "unnamed";
+ return element.getAttributeValue(name);
}
@NotNull
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileManager.java b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileManager.java
index ea3c4bd20d07..a6850e29a621 100644
--- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileManager.java
+++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProfileManager.java
@@ -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.
@@ -15,78 +15,45 @@
*/
package com.intellij.profile.codeInspection;
-import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager;
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.profile.ApplicationProfileManager;
+import com.intellij.openapi.project.Project;
import com.intellij.profile.Profile;
import com.intellij.profile.ProfileChangeAdapter;
-import com.intellij.profile.ProfileEx;
-import com.intellij.psi.search.scope.packageSet.NamedScope;
-import com.intellij.util.containers.ContainerUtil;
-import org.jdom.JDOMException;
-import org.jetbrains.annotations.NonNls;
+import com.intellij.profile.ProfileManager;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-import java.io.IOException;
-import java.util.List;
+public interface InspectionProfileManager extends ProfileManager, SeverityProvider {
+ String INSPECTION_DIR = "inspection";
-/**
- * User: anna
- * Date: 29-Nov-2005
- */
-public abstract class InspectionProfileManager extends ApplicationProfileManager implements SeverityProvider {
- @NonNls public static final String INSPECTION_DIR = "inspection";
-
- private final List myProfileChangeAdapters = ContainerUtil.createLockFreeCopyOnWriteList();
-
- protected static final Logger LOG = Logger.getInstance("#com.intellij.profile.DefaultProfileManager");
-
- public static InspectionProfileManager getInstance() {
+ @NotNull
+ static InspectionProfileManager getInstance() {
return ServiceManager.getService(InspectionProfileManager.class);
}
- public InspectionProfileManager() {
+ @NotNull
+ static InspectionProfileManager getInstance(@NotNull Project project) {
+ return InspectionProjectProfileManager.getInstance(project);
}
- protected abstract void initProfiles();
+ @Deprecated
+ @SuppressWarnings("unused")
+ void addProfileChangeListener(@NotNull ProfileChangeAdapter listener);
- public abstract Profile loadProfile(@NotNull String path) throws IOException, JDOMException;
+ @Deprecated
+ @SuppressWarnings("unused")
+ void removeProfileChangeListener(@NotNull ProfileChangeAdapter listener);
- @Override
- public void addProfileChangeListener(@NotNull final ProfileChangeAdapter listener) {
- myProfileChangeAdapters.add(listener);
+ void fireProfileChanged(@Nullable Profile profile);
+
+ void fireProfileChanged(@Nullable Profile oldProfile, @NotNull Profile profile);
+
+ void setRootProfile(@Nullable String name);
+
+ @SuppressWarnings("unused")
+ @NotNull
+ @Deprecated
+ default Profile getRootProfile() {
+ return getCurrentProfile();
}
-
- @Override
- public void addProfileChangeListener(@NotNull ProfileChangeAdapter listener, @NotNull Disposable parentDisposable) {
- ContainerUtil.add(listener, myProfileChangeAdapters, parentDisposable);
- }
-
- @Override
- public void removeProfileChangeListener(@NotNull final ProfileChangeAdapter listener) {
- myProfileChangeAdapters.remove(listener);
- }
-
- @Override
- public void fireProfileChanged(final Profile profile) {
- if (profile instanceof ProfileEx) {
- ((ProfileEx)profile).profileChanged();
- }
- for (ProfileChangeAdapter adapter : myProfileChangeAdapters) {
- adapter.profileChanged(profile);
- }
- }
-
- @Override
- public void fireProfileChanged(final Profile oldProfile, final Profile profile, final NamedScope scope) {
- for (ProfileChangeAdapter adapter : myProfileChangeAdapters) {
- adapter.profileActivated(oldProfile, profile);
- }
- }
-
- @Override
- public Profile getProfile(@NotNull final String name) {
- return getProfile(name, true);
- }
-}
+}
\ No newline at end of file
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java
index a734765ca23c..068ee1408609 100644
--- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java
+++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.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.
@@ -16,72 +16,29 @@
package com.intellij.profile.codeInspection;
import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.openapi.components.PersistentStateComponent;
-import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
-import com.intellij.packageDependencies.DependencyValidationManager;
-import com.intellij.profile.DefaultProjectProfileManager;
-import com.intellij.profile.Profile;
import com.intellij.psi.PsiElement;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
-/**
- * User: anna
- * Date: 30-Nov-2005
- */
-public abstract class InspectionProjectProfileManager extends DefaultProjectProfileManager implements ProjectComponent, SeverityProvider, PersistentStateComponent {
- public InspectionProjectProfileManager(@NotNull Project project,
- @NotNull InspectionProfileManager inspectionProfileManager,
- @NotNull DependencyValidationManager holder) {
- super(project, inspectionProfileManager, holder);
- }
-
- public static InspectionProjectProfileManager getInstance(Project project){
+// todo deprecate
+// cannot be interface due to backward compatibility
+public abstract class InspectionProjectProfileManager implements InspectionProfileManager {
+ public static InspectionProjectProfileManager getInstance(@NotNull Project project){
return project.getComponent(InspectionProjectProfileManager.class);
}
- @Override
- public String getProfileName() {
- return getInspectionProfile().getName();
- }
-
@NotNull
- public InspectionProfile getInspectionProfile(){
- return (InspectionProfile)getProjectProfileImpl();
+ @Deprecated
+ public InspectionProfile getInspectionProfile() {
+ return getCurrentProfile();
}
/**
- * @deprecated use {@link #getInspectionProfile()} instead
+ * @deprecated use {@link #getCurrentProfile()} instead
*/
@SuppressWarnings({"UnusedDeclaration"})
@NotNull
public InspectionProfile getInspectionProfile(PsiElement element){
- return getInspectionProfile();
- }
-
- public abstract boolean isProfileLoaded();
-
- @Override
- @NotNull
- @NonNls
- public String getComponentName() {
- return "InspectionProjectProfileManager";
- }
-
- @Override
- public void initComponent() {
- }
-
- @Override
- public void disposeComponent() {
- }
-
- public abstract void initProfileWrapper(@NotNull Profile profile);
-
- @Override
- public Profile getProfile(@NotNull final String name) {
- return getProfile(name, true);
+ return getCurrentProfile();
}
}
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.java b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.java
deleted file mode 100644
index 5a275782e8a9..000000000000
--- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright 2000-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.profile.codeInspection;
-
-import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
-import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.codeInspection.ex.InspectionProfileWrapper;
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.project.DumbAwareRunnable;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.startup.StartupManager;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.packageDependencies.DependencyValidationManager;
-import com.intellij.profile.DefaultProjectProfileManager;
-import com.intellij.profile.Profile;
-import com.intellij.profile.ProfileEx;
-import com.intellij.psi.search.scope.packageSet.NamedScopeManager;
-import com.intellij.psi.search.scope.packageSet.NamedScopesHolder;
-import com.intellij.util.ui.UIUtil;
-import org.jdom.Element;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * User: anna
- * Date: 30-Nov-2005
- */
-@State(
- name = "InspectionProjectProfileManager",
- storages = @Storage(value = "inspectionProfiles", stateSplitter = DefaultProjectProfileManager.ProfileStateSplitter.class)
-)
-public class InspectionProjectProfileManagerImpl extends InspectionProjectProfileManager {
- private final Map myName2Profile = new ConcurrentHashMap();
- private final Map myAppName2Profile = new ConcurrentHashMap();
- private final SeverityRegistrar mySeverityRegistrar;
- private final NamedScopeManager myLocalScopesHolder;
- private NamedScopesHolder.ScopeListener myScopeListener;
-
- public InspectionProjectProfileManagerImpl(@NotNull Project project,
- @NotNull InspectionProfileManager inspectionProfileManager,
- @NotNull DependencyValidationManager holder,
- @NotNull NamedScopeManager localScopesHolder) {
- super(project, inspectionProfileManager, holder);
- myLocalScopesHolder = localScopesHolder;
- mySeverityRegistrar = new SeverityRegistrar(project.getMessageBus());
- }
-
- public static InspectionProjectProfileManagerImpl getInstanceImpl(Project project){
- return (InspectionProjectProfileManagerImpl)project.getComponent(InspectionProjectProfileManager.class);
- }
-
- @Override
- public boolean isProfileLoaded() {
- final InspectionProfile profile = getInspectionProfile();
- final String name = profile.getName();
- return profile.getProfileManager() == this ? myName2Profile.containsKey(name) : myAppName2Profile.containsKey(name);
- }
-
- @NotNull
- public synchronized InspectionProfileWrapper getProfileWrapper(){
- final InspectionProfile profile = getInspectionProfile();
- final String profileName = profile.getName();
- if (profile.getProfileManager() == this) {
- if (!myName2Profile.containsKey(profileName)){
- initProfileWrapper(profile);
- }
- return myName2Profile.get(profileName);
- }
- else {
- if (!myAppName2Profile.containsKey(profileName)) {
- initProfileWrapper(profile);
- }
- return myAppName2Profile.get(profileName);
- }
- }
-
- public InspectionProfileWrapper getProfileWrapper(final String profileName){
- return myName2Profile.get(profileName);
- }
-
- @Override
- public void updateProfile(@NotNull Profile profile) {
- super.updateProfile(profile);
- initProfileWrapper(profile);
- }
-
- @Override
- public void deleteProfile(@NotNull String name) {
- super.deleteProfile(name);
- final InspectionProfileWrapper profileWrapper = myName2Profile.remove(name);
- if (profileWrapper != null) {
- profileWrapper.cleanup(myProject);
- }
- }
-
- @Override
- public void projectOpened() {
- StartupManager startupManager = StartupManager.getInstance(myProject);
- if (startupManager == null) {
- return; // upsource
- }
- startupManager.registerPostStartupActivity(new DumbAwareRunnable() {
- @Override
- public void run() {
- final Set profiles = new HashSet();
- profiles.add(getProjectProfileImpl());
- profiles.addAll(getProfiles());
- profiles.addAll(InspectionProfileManager.getInstance().getProfiles());
- final Application app = ApplicationManager.getApplication();
- Runnable initInspectionProfilesRunnable = () -> {
- for (Profile profile : profiles) {
- initProfileWrapper(profile);
- }
- fireProfilesInitialized();
- };
- if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
- initInspectionProfilesRunnable.run();
- UIUtil.dispatchAllInvocationEvents(); //do not restart daemon in the middle of the test
- }
- else {
- app.executeOnPooledThread(initInspectionProfilesRunnable);
- }
- myScopeListener = new NamedScopesHolder.ScopeListener() {
- @Override
- public void scopesChanged() {
- for (Profile profile : getProfiles()) {
- ((InspectionProfile)profile).scopesChanged();
- }
- }
- };
- myHolder.addScopeListener(myScopeListener);
- myLocalScopesHolder.addScopeListener(myScopeListener);
- Disposer.register(myProject, new Disposable() {
- @Override
- public void dispose() {
- myHolder.removeScopeListener(myScopeListener);
- myLocalScopesHolder.removeScopeListener(myScopeListener);
- }
- });
- }
- });
- }
-
- @Override
- public void initProfileWrapper(@NotNull Profile profile) {
- final InspectionProfileWrapper wrapper = new InspectionProfileWrapper((InspectionProfile)profile);
- wrapper.init(myProject);
- String profileName = profile.getName();
- if (profile.getProfileManager() == this) {
- myName2Profile.put(profileName, wrapper);
- }
- else {
- myAppName2Profile.put(profileName, wrapper);
- }
- }
-
- @Override
- public void projectClosed() {
- final Application app = ApplicationManager.getApplication();
- Runnable cleanupInspectionProfilesRunnable = () -> {
- for (InspectionProfileWrapper wrapper : myName2Profile.values()) {
- wrapper.cleanup(myProject);
- }
- for (InspectionProfileWrapper wrapper : myAppName2Profile.values()) {
- wrapper.cleanup(myProject);
- }
- fireProfilesShutdown();
- };
- if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
- cleanupInspectionProfilesRunnable.run();
- }
- else {
- app.executeOnPooledThread(cleanupInspectionProfilesRunnable);
- }
- }
-
- @NotNull
- @Override
- public SeverityRegistrar getSeverityRegistrar() {
- return mySeverityRegistrar;
- }
-
- @NotNull
- @Override
- public SeverityRegistrar getOwnSeverityRegistrar() {
- return mySeverityRegistrar;
- }
-
- @Override
- public void loadState(Element state) {
- try {
- mySeverityRegistrar.readExternal(state);
- }
- catch (Throwable e) {
- LOG.error(e);
- }
- super.loadState(state);
- }
-
- @Override
- public Element getState() {
- Element state = super.getState();
- mySeverityRegistrar.writeExternal(state);
- return state;
- }
-
- @Override
- public Profile getProfile(@NotNull final String name) {
- return getProfile(name, true);
- }
-
- @Override
- public void convert(Element element) {
- super.convert(element);
- if (getProjectProfile() != null) {
- ((ProfileEx)getProjectProfileImpl()).convert(element, getProject());
- }
- }
-}
diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt
new file mode 100644
index 000000000000..bc3ac0a6481d
--- /dev/null
+++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt
@@ -0,0 +1,322 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.profile.codeInspection
+
+import com.intellij.codeInspection.InspectionProfile
+import com.intellij.codeInspection.ex.InspectionProfileImpl
+import com.intellij.codeInspection.ex.InspectionToolRegistrar
+import com.intellij.concurrency.runAsync
+import com.intellij.configurationStore.SchemeDataHolder
+import com.intellij.configurationStore.digest
+import com.intellij.openapi.Disposable
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.components.PersistentStateComponent
+import com.intellij.openapi.components.State
+import com.intellij.openapi.components.Storage
+import com.intellij.openapi.options.SchemeManager
+import com.intellij.openapi.options.SchemeManagerFactory
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.project.ProjectManager
+import com.intellij.openapi.project.ProjectManagerListener
+import com.intellij.openapi.startup.StartupActivity
+import com.intellij.openapi.util.Disposer
+import com.intellij.openapi.util.JDOMUtil
+import com.intellij.openapi.util.text.StringUtil
+import com.intellij.packageDependencies.DependencyValidationManager
+import com.intellij.profile.Profile
+import com.intellij.psi.search.scope.packageSet.NamedScopeManager
+import com.intellij.psi.search.scope.packageSet.NamedScopesHolder
+import com.intellij.util.loadElement
+import com.intellij.util.ui.UIUtil
+import com.intellij.util.xmlb.Accessor
+import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
+import com.intellij.util.xmlb.XmlSerializer
+import org.jdom.Element
+import org.jetbrains.annotations.TestOnly
+import java.util.*
+import java.util.concurrent.CompletableFuture
+import java.util.function.Function
+
+const val PROFILE = "profile"
+
+private const val VERSION = "1.0"
+private const val SCOPE = "scope"
+private const val NAME = "name"
+private const val PROJECT_DEFAULT_PROFILE_NAME = "Project Default"
+
+private val defaultSchemeDigest = loadElement("""
+
+
+
+ """).digest()
+
+@State(name = "InspectionProjectProfileManager", storages = arrayOf(Storage(value = "inspectionProfiles/profiles_settings.xml", exclusive = true)))
+class ProjectInspectionProfileManager(val project: Project,
+ private val applicationProfileManager: InspectionProfileManager,
+ private val scopeManager: DependencyValidationManager,
+ private val localScopesHolder: NamedScopeManager,
+ schemeManagerFactory: SchemeManagerFactory) : BaseInspectionProfileManager(project.messageBus), PersistentStateComponent {
+ companion object {
+ @JvmStatic
+ fun getInstanceImpl(project: Project): ProjectInspectionProfileManager {
+ return InspectionProjectProfileManager.getInstance(project) as ProjectInspectionProfileManager
+ }
+ }
+
+ private var scopeListener: NamedScopesHolder.ScopeListener? = null
+
+ private var state = State()
+
+ private val initialLoadSchemesFuture: CompletableFuture<*>
+
+ private val skipDefaultsSerializationFilter = object : SkipDefaultValuesSerializationFilters(State()) {
+ override fun accepts(accessor: Accessor, bean: Any, beanValue: Any?): Boolean {
+ if (beanValue == null && accessor.name == "projectProfile") {
+ return false
+ }
+ return super.accepts(accessor, bean, beanValue)
+ }
+ }
+
+ override val schemeManager: SchemeManager
+
+ private data class State(@field:com.intellij.util.xmlb.annotations.OptionTag("PROJECT_PROFILE") var projectProfile: String? = PROJECT_DEFAULT_PROFILE_NAME,
+ @field:com.intellij.util.xmlb.annotations.OptionTag("USE_PROJECT_PROFILE") var useProjectProfile: Boolean = true)
+
+ init {
+ schemeManager = schemeManagerFactory.create("inspectionProfiles", object : InspectionProfileProcessor() {
+ override fun createScheme(dataHolder: SchemeDataHolder, name: String, attributeProvider: Function, duringLoad: Boolean): InspectionProfileImpl {
+ val profile = InspectionProfileImpl(name, InspectionToolRegistrar.getInstance(), this@ProjectInspectionProfileManager, InspectionProfileImpl.getDefaultProfile(), dataHolder)
+ profile.isProjectLevel = true
+ return profile
+ }
+
+ override fun isSchemeFile(name: CharSequence) = !StringUtil.equals(name, "profiles_settings.xml")
+
+ override fun isSchemeDefault(scheme: InspectionProfileImpl, digest: ByteArray): Boolean {
+ return scheme.name == PROJECT_DEFAULT_PROFILE_NAME && Arrays.equals(digest, defaultSchemeDigest)
+ }
+
+ override fun onSchemeDeleted(scheme: InspectionProfileImpl) {
+ schemeRemoved(scheme)
+ }
+
+ override fun onSchemeAdded(scheme: InspectionProfileImpl) {
+ if (scheme.wasInitialized()) {
+ fireProfileChanged(scheme)
+ }
+ }
+
+ override fun onCurrentSchemeSwitched(oldScheme: InspectionProfileImpl?, newScheme: InspectionProfileImpl?) {
+ for (adapter in profileListeners) {
+ adapter.profileActivated(oldScheme, newScheme)
+ }
+ }
+ }, isUseOldFileNameSanitize = true)
+
+ val app = ApplicationManager.getApplication()
+ if (app.isUnitTestMode) {
+ initialLoadSchemesFuture = CompletableFuture.completedFuture(null)
+ }
+ else {
+ initialLoadSchemesFuture = runAsync { schemeManager.loadSchemes() }
+ }
+
+ project.messageBus.connect().subscribe(ProjectManager.TOPIC, object: ProjectManagerListener {
+ override fun projectClosed(project: Project) {
+ val cleanupInspectionProfilesRunnable = {
+ cleanupSchemes(project)
+ (InspectionProfileManager.getInstance() as BaseInspectionProfileManager).cleanupSchemes(project)
+ fireProfilesShutdown()
+ }
+
+ if (app.isUnitTestMode || app.isHeadlessEnvironment) {
+ cleanupInspectionProfilesRunnable.invoke()
+ }
+ else {
+ app.executeOnPooledThread(cleanupInspectionProfilesRunnable)
+ }
+ }
+ })
+ }
+
+ @TestOnly
+ fun forceLoadSchemes() {
+ LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode)
+ schemeManager.loadSchemes()
+ }
+
+ fun isCurrentProfileInitialized() = currentProfile.wasInitialized()
+
+ @Synchronized override fun updateProfile(profile: Profile) {
+ super.updateProfile(profile)
+
+ (profile as InspectionProfileImpl).initInspectionTools(project)
+ }
+
+ override fun schemeRemoved(scheme: InspectionProfile) {
+ scheme.cleanup(project)
+ }
+
+ @Suppress("unused")
+ private class ProjectInspectionProfileStartUpActivity : StartupActivity {
+ override fun runActivity(project: Project) {
+ getInstanceImpl(project).apply {
+ initialLoadSchemesFuture.thenAccept {
+ currentProfile.initInspectionTools(project)
+ fireProfilesInitialized()
+
+ val app = ApplicationManager.getApplication()
+ if (app.isUnitTestMode && app.isDispatchThread) {
+ // do not restart daemon in the middle of the test
+ //noinspection TestOnlyProblems
+ UIUtil.dispatchAllInvocationEvents()
+ }
+ }
+
+ scopeListener = NamedScopesHolder.ScopeListener {
+ for (profile in schemeManager.allSchemes) {
+ profile.scopesChanged()
+ }
+ }
+
+ scopeManager.addScopeListener(scopeListener!!)
+ localScopesHolder.addScopeListener(scopeListener!!)
+ Disposer.register(project, Disposable {
+ scopeManager.removeScopeListener(scopeListener!!)
+ localScopesHolder.removeScopeListener(scopeListener!!)
+ })
+ }
+ }
+ }
+
+ @Synchronized override fun loadState(state: Element) {
+ val data = state.getChild("settings")
+
+ val newState = State()
+
+ data?.let {
+ try {
+ severityRegistrar.readExternal(it)
+ }
+ catch (e: Throwable) {
+ LOG.error(e)
+ }
+
+ XmlSerializer.deserializeInto(newState, it)
+ }
+
+ this.state = newState
+
+ if (data != null && data.getChild("version")?.getAttributeValue("value") != VERSION) {
+ for (o in data.getChildren("option")) {
+ if (o.getAttributeValue("name") == "USE_PROJECT_LEVEL_SETTINGS") {
+ if (o.getAttributeValue("value").toBoolean()) {
+ if (newState.projectProfile != null) {
+ currentProfile.convert(data, project)
+ }
+ }
+ break
+ }
+ }
+ }
+
+ if (newState.useProjectProfile) {
+ schemeManager.currentSchemeName = newState.projectProfile
+ }
+ }
+
+ @Synchronized override fun getState(): Element? {
+ val result = Element("settings")
+ val state = this.state
+ state.projectProfile = schemeManager.currentSchemeName
+ XmlSerializer.serializeInto(state, result, skipDefaultsSerializationFilter)
+ if (!result.children.isEmpty()) {
+ result.addContent(Element("version").setAttribute("value", VERSION))
+ }
+
+ severityRegistrar.writeExternal(result)
+ if (JDOMUtil.isEmpty(result)) {
+ result.name = "state"
+ return result
+ }
+ else {
+ return Element("state").addContent(result)
+ }
+ }
+
+ override fun getScopesManager() = scopeManager
+
+ @Synchronized override fun getProfiles(): Collection {
+ currentProfile
+ return schemeManager.allSchemes
+ }
+
+ @Synchronized override fun getAvailableProfileNames(): Array = schemeManager.allSchemeNames.toTypedArray()
+
+ val projectProfile: String?
+ get() = schemeManager.currentSchemeName
+
+ @Synchronized override fun setRootProfile(name: String?) {
+ if (name != schemeManager.currentSchemeName) {
+ schemeManager.currentSchemeName = name
+ state.useProjectProfile = name != null
+ }
+ }
+
+ @Synchronized fun setCurrentProfile(profile: InspectionProfileImpl?) {
+ schemeManager.setCurrent(profile)
+ state.useProjectProfile = profile != null
+ }
+
+ @Synchronized override fun getCurrentProfile(): InspectionProfileImpl {
+ if (!state.useProjectProfile) {
+ return applicationProfileManager.currentProfile as InspectionProfileImpl
+ }
+
+ var currentScheme = schemeManager.currentScheme
+ if (currentScheme == null) {
+ currentScheme = schemeManager.allSchemes.firstOrNull()
+ if (currentScheme == null) {
+ currentScheme = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this,
+ InspectionProfileImpl.getDefaultProfile(), null)
+ currentScheme.copyFrom(applicationProfileManager.currentProfile)
+ currentScheme.isProjectLevel = true
+ currentScheme.setName(PROJECT_DEFAULT_PROFILE_NAME)
+ schemeManager.addScheme(currentScheme)
+ }
+ schemeManager.setCurrent(currentScheme, false)
+ }
+ return currentScheme
+ }
+
+ private fun fireProfilesInitialized() {
+ for (listener in profileListeners) {
+ listener.profilesInitialized()
+ }
+ }
+
+ private fun fireProfilesShutdown() {
+ for (profileChangeAdapter in profileListeners) {
+ profileChangeAdapter.profilesShutdown()
+ }
+ }
+
+ @Synchronized override fun getProfile(name: String, returnRootProfileIfNamedIsAbsent: Boolean): Profile? {
+ val profile = schemeManager.findSchemeByName(name)
+ return profile ?: applicationProfileManager.getProfile(name, returnRootProfileIfNamedIsAbsent)
+ }
+}
\ No newline at end of file
diff --git a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt
index 05d4a01735cb..8d160a67f44d 100644
--- a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt
+++ b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt
@@ -26,9 +26,10 @@ import com.intellij.openapi.components.impl.ServiceManagerImpl
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.NamedJDOMExternalizable
-import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VfsUtil
+import com.intellij.util.delete
+import com.intellij.util.outputStream
import org.jdom.Element
private class ApplicationPathMacroManager : BasePathMacroManager(null)
@@ -67,7 +68,7 @@ class ApplicationStoreImpl(private val application: Application, pathMacroManage
}
}
-class ApplicationStorageManager(private val application: Application, pathMacroManager: PathMacroManager? = null) : StateStorageManagerImpl("application", pathMacroManager?.createTrackingSubstitutor(), application) {
+class ApplicationStorageManager(application: Application, pathMacroManager: PathMacroManager? = null) : StateStorageManagerImpl("application", pathMacroManager?.createTrackingSubstitutor(), application) {
companion object {
private val DEFAULT_STORAGE_SPEC = "${PathManager.DEFAULT_OPTIONS_FILE_NAME}${FileStorageCoreUtil.DEFAULT_EXT}"
@@ -95,8 +96,7 @@ class ApplicationStorageManager(private val application: Application, pathMacroM
storage.file.delete()
}
else {
- FileUtilRt.createParentDirs(storage.file)
- JDOMUtil.writeElement(element, storage.file.writer(), "\n")
+ JDOMUtil.writeElement(element, storage.file.outputStream().writer(), "\n")
}
}
catch (e: Throwable) {
diff --git a/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt b/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt
index bcf5595f007f..bdb7fa0c70a7 100644
--- a/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt
+++ b/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt
@@ -21,7 +21,8 @@ import com.intellij.openapi.components.impl.stores.StateStorageManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.impl.ProjectImpl
import org.jdom.Element
-import java.io.File
+import java.nio.file.Path
+import java.nio.file.Paths
internal class DefaultProjectStoreImpl(override val project: ProjectImpl, private val pathMacroManager: PathMacroManager) : ComponentStoreImpl() {
companion object {
@@ -36,9 +37,9 @@ internal class DefaultProjectStoreImpl(override val project: ProjectImpl, privat
service().project = project
}
- private val storage by lazy { DefaultProjectStorage(File(ApplicationManager.getApplication().stateStore.stateStorageManager.expandMacros(FILE_SPEC)), FILE_SPEC, pathMacroManager) }
+ private val storage by lazy { DefaultProjectStorage(Paths.get(ApplicationManager.getApplication().stateStore.stateStorageManager.expandMacros(FILE_SPEC)), FILE_SPEC, pathMacroManager) }
- private class DefaultProjectStorage(file: File, fileSpec: String, pathMacroManager: PathMacroManager) : FileBasedStorage(file, fileSpec, "defaultProject", pathMacroManager.createTrackingSubstitutor(), RoamingType.DISABLED) {
+ private class DefaultProjectStorage(file: Path, fileSpec: String, pathMacroManager: PathMacroManager) : FileBasedStorage(file, fileSpec, "defaultProject", pathMacroManager.createTrackingSubstitutor(), RoamingType.DISABLED) {
override public fun loadLocalData(): Element? {
val element = super.loadLocalData() ?: return null
try {
@@ -77,7 +78,7 @@ internal class DefaultProjectStoreImpl(override val project: ProjectImpl, privat
// don't want to optimize and use already loaded data - it will add unnecessary complexity and implementation-lock (currently we store loaded archived state in memory, but later implementation can be changed)
fun getStateCopy() = storage.loadLocalData()
- override final fun getPathMacroManagerForDefaults() = pathMacroManager
+ override fun getPathMacroManagerForDefaults() = pathMacroManager
override fun getStorageSpecs(component: PersistentStateComponent, stateSpec: State, operation: StateStorageOperation) = arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
diff --git a/platform/configuration-store-impl/src/DirectoryBasedStorage.kt b/platform/configuration-store-impl/src/DirectoryBasedStorage.kt
index 81b09e8d6281..d8d2531a487b 100644
--- a/platform/configuration-store-impl/src/DirectoryBasedStorage.kt
+++ b/platform/configuration-store-impl/src/DirectoryBasedStorage.kt
@@ -23,16 +23,11 @@ import com.intellij.openapi.components.TrackingPathMacroSubstitutor
import com.intellij.openapi.components.impl.stores.DirectoryStorageUtil
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
import com.intellij.openapi.components.impl.stores.StateStorageBase
-import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.Pair
-import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
-import com.intellij.util.LineSeparator
-import com.intellij.util.SmartList
-import com.intellij.util.SystemProperties
+import com.intellij.util.*
import com.intellij.util.containers.SmartHashSet
-import com.intellij.util.systemIndependentPath
import gnu.trove.THashMap
import org.jdom.Element
import java.io.IOException
@@ -119,7 +114,7 @@ open class DirectoryBasedStorage(private val dir: Path,
override fun setSerializedState(componentName: String, element: Element?) {
storage.componentName = componentName
- if (JDOMUtil.isEmpty(element)) {
+ if (element.isEmpty()) {
if (copiedStorageData != null) {
copiedStorageData!!.clear()
}
@@ -254,9 +249,6 @@ private fun loadFile(file: VirtualFile?): Pair {
}
val bytes = file.contentsToByteArray()
- var lineSeparator: String? = file.detectedLineSeparator
- if (lineSeparator == null) {
- lineSeparator = detectLineSeparators(CharsetToolkit.UTF8_CHARSET.decode(ByteBuffer.wrap(bytes)), null).separatorString
- }
+ val lineSeparator = file.detectedLineSeparator ?: detectLineSeparators(Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)), null).separatorString
return Pair.create(bytes, lineSeparator)
}
\ No newline at end of file
diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt
index e5ff1d7d0ba7..d3e02082de94 100644
--- a/platform/configuration-store-impl/src/ExportSettingsAction.kt
+++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt
@@ -38,7 +38,7 @@ import com.intellij.openapi.components.impl.stores.StoreUtil
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.extensions.PluginDescriptor
import com.intellij.openapi.options.OptionsBundle
-import com.intellij.openapi.options.SchemesManagerFactory
+import com.intellij.openapi.options.SchemeManagerFactory
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.io.FileUtilRt
@@ -240,7 +240,7 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
})
// must be in the end - because most of SchemeManager clients specify additionalExportFile in the State spec
- (SchemesManagerFactory.getInstance() as SchemeManagerFactoryBase).process {
+ (SchemeManagerFactory.getInstance() as SchemeManagerFactoryBase).process {
if (it.roamingType != RoamingType.DISABLED && it.presentableName != null && it.fileSpec.getOrNull(0) != '$') {
val file = Paths.get(storageManager.expandMacros(ROOT_CONFIG), it.fileSpec)
if (!result.containsKey(file) && !isSkipFile(file)) {
diff --git a/platform/configuration-store-impl/src/FileBasedStorage.kt b/platform/configuration-store-impl/src/FileBasedStorage.kt
index c08fa660cbc2..da3320122ea9 100644
--- a/platform/configuration-store-impl/src/FileBasedStorage.kt
+++ b/platform/configuration-store-impl/src/FileBasedStorage.kt
@@ -29,24 +29,21 @@ import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream
-import com.intellij.openapi.util.io.FileUtil
-import com.intellij.openapi.util.io.systemIndependentPath
-import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
-import com.intellij.util.ArrayUtil
-import com.intellij.util.LineSeparator
-import com.intellij.util.loadElement
+import com.intellij.util.*
import org.jdom.Element
import org.jdom.JDOMException
import org.jdom.Parent
-import java.io.File
import java.io.IOException
-import java.nio.ByteBuffer
+import java.nio.file.Files
+import java.nio.file.NoSuchFileException
+import java.nio.file.Path
+import java.nio.file.attribute.BasicFileAttributes
-open class FileBasedStorage(file: File,
+open class FileBasedStorage(file: Path,
fileSpec: String,
- rootElementName: String,
+ rootElementName: String?,
pathMacroManager: TrackingPathMacroSubstitutor? = null,
roamingType: RoamingType? = null,
provider: StreamProvider? = null) : XmlElementStorage(fileSpec, rootElementName, pathMacroManager, roamingType, provider) {
@@ -58,7 +55,7 @@ open class FileBasedStorage(file: File,
private set
init {
- if (ApplicationManager.getApplication().isUnitTestMode && file.path.startsWith('$')) {
+ if (ApplicationManager.getApplication().isUnitTestMode && file.toString().startsWith('$')) {
throw AssertionError("It seems like some macros were not expanded for path: $file")
}
}
@@ -66,7 +63,7 @@ open class FileBasedStorage(file: File,
protected open val isUseXmlProlog: Boolean = false
// we never set io file to null
- fun setFile(virtualFile: VirtualFile?, ioFileIfChanged: File?) {
+ fun setFile(virtualFile: VirtualFile?, ioFileIfChanged: Path?) {
cachedVirtualFile = virtualFile
if (ioFileIfChanged != null) {
file = ioFileIfChanged
@@ -87,7 +84,7 @@ open class FileBasedStorage(file: File,
storage.lineSeparator = if (storage.isUseXmlProlog) LineSeparator.LF else LineSeparator.getSystemLineSeparator()
}
- val virtualFile = storage.getVirtualFile()
+ val virtualFile = storage.virtualFile
if (element == null) {
deleteFile(storage.file, this, virtualFile)
storage.cachedVirtualFile = null
@@ -98,29 +95,43 @@ open class FileBasedStorage(file: File,
}
}
- fun getVirtualFile(): VirtualFile? {
- var result = cachedVirtualFile
- if (result == null) {
- result = LocalFileSystem.getInstance().findFileByIoFile(file)
- cachedVirtualFile = result
+ val virtualFile: VirtualFile?
+ get() {
+ var result = cachedVirtualFile
+ if (result == null) {
+ result = LocalFileSystem.getInstance().findFileByPath(file.systemIndependentPath)
+ cachedVirtualFile = result
+ }
+ return cachedVirtualFile
}
- return cachedVirtualFile
- }
override fun loadLocalData(): Element? {
blockSavingTheContent = false
+
+ val attributes: BasicFileAttributes?
try {
- val file = getVirtualFile()
- if (file == null || file.isDirectory || !file.isValid) {
- LOG.debug { "Document was not loaded for $fileSpec file is ${if (file == null) "null" else "directory"}" }
+ attributes = Files.readAttributes(file, BasicFileAttributes::class.java)
+ }
+ catch (e: NoSuchFileException) {
+ LOG.debug(e) { "Document was not loaded for $fileSpec, doesn't exists" }
+ return null
+ }
+ catch (e: IOException) {
+ processReadException(e)
+ return null
+ }
+
+ try {
+ if (!attributes.isRegularFile) {
+ LOG.debug { "Document was not loaded for $fileSpec, not a file" }
}
- else if (file.length == 0L) {
+ else if (attributes.size() == 0L) {
processReadException(null)
}
else {
- val charBuffer = CharsetToolkit.UTF8_CHARSET.decode(ByteBuffer.wrap(file.contentsToByteArray()))
- lineSeparator = detectLineSeparators(charBuffer, if (isUseXmlProlog) null else LineSeparator.LF)
- return loadElement(charBuffer)
+ val data = file.readChars()
+ lineSeparator = detectLineSeparators(data, if (isUseXmlProlog) null else LineSeparator.LF)
+ return loadElement(data)
}
}
catch (e: JDOMException) {
@@ -150,7 +161,7 @@ open class FileBasedStorage(file: File,
override fun toString() = file.systemIndependentPath
}
-fun writeFile(file: File?, requestor: Any, virtualFile: VirtualFile?, element: Element, lineSeparator: LineSeparator, prependXmlProlog: Boolean): VirtualFile {
+fun writeFile(file: Path?, requestor: Any, virtualFile: VirtualFile?, element: Element, lineSeparator: LineSeparator, prependXmlProlog: Boolean): VirtualFile {
val result = if (file != null && (virtualFile == null || !virtualFile.isValid)) {
StorageUtil.getOrCreateVirtualFile(requestor, file)
}
@@ -238,14 +249,14 @@ internal fun detectLineSeparators(chars: CharSequence, defaultSeparator: LineSep
return defaultSeparator ?: LineSeparator.getSystemLineSeparator()
}
-private fun deleteFile(file: File, requestor: Any, virtualFile: VirtualFile?) {
+private fun deleteFile(file: Path, requestor: Any, virtualFile: VirtualFile?) {
if (virtualFile == null) {
- LOG.warn("Cannot find virtual file ${file.absolutePath}")
+ LOG.warn("Cannot find virtual file $file")
}
if (virtualFile == null) {
if (file.exists()) {
- FileUtil.delete(file)
+ file.delete()
}
}
else if (virtualFile.exists()) {
diff --git a/platform/configuration-store-impl/src/ModuleStoreImpl.kt b/platform/configuration-store-impl/src/ModuleStoreImpl.kt
index 918776deb123..0f721ed34ee3 100644
--- a/platform/configuration-store-impl/src/ModuleStoreImpl.kt
+++ b/platform/configuration-store-impl/src/ModuleStoreImpl.kt
@@ -18,8 +18,9 @@ package com.intellij.configurationStore
import com.intellij.openapi.components.*
import com.intellij.openapi.module.Module
import java.io.File
+import java.nio.file.Paths
-private val MODULE_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(StoragePathMacros.MODULE_FILE, false)
+private val MODULE_FILE_STORAGE_ANNOTATION = FileStorageAnnotation(StoragePathMacros.MODULE_FILE, false)
private open class ModuleStoreImpl(module: Module, private val pathMacroManager: PathMacroManager) : ModuleStoreBase() {
override val project = module.project
@@ -60,7 +61,7 @@ abstract class ModuleStoreBase : ComponentStoreImpl() {
override fun setPath(path: String) {
if (!storageManager.addMacro(StoragePathMacros.MODULE_FILE, path)) {
- storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, File(path))
+ storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, Paths.get(path))
}
}
}
\ No newline at end of file
diff --git a/platform/configuration-store-impl/src/ProjectStateStorageManager.kt b/platform/configuration-store-impl/src/ProjectStateStorageManager.kt
index e550dbcfcd86..a73abe689fbc 100644
--- a/platform/configuration-store-impl/src/ProjectStateStorageManager.kt
+++ b/platform/configuration-store-impl/src/ProjectStateStorageManager.kt
@@ -27,7 +27,7 @@ open class ProjectStateStorageManager(macroSubstitutor: TrackingPathMacroSubstit
private val project: ProjectImpl,
useVirtualFileTracker: Boolean = true) : StateStorageManagerImpl("project", macroSubstitutor, if (useVirtualFileTracker) project else null) {
companion object {
- val VERSION_OPTION = "version"
+ internal val VERSION_OPTION = "version"
}
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), PROJECT_CONFIG_DIR)
diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt
index 7427c2ced579..e7a75bf87f87 100644
--- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt
+++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt
@@ -53,8 +53,8 @@ const val PROJECT_CONFIG_DIR = "\$PROJECT_CONFIG_DIR$"
val IProjectStore.nameFile: Path
get() = Paths.get(projectBasePath, Project.DIRECTORY_STORE_FOLDER, ProjectImpl.NAME_FILE)
-internal val PROJECT_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(PROJECT_FILE, false)
-internal val DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(PROJECT_FILE, true)
+internal val PROJECT_FILE_STORAGE_ANNOTATION = FileStorageAnnotation(PROJECT_FILE, false)
+internal val DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION = FileStorageAnnotation(PROJECT_FILE, true)
abstract class ProjectStoreBase(override final val project: ProjectImpl) : ComponentStoreImpl(), IProjectStore {
// protected setter used in upsource
diff --git a/platform/configuration-store-impl/src/SchemeManagerFactoryImpl.kt b/platform/configuration-store-impl/src/SchemeManagerFactoryImpl.kt
index 6508108e5882..78ce881f97f0 100644
--- a/platform/configuration-store-impl/src/SchemeManagerFactoryImpl.kt
+++ b/platform/configuration-store-impl/src/SchemeManagerFactoryImpl.kt
@@ -20,30 +20,38 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ComponentManager
import com.intellij.openapi.components.RoamingType
import com.intellij.openapi.components.SettingsSavingComponent
-import com.intellij.openapi.components.impl.stores.StateStorageManager
import com.intellij.openapi.components.stateStore
-import com.intellij.openapi.options.*
+import com.intellij.openapi.options.Scheme
+import com.intellij.openapi.options.SchemeManager
+import com.intellij.openapi.options.SchemeManagerFactory
+import com.intellij.openapi.options.SchemeProcessor
import com.intellij.openapi.project.Project
import com.intellij.util.SmartList
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.lang.CompoundRuntimeException
+import org.jetbrains.annotations.TestOnly
import java.nio.file.Path
import java.nio.file.Paths
const val ROOT_CONFIG = "\$ROOT_CONFIG$"
-sealed class SchemeManagerFactoryBase : SchemesManagerFactory(), SettingsSavingComponent {
- private val managers = ContainerUtil.createLockFreeCopyOnWriteList>()
+sealed class SchemeManagerFactoryBase : SchemeManagerFactory(), SettingsSavingComponent {
+ private val managers = ContainerUtil.createLockFreeCopyOnWriteList>()
- abstract val componentManager: ComponentManager
-
- override final fun create(directoryName: String, processor: SchemeProcessor, roamingType: RoamingType, presentableName: String?): SchemesManager {
- val storageManager = (componentManager.stateStore).stateStorageManager
+ protected open val componentManager: ComponentManager? = null
+ override final fun