diff --git a/.idea/libraries/memoryfilesystem.xml b/.idea/libraries/memoryfilesystem.xml new file mode 100644 index 000000000000..343101b9af73 --- /dev/null +++ b/.idea/libraries/memoryfilesystem.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/build/order.txt b/build/order.txt index d1730e8a0780..75cfa9c4af0d 100644 --- a/build/order.txt +++ b/build/order.txt @@ -1143,7 +1143,7 @@ com/intellij/ide/ui/LafManagerImpl$IdeaLaf.class:/lib/idea.jar com/intellij/ide/ui/LafManagerImpl$1.class:/lib/idea.jar com/intellij/ide/ui/LafManagerImpl$2.class:/lib/idea.jar com/intellij/diagnostic/PerformanceWatcher.class:/lib/idea.jar -com/intellij/openapi/options/SchemesManagerFactory.class:/lib/openapi.jar +com/intellij/openapi/options/SchemeManagerFactory.class:/lib/openapi.jar com/intellij/openapi/components/SettingsSavingComponent.class:/lib/openapi.jar com/intellij/openapi/options/SchemesManager.class:/lib/openapi.jar com/intellij/ide/XmlRpcServer.class:/lib/openapi.jar diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index 4d8bd26f32ee..5185e48d5dfb 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -70,15 +70,14 @@ import org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfig import java.io.File; import java.util.*; +import static org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfigurationSerializer.DEFAULT_WILDCARD_PATTERNS; + @State(name = "CompilerConfiguration", storages = @Storage("compiler.xml")) public class CompilerConfigurationImpl extends CompilerConfiguration implements PersistentStateComponent, ProjectComponent { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.CompilerConfiguration"); public static final String TESTS_EXTERNAL_COMPILER_HOME_PROPERTY_NAME = "tests.external.compiler.home"; public static final int DEFAULT_BUILD_PROCESS_HEAP_SIZE = 700; - private static final List DEFAULT_WILDCARD_PATTERNS = - Arrays.asList("!?*.java", "!?*.form", "!?*.class", "!?*.groovy", "!?*.scala", "!?*.flex", "!?*.kt", "!?*.clj", "!?*.aj"); - private BackendCompiler myDefaultJavaCompiler; private State myState = new State(); @@ -139,7 +138,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements @Override public Element getState() { - final boolean savingStateInNewFormatAllowed = Registry.is("saving.state.in.new.format.is.allowed", false); + final boolean savingStateInNewFormatAllowed = Registry.is("saving.state.in.new.format.is.allowed", true); Element state = new Element("state"); XmlSerializer.serializeInto(myState, state, new SkipDefaultValuesSerializationFilters() { diff --git a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java index de244d3c0800..7388509bd104 100644 --- a/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java +++ b/java/compiler/impl/src/com/intellij/compiler/progress/CompilerTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -620,10 +620,6 @@ public class CompilerTask extends Task.Backgroundable { return !myUserAcceptedCancel && !myIsApplicationExitingOrProjectClosing && myIndicator.isRunning(); } - @Override - public void projectOpened(Project project) { - } - @Override public void projectClosed(Project project) { if (project.equals(myProject) && myContent != null) { @@ -652,4 +648,3 @@ public class CompilerTask extends Task.Backgroundable { } } } - \ No newline at end of file diff --git a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java index 0c9bec8c2cf8..b55549968d90 100644 --- a/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java +++ b/java/compiler/impl/src/com/intellij/openapi/compiler/util/InspectionValidatorWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -232,7 +232,7 @@ public class InspectionValidatorWrapper implements Validator { } - final InspectionProfile inspectionProfile = myProfileManager.getInspectionProfile(); + final InspectionProfile inspectionProfile = myProfileManager.getCurrentProfile(); for (final LocalInspectionTool inspectionTool : inspections) { if (!checkUnderReadAction(item, context, () -> { final PsiFile file = item.getPsiFile(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java index a3a350eae34c..3dec80734559 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/PostHighlightingVisitor.java @@ -123,7 +123,7 @@ class PostHighlightingVisitor { ApplicationManager.getApplication().assertReadAccessAllowed(); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME); @@ -141,7 +141,7 @@ class PostHighlightingVisitor { void collectHighlights(@NotNull HighlightInfoHolder result, @NotNull ProgressIndicator progress) { DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); FileStatusMap fileStatusMap = daemonCodeAnalyzer.getFileStatusMap(); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); boolean unusedSymbolEnabled = profile.isToolEnabled(myDeadCodeKey, myFile); GlobalUsageHelper globalUsageHelper = myRefCountHolder.getGlobalUsageHelper(myFile, myDeadCodeInspection, unusedSymbolEnabled); @@ -194,7 +194,7 @@ class PostHighlightingVisitor { } private boolean isUnusedImportEnabled(HighlightDisplayKey unusedImportKey) { - InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); if (profile.isToolEnabled(unusedImportKey, myFile) && myFile instanceof PsiJavaFile && HighlightingLevelManager.getInstance(myProject).shouldHighlight(myFile)) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java index 45692e9006b7..3c2ff0ef3ea3 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/RedundantSuppressInspectionBase.java @@ -19,11 +19,13 @@ import com.intellij.analysis.AnalysisScope; import com.intellij.codeInsight.daemon.GroupNames; import com.intellij.codeInsight.daemon.impl.RemoveSuppressWarningAction; import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase; -import com.intellij.codeInspection.ex.*; +import com.intellij.codeInspection.ex.GlobalInspectionContextBase; +import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; +import com.intellij.codeInspection.ex.InspectionToolWrapper; +import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.text.StringUtil; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; @@ -88,7 +90,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { globalContext.getRefManager().iterate(new RefJavaVisitor() { @Override public void visitClass(@NotNull RefClass refClass) { if (!globalContext.shouldCheck(refClass, RedundantSuppressInspectionBase.this)) return; - CommonProblemDescriptor[] descriptors = checkElement(refClass, manager, globalContext.getProject()); + CommonProblemDescriptor[] descriptors = checkElement(refClass, manager); if (descriptors != null) { for (CommonProblemDescriptor descriptor : descriptors) { if (descriptor instanceof ProblemDescriptor) { @@ -108,13 +110,13 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { } @Nullable - private CommonProblemDescriptor[] checkElement(@NotNull RefClass refEntity, @NotNull InspectionManager manager, @NotNull Project project) { + private CommonProblemDescriptor[] checkElement(@NotNull RefClass refEntity, @NotNull InspectionManager manager) { final PsiClass psiClass = refEntity.getElement(); if (psiClass == null) return null; - return checkElement(psiClass, manager, project); + return checkElement(psiClass, manager); } - public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull final InspectionManager manager, @NotNull Project project) { + public CommonProblemDescriptor[] checkElement(@NotNull final PsiElement psiElement, @NotNull final InspectionManager manager) { final Map> suppressedScopes = new THashMap>(); psiElement.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitModifierList(PsiModifierList list) { @@ -159,14 +161,14 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { }); if (suppressedScopes.values().isEmpty()) return null; - // have to visit all file from scratch since inspections can be written in any perversive way including checkFile() overriding + // have to visit all file from scratch since inspections can be written in any pervasive way including checkFile() overriding Map suppressedTools = new THashMap(); InspectionToolWrapper[] toolWrappers = getInspectionTools(psiElement, manager); for (Collection ids : suppressedScopes.values()) { for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) { final String shortName = iterator.next().trim(); for (InspectionToolWrapper toolWrapper : toolWrappers) { - if (toolWrapper instanceof LocalInspectionToolWrapper && + if (toolWrapper instanceof LocalInspectionToolWrapper && (((LocalInspectionToolWrapper)toolWrapper).getTool().getID().equals(shortName) || shortName.equals(((LocalInspectionToolWrapper)toolWrapper).getTool().getAlternativeID()))) { if (((LocalInspectionToolWrapper)toolWrapper).isUnfair()) { @@ -179,7 +181,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { } else if (toolWrapper.getShortName().equals(shortName)) { //ignore global unused as it won't be checked anyway - if (toolWrapper instanceof LocalInspectionToolWrapper || + if (toolWrapper instanceof LocalInspectionToolWrapper || toolWrapper instanceof GlobalInspectionToolWrapper && !isGlobalInspectionRunCustomly(toolWrapper.getTool())) { suppressedTools.put(toolWrapper, shortName); } @@ -222,29 +224,7 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { descriptors = new ArrayList(); globalContext.getRefManager().iterate(new RefVisitor() { @Override public void visitElement(@NotNull RefEntity refEntity) { - CommonProblemDescriptor[] - descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() { - @Nullable - @Override - public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) { - return CommonProblemDescriptor.EMPTY_ARRAY; - } - - @Override - public void ignoreElement(@NotNull RefEntity refEntity) { - - } - - @Override - public void addProblemElement(@Nullable RefEntity refEntity, @NotNull CommonProblemDescriptor... commonProblemDescriptors) { - int i =0; - } - - @Override - public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) { - return null; - } - }); + CommonProblemDescriptor[] descriptors1 = global.getTool().checkElement(refEntity, scope, manager, globalContext, new ProblemDescriptionsProcessor() {}); if (descriptors1 != null) { ContainerUtil.addAll(descriptors, descriptors1); } @@ -330,14 +310,10 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool { } protected InspectionToolWrapper[] getInspectionTools(PsiElement psiElement, @NotNull InspectionManager manager) { - ModifiableModel model = InspectionProjectProfileManager.getInstance(manager.getProject()).getInspectionProfile().getModifiableModel(); - InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile)model); - profile.init(manager.getProject()); - - return profile.getInspectionTools(psiElement); + return InspectionProjectProfileManager.getInstance(manager.getProject()).getCurrentProfile().getModifiableModel() + .getInspectionTools(psiElement); } - @Override @Nullable public QuickFix getQuickFix(final String hint) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java index 28768a4e9aff..692761d7d9da 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/ex/EntryPointsManagerBase.java @@ -84,7 +84,7 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen protected final Project myProject; private long myLastModificationCount = -1; - public EntryPointsManagerBase(final Project project) { + public EntryPointsManagerBase(@NotNull Project project) { myProject = project; myTemporaryEntryPoints = new HashSet(); myPersistentEntryPoints = new LinkedHashMap(); // To keep the order between readExternal to writeExternal @@ -100,11 +100,13 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen if (ADDITIONAL_ANNOS != null) { ADDITIONAL_ANNOS = null; UIUtil.invokeLaterIfNeeded(() -> { - if (ApplicationManager.getApplication().isDisposed()) return; - InspectionProfileManager.getInstance().fireProfileChanged(null); + if (!ApplicationManager.getApplication().isDisposed()) { + InspectionProfileManager.getInstance().fireProfileChanged(null); + } }); } - DaemonCodeAnalyzer.getInstance(project).restart(); // annotations changed + // annotations changed + DaemonCodeAnalyzer.getInstance(myProject).restart(); } }, false, this); } @@ -246,8 +248,8 @@ public abstract class EntryPointsManagerBase extends EntryPointsManager implemen } else if (refConstructors.size() > 1) { // Many constructors here. Need to ask user which ones are used - for (int i = 0; i < refConstructors.size(); i++) { - addEntryPoint(refConstructors.get(i), isPersistent); + for (RefMethod refConstructor : refConstructors) { + addEntryPoint(refConstructor, isPersistent); } } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java index ebe8490b90a2..dff7bdb91b7d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/util/SpecialAnnotationsUtilBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ public class SpecialAnnotationsUtilBase { static void doQuickFixInternal(@NotNull Project project, @NotNull List targetList, @NotNull String qualifiedName) { targetList.add(qualifiedName); Collections.sort(targetList); - final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); + final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); //correct save settings //TODO lesya diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java index 884aa6684388..17aed5039e96 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/visibility/AccessCanBeTightenedInspection.java @@ -83,7 +83,7 @@ class AccessCanBeTightenedInspection extends BaseJavaBatchLocalInspectionTool { public MyVisitor(@NotNull ProblemsHolder holder) { myHolder = holder; - InspectionProfile profile = InspectionProjectProfileManager.getInstance(holder.getProject()).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(holder.getProject()).getCurrentProfile(); UnusedDeclarationInspectionBase tool = (UnusedDeclarationInspectionBase)profile.getUnwrappedTool(UnusedDeclarationInspectionBase.SHORT_NAME, holder.getFile()); myDeadCodeInspection = tool == null ? new UnusedDeclarationInspectionBase() : tool; } diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java index 12a96c284555..661a1ca45cf7 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaDocCompletionContributor.java @@ -46,7 +46,6 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.ProcessingContext; -import com.intellij.util.Processor; import com.intellij.util.SystemProperties; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; @@ -312,7 +311,7 @@ public class JavaDocCompletionContributor extends CompletionContributor { } InspectionProfile inspectionProfile = - InspectionProjectProfileManager.getInstance(position.getProject()).getInspectionProfile(); + InspectionProjectProfileManager.getInstance(position.getProject()).getCurrentProfile(); JavaDocLocalInspection inspection = (JavaDocLocalInspection)inspectionProfile.getUnwrappedTool(JavaDocLocalInspectionBase.SHORT_NAME, position); if (inspection != null) { diff --git a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java index d7b001b5d122..ecdea37b6e68 100644 --- a/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/highlighting/HighlightSuppressedWarningsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,7 +112,7 @@ public class HighlightSuppressedWarningsHandler extends HighlightUsagesHandlerBa parent.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, false, HighlightInfoProcessor.getEmpty()); final InspectionProfile inspectionProfile = - InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); + InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); for (PsiLiteralExpression target : targets) { final Object value = target.getValue(); if (!(value instanceof String)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java index 9859acba2f17..17ee364092fe 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/config/QuickFixFactoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -654,7 +654,7 @@ public class QuickFixFactoryImpl extends QuickFixFactory { @Override public void registerFixesForUnusedParameter(@NotNull PsiParameter parameter, @NotNull Object highlightInfo) { Project myProject = parameter.getProject(); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); UnusedParametersInspection unusedParametersInspection = (UnusedParametersInspection)profile.getUnwrappedTool(UnusedSymbolLocalInspectionBase.UNUSED_PARAMETERS_SHORT_NAME, parameter); LOG.assertTrue(ApplicationManager.getApplication().isUnitTestMode() || unusedParametersInspection != null); diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java index 6a749173e3ed..19483d3ba301 100644 --- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavaDocLocalInspection.java @@ -10,7 +10,6 @@ import com.intellij.codeInspection.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; import com.intellij.pom.Navigatable; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; @@ -398,7 +397,7 @@ public class JavaDocLocalInspection extends JavaDocLocalInspectionBase { @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { myInspection.registerAdditionalTag(myTag); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); InspectionProfileManager.getInstance().fireProfileChanged(profile); } diff --git a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt index 1f3a138fea47..3252c3e6e8b9 100644 --- a/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt +++ b/java/java-impl/src/com/intellij/codeInspection/javaDoc/JavadocHtmlLintAnnotator.kt @@ -118,7 +118,7 @@ class JavadocHtmlLintAnnotator(private val manual: Boolean = false) : file.virtualFile != null && ProjectFileIndex.SERVICE.getInstance(file.project).isInSourceContent(file.virtualFile) private fun isToolEnabled(file: PsiFile) = - manual || InspectionProjectProfileManager.getInstance(file.project).inspectionProfile.isToolEnabled(key.value, file) + manual || InspectionProjectProfileManager.getInstance(file.project).currentProfile.isToolEnabled(key.value, file) private fun createTempFile(bytes: ByteArray): File { val tempFile = FileUtil.createTempFile(File(PathManager.getTempPath()), "javadocHtmlLint", ".java") diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java index 76ef138fa2da..21f6ebcaa1c1 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/LanguageLevelProjectExtensionImpl.java @@ -54,7 +54,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten private void readExternal(final Element element) { String level = element.getAttributeValue(LANGUAGE_LEVEL); if (level == null) { - myLanguageLevel = Registry.is("saving.state.in.new.format.is.allowed", false) ? null : migrateFromIdea7(element); + myLanguageLevel = Registry.is("saving.state.in.new.format.is.allowed", true) ? null : migrateFromIdea7(element); } else { myLanguageLevel = LanguageLevel.valueOf(level); @@ -86,7 +86,7 @@ public class LanguageLevelProjectExtensionImpl extends LanguageLevelProjectExten element.setAttribute(DEFAULT_ATTRIBUTE, Boolean.toString(aBoolean)); } - if (!Registry.is("saving.state.in.new.format.is.allowed", false)) { + if (!Registry.is("saving.state.in.new.format.is.allowed", true)) { writeAttributesForIdea7(element); } } diff --git a/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java b/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java index 927f464b6e64..bee53a8a5070 100644 --- a/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java +++ b/java/java-impl/src/com/intellij/profile/codeInspection/JavaAwareInspectionProfileManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,16 +22,16 @@ package com.intellij.profile.codeInspection; import com.intellij.codeInsight.daemon.InspectionProfileConvertor; import com.intellij.codeInsight.daemon.JavaAwareInspectionProfileCoverter; -import com.intellij.codeInspection.ex.InspectionProfileManagerImpl; +import com.intellij.codeInspection.ex.ApplicationInspectionProfileManager; import com.intellij.codeInspection.ex.InspectionToolRegistrar; -import com.intellij.openapi.options.SchemesManagerFactory; +import com.intellij.openapi.options.SchemeManagerFactory; import com.intellij.util.messages.MessageBus; -public class JavaAwareInspectionProfileManager extends InspectionProfileManagerImpl { +public class JavaAwareInspectionProfileManager extends ApplicationInspectionProfileManager { public JavaAwareInspectionProfileManager(InspectionToolRegistrar registrar, - SchemesManagerFactory schemesManagerFactory, + SchemeManagerFactory schemeManagerFactory, MessageBus messageBus) { - super(registrar, schemesManagerFactory, messageBus); + super(registrar, schemeManagerFactory, messageBus); } @Override diff --git a/java/java-tests/java-tests.iml b/java/java-tests/java-tests.iml index 1008e1276345..3edaf9d0e1fc 100644 --- a/java/java-tests/java-tests.iml +++ b/java/java-tests/java-tests.iml @@ -53,5 +53,8 @@ + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/converter/options/options.after.xml b/java/java-tests/testData/inspection/converter/options/options.after.xml deleted file mode 100644 index 321bff7d639f..000000000000 --- a/java/java-tests/testData/inspection/converter/options/options.after.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy index 7f181760e1ea..6703d1b2064d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateGetterSetterTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ package com.intellij.codeInsight + import com.intellij.codeInsight.generation.ClassMember import com.intellij.codeInsight.generation.GenerateGetterHandler import com.intellij.codeInsight.generation.GenerateSetterHandler import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project -import com.intellij.psi.codeStyle.CodeStyleSettings import com.intellij.psi.codeStyle.CodeStyleSettingsManager -import com.intellij.psi.codeStyle.JavaCodeStyleManager import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.ui.UIUtil import com.siyeh.ig.style.UnqualifiedFieldAccessInspection import org.jetbrains.annotations.Nullable + /** * @author peter */ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java index b1a8368ec333..f70060746615 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.LocalInspectionToolSession; import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.psi.JavaElementVisitor; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiIdentifier; @@ -32,7 +31,7 @@ public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase { public void testErrorLikeUnusedSymbol() throws Exception { - enableInspectionTool(new LocalInspectionToolWrapper(new LocalInspectionTool() { + enableInspectionTool(new LocalInspectionTool() { @NotNull @Override public String getShortName() { @@ -73,7 +72,7 @@ public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase { public String getGroupDisplayName() { return getDisplayName(); } - })); + }); doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java index 9f94acbbdd8e..def1ddf09142 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -114,8 +114,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { @Override public String[] getIgnoreAnnotations() { return new String[]{"MyAnno"}; } }; - UnusedDeclarationInspectionBase deadCodeInspection = new UnusedDeclarationInspectionBase(true); - enableInspectionTool(deadCodeInspection); + enableInspectionTool(new UnusedDeclarationInspectionBase(true)); doTest(true, false); List infos = doHighlighting(HighlightSeverity.WARNING); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java index d88664a0cbd5..b1949d5b722f 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/impl/DaemonRespondToChangesTest.java @@ -1278,8 +1278,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { public void testDaemonIgnoresFrameDeactivation() throws Throwable { DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save - final InspectionProfileManager inspectionProfileManager = InspectionProfileManager.getInstance(); - inspectionProfileManager.setRootProfile(InspectionProfileImpl.getDefaultProfile().getName()); // reset to default profile from the custom one to avoid unnecessary save + InspectionProfileManager.getInstance().setRootProfile(InspectionProfileImpl.getDefaultProfile().getName()); // reset to default profile from the custom one to avoid unnecessary save String text = "class S { ArrayListXXX x;}"; configureByText(StdFileTypes.JAVA, text); @@ -1773,7 +1772,7 @@ public class DaemonRespondToChangesTest extends DaemonAnalyzerTestCase { PsiFile use = createFile("Use.java", "public class Use { { X.ffffffffffffff(); } }"); configureByExistingFile(use.getVirtualFile()); - InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getInspectionProfile(); + InspectionProfile profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile(); HighlightDisplayKey myDeadCodeKey = HighlightDisplayKey.find(UnusedDeclarationInspectionBase.SHORT_NAME); if (myDeadCodeKey == null) { myDeadCodeKey = HighlightDisplayKey.register(UnusedDeclarationInspectionBase.SHORT_NAME, UnusedDeclarationInspectionBase.DISPLAY_NAME); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java index 80b5f6256dd4..3f4f6f80be99 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/RemoveRedundantUncheckedSuppressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -82,7 +82,7 @@ public class RemoveRedundantUncheckedSuppressionTest extends LightQuickFixParame private void checkMember(PsiMember member, RedundantSuppressInspection inspection, ProblemsHolder holder) { final ProblemDescriptor[] problemDescriptors = - (ProblemDescriptor[])inspection.checkElement(member, InspectionManager.getInstance(getProject()), getProject()); + (ProblemDescriptor[])inspection.checkElement(member, InspectionManager.getInstance(getProject())); if (problemDescriptors != null) { for (ProblemDescriptor problemDescriptor : problemDescriptors) { holder.registerProblem(problemDescriptor); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java deleted file mode 100644 index c8710e6e290c..000000000000 --- a/java/java-tests/testSrc/com/intellij/codeInspection/InspectionProfilesConverterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInspection; - -import com.intellij.JavaTestUtil; -import com.intellij.codeInspection.ex.InspectionProfileImpl; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.JDOMUtil; -import com.intellij.profile.codeInspection.InspectionProjectProfileManager; -import com.intellij.testFramework.LightIdeaTestCase; -import com.intellij.testFramework.PlatformTestUtil; -import org.jdom.Element; - -import java.io.File; - -/** - * @author anna - * Date: 13-Apr-2009 - */ -public class InspectionProfilesConverterTest extends LightIdeaTestCase { - public void testOptions() throws Exception { - doTest("options"); - } - - public void testScope() throws Exception { - doTest("scope"); - } - - private static void doTest(final String dirName) throws Exception { - InspectionProfileImpl.INIT_INSPECTIONS = true; - try { - final String relativePath = "/inspection/converter/"; - final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr"); - for (Element element : JDOMUtil.load(projectFile).getChildren("component")) { - if (Comparing.strEqual(element.getAttributeValue("name"), "InspectionProjectProfileManager")) { - final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject()); - profileManager.loadState(element); - - Element configElement = profileManager.getState(); - final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml"); - PlatformTestUtil.assertElementsEqual(JDOMUtil.load(file), configElement); - break; - } - } - } - finally { - InspectionProfileImpl.INIT_INSPECTIONS = false; - } - } -} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java index d350cbb28ecd..87f0012eaeba 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/OfflineInspectionResultViewTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import com.intellij.util.ui.tree.TreeUtil; import com.siyeh.ig.bugs.EqualsWithItselfInspection; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -71,8 +72,8 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { final InspectionProfileImpl profile = new InspectionProfileImpl("test") { @Override - public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) { - return Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME); + public boolean isToolEnabled(@Nullable final HighlightDisplayKey key, PsiElement element) { + return key != null && Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME); } @Override @@ -83,7 +84,7 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { @Override @NotNull - public ModifiableModel getModifiableModel() { + public InspectionProfileImpl getModifiableModel() { return new InspectionProfileImpl("test") { @Override @NotNull @@ -92,8 +93,8 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { } @Override - public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) { - return Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME); + public boolean isToolEnabled(@Nullable HighlightDisplayKey key, PsiElement element) { + return key != null && Comparing.strEqual(key.toString(), DefUseInspectionBase.SHORT_NAME); } }; } @@ -113,7 +114,7 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { private Map>> parse() throws IOException { final String moduleName = getModule().getName(); - final Map>> map = new HashMap>>(); + final Map>> map = new HashMap<>(); final File res = new File(PathManagerEx.getTestDataPath(), getTestPath() + File.separator + "res"); final File[] files = res.listFiles(); assert files != null; @@ -133,11 +134,15 @@ public class OfflineInspectionResultViewTest extends TestSourceBasedTestCase { @Override protected void tearDown() throws Exception { - Disposer.dispose(myView); - myView = null; - myUnusedToolWrapper = null; - myDataFlowToolWrapper = null; - super.tearDown(); + try { + Disposer.dispose(myView); + myView = null; + myUnusedToolWrapper = null; + myDataFlowToolWrapper = null; + } + finally { + super.tearDown(); + } } public void testOfflineWithInvalid() throws Exception { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java deleted file mode 100644 index f1ebda035c50..000000000000 --- a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInspection; - -import com.intellij.codeInspection.ex.InspectionProfileImpl; -import com.intellij.codeInspection.ex.InspectionProfileTest; -import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; -import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; -import com.intellij.profile.codeInspection.InspectionProjectProfileManager; -import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel; -import com.intellij.testFramework.LightIdeaTestCase; -import org.jetbrains.annotations.NotNull; - -/** - * @author Dmitry Avdeev - * Date: 5/10/12 - */ -public class SingleInspectionProfilePanelTest extends LightIdeaTestCase { - // see IDEA-85700 - public void testSettingsModification() throws Exception { - Project project = ProjectManager.getInstance().getDefaultProject(); - InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); - InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE); - profile.initInspectionTools(project); - - InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel(); - SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(profileManager, PROFILE, model, profile); - panel.setVisible(true); - panel.reset(); - - JavaDocLocalInspection tool = getInspection(model); - assertEquals("", tool.myAdditionalJavadocTags); - tool.myAdditionalJavadocTags = "foo"; - model.setModified(true); - panel.apply(); - assertEquals(1, InspectionProfileTest.countInitializedTools(model)); - - assertEquals("foo", getInspection(profile).myAdditionalJavadocTags); - panel.disposeUI(); - } - - public void testModifyInstantiatedTool() throws Exception { - Project project = ProjectManager.getInstance().getDefaultProject(); - InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); - InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE); - profile.initInspectionTools(project); - - JavaDocLocalInspection originalTool = getInspection(profile); - originalTool.myAdditionalJavadocTags = "foo"; - - InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel(); - - SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(profileManager, PROFILE, model, profile); - panel.setVisible(true); - panel.reset(); - assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1, InspectionProfileTest.countInitializedTools(model)); - - JavaDocLocalInspection copyTool = getInspection(model); - copyTool.myAdditionalJavadocTags = "bar"; - - model.setModified(true); - panel.apply(); - assertEquals(1, InspectionProfileTest.countInitializedTools(model)); - - assertEquals("bar", getInspection(profile).myAdditionalJavadocTags); - panel.disposeUI(); - } - - public void testDoNotChangeSettingsOnCancel() throws Exception { - Project project = ProjectManager.getInstance().getDefaultProject(); - InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(project); - InspectionProfileImpl profile = (InspectionProfileImpl)profileManager.getProfile(PROFILE); - profile.initInspectionTools(project); - - JavaDocLocalInspection originalTool = getInspection(profile); - assertEquals("", originalTool.myAdditionalJavadocTags); - - InspectionProfileImpl model = (InspectionProfileImpl)profile.getModifiableModel(); - JavaDocLocalInspection copyTool = getInspection(model); - copyTool.myAdditionalJavadocTags = "foo"; - // this change IS NOT COMMITTED - - assertEquals("", getInspection(profile).myAdditionalJavadocTags); - } - - private JavaDocLocalInspection getInspection(InspectionProfileImpl profile) { - LocalInspectionToolWrapper original = (LocalInspectionToolWrapper)profile.getInspectionTool(myInspection.getShortName(), getProject()); - assert original != null; - return (JavaDocLocalInspection)original.getTool(); - } - - @Override - public void setUp() throws Exception { - InspectionProfileImpl.INIT_INSPECTIONS = true; - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - InspectionProfileImpl.INIT_INSPECTIONS = false; - super.tearDown(); - } - - private final JavaDocLocalInspection myInspection = new JavaDocLocalInspection(); - - @NotNull - @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[] {myInspection}; - } -} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt new file mode 100644 index 000000000000..5471f2a1d872 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInspection/SingleInspectionProfilePanelTest.kt @@ -0,0 +1,115 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection + +import com.intellij.codeInspection.ex.InspectionProfileImpl +import com.intellij.codeInspection.ex.InspectionProfileTest +import com.intellij.codeInspection.ex.LocalInspectionToolWrapper +import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection +import com.intellij.openapi.project.ProjectManager +import com.intellij.profile.codeInspection.ProjectInspectionProfileManager +import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.configureInspections +import com.intellij.testFramework.createProfile +import junit.framework.TestCase +import org.assertj.core.api.Assertions.assertThat + +class SingleInspectionProfilePanelTest : LightIdeaTestCase() { + private val myInspection = JavaDocLocalInspection() + + // see IDEA-85700 + fun testSettingsModification() { + val project = ProjectManager.getInstance().defaultProject + val profile = configureInspections(arrayOf(myInspection), project, testRootDisposable) + + val model = profile.modifiableModel + val panel = SingleInspectionProfilePanel(ProjectInspectionProfileManager.getInstanceImpl(project), profile.name, model, profile) + panel.isVisible = true + panel.reset() + + val tool = getInspection(model) + assertEquals("", tool.myAdditionalJavadocTags) + tool.myAdditionalJavadocTags = "foo" + model.setModified(true) + panel.apply() + assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1) + + assertThat(getInspection(profile).myAdditionalJavadocTags).isEqualTo("foo") + panel.disposeUI() + } + + fun testModifyInstantiatedTool() { + val project = ProjectManager.getInstance().defaultProject + val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project) + val profile = profileManager.createProfile(myInspection, testRootDisposable) + profile.initInspectionTools(project) + + val originalTool = getInspection(profile) + originalTool.myAdditionalJavadocTags = "foo" + + val model = profile.modifiableModel + + val panel = SingleInspectionProfilePanel(profileManager, profile.name, model, profile) + panel.isVisible = true + panel.reset() + TestCase.assertEquals(InspectionProfileTest.getInitializedTools(model).toString(), 1, + InspectionProfileTest.countInitializedTools(model)) + + val copyTool = getInspection(model) + copyTool.myAdditionalJavadocTags = "bar" + + model.setModified(true) + panel.apply() + assertThat(InspectionProfileTest.countInitializedTools(model)).isEqualTo(1) + + assertEquals("bar", getInspection(profile).myAdditionalJavadocTags) + panel.disposeUI() + } + + fun testDoNotChangeSettingsOnCancel() { + val project = ProjectManager.getInstance().defaultProject + val profileManager = ProjectInspectionProfileManager.getInstanceImpl(project) + val profile = profileManager.createProfile(myInspection, testRootDisposable) + profile.initInspectionTools(project) + + val originalTool = getInspection(profile) + assertThat(originalTool.myAdditionalJavadocTags).isEmpty() + + val model = profile.modifiableModel + val copyTool = getInspection(model) + copyTool.myAdditionalJavadocTags = "foo" + // this change IS NOT COMMITTED + + assertEquals("", getInspection(profile).myAdditionalJavadocTags) + } + + private fun getInspection(profile: InspectionProfileImpl): JavaDocLocalInspection { + return (profile.getInspectionTool(myInspection.shortName, getProject()) as LocalInspectionToolWrapper?)!!.tool as JavaDocLocalInspection + } + + override fun setUp() { + InspectionProfileImpl.INIT_INSPECTIONS = true + super.setUp() + } + + override fun tearDown() { + InspectionProfileImpl.INIT_INSPECTIONS = false + super.tearDown() + } + + override fun configureLocalInspectionTools() = arrayOf(myInspection) +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java index f3ee0565b991..d538376f91c2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java @@ -28,17 +28,22 @@ import com.intellij.openapi.util.WriteExternalException; import com.intellij.profile.Profile; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; +import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; import com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable; import com.intellij.psi.PsiModifier; import com.intellij.testFramework.LightIdeaTestCase; +import com.intellij.util.JdomKt; +import com.intellij.util.SmartList; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import static com.intellij.profile.ProfileEx.serializeProfile; import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual; /** @@ -58,10 +63,15 @@ public class InspectionProfileTest extends LightIdeaTestCase { @Override protected void tearDown() throws Exception { - super.tearDown(); - //noinspection AssignmentToStaticFieldFromInstanceMethod - InspectionProfileImpl.INIT_INSPECTIONS = false; - InspectionProfileManager.getInstance().deleteProfile(PROFILE); + try { + //noinspection SuperTearDownInFinally + super.tearDown(); + } + finally { + //noinspection AssignmentToStaticFieldFromInstanceMethod + InspectionProfileImpl.INIT_INSPECTIONS = false; + InspectionProfileManager.getInstance().deleteProfile(PROFILE); + } } public void testCopyProjectProfile() throws Exception { @@ -70,16 +80,14 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); - final Element copy = new Element("inspections"); - profile.writeExternal(copy); - assertElementsEqual(element, copy); + assertElementsEqual(element, serializeProfile(profile)); } private static InspectionProfileImpl createProfile() { - return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile()); + return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), InspectionProfileImpl.getDefaultProfile(), null); } private static InspectionProfileImpl createProfile(@NotNull InspectionProfileImpl base) { - return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), base); + return new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), InspectionProfileManager.getInstance(), base, null); } public void testSameNameSharedProfile() throws Exception { @@ -87,16 +95,16 @@ public class InspectionProfileTest extends LightIdeaTestCase { InspectionProfileImpl localProfile = createProfile(); profileManager.updateProfile(localProfile); - InspectionProjectProfileManager projectProfileManager = InspectionProjectProfileManager.getInstance(getProject()); + ProjectInspectionProfileManager projectProfileManager = ProjectInspectionProfileManager.getInstanceImpl(getProject()); try { //normally on open project profile wrappers are init for both managers profileManager.updateProfile(localProfile); InspectionProfileImpl profile = new InspectionProfileImpl(PROFILE, InspectionToolRegistrar.getInstance(), projectProfileManager, - InspectionProfileImpl.getDefaultProfile()); + InspectionProfileImpl.getDefaultProfile(), null); projectProfileManager.updateProfile(profile); - projectProfileManager.setProjectProfile(profile.getName()); + projectProfileManager.setRootProfile(profile.getName()); - assertTrue(projectProfileManager.getInspectionProfile() == profile); + assertTrue(projectProfileManager.getCurrentProfile() == profile); } finally { projectProfileManager.deleteProfile(PROFILE); @@ -142,49 +150,47 @@ public class InspectionProfileTest extends LightIdeaTestCase { ModifiableModel model = profile.getModifiableModel(); model.commit(); - Element copy = new Element("inspections"); - profile.writeExternal(copy); - assertElementsEqual(loadProfile(), copy); + assertElementsEqual(loadProfile(), serializeProfile(profile)); } private static Element loadProfile() throws IOException, JDOMException { - return JDOMUtil.loadDocument("\n" + - " ").getRootElement(); + return JdomKt.loadElement("\n" + + " "); } public void testReloadProfileWithUnknownScopes() throws Exception { - final Element element = JDOMUtil.loadDocument("\n" + + final Element element = JdomKt.loadElement("\n" + " ").getRootElement(); + ""); final InspectionProfileImpl profile = createProfile(); profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); - final Element copy = new Element("inspections"); - profile.writeExternal(copy); - assertElementsEqual(element, copy); + assertElementsEqual(element, serializeProfile(profile)); } public void testMergeUnusedDeclarationAndUnusedSymbol() throws Exception { //no specific settings - final Element element = JDOMUtil.loadDocument("\n" + + final Element element = JdomKt.loadElement("\n" + " ").getRootElement(); + ""); InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo")); profile.readExternal(element); ModifiableModel model = profile.getModifiableModel(); model.commit(); - final Element copy = new Element("inspections"); - profile.writeExternal(copy); - assertElementsEqual(element, copy); + assertElementsEqual(element, serializeProfile(profile)); //settings to merge - final Element unusedProfile = JDOMUtil.loadDocument("\n" + + final Element unusedProfile = JdomKt.loadElement("\n" + " ").getRootElement(); + ""); profile.readExternal(unusedProfile); model = profile.getModifiableModel(); model.commit(); @@ -288,8 +290,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { ""; assertEquals(mergedText, serialize(profile)); - Element toImportElement = new Element("profile"); - profile.writeExternal(toImportElement); + Element toImportElement = serializeProfile(profile); final InspectionProfileImpl importedProfile = InspectionToolsConfigurable.importInspectionProfile(toImportElement, InspectionProfileManager.getInstance(), getProject(), null); @@ -299,13 +300,9 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(mergedElement); model = profile.getModifiableModel(); model.commit(); - Element copyMerged = new Element("profile"); - profile.writeExternal(copyMerged); - assertElementsEqual(mergedElement, copyMerged); + assertElementsEqual(mergedElement, serializeProfile(profile)); - Element imported = new Element("profile"); - importedProfile.writeExternal(imported); - assertElementsEqual(mergedElement, imported); + assertElementsEqual(mergedElement, serializeProfile(importedProfile)); } public void testStoredMemberVisibility() throws Exception { @@ -324,7 +321,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { "