diff --git a/platform/lang-api/src/com/intellij/codeInspection/InspectionProfile.java b/platform/lang-api/src/com/intellij/codeInspection/InspectionProfile.java index 0ddf5937e5ab..07766bacc783 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/InspectionProfile.java +++ b/platform/lang-api/src/com/intellij/codeInspection/InspectionProfile.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.openapi.project.Project; import com.intellij.profile.Profile; import com.intellij.psi.PsiElement; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,15 +32,19 @@ import org.jetbrains.annotations.Nullable; public interface InspectionProfile extends Profile { HighlightDisplayLevel getErrorLevel(@NotNull HighlightDisplayKey inspectionToolKey, PsiElement element); - + + /** + * If you need to modify tool's settings, please use {@link #modifyProfile(com.intellij.util.Consumer)} + */ InspectionProfileEntry getInspectionTool(@NotNull String shortName, @NotNull PsiElement element); + @Nullable + InspectionProfileEntry getInspectionTool(@NotNull String shortName); + /** Returns (unwrapped) inspection */ InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element); - @Nullable - @Deprecated - InspectionProfileEntry getInspectionTool(@NotNull String shortName); + void modifyProfile(Consumer modelConsumer); /** * @param element context element @@ -50,6 +55,9 @@ public interface InspectionProfile extends Profile { void cleanup(Project project); + /** + * @see #modifyProfile(com.intellij.util.Consumer) + */ @NotNull ModifiableModel getModifiableModel(); diff --git a/platform/lang-api/src/com/intellij/codeInspection/ModifiableModel.java b/platform/lang-api/src/com/intellij/codeInspection/ModifiableModel.java index 01ee7fb3e68f..4780f4054cf0 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/ModifiableModel.java +++ b/platform/lang-api/src/com/intellij/codeInspection/ModifiableModel.java @@ -21,6 +21,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.profile.Profile; import com.intellij.psi.PsiElement; import com.intellij.psi.search.scope.packageSet.NamedScope; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -65,8 +66,14 @@ public interface ModifiableModel extends Profile { void resetToEmpty(); + /** + * @return {@link com.intellij.codeInspection.ex.InspectionToolWrapper} + * @see #getUnwrappedTool(String, com.intellij.psi.PsiElement) + */ InspectionProfileEntry getInspectionTool(String shortName, PsiElement element); + InspectionProfileEntry getUnwrappedTool(@NotNull String shortName, @NotNull PsiElement element); + InspectionProfileEntry[] getInspectionTools(PsiElement element); void copyFrom(InspectionProfile profile); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index b60b58736eb3..f07f264c0a3a 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -38,6 +38,7 @@ import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.SeverityProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.search.scope.packageSet.NamedScope; +import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.StringInterner; @@ -338,6 +339,18 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, return tool instanceof InspectionToolWrapper ? ((InspectionToolWrapper)tool).getTool() : tool; } + @Override + public void modifyProfile(Consumer modelConsumer) { + ModifiableModel model = getModifiableModel(); + modelConsumer.consume(model); + try { + model.commit(); + } + catch (IOException e) { + LOG.error(e); + } + } + @Override @Nullable public InspectionProfileEntry getInspectionTool(@NotNull String shortName) { @@ -812,6 +825,9 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, getTools(toolId).moveScope(idx, dir); } + /** + * @return null if it has no base profile + */ @Nullable private Map getDisplayLevelMap() { if (myBaseProfile == null) return null;