[reassigned variable] completely convert to an inspection; severity which doesn't appear in problems

and gutter or file status, to fully mimic existing behaviour

GitOrigin-RevId: 24bcdbc058e64a79d543737169a649a8cd3fdc89
This commit is contained in:
Anna Kozlova
2022-05-04 21:58:51 +02:00
committed by intellij-monorepo-bot
parent 0fb4828c67
commit 479a793bb4
16 changed files with 125 additions and 212 deletions

View File

@@ -51,8 +51,8 @@
implementationClass="org.jetbrains.java.generate.inspection.FieldNotUsedInToStringInspection"
key="inspection.field.not.used.in.to.string.display.name" bundle="messages.JavaAnalysisBundle"/>
<localInspection groupPath="Java" language="JAVA" shortName="ReassignedVariable" groupKey="group.names.code.style.issues" groupBundle="messages.InspectionsBundle"
enabledByDefault="true" level="INFORMATION"
implementationClass="com.intellij.codeInspection.ReassignedVariableInspection" unfair="true"
enabledByDefault="true" level="TEXT ATTRIBUTES"
implementationClass="com.intellij.codeInspection.ReassignedVariableInspection"
editorAttributes="REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES"
key="reassign.variable.display.name" bundle="messages.JavaAnalysisBundle" />
<!--suppress PluginXmlCapitalization -->

View File

