mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'develar/is'
This commit is contained in:
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="memoryfilesystem">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/memoryfilesystem-0.8.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/dev/memoryfilesystem-0.8.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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<Element>, 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<String> 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() {
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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();
|
||||
|
||||
+3
-3
@@ -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)) {
|
||||
|
||||
+14
-38
@@ -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<PsiElement, Collection<String>> suppressedScopes = new THashMap<PsiElement, Collection<String>>();
|
||||
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<InspectionToolWrapper, String> suppressedTools = new THashMap<InspectionToolWrapper, String>();
|
||||
InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager);
|
||||
for (Collection<String> ids : suppressedScopes.values()) {
|
||||
for (Iterator<String> 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<CommonProblemDescriptor>();
|
||||
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) {
|
||||
|
||||
+8
-6
@@ -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<RefElement>();
|
||||
myPersistentEntryPoints = new LinkedHashMap<String, SmartRefElementPointer>(); // 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<String> 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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+1
-2
@@ -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) {
|
||||
|
||||
+2
-2
@@ -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)) {
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -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
|
||||
|
||||
@@ -53,5 +53,8 @@
|
||||
<orderEntry type="module" module-name="xml-psi-impl" />
|
||||
<orderEntry type="library" scope="TEST" name="KotlinTest" level="project" />
|
||||
<orderEntry type="module" module-name="built-in-server-api" scope="TEST" />
|
||||
<orderEntry type="module" module-name="configuration-store-impl" scope="TEST" />
|
||||
<orderEntry type="library" scope="TEST" name="memoryfilesystem" level="project" />
|
||||
<orderEntry type="module" module-name="configuration-store-tests" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="Project Default"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
</profile>
|
||||
<profile version="1.0" is_locked="false">
|
||||
<option name="myName" value="p1"/>
|
||||
<option name="myLocal" value="false"/>
|
||||
<inspection_tool class="ConstantConditions" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="SUGGEST_NULLABLE_ANNOTATIONS" value="true"/>
|
||||
<option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="true"/>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
<option name="PROJECT_PROFILE" value="p1"/>
|
||||
<option name="USE_PROJECT_PROFILE" value="true"/>
|
||||
<version value="1.0"/>
|
||||
</settings>
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
|
||||
|
||||
+2
-3
@@ -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 { ArrayList<caret>XXX x;}";
|
||||
configureByText(StdFileTypes.JAVA, text);
|
||||
@@ -1773,7 +1772,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase {
|
||||
PsiFile use = createFile("Use.java", "public class Use { { <caret>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);
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
-63
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-12
@@ -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<String, Map<String, Set<OfflineProblemDescriptor>>> parse() throws IOException {
|
||||
final String moduleName = getModule().getName();
|
||||
final Map<String, Map<String, Set<OfflineProblemDescriptor>>> map = new HashMap<String, Map<String, Set<OfflineProblemDescriptor>>>();
|
||||
final Map<String, Map<String, Set<OfflineProblemDescriptor>>> 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 {
|
||||
|
||||
-126
@@ -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};
|
||||
}
|
||||
}
|
||||
+115
@@ -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)
|
||||
}
|
||||
@@ -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("<inspections version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"JavaDoc\" enabled=\"false\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
" <option name=\"TOP_LEVEL_CLASS_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"INNER_CLASS_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"METHOD_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"@return@param@throws or @exception\" />\n" +
|
||||
" </value>\n" + " </option>\n" +
|
||||
" <option name=\"FIELD_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"IGNORE_DEPRECATED\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_JAVADOC_PERIOD\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_DUPLICATED_THROWS\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_POINT_TO_ITSELF\" value=\"false\" />\n" +
|
||||
" <option name=\"myAdditionalJavadocTags\" value=\"tag1,tag2 \" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</inspections>").getRootElement();
|
||||
return JdomKt.loadElement("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"ToConvert\" />\n" +
|
||||
" <inspection_tool class=\"JavaDoc\" enabled=\"false\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
" <option name=\"TOP_LEVEL_CLASS_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"INNER_CLASS_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"METHOD_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"@return@param@throws or @exception\" />\n" +
|
||||
" </value>\n" + " </option>\n" +
|
||||
" <option name=\"FIELD_OPTIONS\">\n" +
|
||||
" <value>\n" +
|
||||
" <option name=\"ACCESS_JAVADOC_REQUIRED_FOR\" value=\"none\" />\n" +
|
||||
" <option name=\"REQUIRED_TAGS\" value=\"\" />\n" +
|
||||
" </value>\n" +
|
||||
" </option>\n" +
|
||||
" <option name=\"IGNORE_DEPRECATED\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_JAVADOC_PERIOD\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_DUPLICATED_THROWS\" value=\"false\" />\n" +
|
||||
" <option name=\"IGNORE_POINT_TO_ITSELF\" value=\"false\" />\n" +
|
||||
" <option name=\"myAdditionalJavadocTags\" value=\"tag1,tag2 \" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
public void testReloadProfileWithUnknownScopes() throws Exception {
|
||||
final Element element = JDOMUtil.loadDocument("<inspections version=\"1.0\">\n" +
|
||||
final Element element = JdomKt.loadElement("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"ArgNamesErrorsInspection\" enabled=\"true\" level=\"ERROR\" enabled_by_default=\"false\" />\n" +
|
||||
" <inspection_tool class=\"ArgNamesWarningsInspection\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
|
||||
@@ -195,32 +201,28 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
" <inspection_tool class=\"UNUSED_IMPORT\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" +
|
||||
" <scope name=\"Unknown scope name\" level=\"WARNING\" enabled=\"true\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</inspections>").getRootElement();
|
||||
"</profile>");
|
||||
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("<inspections version=\"1.0\">\n" +
|
||||
final Element element = JdomKt.loadElement("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
"</inspections>").getRootElement();
|
||||
"</profile>");
|
||||
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("<inspections version=\"1.0\">\n" +
|
||||
final Element unusedProfile = JdomKt.loadElement("<profile version=\"1.0\">\n" +
|
||||
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
|
||||
" <inspection_tool class=\"UNUSED_SYMBOL\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\">\n" +
|
||||
" <option name=\"LOCAL_VARIABLE\" value=\"true\" />\n" +
|
||||
@@ -236,7 +238,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
" <option name=\"ADD_SERVLET_TO_ENTRIES\" value=\"true\" />\n" +
|
||||
" <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</inspections>").getRootElement();
|
||||
"</profile>");
|
||||
profile.readExternal(unusedProfile);
|
||||
model = profile.getModifiableModel();
|
||||
model.commit();
|
||||
@@ -288,8 +290,7 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
"</profile>";
|
||||
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 {
|
||||
" <option name=\"ADD_NONJAVA_TO_ENTRIES\" value=\"false\" />\n" +
|
||||
" </inspection_tool>\n" +
|
||||
"</profile>").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 {
|
||||
"</profile>");
|
||||
}
|
||||
|
||||
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<InspectionToolWrapper> list = new ArrayList<InspectionToolWrapper>();
|
||||
final List<InspectionToolWrapper> 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 {
|
||||
"</profile>",
|
||||
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<Tools>(), new ArrayList<Tools>(), new ArrayList<Tools>());
|
||||
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<InspectionToolWrapper> initializedTools = getInitializedTools(profile);
|
||||
if (initializedTools.size() > 0) {
|
||||
for (InspectionToolWrapper initializedTool : initializedTools) {
|
||||
@@ -607,26 +601,27 @@ public class InspectionProfileTest extends LightIdeaTestCase {
|
||||
"</profile>";
|
||||
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<InspectionToolWrapper> getInitializedTools(@NotNull Profile foo) {
|
||||
List<InspectionToolWrapper> initialized = new ArrayList<InspectionToolWrapper>();
|
||||
List<ScopeToolState> tools = ((InspectionProfileImpl)foo).getAllTools(getProject());
|
||||
public static List<InspectionToolWrapper> getInitializedTools(@NotNull InspectionProfileImpl foo) {
|
||||
List<InspectionToolWrapper> initialized = null;
|
||||
List<ScopeToolState> tools = foo.getAllTools(getProject());
|
||||
for (ScopeToolState tool : tools) {
|
||||
InspectionToolWrapper toolWrapper = tool.getTool();
|
||||
if (toolWrapper.isInitialized()) {
|
||||
if (initialized == null) {
|
||||
initialized = new SmartList<>();
|
||||
}
|
||||
initialized.add(toolWrapper);
|
||||
}
|
||||
}
|
||||
return initialized;
|
||||
return initialized == null ? Collections.emptyList() : initialized;
|
||||
}
|
||||
|
||||
private static LocalInspectionToolWrapper createTool(String s, boolean enabled) {
|
||||
|
||||
@@ -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 = """
|
||||
<inspections profile_name="Bar" version="1.0">
|
||||
<option name="myName" value="Bar" />
|
||||
<inspection_tool class="Since15" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||
"</inspections>""".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
|
||||
}
|
||||
}
|
||||
+165
@@ -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 = """
|
||||
<state>
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</state>""".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 = """
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>""".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("""
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Convert2Diamond" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>""".trimIndent())
|
||||
|
||||
profileFile.write("""
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Convert2Diamond" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>""".trimIndent())
|
||||
|
||||
project.baseDir.refresh(false, true)
|
||||
(ProjectManager.getInstance() as StoreAwareProjectManager).flushChangedAlarm()
|
||||
assertThat(projectInspectionProfileManager.currentProfile.getToolDefaultState("Convert2Diamond", project).level).isEqualTo(HighlightDisplayLevel.ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,12 @@
|
||||
<item name='org.jdom.Element java.util.List<org.jdom.Content> getContent()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name='org.jdom.Element org.jdom.Attribute getAttribute(java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||
</item>
|
||||
<item name='org.jdom.Element org.jdom.Element getChild(java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||
</item>
|
||||
<item name='org.jdom.Element org.jdom.Element setAttribute(java.lang.String, java.lang.String) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.<String>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<LocalInspectionTool> result = new ArrayList<LocalInspectionTool>();
|
||||
final ArrayList<LocalInspectionTool> 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<HighlightInfo> filter(@NotNull List<HighlightInfo> infos, @NotNull HighlightSeverity minSeverity) {
|
||||
ArrayList<HighlightInfo> result = new ArrayList<HighlightInfo>();
|
||||
ArrayList<HighlightInfo> result = new ArrayList<>();
|
||||
for (final HighlightInfo info : infos) {
|
||||
if (info.getSeverity().compareTo(minSeverity) >= 0) result.add(info);
|
||||
}
|
||||
@@ -376,7 +369,7 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
|
||||
|
||||
if (intentionAction == null) {
|
||||
final List<IntentionAction> availableActions = new ArrayList<IntentionAction>();
|
||||
final List<IntentionAction> availableActions = new ArrayList<>();
|
||||
|
||||
for (HighlightInfo info :infos) {
|
||||
if (info.quickFixActionRanges != null) {
|
||||
|
||||
+9
-3
@@ -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());
|
||||
|
||||
@@ -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<InspectionToolWrapper<?, ?>> 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<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
|
||||
point.unregisterExtension(myUnusedCodeExtension);
|
||||
myUnusedCodeExtension = null;
|
||||
ext_src = null;
|
||||
super.tearDown();
|
||||
try {
|
||||
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ToolExtensionPoints.DEAD_CODE_TOOL);
|
||||
point.unregisterExtension(myUnusedCodeExtension);
|
||||
myUnusedCodeExtension = null;
|
||||
ext_src = null;
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -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()));
|
||||
}
|
||||
|
||||
+23
-4
@@ -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<String> 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")) {
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<root>
|
||||
<item
|
||||
name='java.util.concurrent.CompletableFuture java.util.concurrent.CompletableFuture<java.lang.Void> runAsync(java.lang.Runnable, java.util.concurrent.Executor)'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
</root>
|
||||
Binary file not shown.
Binary file not shown.
@@ -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<String,HighlightDisplayKey> ourNameToKeyMap = new THashMap<String, HighlightDisplayKey>();
|
||||
private static final Map<String,HighlightDisplayKey> ourIdToKeyMap = new THashMap<String, HighlightDisplayKey>();
|
||||
private static final Map<HighlightDisplayKey, Computable<String>> ourKeyToDisplayNameMap = new THashMap<HighlightDisplayKey, Computable<String>>();
|
||||
private static final Map<HighlightDisplayKey, String> ourKeyToAlternativeIDMap = new THashMap<HighlightDisplayKey, String>();
|
||||
private static final Map<String,HighlightDisplayKey> ourNameToKeyMap = new THashMap<>();
|
||||
private static final Map<String,HighlightDisplayKey> ourIdToKeyMap = new THashMap<>();
|
||||
private static final Map<HighlightDisplayKey, Computable<String>> ourKeyToDisplayNameMap = new THashMap<>();
|
||||
private static final Map<HighlightDisplayKey, String> 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<String>(displayName), id);
|
||||
return register(name, new Computable.PredefinedValueComputable<>(displayName), id);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<InspectionSuppressor> 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.<InspectionSuppressor>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.
|
||||
*
|
||||
|
||||
@@ -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<InspectionToolsFactory> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.inspectionToolsFactory");
|
||||
|
||||
InspectionProfileEntry[] createTools();
|
||||
}
|
||||
@@ -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()
|
||||
*/
|
||||
|
||||
+11
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-18
@@ -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<T extends InspectionProfileEntry, E
|
||||
protected InspectionToolWrapper(@NotNull InspectionToolWrapper<T, E> other) {
|
||||
myEP = other.myEP;
|
||||
// we need to create a copy for buffering
|
||||
if (other.myTool != null) {
|
||||
//noinspection unchecked
|
||||
myTool = myEP != null ? (T)myEP.instantiateTool() : (T)InspectionToolsRegistrarCore.instantiateTool(other.myTool.getClass());
|
||||
if (other.myTool == null) {
|
||||
myTool = null;
|
||||
}
|
||||
else {
|
||||
myTool = null;
|
||||
//noinspection unchecked
|
||||
myTool = (T)(myEP == null ? InspectionToolsRegistrarCore.instantiateTool(other.myTool.getClass()) : myEP.instantiateTool());
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
projectOpened(context.getProject());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -166,18 +165,6 @@ public abstract class InspectionToolWrapper<T extends InspectionProfileEntry, E
|
||||
}
|
||||
}
|
||||
|
||||
public void projectOpened(@NotNull Project project) {
|
||||
if (myEP == null) {
|
||||
getTool().projectOpened(project);
|
||||
}
|
||||
}
|
||||
|
||||
public void projectClosed(@NotNull Project project) {
|
||||
if (myEP == null) {
|
||||
getTool().projectClosed(project);
|
||||
}
|
||||
}
|
||||
|
||||
public String getStaticDescription() {
|
||||
return myEP == null || myEP.hasStaticDescription ? getTool().getStaticDescription() : null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InspectionToolsRegistrarCore {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.ex.InspectionToolsRegistrarCore");
|
||||
static Object instantiateTool(@NotNull Class<?> toolClass) {
|
||||
static <T> T instantiateTool(@NotNull Class<T> toolClass) {
|
||||
try {
|
||||
return ReflectionUtil.newInstance(toolClass);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import java.util.List;
|
||||
|
||||
public interface Tools {
|
||||
@NotNull
|
||||
InspectionToolWrapper getInspectionTool(PsiElement element);
|
||||
InspectionToolWrapper getInspectionTool(@Nullable PsiElement element);
|
||||
|
||||
@NotNull
|
||||
String getShortName();
|
||||
@@ -39,6 +39,8 @@ public interface Tools {
|
||||
@NotNull
|
||||
List<ScopeToolState> getTools();
|
||||
|
||||
void collectTools(@NotNull List<ScopeToolState> result);
|
||||
|
||||
@NotNull
|
||||
ScopeToolState getDefaultState();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Element> {
|
||||
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<String, Profile> myProfiles = new THashMap<String, Profile>();
|
||||
protected final DependencyValidationManager myHolder;
|
||||
private final List<ProfileChangeAdapter> 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<String> profileKeys = new HashSet<String>();
|
||||
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<Profile> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Profile> 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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+2
-3
@@ -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<Elem
|
||||
|
||||
@Nullable
|
||||
public static NamedScope getScope(@NotNull Project project, final String scopeName) {
|
||||
final NamedScopesHolder[] holders = getAllNamedScopeHolders(project);
|
||||
for (NamedScopesHolder holder : holders) {
|
||||
for (NamedScopesHolder holder : getAllNamedScopeHolders(project)) {
|
||||
final NamedScope scope = holder.getScope(scopeName);
|
||||
if (scope != null) {
|
||||
return scope;
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
<orderEntry type="module" module-name="projectModel-impl" />
|
||||
<orderEntry type="module" module-name="editor-ui-ex" />
|
||||
<orderEntry type="module" module-name="indexing-impl" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
</module>
|
||||
+10
-21
@@ -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<String, HighlightDisplayLevel> myDisplayLevelMap = new HashMap<String, HighlightDisplayLevel>();
|
||||
private final Map<String, HighlightDisplayLevel> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<IntentionAction> 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());
|
||||
|
||||
+27
-27
@@ -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();
|
||||
}
|
||||
|
||||
+5
-6
@@ -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<HighlightSeverity> {
|
||||
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<HighlightSeverity> {
|
||||
}
|
||||
|
||||
|
||||
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<HighlightSeverity> {
|
||||
final List<HighlightSeverity> 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<HighlightSeverity> {
|
||||
return o1 - o2;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private OrderMap getOrderMap() {
|
||||
OrderMap orderMap;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-13
@@ -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<JobDescriptor> myJobDescriptors = new ArrayList<JobDescriptor>();
|
||||
private final List<JobDescriptor> myJobDescriptors = new ArrayList<>();
|
||||
|
||||
private final StdJobDescriptors myStdJobDescriptors = new StdJobDescriptors();
|
||||
protected ProgressIndicator myProgressIndicator = new EmptyProgressIndicator();
|
||||
|
||||
private InspectionProfile myExternalProfile;
|
||||
|
||||
protected final Map<Key, GlobalInspectionContextExtension> myExtensions = new HashMap<Key, GlobalInspectionContextExtension>();
|
||||
protected final Map<Key, GlobalInspectionContextExtension> myExtensions = new HashMap<>();
|
||||
|
||||
protected final Map<String, Tools> myTools = new THashMap<String, Tools>();
|
||||
protected final Map<String, Tools> myTools = new THashMap<>();
|
||||
|
||||
@NonNls public static final String LOCAL_TOOL_ATTRIBUTE = "is_local_tool";
|
||||
|
||||
@@ -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<Tools> getUsedTools() {
|
||||
InspectionProfileImpl profile = (InspectionProfileImpl)getCurrentProfile();
|
||||
List<Tools> tools = profile.getAllEnabledInspectionTools(myProject);
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<InspectionToolWrapper>();
|
||||
Set<InspectionToolWrapper> dependentTools = new LinkedHashSet<>();
|
||||
for (Tools tool : tools) {
|
||||
profile.collectDependentInspections(tool.getTool(), dependentTools, getProject());
|
||||
}
|
||||
@@ -337,9 +336,9 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
if (dependentTools.isEmpty()) {
|
||||
return tools;
|
||||
}
|
||||
Set<Tools> set = new THashSet<Tools>(tools, TOOLS_HASHING_STRATEGY);
|
||||
Set<Tools> set = new THashSet<>(tools, TOOLS_HASHING_STRATEGY);
|
||||
set.addAll(ContainerUtil.map(dependentTools, toolWrapper -> new ToolsImpl(toolWrapper, toolWrapper.getDefaultLevel(), true, true)));
|
||||
return new ArrayList<Tools>(set);
|
||||
return new ArrayList<>(set);
|
||||
}
|
||||
|
||||
private static void classifyTool(@NotNull List<Tools> outGlobalTools,
|
||||
@@ -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<SmartPsiElementPointer<PsiElement>> elements = new ArrayList<SmartPsiElementPointer<PsiElement>>();
|
||||
final List<SmartPsiElementPointer<PsiElement>> elements = new ArrayList<>();
|
||||
final SmartPointerManager manager = SmartPointerManager.getInstance(project);
|
||||
for (PsiElement element : scope) {
|
||||
elements.add(manager.createSmartPsiElementPointer(element));
|
||||
@@ -404,7 +403,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G
|
||||
@Nullable final Runnable runnable,
|
||||
final List<SmartPsiElementPointer<PsiElement>> elements) {
|
||||
Runnable cleanupRunnable = () -> {
|
||||
final List<PsiElement> psiElements = new ArrayList<PsiElement>();
|
||||
final List<PsiElement> psiElements = new ArrayList<>();
|
||||
for (SmartPsiElementPointer<PsiElement> element : elements) {
|
||||
PsiElement psiElement = element.getElement();
|
||||
if (psiElement != null && psiElement.isPhysical()) {
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
+161
-168
@@ -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<String, Element> myUninstalledInspectionsSettings;
|
||||
private final Map<String, Element> myUninitializedSettings = new TreeMap<>();
|
||||
protected InspectionProfileImpl mySource;
|
||||
private Map<String, ToolsImpl> myTools = new THashMap<String, ToolsImpl>();
|
||||
private Map<String, ToolsImpl> myTools = new THashMap<>();
|
||||
private volatile Map<String, Boolean> 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<String, Element>();
|
||||
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<InspectionToolWrapper> toolWrappers) {
|
||||
InspectionProfileImpl profile = new InspectionProfileImpl(name, new InspectionToolRegistrar() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<InspectionToolWrapper> 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<HighlightSeverity> getUsedSeverities() {
|
||||
LOG.assertTrue(myInitialized);
|
||||
final Set<HighlightSeverity> result = new HashSet<HighlightSeverity>();
|
||||
Set<HighlightSeverity> 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<String, Boolean> diffMap = getDisplayLevelMap();
|
||||
if (diffMap != null) {
|
||||
diffMap = new TreeMap<String, Boolean>(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<ModifiableModel> 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<InspectionToolWrapper>();
|
||||
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<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
|
||||
List<InspectionToolWrapper> 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<Tools> getAllEnabledInspectionTools(Project project) {
|
||||
initInspectionTools(project);
|
||||
List<Tools> result = new ArrayList<Tools>();
|
||||
List<Tools> 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<String> toolIds, Project project) {
|
||||
for (final String toolId : toolIds) {
|
||||
public void disableToolByDefault(@NotNull Collection<String> 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<String, List<String>> dependencies = new HashMap<String, List<String>>();
|
||||
|
||||
final Map<String, List<String>> dependencies = new THashMap<>();
|
||||
for (InspectionToolWrapper toolWrapper : tools) {
|
||||
addTool(project, toolWrapper, dependencies);
|
||||
}
|
||||
final GraphGenerator<String> graphGenerator = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<String>() {
|
||||
|
||||
DFSTBuilder<String> builder = new DFSTBuilder<>(GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<String>() {
|
||||
@Override
|
||||
public Collection<String> getNodes() {
|
||||
return dependencies.keySet();
|
||||
@@ -560,22 +572,20 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
public Iterator<String> getIn(String n) {
|
||||
return dependencies.get(n).iterator();
|
||||
}
|
||||
}));
|
||||
|
||||
DFSTBuilder<String> builder = new DFSTBuilder<String>(graphGenerator);
|
||||
})));
|
||||
if (builder.isAcyclic()) {
|
||||
final List<String> 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<String, List<String>> 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<String> computable = extension == null ? new Computable.PredefinedValueComputable<String>(toolWrapper.getDisplayName()) : (Computable<String>)() -> extension.getDisplayName();
|
||||
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName()) : extension::getDisplayName;
|
||||
if (toolWrapper instanceof LocalInspectionToolWrapper) {
|
||||
key = HighlightDisplayKey.register(shortName, computable, toolWrapper.getID(),
|
||||
((LocalInspectionToolWrapper)toolWrapper).getAlternativeID());
|
||||
@@ -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<InspectionToolWrapper> createTools(Project project) {
|
||||
private List<InspectionToolWrapper> 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<ScopeToolState> getAllTools(Project project) {
|
||||
public List<ScopeToolState> getAllTools(@Nullable Project project) {
|
||||
initInspectionTools(project);
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
|
||||
List<ScopeToolState> result = new ArrayList<>();
|
||||
for (Tools tools : myTools.values()) {
|
||||
result.addAll(tools.getTools());
|
||||
tools.collectTools(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ScopeToolState> getDefaultStates(Project project) {
|
||||
public List<ScopeToolState> getDefaultStates(@Nullable Project project) {
|
||||
initInspectionTools(project);
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
final List<ScopeToolState> 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<ScopeToolState> getNonDefaultTools(@NotNull String shortName, Project project) {
|
||||
final List<ScopeToolState> result = new ArrayList<ScopeToolState>();
|
||||
final List<ScopeToolState> result = new ArrayList<>();
|
||||
final List<ScopeToolState> 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<String, Boolean> 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<String,Boolean> map = new TreeMap<String, Boolean>();
|
||||
for (String toolId : myTools.keySet()) {
|
||||
Set<String> names = myTools.keySet();
|
||||
Map<String, Boolean> 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> T initAndDo(@NotNull Computable<T> runnable) {
|
||||
boolean old = INIT_INSPECTIONS;
|
||||
try {
|
||||
INIT_INSPECTIONS = true;
|
||||
return runnable.compute();
|
||||
}
|
||||
finally {
|
||||
INIT_INSPECTIONS = old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-29
@@ -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<NotNullFunction<InspectionProfileWrapper, InspectionProfileWrapper>> CUSTOMIZATION_KEY = Key.create("Inspection Profile Wrapper Customization");
|
||||
public static final Key<Function<InspectionProfile, InspectionProfileWrapper>> 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<InspectionProfileEntry> uniqTools = new THashSet<InspectionProfileEntry>(toolWrappers.length);
|
||||
Set<InspectionProfileEntry> 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<Tools> 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);
|
||||
}
|
||||
|
||||
|
||||
+41
-37
@@ -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<Factory<InspectionToolWrapper>> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final List<Supplier<InspectionToolWrapper>> myInspectionToolFactories = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
private boolean myInspectionComponentsLoaded = false;
|
||||
private boolean myInspectionComponentsLoaded;
|
||||
|
||||
private synchronized void ensureInitialized() {
|
||||
if (!myInspectionComponentsLoaded) {
|
||||
myInspectionComponentsLoaded = true;
|
||||
Set<InspectionToolProvider> providers = new THashSet<InspectionToolProvider>();
|
||||
//noinspection unchecked
|
||||
providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class)));
|
||||
ContainerUtil.addAll(providers, Extensions.getExtensions(InspectionToolProvider.EXTENSION_POINT_NAME));
|
||||
List<Factory<InspectionToolWrapper>> factories = new ArrayList<Factory<InspectionToolWrapper>>();
|
||||
registerTools(providers, factories);
|
||||
final boolean isInternal = ApplicationManager.getApplication().isInternal();
|
||||
for (final LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
|
||||
if (!isInternal && ep.isInternal) continue;
|
||||
factories.add(() -> new LocalInspectionToolWrapper(ep));
|
||||
}
|
||||
for (final InspectionEP ep : Extensions.getExtensions(InspectionEP.GLOBAL_INSPECTION)) {
|
||||
if (!isInternal && ep.isInternal) continue;
|
||||
factories.add(() -> new GlobalInspectionToolWrapper(ep));
|
||||
}
|
||||
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<InspectionToolProvider> providers = new THashSet<>();
|
||||
//noinspection deprecation
|
||||
providers.addAll((((ComponentManagerEx)ApplicationManager.getApplication()).getComponentInstancesOfType(InspectionToolProvider.class)));
|
||||
ContainerUtil.addAll(providers, InspectionToolProvider.EXTENSION_POINT_NAME.getExtensions());
|
||||
List<Supplier<InspectionToolWrapper>> factories = new ArrayList<>();
|
||||
registerTools(providers, factories);
|
||||
boolean isInternal = ApplicationManager.getApplication().isInternal();
|
||||
for (LocalInspectionEP ep : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
|
||||
if (!isInternal && ep.isInternal) {
|
||||
continue;
|
||||
}
|
||||
|
||||
factories.add(() -> new LocalInspectionToolWrapper(ep));
|
||||
}
|
||||
for (InspectionEP ep : InspectionEP.GLOBAL_INSPECTION.getExtensions()) {
|
||||
if (!isInternal && ep.isInternal) {
|
||||
continue;
|
||||
}
|
||||
|
||||
factories.add(() -> new GlobalInspectionToolWrapper(ep));
|
||||
}
|
||||
myInspectionToolFactories.addAll(factories);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InspectionToolWrapper wrapTool(@NotNull InspectionProfileEntry profileEntry) {
|
||||
if (profileEntry instanceof LocalInspectionTool) {
|
||||
//noinspection TestOnlyProblems
|
||||
return new LocalInspectionToolWrapper((LocalInspectionTool)profileEntry);
|
||||
}
|
||||
if (profileEntry instanceof GlobalInspectionTool) {
|
||||
@@ -82,13 +85,14 @@ public class InspectionToolRegistrar {
|
||||
}
|
||||
|
||||
private static void registerTools(@NotNull Collection<InspectionToolProvider> providers,
|
||||
@NotNull List<Factory<InspectionToolWrapper>> factories) {
|
||||
@NotNull List<Supplier<InspectionToolWrapper>> factories) {
|
||||
for (InspectionToolProvider provider : providers) {
|
||||
Class[] classes = provider.getInspectionClasses();
|
||||
for (final Class aClass : classes) {
|
||||
Factory<InspectionToolWrapper> factory =
|
||||
() -> wrapTool((InspectionProfileEntry)InspectionToolsRegistrarCore.instantiateTool(aClass));
|
||||
factories.add(factory);
|
||||
//noinspection unchecked
|
||||
for (Class<InspectionProfileEntry> 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<InspectionToolWrapper> createTools() {
|
||||
ensureInitialized();
|
||||
|
||||
final List<InspectionToolWrapper> tools = new ArrayList<InspectionToolWrapper>(myInspectionToolFactories.size());
|
||||
for (final Factory<InspectionToolWrapper> factory : myInspectionToolFactories) {
|
||||
List<InspectionToolWrapper> tools = new ArrayList<>(myInspectionToolFactories.size());
|
||||
for (Supplier<InspectionToolWrapper> factory : myInspectionToolFactories) {
|
||||
ProgressManager.checkCanceled();
|
||||
final InspectionToolWrapper toolWrapper = factory.create();
|
||||
InspectionToolWrapper toolWrapper = factory.get();
|
||||
if (toolWrapper != null && checkTool(toolWrapper) == null) {
|
||||
tools.add(toolWrapper);
|
||||
}
|
||||
|
||||
+5
-7
@@ -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<LocalInspe
|
||||
return context.getStdJobDescriptors().LOCAL_ANALYSIS_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
public boolean isUnfair() {
|
||||
return myEP == null ? getTool() instanceof UnfairLocalInspectionTool : myEP.unfair;
|
||||
}
|
||||
@@ -85,8 +83,8 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, LocalInspectionEP> compute() {
|
||||
HashMap<String, LocalInspectionEP> map = new HashMap<String, LocalInspectionEP>();
|
||||
for (LocalInspectionEP ep : Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION)) {
|
||||
Map<String, LocalInspectionEP> map = new THashMap<>();
|
||||
for (LocalInspectionEP ep : LocalInspectionEP.LOCAL_INSPECTION.getExtensions()) {
|
||||
map.put(ep.getShortName(), ep);
|
||||
}
|
||||
return map;
|
||||
@@ -95,7 +93,7 @@ public class LocalInspectionToolWrapper extends InspectionToolWrapper<LocalInspe
|
||||
|
||||
@Nullable
|
||||
public static InspectionToolWrapper findTool2RunInBatch(@NotNull Project project, @Nullable PsiElement element, @NotNull String name) {
|
||||
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
|
||||
final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile();
|
||||
final InspectionToolWrapper toolWrapper = element == null
|
||||
? inspectionProfile.getInspectionTool(name, project)
|
||||
: inspectionProfile.getInspectionTool(name, element);
|
||||
|
||||
@@ -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.
|
||||
@@ -90,7 +90,7 @@ public class ToolsImpl implements Tools {
|
||||
@NotNull
|
||||
private ScopeToolState insertTool(@NotNull final ScopeToolState scopeToolState, final int idx) {
|
||||
if (myTools == null) {
|
||||
myTools = new ArrayList<ScopeToolState>();
|
||||
myTools = new ArrayList<>();
|
||||
if (scopeToolState.isEnabled()) {
|
||||
setEnabled(true);
|
||||
}
|
||||
@@ -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<InspectionToolWrapper> getAllTools() {
|
||||
List<InspectionToolWrapper> result = new ArrayList<InspectionToolWrapper>();
|
||||
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<String> scopeNames = new ArrayList<String>();
|
||||
for (Object sO : scopeElements) {
|
||||
final Element scopeElement = (Element)sO;
|
||||
final List<Element> scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
|
||||
final List<String> 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<String> order = dependencies.get(scopeName);
|
||||
if (order == null) {
|
||||
order = new ArrayList<String>();
|
||||
order = new ArrayList<>();
|
||||
dependencies.put(scopeName, order);
|
||||
}
|
||||
for (int j = i + 1; j < scopeNames.size(); j++) {
|
||||
@@ -244,12 +239,23 @@ public class ToolsImpl implements Tools {
|
||||
@Override
|
||||
@NotNull
|
||||
public List<ScopeToolState> getTools() {
|
||||
if (myTools == null) return Collections.singletonList(myDefaultState);
|
||||
List<ScopeToolState> result = new ArrayList<ScopeToolState>(myTools);
|
||||
if (myTools == null) {
|
||||
return Collections.singletonList(myDefaultState);
|
||||
}
|
||||
|
||||
List<ScopeToolState> result = new ArrayList<>(myTools);
|
||||
result.add(myDefaultState);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectTools(@NotNull List<ScopeToolState> result) {
|
||||
if (myTools != null) {
|
||||
result.addAll(myTools);
|
||||
}
|
||||
result.add(myDefaultState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ScopeToolState getDefaultState() {
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+108
@@ -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<InspectionProfileImpl>
|
||||
|
||||
protected val profileListeners: MutableList<ProfileChangeAdapter> = ContainerUtil.createLockFreeCopyOnWriteList<ProfileChangeAdapter>()
|
||||
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<InspectionProfileImpl, InspectionProfileImpl>() {
|
||||
override fun getState(scheme: InspectionProfileImpl): SchemeState {
|
||||
return if (scheme.wasInitialized()) SchemeState.POSSIBLY_CHANGED else SchemeState.UNCHANGED
|
||||
}
|
||||
}
|
||||
+2
-13
@@ -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
|
||||
|
||||
+29
-62
@@ -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<ProfileChangeAdapter> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-53
@@ -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<Element> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
-240
@@ -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<String, InspectionProfileWrapper> myName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
|
||||
private final Map<String, InspectionProfileWrapper> myAppName2Profile = new ConcurrentHashMap<String, InspectionProfileWrapper>();
|
||||
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<Profile> profiles = new HashSet<Profile>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+322
@@ -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("""<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
</profile>
|
||||
</component>""").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<Element> {
|
||||
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<InspectionProfileImpl>
|
||||
|
||||
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<InspectionProfileImpl>, name: String, attributeProvider: Function<String, String?>, 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<Profile> {
|
||||
currentProfile
|
||||
return schemeManager.allSchemes
|
||||
}
|
||||
|
||||
@Synchronized override fun getAvailableProfileNames(): Array<String> = 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)
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<DefaultProjectExportableAndSaveTrigger>().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 <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation) = arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
||||
|
||||
|
||||
@@ -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<ByteArray, String> {
|
||||
}
|
||||
|
||||
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<ByteArray, String>(bytes, lineSeparator)
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<SchemeManagerImpl<Scheme, ExternalizableScheme>>()
|
||||
sealed class SchemeManagerFactoryBase : SchemeManagerFactory(), SettingsSavingComponent {
|
||||
private val managers = ContainerUtil.createLockFreeCopyOnWriteList<SchemeManagerImpl<Scheme, out Scheme>>()
|
||||
|
||||
abstract val componentManager: ComponentManager
|
||||
|
||||
override final fun <T : Scheme, E : ExternalizableScheme> create(directoryName: String, processor: SchemeProcessor<E>, roamingType: RoamingType, presentableName: String?): SchemesManager<T, E> {
|
||||
val storageManager = (componentManager.stateStore).stateStorageManager
|
||||
protected open val componentManager: ComponentManager? = null
|
||||
|
||||
override final fun <T : Scheme, MutableT : T> create(directoryName: String, processor: SchemeProcessor<T, MutableT>, presentableName: String?, roamingType: RoamingType, isUseOldFileNameSanitize: Boolean): SchemeManager<T> {
|
||||
val path = checkPath(directoryName)
|
||||
val manager = SchemeManagerImpl<T, E>(path, processor, (storageManager as? StateStorageManagerImpl)?.streamProvider, pathToFile(path, storageManager), roamingType, componentManager, presentableName)
|
||||
@Suppress("CAST_NEVER_SUCCEEDS")
|
||||
managers.add(manager as SchemeManagerImpl<Scheme, ExternalizableScheme>)
|
||||
val manager = SchemeManagerImpl(path,
|
||||
processor,
|
||||
(componentManager?.stateStore?.stateStorageManager as? StateStorageManagerImpl)?.streamProvider,
|
||||
pathToFile(path),
|
||||
roamingType,
|
||||
presentableName,
|
||||
isUseOldFileNameSanitize,
|
||||
componentManager?.messageBus)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
managers.add(manager as SchemeManagerImpl<Scheme, out Scheme>)
|
||||
return manager
|
||||
}
|
||||
|
||||
@@ -60,9 +68,9 @@ sealed class SchemeManagerFactoryBase : SchemesManagerFactory(), SettingsSavingC
|
||||
return originalPath
|
||||
}
|
||||
|
||||
abstract fun pathToFile(path: String, storageManager: StateStorageManager): Path
|
||||
abstract fun pathToFile(path: String): Path
|
||||
|
||||
fun process(processor: (SchemeManagerImpl<Scheme, ExternalizableScheme>) -> Unit) {
|
||||
fun process(processor: (SchemeManagerImpl<Scheme, out Scheme>) -> Unit) {
|
||||
for (manager in managers) {
|
||||
try {
|
||||
processor(manager)
|
||||
@@ -83,10 +91,10 @@ sealed class SchemeManagerFactoryBase : SchemesManagerFactory(), SettingsSavingC
|
||||
errors.add(e)
|
||||
}
|
||||
}
|
||||
|
||||
CompoundRuntimeException.throwIfNotEmpty(errors)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private class ApplicationSchemeManagerFactory : SchemeManagerFactoryBase() {
|
||||
override val componentManager: ComponentManager
|
||||
get() = ApplicationManager.getApplication()
|
||||
@@ -101,12 +109,18 @@ sealed class SchemeManagerFactoryBase : SchemesManagerFactory(), SettingsSavingC
|
||||
return path
|
||||
}
|
||||
|
||||
override fun pathToFile(path: String, storageManager: StateStorageManager) = Paths.get(storageManager.expandMacros(ROOT_CONFIG), path)
|
||||
override fun pathToFile(path: String) = Paths.get(ApplicationManager.getApplication().stateStore.stateStorageManager.expandMacros(ROOT_CONFIG), path)!!
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private class ProjectSchemeManagerFactory(private val project: Project) : SchemeManagerFactoryBase() {
|
||||
override val componentManager = project
|
||||
|
||||
override fun pathToFile(path: String, storageManager: StateStorageManager) = Paths.get(project.basePath, if (ProjectUtil.isDirectoryBased(project)) "${Project.DIRECTORY_STORE_FOLDER}/$path" else ".$path")
|
||||
override fun pathToFile(path: String) = Paths.get(project.basePath, if (ProjectUtil.isDirectoryBased(project)) "${Project.DIRECTORY_STORE_FOLDER}/$path" else ".$path")!!
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
class TestSchemeManagerFactory(private val basePath: Path) : SchemeManagerFactoryBase() {
|
||||
override fun pathToFile(path: String) = basePath.resolve(path)!!
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray
|
||||
fun archiveState(state: Element): BufferExposingByteArrayOutputStream {
|
||||
val byteOut = BufferExposingByteArrayOutputStream()
|
||||
SnappyOutputStream(byteOut).use {
|
||||
writeElement(state, it)
|
||||
serializeElementToBinary(state, it)
|
||||
}
|
||||
return byteOut
|
||||
}
|
||||
|
||||
@@ -34,26 +34,26 @@ import com.intellij.util.containers.ContainerUtil
|
||||
import gnu.trove.THashMap
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.concurrent.withLock
|
||||
import kotlin.concurrent.read
|
||||
import kotlin.concurrent.write
|
||||
|
||||
private val MACRO_PATTERN = Pattern.compile("(\\$[^\\$]*\\$)")
|
||||
private val MACRO_PATTERN = Pattern.compile("(\\$[^$]*\\$)")
|
||||
|
||||
/**
|
||||
* If componentManager not specified, storage will not add file tracker (see VirtualFileTracker)
|
||||
* If componentManager not specified, storage will not add file tracker
|
||||
*/
|
||||
open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
private val pathMacroSubstitutor: TrackingPathMacroSubstitutor? = null,
|
||||
val componentManager: ComponentManager? = null,
|
||||
private val virtualFileTracker: StorageVirtualFileTracker? = StateStorageManagerImpl.createDefaultVirtualTracker(componentManager) ) : StateStorageManager {
|
||||
private val macros: MutableList<Macro> = ContainerUtil.createLockFreeCopyOnWriteList()
|
||||
private val storageLock = ReentrantLock()
|
||||
private val storageLock = ReentrantReadWriteLock()
|
||||
private val storages = THashMap<String, StateStorage>()
|
||||
|
||||
var streamProvider: StreamProvider? = null
|
||||
@@ -132,11 +132,13 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
}
|
||||
}
|
||||
|
||||
override final fun getStateStorage(storageSpec: Storage): StateStorage {
|
||||
return getOrCreateStorage(storageSpec.path, storageSpec.roamingType,
|
||||
JavaAnnotationHelperForKotlin.getStorageClass(storageSpec),
|
||||
JavaAnnotationHelperForKotlin.getStateSplitterClass(storageSpec))
|
||||
}
|
||||
override final fun getStateStorage(storageSpec: Storage) = getOrCreateStorage(
|
||||
storageSpec.path,
|
||||
storageSpec.roamingType,
|
||||
storageSpec.storageClass.java,
|
||||
storageSpec.stateSplitter.java,
|
||||
storageSpec.exclusive
|
||||
)
|
||||
|
||||
protected open fun normalizeFileSpec(fileSpec: String): String {
|
||||
val path = FileUtilRt.toSystemIndependentName(fileSpec)
|
||||
@@ -147,7 +149,8 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
fun getOrCreateStorage(collapsedPath: String,
|
||||
roamingType: RoamingType = RoamingType.DEFAULT,
|
||||
storageClass: Class<out StateStorage> = StateStorage::class.java,
|
||||
@Suppress("DEPRECATION") stateSplitter: Class<out StateSplitter> = StateSplitterEx::class.java): StateStorage {
|
||||
@Suppress("DEPRECATION") stateSplitter: Class<out StateSplitter> = StateSplitterEx::class.java,
|
||||
exclusive: Boolean = false): StateStorage {
|
||||
val normalizedCollapsedPath = normalizeFileSpec(collapsedPath)
|
||||
val key: String
|
||||
if (storageClass == StateStorage::class.java) {
|
||||
@@ -159,17 +162,17 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
else {
|
||||
key = storageClass.name!!
|
||||
}
|
||||
storageLock.withLock {
|
||||
storageLock.read {
|
||||
var storage = storages[key]
|
||||
if (storage == null) {
|
||||
storage = createStateStorage(storageClass, normalizedCollapsedPath, roamingType, stateSplitter)
|
||||
storage = createStateStorage(storageClass, normalizedCollapsedPath, roamingType, stateSplitter, exclusive)
|
||||
storages.put(key, storage)
|
||||
}
|
||||
return storage
|
||||
}
|
||||
}
|
||||
|
||||
fun getCachedFileStorages(changed: Collection<String>, deleted: Collection<String>, pathNormalizer: ((String) -> String)? = null) = storageLock.withLock {
|
||||
fun getCachedFileStorages(changed: Collection<String>, deleted: Collection<String>, pathNormalizer: ((String) -> String)? = null) = storageLock.read {
|
||||
Pair(getCachedFileStorages(changed, pathNormalizer), getCachedFileStorages(deleted, pathNormalizer))
|
||||
}
|
||||
|
||||
@@ -178,7 +181,7 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
storageLock.withLock {
|
||||
storageLock.read {
|
||||
var result: MutableList<FileBasedStorage>? = null
|
||||
for (fileSpec in fileSpecs) {
|
||||
val path = normalizeFileSpec(pathNormalizer?.invoke(fileSpec) ?: fileSpec)
|
||||
@@ -198,7 +201,8 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
protected open fun createStateStorage(storageClass: Class<out StateStorage>,
|
||||
collapsedPath: String,
|
||||
roamingType: RoamingType,
|
||||
@Suppress("DEPRECATION") stateSplitter: Class<out StateSplitter>): StateStorage {
|
||||
@Suppress("DEPRECATION") stateSplitter: Class<out StateSplitter>,
|
||||
exclusive: Boolean = false): StateStorage {
|
||||
if (storageClass != StateStorage::class.java) {
|
||||
val constructor = storageClass.constructors[0]!!
|
||||
constructor.isAccessible = true
|
||||
@@ -231,15 +235,15 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
effectiveRoamingType = roamingType
|
||||
}
|
||||
|
||||
val storage = createFileBasedStorage(filePath, collapsedPath, effectiveRoamingType)
|
||||
val storage = createFileBasedStorage(filePath, collapsedPath, effectiveRoamingType, if (exclusive) null else this.rootTagName)
|
||||
if (isUseVfsListener == ThreeState.YES && storage is StorageVirtualFileTracker.TrackedStorage) {
|
||||
virtualFileTracker?.put(filePath, storage)
|
||||
}
|
||||
return storage
|
||||
}
|
||||
|
||||
protected open fun createFileBasedStorage(path: String, collapsedPath: String, roamingType: RoamingType): StateStorage
|
||||
= MyFileStorage(this, File(path), collapsedPath, rootTagName, roamingType, getMacroSubstitutor(collapsedPath), streamProvider)
|
||||
protected open fun createFileBasedStorage(path: String, collapsedPath: String, roamingType: RoamingType, rootTagName: String?): StateStorage
|
||||
= MyFileStorage(this, Paths.get(path), collapsedPath, rootTagName, roamingType, getMacroSubstitutor(collapsedPath), streamProvider)
|
||||
|
||||
protected open fun createDirectoryBasedStorage(path: String, collapsedPath: String, @Suppress("DEPRECATION") splitter: StateSplitter): StateStorage
|
||||
= MyDirectoryStorage(this, Paths.get(path), splitter)
|
||||
@@ -248,17 +252,19 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
DirectoryBasedStorage(file, splitter, storageManager.pathMacroSubstitutor), StorageVirtualFileTracker.TrackedStorage
|
||||
|
||||
private class MyFileStorage(override val storageManager: StateStorageManagerImpl,
|
||||
file: File,
|
||||
file: Path,
|
||||
fileSpec: String,
|
||||
rootElementName: String,
|
||||
rootElementName: String?,
|
||||
roamingType: RoamingType,
|
||||
pathMacroManager: TrackingPathMacroSubstitutor? = null,
|
||||
provider: StreamProvider? = null) : FileBasedStorage(file, fileSpec, rootElementName, pathMacroManager, roamingType, provider), StorageVirtualFileTracker.TrackedStorage {
|
||||
override val isUseXmlProlog: Boolean
|
||||
get() = storageManager.isUseXmlProlog
|
||||
get() = rootElementName != null && storageManager.isUseXmlProlog
|
||||
|
||||
override fun beforeElementSaved(element: Element) {
|
||||
storageManager.beforeElementSaved(element)
|
||||
if (rootElementName != null) {
|
||||
storageManager.beforeElementSaved(element)
|
||||
}
|
||||
super.beforeElementSaved(element)
|
||||
}
|
||||
|
||||
@@ -282,19 +288,19 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
}
|
||||
|
||||
override final fun rename(path: String, newName: String) {
|
||||
storageLock.withLock {
|
||||
storageLock.write {
|
||||
val storage = getOrCreateStorage(collapseMacros(path), RoamingType.DEFAULT) as FileBasedStorage
|
||||
|
||||
val file = storage.getVirtualFile()
|
||||
val file = storage.virtualFile
|
||||
try {
|
||||
if (file != null) {
|
||||
file.rename(storage, newName)
|
||||
}
|
||||
else if (storage.file.name != newName) {
|
||||
else if (storage.file.fileName.toString() != newName) {
|
||||
// old file didn't exist or renaming failed
|
||||
val expandedPath = expandMacros(path)
|
||||
val parentPath = PathUtilRt.getParentPath(expandedPath)
|
||||
storage.setFile(null, File(parentPath, newName))
|
||||
storage.setFile(null, Paths.get(parentPath, newName))
|
||||
pathRenamed(expandedPath, "$parentPath/$newName", null)
|
||||
}
|
||||
}
|
||||
@@ -305,13 +311,13 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
}
|
||||
|
||||
fun clearStorages() {
|
||||
storageLock.withLock {
|
||||
storageLock.write {
|
||||
try {
|
||||
if (virtualFileTracker != null) {
|
||||
storages.forEachEntry({ collapsedPath, storage ->
|
||||
virtualFileTracker.remove(expandMacros(collapsedPath))
|
||||
virtualFileTracker?.let {
|
||||
storages.forEachEntry { collapsedPath, storage ->
|
||||
it.remove(expandMacros(collapsedPath))
|
||||
true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -328,8 +334,8 @@ open class StateStorageManagerImpl(private val rootTagName: String,
|
||||
matcherLoop@
|
||||
while (matcher.find()) {
|
||||
val m = matcher.group(1)
|
||||
for (macro in macros) {
|
||||
if (macro.key == m) {
|
||||
for ((key) in macros) {
|
||||
if (key == m) {
|
||||
continue@matcherLoop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.intellij.configurationStore
|
||||
import com.intellij.openapi.components.StateStorage
|
||||
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
|
||||
import com.intellij.openapi.components.impl.stores.StateStorageManager
|
||||
import com.intellij.openapi.util.text.StringUtilRt
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
@@ -11,7 +10,7 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
|
||||
import com.intellij.openapi.vfs.newvfs.events.*
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.messages.MessageBus
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@@ -61,7 +60,7 @@ class StorageVirtualFileTracker(private val messageBus: MessageBus) {
|
||||
if (storage != null) {
|
||||
filePathToStorage.put(event.path, storage)
|
||||
if (storage is FileBasedStorage) {
|
||||
storage.setFile(null, File(event.path))
|
||||
storage.setFile(null, Paths.get(event.path))
|
||||
}
|
||||
// we don't support DirectoryBasedStorage renaming
|
||||
|
||||
@@ -71,13 +70,13 @@ class StorageVirtualFileTracker(private val messageBus: MessageBus) {
|
||||
}
|
||||
else {
|
||||
val path = event.path
|
||||
storage = filePathToStorage[path]
|
||||
storage = filePathToStorage.get(path)
|
||||
// we don't care about parent directory create (because it doesn't affect anything) and move (because it is not supported case),
|
||||
// but we should detect deletion - but again, it is not supported case. So, we don't check if some of registered storages located inside changed directory.
|
||||
|
||||
// but if we have DirectoryBasedStorage, we check - if file located inside it
|
||||
if (storage == null && hasDirectoryBasedStorages && StringUtilRt.endsWithIgnoreCase(path, FileStorageCoreUtil.DEFAULT_EXT)) {
|
||||
storage = filePathToStorage[VfsUtil.getParentDir(path)]
|
||||
if (storage == null && hasDirectoryBasedStorages && path.endsWith(FileStorageCoreUtil.DEFAULT_EXT, ignoreCase = true)) {
|
||||
storage = filePathToStorage.get(VfsUtil.getParentDir(path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +87,7 @@ class StorageVirtualFileTracker(private val messageBus: MessageBus) {
|
||||
when (event) {
|
||||
is VFileMoveEvent -> {
|
||||
if (storage is FileBasedStorage) {
|
||||
storage.setFile(null, File(event.path))
|
||||
storage.setFile(null, Paths.get(event.path))
|
||||
}
|
||||
}
|
||||
is VFileCreateEvent -> {
|
||||
|
||||
@@ -44,53 +44,53 @@ import org.jetbrains.annotations.TestOnly
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
private val CHANGED_FILES_KEY = Key.create<MultiMap<ComponentStoreImpl, StateStorage>>("CHANGED_FILES_KEY")
|
||||
|
||||
/**
|
||||
* Should be a separate service, not closely related to ProjectManager, but it requires some cleanup/investigation.
|
||||
*/
|
||||
class StoreAwareProjectManager(virtualFileManager: VirtualFileManager, progressManager: ProgressManager) : ProjectManagerImpl(progressManager) {
|
||||
companion object {
|
||||
private val CHANGED_FILES_KEY = Key.create<MultiMap<ComponentStoreImpl, StateStorage>>("CHANGED_FILES_KEY")
|
||||
}
|
||||
|
||||
private val reloadBlockCount = AtomicInteger()
|
||||
private val changedApplicationFiles = LinkedHashSet<StateStorage>()
|
||||
|
||||
private val restartApplicationOrReloadProjectTask = Runnable {
|
||||
if (isReloadUnblocked() && tryToReloadApplication()) {
|
||||
val projectsToReload = THashSet<Project>()
|
||||
for (project in openProjects) {
|
||||
if (project.isDisposed) {
|
||||
continue
|
||||
}
|
||||
if (!isReloadUnblocked() || !tryToReloadApplication()) {
|
||||
return@Runnable
|
||||
}
|
||||
|
||||
val changes = CHANGED_FILES_KEY.get(project) ?: continue
|
||||
CHANGED_FILES_KEY.set(project, null)
|
||||
if (!changes.isEmpty) {
|
||||
runBatchUpdate(project.messageBus) {
|
||||
for ((store, storages) in changes.entrySet()) {
|
||||
if ((store.storageManager as? StateStorageManagerImpl)?.componentManager?.isDisposed ?: false) {
|
||||
continue
|
||||
}
|
||||
val projectsToReload = THashSet<Project>()
|
||||
for (project in openProjects) {
|
||||
if (project.isDisposed) {
|
||||
continue
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (reloadStore(storages as Set<StateStorage>, store, false) == ReloadComponentStoreStatus.RESTART_AGREED) {
|
||||
projectsToReload.add(project)
|
||||
}
|
||||
val changes = CHANGED_FILES_KEY.get(project) ?: continue
|
||||
CHANGED_FILES_KEY.set(project, null)
|
||||
if (!changes.isEmpty) {
|
||||
runBatchUpdate(project.messageBus) {
|
||||
for ((store, storages) in changes.entrySet()) {
|
||||
if ((store.storageManager as? StateStorageManagerImpl)?.componentManager?.isDisposed ?: false) {
|
||||
continue
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (reloadStore(storages as Set<StateStorage>, store, false) == ReloadComponentStoreStatus.RESTART_AGREED) {
|
||||
projectsToReload.add(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (project in projectsToReload) {
|
||||
ProjectManagerImpl.doReloadProject(project)
|
||||
}
|
||||
for (project in projectsToReload) {
|
||||
ProjectManagerImpl.doReloadProject(project)
|
||||
}
|
||||
}
|
||||
|
||||
private val changedFilesAlarm = SingleAlarm(restartApplicationOrReloadProjectTask, 300, this)
|
||||
|
||||
init {
|
||||
ApplicationManager.getApplication().messageBus.connect().subscribe(StateStorageManager.STORAGE_TOPIC, object : StorageManagerListener() {
|
||||
ApplicationManager.getApplication().messageBus.connect().subscribe(StateStorageManager.STORAGE_TOPIC, object : StorageManagerListener {
|
||||
override fun storageFileChanged(event: VFileEvent, storage: StateStorage, componentManager: ComponentManager) {
|
||||
if (event is VFilePropertyChangeEvent) {
|
||||
// ignore because doesn't affect content
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.components.TrackingPathMacroSubstitutor
|
||||
import com.intellij.openapi.components.impl.stores.FileStorageCoreUtil
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.containers.SmartHashSet
|
||||
import com.intellij.util.loadElement
|
||||
import gnu.trove.THashMap
|
||||
@@ -29,7 +28,7 @@ import org.jdom.Attribute
|
||||
import org.jdom.Element
|
||||
|
||||
abstract class XmlElementStorage protected constructor(protected val fileSpec: String,
|
||||
protected val rootElementName: String,
|
||||
protected val rootElementName: String?,
|
||||
protected val pathMacroSubstitutor: TrackingPathMacroSubstitutor? = null,
|
||||
roamingType: RoamingType? = RoamingType.DEFAULT,
|
||||
provider: StreamProvider? = null) : StorageBaseEx<StateMap>() {
|
||||
@@ -62,7 +61,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
else {
|
||||
element = loadLocalData()
|
||||
}
|
||||
return if (element == null) StateMap.EMPTY else loadState(element)
|
||||
return element?.let { loadState(element) } ?: StateMap.EMPTY
|
||||
}
|
||||
|
||||
protected open fun dataLoadedFromProvider(element: Element?) {
|
||||
@@ -76,7 +75,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
}
|
||||
|
||||
fun setDefaultState(element: Element) {
|
||||
element.name = rootElementName
|
||||
element.name = rootElementName!!
|
||||
storageDataRef.set(loadState(element))
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
else {
|
||||
val changedComponentNames = oldData.getChangedComponentNames(newData)
|
||||
LOG.debug { "analyzeExternalChangesAndUpdateIfNeed: changedComponentNames $changedComponentNames for ${toString()}" }
|
||||
if (!ContainerUtil.isEmpty(changedComponentNames)) {
|
||||
if (changedComponentNames.isNotEmpty()) {
|
||||
componentNames.addAll(changedComponentNames)
|
||||
}
|
||||
}
|
||||
@@ -111,7 +110,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
|
||||
private val newLiveStates = THashMap<String, Element>()
|
||||
|
||||
override fun createSaveSession() = if (storage.checkIsSavingDisabled() || copiedStates == null) null else this
|
||||
override fun createSaveSession() = if (copiedStates == null || storage.checkIsSavingDisabled()) null else this
|
||||
|
||||
override fun setSerializedState(componentName: String, element: Element?) {
|
||||
element?.normalizeRootName()
|
||||
@@ -125,11 +124,8 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
|
||||
override fun save() {
|
||||
val stateMap = StateMap.fromMap(copiedStates!!)
|
||||
var element = save(stateMap, storage.rootElementName, newLiveStates)
|
||||
if (element == null || JDOMUtil.isEmpty(element)) {
|
||||
element = null
|
||||
}
|
||||
else {
|
||||
val element = save(stateMap, storage.rootElementName, newLiveStates)
|
||||
if (element != null) {
|
||||
storage.beforeElementSaved(element)
|
||||
}
|
||||
|
||||
@@ -194,12 +190,12 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S
|
||||
}
|
||||
}
|
||||
|
||||
fun save(states: StateMap, rootElementName: String, newLiveStates: Map<String, Element>? = null): Element? {
|
||||
private fun save(states: StateMap, rootElementName: String?, newLiveStates: Map<String, Element>? = null): Element? {
|
||||
if (states.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
|
||||
val rootElement = Element(rootElementName)
|
||||
val rootElement = if (rootElementName == null) null else Element(rootElementName)
|
||||
for (componentName in states.keys()) {
|
||||
val element = states.getElement(componentName, newLiveStates) ?: continue
|
||||
// name attribute should be first
|
||||
@@ -208,7 +204,7 @@ fun save(states: StateMap, rootElementName: String, newLiveStates: Map<String, E
|
||||
element.setAttribute(FileStorageCoreUtil.NAME, componentName)
|
||||
}
|
||||
else {
|
||||
var nameAttribute: Attribute? = element.getAttribute(FileStorageCoreUtil.NAME)
|
||||
var nameAttribute = element.getAttribute(FileStorageCoreUtil.NAME)
|
||||
if (nameAttribute == null) {
|
||||
nameAttribute = Attribute(FileStorageCoreUtil.NAME, componentName)
|
||||
elementAttributes.add(0, nameAttribute)
|
||||
@@ -222,9 +218,13 @@ fun save(states: StateMap, rootElementName: String, newLiveStates: Map<String, E
|
||||
}
|
||||
}
|
||||
|
||||
if (rootElement == null) {
|
||||
return element
|
||||
}
|
||||
|
||||
rootElement.addContent(element)
|
||||
}
|
||||
return rootElement
|
||||
return if (JDOMUtil.isEmpty(rootElement)) null else rootElement
|
||||
}
|
||||
|
||||
internal fun Element.normalizeRootName(): Element {
|
||||
|
||||
+7
-2
@@ -6,12 +6,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
@SuppressWarnings("ClassExplicitlyAnnotation")
|
||||
final class ProjectFileStorageAnnotation implements Storage {
|
||||
final class FileStorageAnnotation implements Storage {
|
||||
private String path;
|
||||
|
||||
private boolean deprecated;
|
||||
|
||||
ProjectFileStorageAnnotation(String path, boolean deprecated) {
|
||||
FileStorageAnnotation(String path, boolean deprecated) {
|
||||
this.path = path;
|
||||
this.deprecated = deprecated;
|
||||
}
|
||||
@@ -21,6 +21,11 @@ final class ProjectFileStorageAnnotation implements Storage {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exclusive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String file() {
|
||||
return value();
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.intellij.configurationStore;
|
||||
|
||||
import com.intellij.openapi.components.StateSplitter;
|
||||
import com.intellij.openapi.components.StateStorage;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
|
||||
/**
|
||||
* This class was introduced as a workaround for Kotlin bug (https://youtrack.jetbrains.com/issue/KT-9670) to avoid creation of
|
||||
* unnecessary instances of KClass
|
||||
* todo[nik] remove when KT-9670 is fixed
|
||||
*/
|
||||
public class JavaAnnotationHelperForKotlin {
|
||||
public static Class<? extends StateStorage> getStorageClass(Storage storage) {
|
||||
return storage.storageClass();
|
||||
}
|
||||
|
||||
public static Class<? extends StateSplitter> getStateSplitterClass(Storage storage) {
|
||||
return storage.stateSplitter();
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class BinaryXmlOutputterTest {
|
||||
private fun test(xml: String) {
|
||||
val byteOut = BufferExposingByteArrayOutputStream()
|
||||
byteOut.use {
|
||||
writeElement(loadElement(xml), it)
|
||||
serializeElementToBinary(loadElement(xml), it)
|
||||
}
|
||||
|
||||
val xmlAfter = JDOMUtil.writeElement(byteOut.toByteArray().inputStream().use { readElement(it) })
|
||||
|
||||
@@ -11,17 +11,17 @@ import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.ModuleAdapter
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.io.systemIndependentPath
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.testFramework.*
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.systemIndependentPath
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExternalResource
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import kotlin.properties.Delegates
|
||||
@@ -88,7 +88,7 @@ internal class ModuleStoreRenameTest {
|
||||
runInEdtAndWait { module.saveStore() }
|
||||
val storage = module.storage
|
||||
val oldFile = storage.file
|
||||
assertThat(oldFile).isFile()
|
||||
assertThat(oldFile).isRegularFile()
|
||||
|
||||
val oldName = module.name
|
||||
val newName = "foo"
|
||||
@@ -100,26 +100,26 @@ internal class ModuleStoreRenameTest {
|
||||
// project view
|
||||
@Test fun `rename module using rename virtual file`() {
|
||||
runInEdtAndWait { module.saveStore() }
|
||||
var storage = module.storage
|
||||
val storage = module.storage
|
||||
val oldFile = storage.file
|
||||
assertThat(oldFile).isFile()
|
||||
assertThat(oldFile).isRegularFile()
|
||||
|
||||
val oldName = module.name
|
||||
val newName = "foo"
|
||||
runInEdtAndWait { runWriteAction { LocalFileSystem.getInstance().refreshAndFindFileByIoFile(oldFile)!!.rename(null, "$newName${ModuleFileType.DOT_DEFAULT_EXTENSION}") } }
|
||||
runInEdtAndWait { runWriteAction { LocalFileSystem.getInstance().refreshAndFindFileByPath(oldFile.systemIndependentPath)!!.rename(null, "$newName${ModuleFileType.DOT_DEFAULT_EXTENSION}") } }
|
||||
assertRename(newName, oldFile)
|
||||
assertThat(oldModuleNames).containsOnly(oldName)
|
||||
}
|
||||
|
||||
// we cannot test external rename yet, because it is not supported - ModuleImpl doesn't support delete and create events (in case of external change we don't get move event, but get "delete old" and "create new")
|
||||
|
||||
private fun assertRename(newName: String, oldFile: File) {
|
||||
private fun assertRename(newName: String, oldFile: Path) {
|
||||
val newFile = module.storage.file
|
||||
assertThat(newFile.name).isEqualTo("$newName${ModuleFileType.DOT_DEFAULT_EXTENSION}")
|
||||
assertThat(newFile.fileName.toString()).isEqualTo("$newName${ModuleFileType.DOT_DEFAULT_EXTENSION}")
|
||||
assertThat(oldFile)
|
||||
.doesNotExist()
|
||||
.isNotEqualTo(newFile)
|
||||
assertThat(newFile).isFile()
|
||||
assertThat(newFile).isRegularFile()
|
||||
|
||||
// ensure that macro value updated
|
||||
assertThat(module.stateStore.stateStorageManager.expandMacros(StoragePathMacros.MODULE_FILE)).isEqualTo(newFile.systemIndependentPath)
|
||||
@@ -129,7 +129,7 @@ internal class ModuleStoreRenameTest {
|
||||
runInEdtAndWait { module.saveStore() }
|
||||
val storage = module.storage
|
||||
val oldFile = storage.file
|
||||
val parentVirtualDir = storage.getVirtualFile()!!.parent
|
||||
val parentVirtualDir = storage.virtualFile!!.parent
|
||||
runInEdtAndWait { runWriteAction { parentVirtualDir.rename(null, UUID.randomUUID().toString()) } }
|
||||
|
||||
val newFile = Paths.get(parentVirtualDir.path, "${module.name}${ModuleFileType.DOT_DEFAULT_EXTENSION}")
|
||||
|
||||
@@ -26,14 +26,13 @@ import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ex.ProjectEx
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||
import com.intellij.openapi.project.impl.ProjectImpl
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.*
|
||||
import com.intellij.testFramework.Assertions.assertThat
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.readText
|
||||
import com.intellij.util.systemIndependentPath
|
||||
import com.intellij.util.write
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.junit.ClassRule
|
||||
import org.junit.Rule
|
||||
@@ -58,8 +57,7 @@ private fun createOrLoadProject(tempDirManager: TemporaryDirectory, task: (Proje
|
||||
filePath = runWriteAction { projectCreator(tempDirManager.newVirtualDirectory()) }
|
||||
}
|
||||
|
||||
val projectManager = ProjectManagerEx.getInstanceEx() as ProjectManagerImpl
|
||||
val project = if (projectCreator == null) createHeavyProject(filePath, true) else projectManager.loadProject(filePath)!!
|
||||
val project = if (projectCreator == null) createHeavyProject(filePath, true) else ProjectManagerEx.getInstanceEx().loadProject(filePath)!!
|
||||
project.runInLoadComponentStateMode {
|
||||
project.use(task)
|
||||
}
|
||||
@@ -69,7 +67,8 @@ private fun createOrLoadProject(tempDirManager: TemporaryDirectory, task: (Proje
|
||||
internal class ProjectStoreTest {
|
||||
companion object {
|
||||
@JvmField
|
||||
@ClassRule val projectRule = ProjectRule()
|
||||
@ClassRule
|
||||
val projectRule = ProjectRule()
|
||||
}
|
||||
|
||||
val tempDirManager = TemporaryDirectory()
|
||||
@@ -116,7 +115,7 @@ internal class ProjectStoreTest {
|
||||
|
||||
@Test fun fileBasedStorage() {
|
||||
loadAndUseProject(tempDirManager, { it.writeChild("test${ProjectFileType.DOT_DEFAULT_EXTENSION}", iprFileContent).path }) { project ->
|
||||
test(project as ProjectEx)
|
||||
test(project)
|
||||
|
||||
assertThat(project.basePath).isEqualTo(PathUtil.getParentPath(project.projectFilePath!!))
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.options.BaseSchemeProcessor
|
||||
import com.intellij.openapi.options.ExternalizableScheme
|
||||
import com.intellij.openapi.options.SchemesManagerFactory
|
||||
import com.intellij.openapi.options.SchemeManagerFactory
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
@@ -26,9 +26,7 @@ import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.util.*
|
||||
import com.intellij.util.lang.CompoundRuntimeException
|
||||
import com.intellij.util.xmlb.XmlSerializer
|
||||
import com.intellij.util.xmlb.annotations.Attribute
|
||||
import com.intellij.util.xmlb.annotations.Tag
|
||||
import com.intellij.util.xmlb.annotations.Transient
|
||||
import com.intellij.util.xmlb.serialize
|
||||
import com.intellij.util.xmlb.toByteArray
|
||||
import gnu.trove.THashMap
|
||||
@@ -70,7 +68,7 @@ internal class SchemeManagerTest {
|
||||
|
||||
@Test fun deleteScheme() {
|
||||
val manager = createAndLoad("options1")
|
||||
manager.removeScheme(TestScheme("first"))
|
||||
manager.removeScheme("first")
|
||||
manager.save()
|
||||
|
||||
checkSchemes("2->second")
|
||||
@@ -153,10 +151,10 @@ internal class SchemeManagerTest {
|
||||
scheme.save(dir.resolve("1.icls"))
|
||||
TestScheme("local", "false").save(dir.resolve("1.xml"))
|
||||
|
||||
val schemesManager = SchemeManagerImpl<TestScheme, TestScheme>(FILE_SPEC, object: TestSchemesProcessor() {
|
||||
override fun isUpgradeNeeded() = true
|
||||
val schemesManager = SchemeManagerImpl(FILE_SPEC, object: TestSchemesProcessor() {
|
||||
override val isUpgradeNeeded = true
|
||||
|
||||
override fun getSchemeExtension() = ".icls"
|
||||
override val schemeExtension = ".icls"
|
||||
}, null, dir)
|
||||
schemesManager.loadSchemes()
|
||||
assertThat(schemesManager.allSchemes).containsOnly(scheme)
|
||||
@@ -203,9 +201,8 @@ internal class SchemeManagerTest {
|
||||
val converter: (Element) -> TestScheme = { XmlSerializer.deserialize(it, TestScheme::class.java)!! }
|
||||
val bundledPath = "/bundledSchemes/default"
|
||||
schemeManager.loadBundledScheme(bundledPath, this, converter)
|
||||
var schemes = schemeManager.allSchemes
|
||||
val customScheme = TestScheme("default")
|
||||
assertThat(schemes).containsOnly(customScheme)
|
||||
assertThat(schemeManager.allSchemes).containsOnly(customScheme)
|
||||
|
||||
schemeManager.save()
|
||||
assertThat(dir).doesNotExist()
|
||||
@@ -214,8 +211,7 @@ internal class SchemeManagerTest {
|
||||
schemeManager.setSchemes(listOf(customScheme))
|
||||
assertThat(dir).doesNotExist()
|
||||
|
||||
schemes = schemeManager.allSchemes
|
||||
assertThat(schemes).containsOnly(customScheme)
|
||||
assertThat(schemeManager.allSchemes).containsOnly(customScheme)
|
||||
|
||||
customScheme.data = "foo"
|
||||
schemeManager.save()
|
||||
@@ -225,8 +221,7 @@ internal class SchemeManagerTest {
|
||||
schemeManager.loadBundledScheme(bundledPath, this, converter)
|
||||
schemeManager.loadSchemes()
|
||||
|
||||
schemes = schemeManager.allSchemes
|
||||
assertThat(schemes).containsOnly(customScheme)
|
||||
assertThat(schemeManager.allSchemes).containsOnly(customScheme)
|
||||
}
|
||||
|
||||
@Test fun `don't remove dir if no schemes but at least one non-hidden file exists`() {
|
||||
@@ -297,14 +292,14 @@ internal class SchemeManagerTest {
|
||||
}
|
||||
|
||||
@Test fun `path must not contains ROOT_CONFIG macro`() {
|
||||
assertThatThrownBy({ SchemesManagerFactory.getInstance().create<TestScheme, TestScheme>("\$ROOT_CONFIG$/foo", TestSchemesProcessor()) }).hasMessage("Path must not contains ROOT_CONFIG macro, corrected: foo")
|
||||
assertThatThrownBy({ SchemeManagerFactory.getInstance().create("\$ROOT_CONFIG$/foo", TestSchemesProcessor()) }).hasMessage("Path must not contains ROOT_CONFIG macro, corrected: foo")
|
||||
}
|
||||
|
||||
@Test fun `path must be system-independent`() {
|
||||
assertThatThrownBy({SchemesManagerFactory.getInstance().create<TestScheme, TestScheme>("foo\\bar", TestSchemesProcessor())}).hasMessage("Path must be system-independent, use forward slash instead of backslash")
|
||||
assertThatThrownBy({ SchemeManagerFactory.getInstance().create("foo\\bar", TestSchemesProcessor())}).hasMessage("Path must be system-independent, use forward slash instead of backslash")
|
||||
}
|
||||
|
||||
private fun createSchemeManager(dir: Path) = SchemeManagerImpl<TestScheme, TestScheme>(FILE_SPEC, TestSchemesProcessor(), null, dir)
|
||||
private fun createSchemeManager(dir: Path) = SchemeManagerImpl(FILE_SPEC, TestSchemesProcessor(), null, dir)
|
||||
|
||||
private fun createAndLoad(testData: String): SchemeManagerImpl<TestScheme, TestScheme> {
|
||||
createTempFiles(testData)
|
||||
@@ -324,7 +319,7 @@ internal class SchemeManagerTest {
|
||||
}
|
||||
|
||||
private fun createAndLoad(): SchemeManagerImpl<TestScheme, TestScheme> {
|
||||
val schemesManager = SchemeManagerImpl<TestScheme, TestScheme>(FILE_SPEC, TestSchemesProcessor(), MockStreamProvider(remoteBaseDir!!), localBaseDir!!)
|
||||
val schemesManager = SchemeManagerImpl(FILE_SPEC, TestSchemesProcessor(), MockStreamProvider(remoteBaseDir!!), localBaseDir!!)
|
||||
schemesManager.loadSchemes()
|
||||
return schemesManager
|
||||
}
|
||||
@@ -368,16 +363,11 @@ private fun checkSchemes(baseDir: Path, expected: String, ignoreDeleted: Boolean
|
||||
}
|
||||
|
||||
@Tag("scheme")
|
||||
data class TestScheme(@field:Attribute private var name: String = "", @field:Attribute var data: String? = null) : ExternalizableScheme {
|
||||
override fun getName() = name
|
||||
|
||||
override @Transient fun setName(newName: String) {
|
||||
name = newName
|
||||
}
|
||||
data class TestScheme(override @field:com.intellij.util.xmlb.annotations.Attribute var name: String = "", @field:com.intellij.util.xmlb.annotations.Attribute var data: String? = null) : ExternalizableScheme {
|
||||
}
|
||||
|
||||
open class TestSchemesProcessor : BaseSchemeProcessor<TestScheme>() {
|
||||
override fun readScheme(element: Element) = XmlSerializer.deserialize(element, TestScheme::class.java)
|
||||
open class TestSchemesProcessor : BaseSchemeProcessor<TestScheme, TestScheme>() {
|
||||
override fun readScheme(element: Element, duringLoad: Boolean) = XmlSerializer.deserialize(element, TestScheme::class.java)
|
||||
|
||||
override fun writeScheme(scheme: TestScheme) = scheme.serialize()
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user