From aae0232446981fdac4b00b258b60637a91946dda Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 26 Jul 2011 13:36:29 +0400 Subject: [PATCH] like unused symbol: use psi element to determine profile to get severity from (IDEA-72411) like unused symbol: can be error in editor --- .../ErrorLikeUnusedSymbol.java | 5 +++ .../daemon/HighlightSeverityTest.java | 44 +++++++++++++++++++ .../daemon/impl/HighlightInfo.java | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/highlightSeverity/ErrorLikeUnusedSymbol.java create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/highlightSeverity/ErrorLikeUnusedSymbol.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/highlightSeverity/ErrorLikeUnusedSymbol.java new file mode 100644 index 000000000000..80639b651be4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/highlightSeverity/ErrorLikeUnusedSymbol.java @@ -0,0 +1,5 @@ +public class Test { + public static void main(String[] args) { + int k = 0; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java new file mode 100644 index 000000000000..383d9a15fa91 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/HighlightSeverityTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2011 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.codeInsight.daemon; + +import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class HighlightSeverityTest extends LightDaemonAnalyzerTestCase { + @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/highlightSeverity"; + + @Override + protected LocalInspectionTool[] configureLocalInspectionTools() { + return new LocalInspectionTool[]{ + new UnusedSymbolLocalInspection() { + @NotNull + @Override + public HighlightDisplayLevel getDefaultLevel() { + return HighlightDisplayLevel.ERROR; + } + } + }; + } + + + public void testErrorLikeUnusedSymbol() throws Exception { + doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java index 31ed3138b919..712d8cc2e53a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfo.java @@ -164,7 +164,7 @@ public class HighlightInfo implements Segment { boolean isEndOfLine, TextAttributes forcedAttributes) { LOG.assertTrue(ArrayUtil.find(HighlightSeverity.DEFAULT_SEVERITIES, type.getSeverity(element)) != -1 || element != null, "Custom type demands element to detect text attributes"); - HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, type, start, end, description, toolTip, type.getSeverity(null), isEndOfLine, null, false); + HighlightInfo highlightInfo = new HighlightInfo(forcedAttributes, type, start, end, description, toolTip, type.getSeverity(element), isEndOfLine, null, false); PsiFile file = element == null ? null : element.getContainingFile(); for (HighlightInfoFilter filter : getFilters()) { if (!filter.accept(highlightInfo, file)) {