@@ -3,30 +3,20 @@ package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.application.options.colors.ScopeAttributesUtil;
import com.intellij.codeHighlighting.RainbowHighlighter;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.JavaHighlightInfoTypes;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
import com.intellij.codeInsight.intention.EmptyIntentionAction;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ReassignedVariableInspection;
import com.intellij.codeInspection.SuppressionUtil;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.ide.highlighter.JavaHighlightingColors;
import com.intellij.java.JavaBundle;
import com.intellij.lang.ASTNode;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.TextAttributesScheme;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.packageDependencies.DependencyValidationManagerImpl;
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.impl.source.tree.TreeUtil;
@@ -39,7 +29,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public final class HighlightNamesUtil {
private static final Logger LOG = Logger.getInstance(HighlightNamesUtil.class);
@@ -248,48 +237,6 @@ public final class HighlightNamesUtil {
return JavaHighlightInfoTypes.CLASS_NAME;
}
@Nullable
static HighlightInfo highlightReassignedVariable(@NotNull PsiVariable variable, @NotNull PsiElement elementToHighlight,
HighlightInfoType.HighlightInfoTypeImpl highlightInfoType,
InspectionProfileEntry reassignVariableTool) {
if (variable instanceof PsiLocalVariable) {
return createReassignedInfo(elementToHighlight,
highlightInfoType,
reassignVariableTool,
JavaBundle.message("tooltip.reassigned.local.variable"));
}
if (variable instanceof PsiParameter) {
return createReassignedInfo(elementToHighlight,
highlightInfoType,
reassignVariableTool, JavaBundle.message("tooltip.reassigned.parameter"));
}
return null;
}
@Nullable
private static HighlightInfo createReassignedInfo(@NotNull PsiElement elementToHighlight,
@NotNull HighlightInfoType highlightInfoType,
InspectionProfileEntry reassignVariableTool, @NotNull @NlsContexts.Tooltip String toolTip) {
HighlightDisplayKey key = HighlightDisplayKey.find(ReassignedVariableInspection.SHORT_NAME);
if (reassignVariableTool != null && SuppressionUtil.inspectionResultSuppressed(elementToHighlight, reassignVariableTool)) {
return null;
}
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(highlightInfoType).range(elementToHighlight);
InspectionProfileImpl profile = ProjectInspectionProfileManager.getInstance(elementToHighlight.getProject()).getCurrentProfile();
TextAttributesKey attributesKey = profile.getEditorAttributes(key.toString(), elementToHighlight);
if (attributesKey == null) {
attributesKey = highlightInfoType.getAttributesKey();
}
HighlightInfo highlightInfo = builder.descriptionAndTooltip(toolTip).textAttributes(attributesKey).create();
if (highlightInfo != null) {
QuickFixAction.registerQuickFixAction(highlightInfo, null,
new EmptyIntentionAction(Objects.requireNonNull(HighlightDisplayKey.getDisplayNameByKey(key))), key);
}
return highlightInfo;
}
private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme) {
PsiFile file = element.getContainingFile();
if (file == null) return null;

View File

@@ -1,35 +1,19 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.HighlightVisitor;
import com.intellij.codeInsight.daemon.impl.JavaHighlightInfoTypes;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ReassignedVariableInspection;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.codeInspection.ex.InspectionProfileWrapper;
import com.intellij.ide.highlighter.JavaHighlightingColors;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.editor.colors.TextAttributesScheme;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
// java highlighting: color names like "reassigned variables"/fields/statics etc.
// NO COMPILATION ERRORS
// for highlighting error see HighlightVisitorImpl
@@ -37,17 +21,6 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
private HighlightInfoHolder myHolder;
private PsiFile myFile;
// map codeBlock->List of PsiReferenceExpression of extra initialization of final variable
private final Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> myFinalVarProblems = new HashMap<>();
private HighlightInfoType.HighlightInfoTypeImpl myHighlightInfoType;
private InspectionProfileEntry myReassignVariableTool;
private enum ReassignedState {
DUNNO, INSIDE_FILE, REASSIGNED
}
private final Map<PsiParameter, ReassignedState> myReassignedParameters = new HashMap<>();
@NotNull
@Override
@SuppressWarnings("MethodDoesntCallSuperMethod")
@@ -73,8 +46,6 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
highlight.run();
}
finally {
myFinalVarProblems.clear();
myReassignedParameters.clear();
myFile = null;
myHolder = null;
}
@@ -85,18 +56,6 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
private void prepare(@NotNull HighlightInfoHolder holder, @NotNull PsiFile file) {
myHolder = holder;
myFile = file;
Function<? super InspectionProfile, ? extends InspectionProfileWrapper> custom = InspectionProfileWrapper.getCustomInspectionProfileWrapper(myFile);
InspectionProfileImpl currentProfile = InspectionProjectProfileManager.getInstance(holder.getProject()).getCurrentProfile();
InspectionProfile profile = custom != null ? custom.apply(currentProfile).getInspectionProfile() : currentProfile;
myReassignVariableTool = profile.getUnwrappedTool(ReassignedVariableInspection.SHORT_NAME, file);
HighlightDisplayKey reassignedKey = HighlightDisplayKey.find(ReassignedVariableInspection.SHORT_NAME);
if (profile.isToolEnabled(reassignedKey, myFile)) {
myHighlightInfoType = new HighlightInfoType.HighlightInfoTypeImpl(profile.getErrorLevel(reassignedKey, myFile).getSeverity(),
JavaHighlightingColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES);
}
}
@Override
@@ -130,20 +89,8 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
PsiElement child = variable.getLastChild();
if (child instanceof PsiErrorElement && child.getPrevSibling() == identifier) return;
}
boolean isMethodParameter = variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiMethod;
if (isMethodParameter) {
myReassignedParameters.put((PsiParameter)variable, ReassignedState.INSIDE_FILE); // mark param as present in current file
}
else {
// method params are highlighted in visitMethod since we should make sure the method body was visited before
if (myHighlightInfoType != null && HighlightControlFlowUtil.isReassigned(variable, myFinalVarProblems)) {
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, identifier, myHighlightInfoType, myReassignVariableTool));
}
else {
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme));
}
}
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme));
}
else if (parent instanceof PsiClass) {
PsiClass aClass = (PsiClass)parent;
@@ -195,29 +142,6 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
}
}
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
// method params are highlighted in visitMethod since we should make sure the method body was visited before
PsiParameter[] parameters = method.getParameterList().getParameters();
for (PsiParameter parameter : parameters) {
ReassignedState info = myReassignedParameters.getOrDefault(parameter, ReassignedState.DUNNO);
if (info == ReassignedState.DUNNO) continue; // out of this file
PsiIdentifier nameIdentifier = parameter.getNameIdentifier();
if (nameIdentifier != null) {
if (info == ReassignedState.REASSIGNED) { // reassigned
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, nameIdentifier, myHighlightInfoType, myReassignVariableTool));
}
else {
myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, nameIdentifier, myHolder.getColorsScheme()));
}
}
}
}
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement ref) {
doVisitReferenceElement(ref);
@@ -227,23 +151,6 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
doVisitReferenceElement(expression);
}
private boolean isReassigned(@NotNull PsiVariable variable) {
try {
boolean reassigned;
if (variable instanceof PsiParameter) {
reassigned = myReassignedParameters.get(variable) == ReassignedState.REASSIGNED;
}
else {
reassigned = HighlightControlFlowUtil.isReassigned(variable, myFinalVarProblems);
}
return reassigned;
}
catch (IndexNotReadyException e) {
return false;
}
}
private void doVisitReferenceElement(@NotNull PsiJavaCodeReferenceElement ref) {
JavaResolveResult result = HighlightVisitorImpl.resolveOptimised(ref, myFile);
if (result == null) return;
@@ -266,19 +173,10 @@ class JavaNamesHighlightVisitor extends JavaElementVisitor implements HighlightV
}
}
if (myHighlightInfoType != null && variable instanceof PsiParameter && ref instanceof PsiExpression && PsiUtil.isAccessedForWriting((PsiExpression)ref)) {
myReassignedParameters.put((PsiParameter)variable, ReassignedState.REASSIGNED);
}
TextAttributesScheme colorsScheme = myHolder.getColorsScheme();
if (myHighlightInfoType != null && !variable.hasModifierProperty(PsiModifier.FINAL) && isReassigned(variable)) {
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, ref, myHighlightInfoType, myReassignVariableTool));
}
else {
PsiElement nameElement = ref.getReferenceNameElement();
if (nameElement != null) {
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, nameElement, colorsScheme));
}
PsiElement nameElement = ref.getReferenceNameElement();
if (nameElement != null) {
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, nameElement, colorsScheme));
}
}
else {

View File

@@ -2,20 +2,37 @@
package com.intellij.codeInspection;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
import com.intellij.codeInspection.ex.PairedUnfairLocalInspectionTool;
import com.intellij.java.JavaBundle;
import com.intellij.openapi.util.Key;
import com.intellij.psi.*;
import com.intellij.psi.controlFlow.ControlFlowUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class ReassignedVariableInspection extends AbstractBaseJavaLocalInspectionTool {
private static final Key<Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>>> LOCAL_KEY = Key.create("LOCAL_REASSIGNS");
private static final Key<Map<PsiParameter, Boolean>> PARAMETER_KEY = Key.create("PARAMETER_REASSIGNS");
public class ReassignedVariableInspection extends AbstractBaseJavaLocalInspectionTool implements PairedUnfairLocalInspectionTool {
public static final String SHORT_NAME = getShortName(ReassignedVariableInspection.class.getSimpleName());
@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
if (isOnTheFly) {
return PsiElementVisitor.EMPTY_VISITOR;
}
public void inspectionFinished(@NotNull LocalInspectionToolSession session, @NotNull ProblemsHolder problemsHolder) {
session.putUserData(LOCAL_KEY, null);
session.putUserData(PARAMETER_KEY, null);
}
@Override
public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) {
session.putUserData(LOCAL_KEY, new HashMap<>());
session.putUserData(PARAMETER_KEY, new HashMap<>());
}
@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder,
boolean isOnTheFly,
@NotNull LocalInspectionToolSession session) {
return new JavaElementVisitor() {
@Override
public void visitLocalVariable(PsiLocalVariable variable) {
@@ -24,24 +41,53 @@ public class ReassignedVariableInspection extends AbstractBaseJavaLocalInspectio
@Override
public void visitParameter(PsiParameter parameter) {
doCheck(parameter);
session.getUserData(PARAMETER_KEY).put(parameter, doCheck(parameter));
}
private void doCheck(PsiVariable variable) {
if (!variable.hasModifierProperty(PsiModifier.FINAL) && HighlightControlFlowUtil.isReassigned(variable, new HashMap<>())) {
PsiIdentifier nameIdentifier = variable.getNameIdentifier();
if (nameIdentifier != null) {
String message = JavaBundle.message(
variable instanceof PsiLocalVariable ? "tooltip.reassigned.local.variable" : "tooltip.reassigned.parameter");
holder.registerProblem(nameIdentifier, message);
private boolean doCheck(PsiVariable variable) {
PsiIdentifier nameIdentifier = variable.getNameIdentifier();
if (nameIdentifier != null &&
!variable.hasModifierProperty(PsiModifier.FINAL) &&
HighlightControlFlowUtil.isReassigned(variable, session.getUserData(LOCAL_KEY))) {
holder.registerProblem(nameIdentifier, getReassignedMessage(variable));
return true;
}
return false;
}
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
if (!holder.isOnTheFly()) return;
PsiElement referenceNameElement = expression.getReferenceNameElement();
if (referenceNameElement != null) {
PsiElement resolve = expression.resolve();
if (resolve instanceof PsiVariable && !((PsiVariable)resolve).hasModifierProperty(PsiModifier.FINAL)) {
if (resolve instanceof PsiLocalVariable) {
if (HighlightControlFlowUtil.isReassigned((PsiVariable)resolve, session.getUserData(LOCAL_KEY))) {
holder.registerProblem(referenceNameElement, getReassignedMessage((PsiVariable)resolve));
}
}
else if (resolve instanceof PsiParameter) {
Map<PsiParameter, Boolean> assigned = session.getUserData(PARAMETER_KEY);
Boolean isAssigned = assigned.get(resolve);
if (isAssigned == null) {
isAssigned = HighlightControlFlowUtil.isAssigned((PsiParameter)resolve);
assigned.put((PsiParameter)resolve, isAssigned);
}
if (isAssigned) {
holder.registerProblem(referenceNameElement, getReassignedMessage((PsiVariable)resolve));
}
}
}
}
}
@NotNull
private String getReassignedMessage(PsiVariable variable) {
return JavaBundle.message(
variable instanceof PsiLocalVariable ? "tooltip.reassigned.local.variable" : "tooltip.reassigned.parameter");
}
};
}
@Override
public @NotNull String getInspectionForBatchShortName() {
return SHORT_NAME;
}
}

View File

@@ -54,11 +54,11 @@ class <symbolName descr="null" type="CLASS_NAME">NoCtrClass</symbolName> {
new <symbolName descr="null" type="CONSTRUCTOR_CALL">NoCtrClass</symbolName>();
}
void <symbolName descr="null" type="METHOD_DECLARATION">ff</symbolName>(int <warning descr="Reassigned parameter">param</warning>) {
int <warning descr="Reassigned local variable">i</warning> = 1;
<warning descr="Reassigned local variable">i</warning> ++;
void <symbolName descr="null">ff</symbolName>(int <symbolName descr="null"><symbolName descr="null">param</symbolName></symbolName>) {
int <symbolName descr="null">i</symbolName> = 1;
<symbolName descr="null">i</symbolName> ++;
<warning descr="Reassigned parameter">param</warning> = 0;
<symbolName descr="null">param</symbolName> = 0;
}
}

View File

@@ -8,9 +8,9 @@ class a {
int f;
JPanel fpanel;
void f(int <info descr="Reassigned parameter">i</info>) {
void f(int <text_attr descr="Reassigned parameter">i</text_attr>) {
<info descr="Reassigned parameter">i</info> = <info descr="Reassigned parameter"><warning descr="Variable 'i' is assigned to itself">i</warning></info>;
<text_attr descr="Reassigned parameter">i</text_attr> = <warning descr="Variable 'i' is assigned to itself"><text_attr descr="Reassigned parameter">i</text_attr></warning>;
}
void f2() {
@@ -19,14 +19,14 @@ class a {
f = <warning descr="Variable 'f' is assigned to itself">this.f</warning>;
}
void f3(Object <info descr="Reassigned parameter">o</info>) {
int <info descr="Reassigned local variable">i</info> = 0;
<info descr="Reassigned local variable">i</info> = <info descr="Reassigned local variable"><warning descr="Variable 'i' is assigned to itself">i</warning></info>;
<info descr="Reassigned local variable">i</info> = (int)<info descr="Reassigned local variable"><warning descr="Variable 'i' is assigned to itself">i</warning></info>;
<info descr="Reassigned parameter">o</info> = ((Object)(<info descr="Reassigned parameter"><warning descr="Variable 'o' is assigned to itself">o</warning></info>));
Object o1 = <info descr="Reassigned parameter">o</info> = ((Object)(<info descr="Reassigned parameter"><warning descr="Variable 'o' is assigned to itself">o</warning></info>));
void f3(Object <text_attr descr="Reassigned parameter">o</text_attr>) {
int <text_attr descr="Reassigned local variable">i</text_attr> = 0;
<text_attr descr="Reassigned local variable">i</text_attr> = <warning descr="Variable 'i' is assigned to itself"><text_attr descr="Reassigned local variable">i</text_attr></warning>;
<text_attr descr="Reassigned local variable">i</text_attr> = (int)<warning descr="Variable 'i' is assigned to itself"><text_attr descr="Reassigned local variable">i</text_attr></warning>;
<text_attr descr="Reassigned parameter">o</text_attr> = ((Object)(<warning descr="Variable 'o' is assigned to itself"><text_attr descr="Reassigned parameter">o</text_attr></warning>));
Object o1 = <text_attr descr="Reassigned parameter">o</text_attr> = ((Object)(<warning descr="Variable 'o' is assigned to itself"><text_attr descr="Reassigned parameter">o</text_attr></warning>));
System.out.println(o1);
<info descr="Reassigned parameter">o</info> = (double)<info descr="Reassigned parameter">o</info>;
<text_attr descr="Reassigned parameter">o</text_attr> = (double)<text_attr descr="Reassigned parameter">o</text_attr>;
}
void f4() {
fpanel.getSize().height = this.fpanel.getSize().height; // not silly. Are you sure you can bet getSize() has no side effects?
@@ -42,7 +42,7 @@ class a {
}
void m() {
double <info descr="Reassigned local variable">m</info> = 1.5;
<info descr="Reassigned local variable">m</info> = (double) (int) <info descr="Reassigned local variable">m</info>;
double <text_attr descr="Reassigned local variable">m</text_attr> = 1.5;
<text_attr descr="Reassigned local variable">m</text_attr> = (double) (int) <text_attr descr="Reassigned local variable">m</text_attr>;
}
}

View File

@@ -71,10 +71,10 @@ class PrivateClassTest {
class IncrementedAndRead{
private int ffff;
void foo(int <info descr="Reassigned parameter">p</info>) {
if (p == 0) return;
<info descr="Reassigned parameter">p</info> = ffff++;
if (<info descr="Reassigned parameter">p</info> == 0) foo(<info descr="Reassigned parameter">p</info>);
void foo(int <text_attr descr="Reassigned parameter">p</text_attr>) {
if (<text_attr descr="Reassigned parameter">p</text_attr> == 0) return;
<text_attr descr="Reassigned parameter">p</text_attr> = ffff++;
if (<text_attr descr="Reassigned parameter">p</text_attr> == 0) foo(<text_attr descr="Reassigned parameter">p</text_attr>);
}
}
}

View File

@@ -36,17 +36,17 @@ public class JavaSymbolHighlightingTest extends LightDaemonAnalyzerTestCase {
"class Test {\n" +
" void foo() {\n" +
" @SuppressWarnings(\"ReassignedVariable\") int x = 0;\n" +
" <info descr=\"Reassigned local variable\">x</info> = 1;\n" +
" <text_attr descr=\"Reassigned local variable\">x</text_attr> = 1;\n" +
" }\n" +
" \n" +
" String loop() {\n" +
" String <info descr=\"Reassigned local variable\">a</info>;\n" +
" String <text_attr descr=\"Reassigned local variable\">a</text_attr>;\n" +
"\n" +
" do {\n" +
" <info descr=\"Reassigned local variable\">a</info> = \"aaaa\";\n" +
" <text_attr descr=\"Reassigned local variable\">a</text_attr> = \"aaaa\";\n" +
" }\n" +
" while (<info descr=\"Reassigned local variable\">a</info>.equals(\"bbb\"));\n" +
" return <info descr=\"Reassigned local variable\">a</info>;\n" +
" while (<text_attr descr=\"Reassigned local variable\">a</text_attr>.equals(\"bbb\"));\n" +
" return <text_attr descr=\"Reassigned local variable\">a</text_attr>;\n" +
" }\n" +
"}");
doTestConfiguredFile(true, true, true, null);

View File

@@ -19,6 +19,10 @@ information.severity=information
information.severity.capitalized=Information
information.severity.count.message={0} information
text.attributes.severity=text attributes
text.attributes.severity.capitalized=Text Attributes
text.attributes.severity.count.message={0} text attributes
server.problem.severity=server problem
server.problem.severity.capitalized=Server Problem
server.problem.severity.count.message={0} {0, choice, 0#server problems|1#server problem|2#server problems}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeHighlighting;
import com.intellij.icons.AllIcons;
@@ -45,6 +45,9 @@ public class HighlightDisplayLevel {
private static final TextAttributesKey DO_NOT_SHOW_KEY = TextAttributesKey.createTextAttributesKey("DO_NOT_SHOW");
public static final HighlightDisplayLevel DO_NOT_SHOW = new HighlightDisplayLevel(HighlightSeverity.INFORMATION, EmptyIcon.ICON_0);
public static final HighlightDisplayLevel TEXT_ATTRIBUTES = new HighlightDisplayLevel(HighlightSeverity.TEXT_ATTRIBUTES, EmptyIcon.ICON_0);
/**
* @deprecated use {@link #WEAK_WARNING} instead
*/

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.annotation;
import com.intellij.BundleBase;
@@ -45,6 +45,15 @@ public final class HighlightSeverity implements Comparable<HighlightSeverity> {
InspectionsBundle.messagePointer("information.severity"),
InspectionsBundle.messagePointer("information.severity.capitalized"),
InspectionsBundle.messagePointer("information.severity.count.message"));
@SuppressWarnings("UnresolvedPropertyKey")
public static final HighlightSeverity TEXT_ATTRIBUTES =
new HighlightSeverity(
"TEXT ATTRIBUTES",
10,
InspectionsBundle.messagePointer("text.attributes.severity"),
InspectionsBundle.messagePointer("text.attributes.severity.capitalized"),
InspectionsBundle.messagePointer("text.attributes.severity.count.message"));
/**
* The severity level for errors or warnings obtained from server.

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.daemon.impl;
import com.intellij.analysis.AnalysisBundle;
@@ -36,6 +36,7 @@ public interface HighlightInfoType {
@Deprecated HighlightInfoType INFO = new HighlightInfoTypeImpl(HighlightSeverity.INFO, CodeInsightColors.INFO_ATTRIBUTES);
HighlightInfoType WEAK_WARNING = new HighlightInfoTypeImpl(HighlightSeverity.WEAK_WARNING, CodeInsightColors.WEAK_WARNING_ATTRIBUTES);
HighlightInfoType INFORMATION = new HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, CodeInsightColors.INFORMATION_ATTRIBUTES);
HighlightInfoType TEXT_ATTRIBUTES = new HighlightInfoTypeImpl(HighlightSeverity.TEXT_ATTRIBUTES, CodeInsightColors.INFORMATION_ATTRIBUTES);
HighlightInfoType WRONG_REF = new HighlightInfoTypeImpl(HighlightSeverity.ERROR, CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.daemon.impl;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
@@ -64,6 +64,7 @@ public final class SeverityRegistrar implements Comparator<HighlightSeverity>, M
map.put(HighlightSeverity.INFO.getName(), HighlightInfoType.INFO);
map.put(HighlightSeverity.WEAK_WARNING.getName(), HighlightInfoType.WEAK_WARNING);
map.put(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING.getName(), HighlightInfoType.GENERIC_WARNINGS_OR_ERRORS_FROM_SERVER);
map.put(HighlightDisplayLevel.TEXT_ATTRIBUTES.getName(), HighlightInfoType.TEXT_ATTRIBUTES);
map.put(HighlightDisplayLevel.DO_NOT_SHOW.getName(), HighlightInfoType.INFORMATION);
STANDARD_SEVERITIES = new ConcurrentHashMap<>(map);
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.testFramework;
import com.intellij.AbstractBundle;
@@ -59,6 +59,7 @@ public class ExpectedHighlightingData {
private static final String WARNING_MARKER = CodeInsightTestFixture.WARNING_MARKER;
private static final String WEAK_WARNING_MARKER = CodeInsightTestFixture.WEAK_WARNING_MARKER;
private static final String INFO_MARKER = CodeInsightTestFixture.INFO_MARKER;
private static final String TEXT_ATTRIBUTES_MARKER = CodeInsightTestFixture.TEXT_ATTRIBUTES_MARKER;
private static final String END_LINE_HIGHLIGHT_MARKER = CodeInsightTestFixture.END_LINE_HIGHLIGHT_MARKER;
private static final String END_LINE_WARNING_MARKER = CodeInsightTestFixture.END_LINE_WARNING_MARKER;
private static final String INJECT_MARKER = "inject";
@@ -128,6 +129,7 @@ public class ExpectedHighlightingData {
registerHighlightingType(HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.HIGHLIGHTED_REFERENCE_SEVERITY, false, false));
registerHighlightingType(INJECTED_SYNTAX_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SYNTAX_SEVERITY, false, false));
registerHighlightingType(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, false));
registerHighlightingType(TEXT_ATTRIBUTES_MARKER, new ExpectedHighlightingSet(HighlightSeverity.TEXT_ATTRIBUTES, false, false));
registerHighlightingType(SYMBOL_NAME_MARKER, new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false));
for (SeveritiesProvider provider : SeveritiesProvider.EP_NAME.getExtensionList()) {
for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) {
@@ -164,6 +166,7 @@ public class ExpectedHighlightingData {
public void checkInfos() {
registerHighlightingType(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true));
registerHighlightingType(TEXT_ATTRIBUTES_MARKER, new ExpectedHighlightingSet(HighlightSeverity.TEXT_ATTRIBUTES, false, true));
registerHighlightingType(INJECT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true));
registerHighlightingType(HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.HIGHLIGHTED_REFERENCE_SEVERITY, false, true));
}

View File

@@ -62,6 +62,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
String WARNING_MARKER = "warning";
String WEAK_WARNING_MARKER = "weak_warning";
String INFO_MARKER = "info";
String TEXT_ATTRIBUTES_MARKER = "text_attr";
String END_LINE_HIGHLIGHT_MARKER = "EOLError";
String END_LINE_WARNING_MARKER = "EOLWarning";

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.siyeh.ig.testFrameworks;
import com.intellij.codeInspection.ProblemDescriptor;