From e31b78ec6dbc92787d20961142855174d4d5ff1f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 16 Aug 2010 12:40:04 +0400 Subject: [PATCH] minimize LIP constructor count, simplify --- .../daemon/impl/LocalInspectionsPass.java | 26 +++--------- .../impl/LocalInspectionsPassFactory.java | 4 +- .../ex/InspectionProfileWrapper.java | 6 +++ .../ex/InspectionProfileWrapperProvider.java | 42 ------------------- .../InspectionProjectProfileManager.java | 2 +- .../openapi/vcs/ui/CommitMessage.java | 19 ++++----- 6 files changed, 22 insertions(+), 77 deletions(-) delete mode 100644 platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapperProvider.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index 7e9bc98562d1..b236ddca9314 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -80,16 +80,10 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass static final Icon IN_PROGRESS_ICON = IconLoader.getIcon("/general/inspectionInProgress.png"); private final String myShortcutText; private final SeverityRegistrar mySeverityRegistrar; - private final InspectionProfileWrapperProvider myProfileWrapperProvider; + private final InspectionProfileWrapper myProfileWrapper; private boolean myFailFastOnAcquireReadAction; public LocalInspectionsPass(@NotNull PsiFile file, @Nullable Document document, int startOffset, int endOffset) { - this(file, document, startOffset, endOffset, null); - } - - public LocalInspectionsPass(@NotNull PsiFile file, @Nullable Document document, int startOffset, int endOffset, - @Nullable InspectionProfileWrapperProvider profileProvider) - { super(file.getProject(), document, IN_PROGRESS_ICON, PRESENTABLE_NAME, file, true); myStartOffset = startOffset; myEndOffset = endOffset; @@ -104,18 +98,8 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass myShortcutText = ""; } mySeverityRegistrar = SeverityRegistrar.getInstance(myProject); - if (profileProvider == null) { - myProfileWrapperProvider = new InspectionProfileWrapperProvider() { - @NotNull - @Override - public InspectionProfileWrapper getWrapper() { - return InspectionProjectProfileManager.getInstance(myProject).getProfileWrapper(); - } - }; - } - else { - myProfileWrapperProvider = profileProvider; - } + InspectionProfileWrapper customProfile = file.getUserData(InspectionProfileWrapper.KEY); + myProfileWrapper = customProfile == null ? InspectionProjectProfileManager.getInstance(myProject).getProfileWrapper() : customProfile; } protected void collectInformationWithProgress(final ProgressIndicator progress) { @@ -124,7 +108,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass myTools = new ArrayList(); if (!HighlightLevelUtil.shouldInspect(myFile)) return; final InspectionManagerEx iManager = (InspectionManagerEx)InspectionManager.getInstance(myProject); - final InspectionProfileWrapper profile = myProfileWrapperProvider.getWrapper(); + final InspectionProfileWrapper profile = myProfileWrapper; final List tools = DumbService.getInstance(myProject).filterByDumbAwareness(getInspectionTools(profile)); inspect(tools, iManager, true, true, true); @@ -402,7 +386,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass @NonNls String message = ProblemDescriptionNode.renderDescriptionMessage(descriptor); final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName()); - final InspectionProfile inspectionProfile = myProfileWrapperProvider.getWrapper().getInspectionProfile(); + final InspectionProfile inspectionProfile = myProfileWrapper.getInspectionProfile(); if (!inspectionProfile.isToolEnabled(key, myFile)) return null; HighlightInfoType type = new HighlightInfoType.HighlightInfoTypeImpl(level.getSeverity(psiElement), level.getAttributesKey()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java index dc7e1686be67..799f3eb739be 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPassFactory.java @@ -22,7 +22,6 @@ import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory; import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.ex.InspectionProfileWrapper; -import com.intellij.codeInspection.ex.InspectionProfileWrapperProvider; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -55,8 +54,7 @@ public class LocalInspectionsPassFactory extends AbstractProjectComponent implem TextRange textRange = calculateRangeToProcess(editor); if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(myProject, editor.getDocument(), LocalInspectionsPass.IN_PROGRESS_ICON, LocalInspectionsPass.PRESENTABLE_NAME); - InspectionProfileWrapperProvider provider = editor.getUserData(InspectionProfileWrapperProvider.KEY); - return new LocalInspectionsPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), provider) { + return new LocalInspectionsPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset()) { List getInspectionTools(InspectionProfileWrapper profile) { List tools = super.getInspectionTools(profile); List result = new ArrayList(tools.size()); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java index d74b2e127ad0..53c39ff8d3e7 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapper.java @@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.psi.PsiElement; import java.util.ArrayList; @@ -30,6 +31,11 @@ import java.util.List; * Date: 15-Feb-2006 */ public class InspectionProfileWrapper { + /** + * Generic-purpose key object that is intended to be used for customizing inspection profile wrapper retrieval + * via {@link com.intellij.openapi.util.UserDataHolder} API. + */ + public static final Key KEY = Key.create("Inspection Profile Wrapper"); private final InspectionProfileImpl myProfile; public InspectionProfileWrapper(final InspectionProfile profile) { diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapperProvider.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapperProvider.java deleted file mode 100644 index 63ef21d54693..000000000000 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileWrapperProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2000-2010 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.openapi.actionSystem.DataKey; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolder; -import org.jetbrains.annotations.NotNull; - -/** - * Defines contract for retrieving {@link InspectionProfileWrapper} objects. - * - * @author Denis Zhdanov - * @since Aug 13, 2010 10:26:33 AM - */ -public interface InspectionProfileWrapperProvider { - - /** - * Generic-purpose key object that is intended to be used for customizing inspection profile wrapper retrieval - * via {@link UserDataHolder} API. - */ - Key KEY = Key.create(InspectionProfileWrapperProvider.class.getName()); - - /** - * @return managed inspection profile wrapper - */ - @NotNull - InspectionProfileWrapper getWrapper(); -} diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java index 6ee071f2a6e3..b414c83073c5 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManager.java @@ -38,7 +38,6 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -109,6 +108,7 @@ public class InspectionProjectProfileManager extends DefaultProjectProfileManage return getInspectionProfile(); } + @NotNull public InspectionProfileWrapper getProfileWrapper(){ final InspectionProfile profile = getInspectionProfile(); final String profileName = profile.getName(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java index 2288bed70cf6..a0f74afaba82 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java @@ -32,7 +32,9 @@ import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.fileTypes.FileTypes; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.ui.EditorTextField; import com.intellij.ui.LanguageTextField; import com.intellij.ui.SeparatorFactory; @@ -89,11 +91,11 @@ public class CommitMessage extends JPanel implements Disposable { * Hence, we define custom profile that is used during highlighting of commit area editor. */ @Nullable - private static final InspectionProfileWrapperProvider INSPECTION_PROFILE_WRAPPER_PROVIDER = initProvider(); + private static final InspectionProfileWrapper INSPECTION_PROFILE_WRAPPER_PROVIDER = initProvider(); @SuppressWarnings("unchecked") @Nullable - private static InspectionProfileWrapperProvider initProvider() { + private static InspectionProfileWrapper initProvider() { // We don't want to add explicit dependency to 'spellchecker' module, hence, use reflection for instantiating // target inspection object. It's assumed that its default settings are just fine for processing commit dialog editor. // Please perform corresponding settings tuning if that assumption is broken at future. @@ -152,13 +154,7 @@ public class CommitMessage extends JPanel implements Disposable { } }; - return new InspectionProfileWrapperProvider() { - @NotNull - @Override - public InspectionProfileWrapper getWrapper() { - return profileWrapper; - } - }; + return profileWrapper; } private final EditorTextField myEditorField; @@ -197,7 +193,10 @@ public class CommitMessage extends JPanel implements Disposable { settings.setUseSoftWraps(true); settings.setAdditionalColumnsCount(0); if (INSPECTION_PROFILE_WRAPPER_PROVIDER != null) { - ex.putUserData(InspectionProfileWrapperProvider.KEY, INSPECTION_PROFILE_WRAPPER_PROVIDER); + PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(getDocument()); + if (file != null) { + file.putUserData(InspectionProfileWrapper.KEY, INSPECTION_PROFILE_WRAPPER_PROVIDER); + } } ex.putUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY, false); return ex;