mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
cleanup HighlightDisplayKey
- remove all `final` keywords - rename `name` to `shortName` - add doc comments with links GitOrigin-RevId: 3f542f0b4e7b8699482f6841857eaf2020cb2b7b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7750d38f8d
commit
57b9c44e8f
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -14,22 +15,33 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.jetbrains.annotations.Nls.Capitalization.Sentence;
|
||||
|
||||
/**
|
||||
* HighlightDisplayKey is a unique identifier of an inspection.
|
||||
*/
|
||||
public final class HighlightDisplayKey {
|
||||
private static final Logger LOG = Logger.getInstance(HighlightDisplayKey.class);
|
||||
|
||||
private static final Map<String,HighlightDisplayKey> ourNameToKeyMap = new ConcurrentHashMap<>();
|
||||
private static final Map<String,HighlightDisplayKey> ourIdToKeyMap = new ConcurrentHashMap<>();
|
||||
private static final Map<String, HighlightDisplayKey> ourShortNameToKeyMap = new ConcurrentHashMap<>();
|
||||
private static final Map<String, HighlightDisplayKey> ourIdToKeyMap = new ConcurrentHashMap<>();
|
||||
private static final Map<HighlightDisplayKey, Computable<@Nls(capitalization = Sentence) String>> ourKeyToDisplayNameMap = new ConcurrentHashMap<>();
|
||||
private static final Map<HighlightDisplayKey, String> ourKeyToAlternativeIDMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final String myName;
|
||||
private final String myShortName;
|
||||
private final String myID;
|
||||
|
||||
public static @Nullable HighlightDisplayKey find(final @NonNls @NotNull String name) {
|
||||
return ourNameToKeyMap.get(name);
|
||||
/**
|
||||
* @return a HighlightDisplayKey for a given inspection by its {@link LocalInspectionTool#getShortName short name}
|
||||
* or {@code null} if the inspection is not registered.
|
||||
*/
|
||||
public static @Nullable HighlightDisplayKey find(@NonNls @NotNull String shortName) {
|
||||
return ourShortNameToKeyMap.get(shortName);
|
||||
}
|
||||
|
||||
public static @Nullable HighlightDisplayKey findById(final @NonNls @NotNull String id) {
|
||||
/**
|
||||
* @return a HighlightDisplayKey for a given inspection by its {@link LocalInspectionTool#getID() id}
|
||||
* or {@code null} if the inspection is not registered.
|
||||
*/
|
||||
public static @Nullable HighlightDisplayKey findById(@NonNls @NotNull String id) {
|
||||
HighlightDisplayKey key = ourIdToKeyMap.get(id);
|
||||
if (key != null) return key;
|
||||
key = find(id);
|
||||
@@ -38,32 +50,34 @@ public final class HighlightDisplayKey {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #register(String, Computable, String)
|
||||
* @deprecated Use {@link #register(String, Computable, String)} instead.
|
||||
* Storing a display name in the key as a String does not work for i18n purposes.
|
||||
*/
|
||||
public static @Nullable HighlightDisplayKey register(final @NonNls @NotNull String name,
|
||||
final @NotNull String displayName,
|
||||
final @NotNull @NonNls String id) {
|
||||
return register(name, new Computable.PredefinedValueComputable<>(displayName), id);
|
||||
@Deprecated
|
||||
public static @Nullable HighlightDisplayKey register(@NonNls @NotNull String shortName,
|
||||
@NotNull String displayName,
|
||||
@NotNull @NonNls String id) {
|
||||
return register(shortName, new Computable.PredefinedValueComputable<>(displayName), id);
|
||||
}
|
||||
|
||||
public static @Nullable HighlightDisplayKey register(final @NonNls @NotNull String name,
|
||||
final @NotNull Computable<@Nls(capitalization = Sentence) String> displayName,
|
||||
final @NotNull @NonNls String id) {
|
||||
final HighlightDisplayKey key = find(name);
|
||||
public static @Nullable HighlightDisplayKey register(@NonNls @NotNull String shortName,
|
||||
@NotNull Computable<@Nls(capitalization = Sentence) String> displayName,
|
||||
@NotNull @NonNls String id) {
|
||||
HighlightDisplayKey key = find(shortName);
|
||||
if (key != null) {
|
||||
LOG.error("Key with name '" + name + "' already registered with display name: " + getDisplayNameByKey(key));
|
||||
LOG.error("Key with shortName '" + shortName + "' already registered with display name: " + getDisplayNameByKey(key));
|
||||
return null;
|
||||
}
|
||||
HighlightDisplayKey highlightDisplayKey = new HighlightDisplayKey(name, id);
|
||||
HighlightDisplayKey highlightDisplayKey = new HighlightDisplayKey(shortName, id);
|
||||
ourKeyToDisplayNameMap.put(highlightDisplayKey, displayName);
|
||||
return highlightDisplayKey;
|
||||
}
|
||||
|
||||
public static @Nullable HighlightDisplayKey register(final @NonNls @NotNull String name,
|
||||
final @NotNull Computable<@Nls(capitalization = Sentence) String> displayName,
|
||||
final @NonNls @NotNull String id,
|
||||
final @NonNls @Nullable String alternativeID) {
|
||||
final HighlightDisplayKey key = register(name, displayName, id);
|
||||
public static @Nullable HighlightDisplayKey register(@NonNls @NotNull String shortName,
|
||||
@NotNull Computable<@Nls(capitalization = Sentence) String> displayName,
|
||||
@NonNls @NotNull String id,
|
||||
@NonNls @Nullable String alternativeID) {
|
||||
HighlightDisplayKey key = register(shortName, displayName, id);
|
||||
if (alternativeID != null) {
|
||||
ourKeyToAlternativeIDMap.put(key, alternativeID);
|
||||
}
|
||||
@@ -71,7 +85,7 @@ public final class HighlightDisplayKey {
|
||||
}
|
||||
|
||||
public static void unregister(@NotNull String shortName) {
|
||||
HighlightDisplayKey key = ourNameToKeyMap.remove(shortName);
|
||||
HighlightDisplayKey key = ourShortNameToKeyMap.remove(shortName);
|
||||
if (key != null) {
|
||||
ourIdToKeyMap.remove(key.myID);
|
||||
ourKeyToAlternativeIDMap.remove(key);
|
||||
@@ -79,17 +93,31 @@ public final class HighlightDisplayKey {
|
||||
}
|
||||
}
|
||||
|
||||
public static @NotNull HighlightDisplayKey findOrRegister(@NonNls @NotNull String name, final @Nls(capitalization = Sentence) @NotNull String displayName) {
|
||||
return findOrRegister(name, displayName, null);
|
||||
/**
|
||||
* @param shortName {@link LocalInspectionTool#getShortName()}
|
||||
* @param displayName {@link LocalInspectionTool#getDisplayName()}
|
||||
*
|
||||
* @return an already existing or a new key corresponding to the provided details
|
||||
*/
|
||||
public static @NotNull HighlightDisplayKey findOrRegister(@NonNls @NotNull String shortName,
|
||||
@Nls(capitalization = Sentence) @NotNull String displayName) {
|
||||
return findOrRegister(shortName, displayName, null);
|
||||
}
|
||||
|
||||
public static @NotNull HighlightDisplayKey findOrRegister(final @NonNls @NotNull String name,
|
||||
final @Nls(capitalization = Sentence) @NotNull String displayName,
|
||||
final @NonNls @Nullable String id) {
|
||||
HighlightDisplayKey key = find(name);
|
||||
/**
|
||||
* @param shortName {@link LocalInspectionTool#getShortName()}
|
||||
* @param displayName {@link LocalInspectionTool#getDisplayName()}
|
||||
* @param id {@link LocalInspectionTool#getID()} or {@code null} if it is equal to shortName.
|
||||
*
|
||||
* @return an already existing or a new key corresponding to the provided details
|
||||
*/
|
||||
public static @NotNull HighlightDisplayKey findOrRegister(@NonNls @NotNull String shortName,
|
||||
@Nls(capitalization = Sentence) @NotNull String displayName,
|
||||
@NonNls @Nullable String id) {
|
||||
HighlightDisplayKey key = find(shortName);
|
||||
if (key == null) {
|
||||
final String registrationId = id != null ? id : name;
|
||||
key = new HighlightDisplayKey(name, registrationId);
|
||||
id = id != null ? id : shortName;
|
||||
key = new HighlightDisplayKey(shortName, id);
|
||||
ourKeyToDisplayNameMap.put(key, new Computable.PredefinedValueComputable<>(displayName));
|
||||
}
|
||||
return key;
|
||||
@@ -102,30 +130,40 @@ public final class HighlightDisplayKey {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
final Computable<@Nls(capitalization = Sentence) String> computable = ourKeyToDisplayNameMap.get(key);
|
||||
Computable<@Nls(capitalization = Sentence) String> computable = ourKeyToDisplayNameMap.get(key);
|
||||
return computable == null ? null : computable.compute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative inspection tool ID is a descriptive name to be used in "suppress" comments and annotations
|
||||
* in modules with alternative classpath storage.
|
||||
*
|
||||
* @return alternative inspection tool ID.
|
||||
*/
|
||||
public static String getAlternativeID(@NotNull HighlightDisplayKey key) {
|
||||
return ourKeyToAlternativeIDMap.get(key);
|
||||
}
|
||||
|
||||
|
||||
public HighlightDisplayKey(final @NonNls @NotNull String name, final @NonNls @NotNull String ID) {
|
||||
myName = name;
|
||||
public HighlightDisplayKey(@NonNls @NotNull String shortName, @NonNls @NotNull String ID) {
|
||||
myShortName = shortName;
|
||||
myID = ID;
|
||||
ourNameToKeyMap.put(myName, this);
|
||||
if (!Objects.equals(ID, name)) {
|
||||
ourShortNameToKeyMap.put(myShortName, this);
|
||||
if (!Objects.equals(ID, shortName)) {
|
||||
ourIdToKeyMap.put(ID, this);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return myName;
|
||||
return myShortName;
|
||||
}
|
||||
|
||||
public @NotNull String getID(){
|
||||
/**
|
||||
* @see LocalInspectionTool#getID()
|
||||
*
|
||||
* @return inspection tool ID.
|
||||
*/
|
||||
public @NotNull String getID() {
|
||||
return myID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool, O
|
||||
private Boolean myUseNewSerializer;
|
||||
|
||||
/**
|
||||
* For global tools read-only, for local tools would be used instead getID for modules with alternative classpath storage
|
||||
* This alternative ID is a descriptive name to be used in "suppress" comments and annotations in modules with alternative
|
||||
* classpath storage.
|
||||
*/
|
||||
public @NonNls @Nullable String getAlternativeID() {
|
||||
return null;
|
||||
@@ -317,6 +318,8 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool, O
|
||||
|
||||
/**
|
||||
* DO NOT OVERRIDE this method.
|
||||
* <p>
|
||||
* This name is used as a unique identifier of the inspection.
|
||||
*
|
||||
* @see InspectionEP#shortName
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
|
||||
import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolWrapper;
|
||||
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.testFramework.fixtures.impl.GlobalInspectionContextForTests;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
@@ -167,7 +168,8 @@ public final class InspectionTestUtil {
|
||||
final String shortName = toolWrapper.getShortName();
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
|
||||
if (key == null){
|
||||
HighlightDisplayKey.register(shortName, toolWrapper.getDisplayName(), toolWrapper.getID());
|
||||
Computable.PredefinedValueComputable<String> displayName = new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName());
|
||||
HighlightDisplayKey.register(shortName, displayName, toolWrapper.getID());
|
||||
}
|
||||
|
||||
globalContext.doInspections(scope);
|
||||
|
||||
Reference in New Issue
Block a user