From da4d18ee22b781619cdda4318a990327ffa660f1 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 22 Nov 2019 02:33:04 +0300 Subject: [PATCH] avoid loading too many class on startup (IDEA-CR-55624) GitOrigin-RevId: f143b86b0330fcb091e5daf4bc88a8f4b6ccc43d --- .../server/BuildMessageDispatcher.java | 12 +-- .../JavaReflectionCompletionConfidence.java | 4 +- .../JavaReflectionReferenceContributor.java | 50 +++++------ .../json/highlighting/JsonRainbowVisitor.java | 26 +++--- .../impl/JsonSchemaReferenceContributor.java | 19 +++-- .../daemon/impl/DaemonListeners.java | 11 +-- .../dom/impl/I18nReferenceContributor.java | 16 ++-- .../PropertiesReferenceContributor.java | 16 ++-- .../TestNGSuiteReferenceContributor.java | 57 +++++++------ ...YAMLLanguageCodeStyleSettingsProvider.java | 26 +++--- .../PyStdReferenceContributor.java | 24 +++--- ...onFormattedStringReferenceContributor.java | 30 ++++--- ...ythonFormattedStringReferenceProvider.java | 2 +- .../python/highlighting/PyRainbowVisitor.kt | 12 +-- .../python/highlighting/PythonColorsPage.java | 2 +- .../relaxNG/RelaxNGReferenceContributor.java | 13 +-- .../impl/analysis/XmlHighlightVisitor.java | 16 ++-- .../ide/highlighter/XmlFileHighlighter.java | 85 ++++++++++--------- 18 files changed, 223 insertions(+), 198 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildMessageDispatcher.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildMessageDispatcher.java index 9c2ac59213a0..b710aa839448 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildMessageDispatcher.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildMessageDispatcher.java @@ -26,7 +26,9 @@ import java.util.concurrent.ConcurrentHashMap; class BuildMessageDispatcher extends SimpleChannelInboundHandlerAdapter { private static final Logger LOG = Logger.getInstance(BuildMessageDispatcher.class); - private static final AttributeKey SESSION_DATA = AttributeKey.valueOf("BuildMessageDispatcher.sessionData"); + private static class Holder { + private static final AttributeKey SESSION_DATA = AttributeKey.valueOf("BuildMessageDispatcher.sessionData"); + } private final Map mySessionDescriptors = new ConcurrentHashMap<>(16, 0.75f, 1); private final Set myCanceledSessions = ContainerUtil.newConcurrentSet(); @@ -62,7 +64,7 @@ class BuildMessageDispatcher extends SimpleChannelInboundHandlerAdapter PATTERN = - psiLiteral().methodCallParameter(psiMethod().withName(GET_FIELD, GET_DECLARED_FIELD, GET_METHOD, GET_DECLARED_METHOD) - .definedInClass(JAVA_LANG_CLASS)); + static class Holder { + public static final PsiJavaElementPattern.Capture PATTERN = + psiLiteral().methodCallParameter(psiMethod().withName(GET_FIELD, GET_DECLARED_FIELD, GET_METHOD, GET_DECLARED_METHOD) + .definedInClass(JAVA_LANG_CLASS)); - public static final PsiJavaElementPattern.Capture CLASS_PATTERN = - psiLiteral().methodCallParameter(0, or( - psiMethod().withName(FOR_NAME).definedInClass(JAVA_LANG_CLASS), - psiMethod().withName(LOAD_CLASS).definedInClass(JAVA_LANG_CLASS_LOADER), - psiMethod().withName(FIND_CLASS).definedInClass(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP))); + static final PsiJavaElementPattern.Capture CLASS_PATTERN = + psiLiteral().methodCallParameter(0, or( + psiMethod().withName(FOR_NAME).definedInClass(JAVA_LANG_CLASS), + psiMethod().withName(LOAD_CLASS).definedInClass(JAVA_LANG_CLASS_LOADER), + psiMethod().withName(FIND_CLASS).definedInClass(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP))); - private static final ElementPattern METHOD_HANDLE_PATTERN = psiLiteral() - .methodCallParameter(1, psiMethod() - .withName(HANDLE_FACTORY_METHOD_NAMES) - .definedInClass(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP)); + private static final ElementPattern METHOD_HANDLE_PATTERN = psiLiteral() + .methodCallParameter(1, psiMethod() + .withName(HANDLE_FACTORY_METHOD_NAMES) + .definedInClass(JAVA_LANG_INVOKE_METHOD_HANDLES_LOOKUP)); - public static final PsiJavaElementPattern.Capture ATOMIC_NUMERIC_PATTERN = - psiLiteral().methodCallParameter(1, psiMethod().withName(NEW_UPDATER) - .definedInClass(PsiJavaPatterns.psiClass().withQualifiedName(string().oneOf(ATOMIC_LONG_FIELD_UPDATER, - ATOMIC_INTEGER_FIELD_UPDATER)))); + public static final PsiJavaElementPattern.Capture ATOMIC_NUMERIC_PATTERN = + psiLiteral().methodCallParameter(1, psiMethod().withName(NEW_UPDATER) + .definedInClass(PsiJavaPatterns.psiClass().withQualifiedName(string().oneOf(ATOMIC_LONG_FIELD_UPDATER, + ATOMIC_INTEGER_FIELD_UPDATER)))); - public static final PsiJavaElementPattern.Capture ATOMIC_REFERENCE_PATTERN = - psiLiteral().methodCallParameter(2, psiMethod().withName(NEW_UPDATER) - .definedInClass(PsiJavaPatterns.psiClass().withQualifiedName(ATOMIC_REFERENCE_FIELD_UPDATER))); + public static final PsiJavaElementPattern.Capture ATOMIC_REFERENCE_PATTERN = + psiLiteral().methodCallParameter(2, psiMethod().withName(NEW_UPDATER) + .definedInClass(PsiJavaPatterns.psiClass().withQualifiedName(ATOMIC_REFERENCE_FIELD_UPDATER))); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { - registrar.registerReferenceProvider(PATTERN, new JavaReflectionReferenceProvider() { + registrar.registerReferenceProvider(Holder.PATTERN, new JavaReflectionReferenceProvider() { @Nullable @Override protected PsiReference[] getReferencesByMethod(@NotNull PsiLiteralExpression literalArgument, @@ -75,9 +77,9 @@ public class JavaReflectionReferenceContributor extends PsiReferenceContributor } }); - registrar.registerReferenceProvider(CLASS_PATTERN, new ReflectionClassNameReferenceProvider()); + registrar.registerReferenceProvider(Holder.CLASS_PATTERN, new ReflectionClassNameReferenceProvider()); - registrar.registerReferenceProvider(METHOD_HANDLE_PATTERN, new JavaLangInvokeHandleReference.JavaLangInvokeHandleReferenceProvider()); + registrar.registerReferenceProvider(Holder.METHOD_HANDLE_PATTERN, new JavaLangInvokeHandleReference.JavaLangInvokeHandleReferenceProvider()); JavaReflectionReferenceProvider atomicProvider = new JavaReflectionReferenceProvider() { @Override @@ -92,8 +94,8 @@ public class JavaReflectionReferenceContributor extends PsiReferenceContributor return PsiReference.EMPTY_ARRAY; } }; - registrar.registerReferenceProvider(ATOMIC_NUMERIC_PATTERN, atomicProvider); - registrar.registerReferenceProvider(ATOMIC_REFERENCE_PATTERN, atomicProvider); + registrar.registerReferenceProvider(Holder.ATOMIC_NUMERIC_PATTERN, atomicProvider); + registrar.registerReferenceProvider(Holder.ATOMIC_REFERENCE_PATTERN, atomicProvider); } private static class ReflectionClassNameReferenceProvider extends JavaClassReferenceProvider { diff --git a/json/src/com/intellij/json/highlighting/JsonRainbowVisitor.java b/json/src/com/intellij/json/highlighting/JsonRainbowVisitor.java index fa05eddd875b..7d9d5b51e2e1 100644 --- a/json/src/com/intellij/json/highlighting/JsonRainbowVisitor.java +++ b/json/src/com/intellij/json/highlighting/JsonRainbowVisitor.java @@ -16,17 +16,19 @@ import java.util.Map; import java.util.Set; public class JsonRainbowVisitor extends RainbowVisitor { - private static final Map> blacklist = createBlacklist(); + private static class Holder { + private static final Map> blacklist = createBlacklist(); - private static Map> createBlacklist() { - Map> blacklist = new HashMap<>(); - blacklist.put("package.json", ContainerUtil.set("/dependencies", - "/devDependencies", - "/peerDependencies", - "/scripts", - "/directories", - "/optionalDependencies")); - return blacklist; + private static Map> createBlacklist() { + Map> blacklist = new HashMap<>(); + blacklist.put("package.json", ContainerUtil.set("/dependencies", + "/devDependencies", + "/peerDependencies", + "/scripts", + "/directories", + "/optionalDependencies")); + return blacklist; + } } @Override @@ -39,9 +41,9 @@ public class JsonRainbowVisitor extends RainbowVisitor { if (element instanceof JsonProperty) { PsiFile file = element.getContainingFile(); String fileName = file.getName(); - if (blacklist.containsKey(fileName)) { + if (Holder.blacklist.containsKey(fileName)) { JsonPointerPosition position = JsonOriginalPsiWalker.INSTANCE.findPosition(element, false); - if (position != null && blacklist.get(fileName).contains(position.toJsonPointer())) return; + if (position != null && Holder.blacklist.get(fileName).contains(position.toJsonPointer())) return; } String name = ((JsonProperty)element).getName(); addInfo(getInfo(file, ((JsonProperty)element).getNameElement(), name, JsonSyntaxHighlighterFactory.JSON_PROPERTY_KEY)); diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReferenceContributor.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReferenceContributor.java index fb6a02d5ce3f..1a528621c9b8 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReferenceContributor.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReferenceContributor.java @@ -34,17 +34,18 @@ import org.jetbrains.annotations.Nullable; * @author Irina.Chernushina on 3/31/2016. */ public class JsonSchemaReferenceContributor extends PsiReferenceContributor { - private static final PsiElementPattern.Capture REF_PATTERN = createPropertyValuePattern("$ref", true, false); - private static final PsiElementPattern.Capture REC_REF_PATTERN = createPropertyValuePattern("$recursiveRef", true, false); - private static final PsiElementPattern.Capture SCHEMA_PATTERN = createPropertyValuePattern("$schema", false, true); - private static final PsiElementPattern.Capture REQUIRED_PROP_PATTERN = createRequiredPropPattern(); - + private static class Holder { + private static final PsiElementPattern.Capture REF_PATTERN = createPropertyValuePattern("$ref", true, false); + private static final PsiElementPattern.Capture REC_REF_PATTERN = createPropertyValuePattern("$recursiveRef", true, false); + private static final PsiElementPattern.Capture SCHEMA_PATTERN = createPropertyValuePattern("$schema", false, true); + private static final PsiElementPattern.Capture REQUIRED_PROP_PATTERN = createRequiredPropPattern(); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { - registrar.registerReferenceProvider(REF_PATTERN, new JsonPointerReferenceProvider(false)); - registrar.registerReferenceProvider(REC_REF_PATTERN, new JsonPointerReferenceProvider(false)); - registrar.registerReferenceProvider(SCHEMA_PATTERN, new JsonPointerReferenceProvider(true)); - registrar.registerReferenceProvider(REQUIRED_PROP_PATTERN, new JsonRequiredPropsReferenceProvider()); + registrar.registerReferenceProvider(Holder.REF_PATTERN, new JsonPointerReferenceProvider(false)); + registrar.registerReferenceProvider(Holder.REC_REF_PATTERN, new JsonPointerReferenceProvider(false)); + registrar.registerReferenceProvider(Holder.SCHEMA_PATTERN, new JsonPointerReferenceProvider(true)); + registrar.registerReferenceProvider(Holder.REQUIRED_PROP_PATTERN, new JsonRequiredPropsReferenceProvider()); } private static PsiElementPattern.Capture createPropertyValuePattern( diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java index ffd89377e1aa..21aff978103c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonListeners.java @@ -465,19 +465,16 @@ public final class DaemonListeners implements Disposable { } } + private static class Holder { + private static final String myCutActionName = ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_CUT).getTemplatePresentation().getText(); + } private class MyCommandListener implements CommandListener { - private final String myCutActionName; - - private MyCommandListener() { - myCutActionName = ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_CUT).getTemplatePresentation().getText(); - } - @Override public void commandStarted(@NotNull CommandEvent event) { Document affectedDocument = extractDocumentFromCommand(event); if (!worthBothering(affectedDocument, event.getProject())) return; - cutOperationJustHappened = myCutActionName.equals(event.getCommandName()); + cutOperationJustHappened = Comparing.strEqual(Holder.myCutActionName, event.getCommandName()); if (!myDaemonCodeAnalyzer.isRunning()) return; if (LOG.isDebugEnabled()) { LOG.debug("cancelling code highlighting by command:" + event.getCommand()); diff --git a/plugins/devkit/devkit-core/src/dom/impl/I18nReferenceContributor.java b/plugins/devkit/devkit-core/src/dom/impl/I18nReferenceContributor.java index 2351e1b9b636..156eb7674786 100644 --- a/plugins/devkit/devkit-core/src/dom/impl/I18nReferenceContributor.java +++ b/plugins/devkit/devkit-core/src/dom/impl/I18nReferenceContributor.java @@ -35,10 +35,12 @@ public class I18nReferenceContributor extends PsiReferenceContributor { private static final String INTENTION_ACTION_TAG = "intentionAction"; private static final String INTENTION_ACTION_BUNDLE_TAG = "bundleName"; - private static final String CONFIGURABLE_EP = ConfigurableEP.class.getName(); - private static final String INSPECTION_EP = InspectionEP.class.getName(); + private static class Holder { + private static final String CONFIGURABLE_EP = ConfigurableEP.class.getName(); + private static final String INSPECTION_EP = InspectionEP.class.getName(); - private static final String TYPE_NAME_EP = TypeNameEP.class.getName(); + private static final String TYPE_NAME_EP = TypeNameEP.class.getName(); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { @@ -49,11 +51,11 @@ public class I18nReferenceContributor extends PsiReferenceContributor { private static void registerKeyProviders(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(extensionAttributePattern(new String[]{"key", "groupKey"}, - CONFIGURABLE_EP, INSPECTION_EP), + Holder.CONFIGURABLE_EP, Holder.INSPECTION_EP), new PropertyKeyReferenceProvider(false, "groupKey", "groupBundle")); registrar.registerReferenceProvider(extensionAttributePattern(new String[]{"resourceKey"}, - TYPE_NAME_EP), + Holder.TYPE_NAME_EP), new PropertyKeyReferenceProvider(false, "resourceKey", "resourceBundle")); final XmlTagPattern.Capture intentionActionKeyTagPattern = @@ -78,11 +80,11 @@ public class I18nReferenceContributor extends PsiReferenceContributor { registrar.registerReferenceProvider(resourceBundleTagPattern, bundleReferenceProvider); registrar.registerReferenceProvider(extensionAttributePattern(new String[]{"bundle"}, "groupBundle", - CONFIGURABLE_EP, INSPECTION_EP), + Holder.CONFIGURABLE_EP, Holder.INSPECTION_EP), bundleReferenceProvider); registrar.registerReferenceProvider(extensionAttributePattern(new String[]{"resourceBundle"}, - TYPE_NAME_EP), + Holder.TYPE_NAME_EP), bundleReferenceProvider); final XmlTagPattern.Capture intentionActionBundleTagPattern = diff --git a/plugins/java-i18n/src/com/intellij/lang/properties/PropertiesReferenceContributor.java b/plugins/java-i18n/src/com/intellij/lang/properties/PropertiesReferenceContributor.java index 1141236dfbb2..18e51b23d79e 100644 --- a/plugins/java-i18n/src/com/intellij/lang/properties/PropertiesReferenceContributor.java +++ b/plugins/java-i18n/src/com/intellij/lang/properties/PropertiesReferenceContributor.java @@ -40,12 +40,14 @@ import java.util.List; public class PropertiesReferenceContributor extends PsiReferenceContributor{ private static final Logger LOG = Logger.getInstance(PropertiesReferenceContributor.class); - private static final JavaClassReferenceProvider CLASS_REFERENCE_PROVIDER = new JavaClassReferenceProvider() { - @Override - public boolean isSoft() { - return true; - } - }; + private static class Holder { + private static final JavaClassReferenceProvider CLASS_REFERENCE_PROVIDER = new JavaClassReferenceProvider() { + @Override + public boolean isSoft() { + return true; + } + }; + } @Override @@ -117,7 +119,7 @@ public class PropertiesReferenceContributor extends PsiReferenceContributor{ String text = element.getText(); String[] words = text.split("\\s"); if (words.length != 1) return PsiReference.EMPTY_ARRAY; - return CLASS_REFERENCE_PROVIDER.getReferencesByString(words[0], element, 0); + return Holder.CLASS_REFERENCE_PROVIDER.getReferencesByString(words[0], element, 0); } }); } diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java index 351ee0c338dd..8c1ed5cd73e2 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java +++ b/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java @@ -25,43 +25,46 @@ import org.jetbrains.annotations.NotNull; import static com.intellij.patterns.XmlPatterns.*; public class TestNGSuiteReferenceContributor extends PsiReferenceContributor { - private static final XmlAttributeValuePattern ourTestClassPattern = - xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("class") - .withParent(xmlTag().withName("classes") - .withParent(xmlTag().withName("test").withParent(xmlTag().withName("suite")))))); + private static class Holder { + private static final XmlAttributeValuePattern ourTestClassPattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("class") + .withParent(xmlTag().withName("classes") + .withParent(xmlTag().withName("test") + .withParent(xmlTag().withName("suite")))))); - private static final XmlAttributeValuePattern ourListenerClassPattern = - xmlAttributeValue(xmlAttribute("class-name").withParent(xmlTag().withName("listener") - .withParent(xmlTag().withName("listeners") - .withParent(xmlTag().withName("suite"))))); + private static final XmlAttributeValuePattern ourListenerClassPattern = + xmlAttributeValue(xmlAttribute("class-name").withParent(xmlTag().withName("listener") + .withParent(xmlTag().withName("listeners") + .withParent(xmlTag().withName("suite"))))); - private static final XmlAttributeValuePattern ourMethodSelectorPattern = - xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("selector-class") - .withParent(xmlTag().withName("method-selector") - .withParent(xmlTag().withName("method-selectors") - .withParent( - xmlTag().withName(string().oneOf("suite", "test"))))))); + private static final XmlAttributeValuePattern ourMethodSelectorPattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("selector-class") + .withParent(xmlTag().withName("method-selector") + .withParent(xmlTag().withName("method-selectors") + .withParent( + xmlTag() + .withName(string().oneOf("suite", "test"))))))); - private static final XmlAttributeValuePattern ourPackagePattern = - xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("package") - .withParent(xmlTag().withName("packages") - .withParent(xmlTag().withName("suite"))))); - - private static final XmlAttributeValuePattern ourSuiteFilePattern = - xmlAttributeValue(xmlAttribute("path").withParent(xmlTag().withName("suite-file") - .withParent(xmlTag().withName("suite-files") - .withParent(xmlTag().withName("suite"))))); + private static final XmlAttributeValuePattern ourPackagePattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("package") + .withParent(xmlTag().withName("packages") + .withParent(xmlTag().withName("suite"))))); + private static final XmlAttributeValuePattern ourSuiteFilePattern = + xmlAttributeValue(xmlAttribute("path").withParent(xmlTag().withName("suite-file") + .withParent(xmlTag().withName("suite-files") + .withParent(xmlTag().withName("suite"))))); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { - registrar.registerReferenceProvider(ourTestClassPattern, new JavaClassReferenceProvider()); - registrar.registerReferenceProvider(ourListenerClassPattern, new JavaClassReferenceProvider()); + registrar.registerReferenceProvider(Holder.ourTestClassPattern, new JavaClassReferenceProvider()); + registrar.registerReferenceProvider(Holder.ourListenerClassPattern, new JavaClassReferenceProvider()); final JavaClassReferenceProvider methodSelectorProvider = new JavaClassReferenceProvider(); methodSelectorProvider.setOption(JavaClassReferenceProvider.EXTEND_CLASS_NAMES, new String[]{"org.testng.IMethodSelector"}); - registrar.registerReferenceProvider(ourMethodSelectorPattern, methodSelectorProvider); + registrar.registerReferenceProvider(Holder.ourMethodSelectorPattern, methodSelectorProvider); - registrar.registerReferenceProvider(ourSuiteFilePattern, new PathListReferenceProvider(){ + registrar.registerReferenceProvider(Holder.ourSuiteFilePattern, new PathListReferenceProvider(){ @Override protected boolean disableNonSlashedPaths() { return false; diff --git a/plugins/yaml/src/org/jetbrains/yaml/YAMLLanguageCodeStyleSettingsProvider.java b/plugins/yaml/src/org/jetbrains/yaml/YAMLLanguageCodeStyleSettingsProvider.java index 725dbb23f9d6..9480db285ebd 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/YAMLLanguageCodeStyleSettingsProvider.java +++ b/plugins/yaml/src/org/jetbrains/yaml/YAMLLanguageCodeStyleSettingsProvider.java @@ -19,17 +19,19 @@ import javax.swing.*; * @author oleg */ public class YAMLLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { - public static final int[] ALIGN_VALUES = new int[]{ - YAMLCodeStyleSettings.DO_NOT_ALIGN, - YAMLCodeStyleSettings.ALIGN_ON_COLON, - YAMLCodeStyleSettings.ALIGN_ON_VALUE - }; + private static class Holder { + private static final int[] ALIGN_VALUES = new int[]{ + YAMLCodeStyleSettings.DO_NOT_ALIGN, + YAMLCodeStyleSettings.ALIGN_ON_COLON, + YAMLCodeStyleSettings.ALIGN_ON_VALUE + }; - public static final String[] ALIGN_OPTIONS = new String[]{ - YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.no"), - YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.colon"), - YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.value") - }; + private static final String[] ALIGN_OPTIONS = new String[]{ + YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.no"), + YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.colon"), + YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.options.value") + }; + } @Override protected void customizeDefaults(@NotNull CommonCodeStyleSettings commonSettings, @@ -62,8 +64,8 @@ public class YAMLLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett "ALIGN_VALUES_PROPERTIES", YAMLBundle.message("YAMLLanguageCodeStyleSettingsProvider.align.values"), null, - ALIGN_OPTIONS, - ALIGN_VALUES); + Holder.ALIGN_OPTIONS, + Holder.ALIGN_VALUES); consumer.showCustomOption(YAMLCodeStyleSettings.class, "SEQUENCE_ON_NEW_LINE", diff --git a/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java index b9ecf6247fca..5dce6ceb3c55 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java @@ -28,17 +28,19 @@ import static com.intellij.patterns.PlatformPatterns.psiElement; * @author yole */ public class PyStdReferenceContributor extends PsiReferenceContributor { - public static final PatternCondition IN_OPTIONAL_PARENTHESIS_INSIDE_ASSIGNMENT = - new PatternCondition("in optional parenthesis inside assignment") { - @Override - public boolean accepts(@NotNull PsiElement element, ProcessingContext context) { - PsiElement parent = element.getParent(); - while (parent instanceof PyParenthesizedExpression) { - parent = parent.getParent(); + private static class Holder { + private static final PatternCondition IN_OPTIONAL_PARENTHESIS_INSIDE_ASSIGNMENT = + new PatternCondition("in optional parenthesis inside assignment") { + @Override + public boolean accepts(@NotNull PsiElement element, ProcessingContext context) { + PsiElement parent = element.getParent(); + while (parent instanceof PyParenthesizedExpression) { + parent = parent.getParent(); + } + return parent instanceof PyAssignmentStatement; } - return parent instanceof PyAssignmentStatement; - } - }; + }; + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { @@ -66,7 +68,7 @@ public class PyStdReferenceContributor extends PsiReferenceContributor { final PsiReferenceProvider provider) { registrar.registerReferenceProvider(psiElement(PyStringLiteralExpression.class) .withParent(psiElement(PySequenceExpression.class) - .with(IN_OPTIONAL_PARENTHESIS_INSIDE_ASSIGNMENT) + .with(Holder.IN_OPTIONAL_PARENTHESIS_INSIDE_ASSIGNMENT) .inside(true, psiElement(PyAssignmentStatement.class) .withFirstChild(psiElement(PyTargetExpression.class).withName(name)))), provider); } diff --git a/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceContributor.java b/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceContributor.java index d3af7b36ad1a..06b096451801 100644 --- a/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceContributor.java @@ -30,25 +30,27 @@ import static com.intellij.patterns.PlatformPatterns.psiElement; public class PythonFormattedStringReferenceContributor extends PsiReferenceContributor { - public static final PsiElementPattern.Capture PERCENT_STRING_PATTERN = - psiElement(PyStringLiteralExpression.class).beforeLeaf(psiElement().withText("%")).withParent(PyBinaryExpression.class); - public static final PsiElementPattern.Capture FORMAT_STRING_PATTERN = - psiElement(PyStringLiteralExpression.class) - .withParent(psiElement(PyReferenceExpression.class) - .with(new PatternCondition("isFormatFunction") { + static class Holder { + private static final PsiElementPattern.Capture PERCENT_STRING_PATTERN = + psiElement(PyStringLiteralExpression.class).beforeLeaf(psiElement().withText("%")).withParent(PyBinaryExpression.class); + static final PsiElementPattern.Capture FORMAT_STRING_PATTERN = + psiElement(PyStringLiteralExpression.class) + .withParent(psiElement(PyReferenceExpression.class) + .with(new PatternCondition("isFormatFunction") { - @Override - public boolean accepts(@NotNull PyReferenceExpression expression, ProcessingContext context) { - String expressionName = expression.getName(); - return expressionName != null && expressionName.equals("format"); - } - })) - .withSuperParent(2, PyCallExpression.class); + @Override + public boolean accepts(@NotNull PyReferenceExpression expression, ProcessingContext context) { + String expressionName = expression.getName(); + return expressionName != null && expressionName.equals("format"); + } + })) + .withSuperParent(2, PyCallExpression.class); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { - registrar.registerReferenceProvider(psiElement().andOr(PERCENT_STRING_PATTERN, FORMAT_STRING_PATTERN), + registrar.registerReferenceProvider(psiElement().andOr(Holder.PERCENT_STRING_PATTERN, Holder.FORMAT_STRING_PATTERN), new PythonFormattedStringReferenceProvider()); } } diff --git a/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceProvider.java b/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceProvider.java index c335a50d441a..24b2dca91035 100644 --- a/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/PythonFormattedStringReferenceProvider.java @@ -30,7 +30,7 @@ public class PythonFormattedStringReferenceProvider extends PsiReferenceProvider @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) { - if (PythonFormattedStringReferenceContributor.FORMAT_STRING_PATTERN.accepts(element)) { + if (PythonFormattedStringReferenceContributor.Holder.FORMAT_STRING_PATTERN.accepts(element)) { return getReferencesFromFormatString((PyStringLiteralExpression)element); } else { diff --git a/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt b/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt index da3b5293fe78..d72dcc4e076f 100644 --- a/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt +++ b/python/src/com/jetbrains/python/highlighting/PyRainbowVisitor.kt @@ -15,9 +15,9 @@ import com.jetbrains.python.psi.resolve.PyResolveContext class PyRainbowVisitor : RainbowVisitor() { - companion object { - private val IGNORED_NAMES = setOf(PyNames.NONE, PyNames.TRUE, PyNames.FALSE) - private val DEFAULT_HIGHLIGHTING_KEY = DefaultLanguageHighlighterColors.LOCAL_VARIABLE + object Holder { + val IGNORED_NAMES = setOf(PyNames.NONE, PyNames.TRUE, PyNames.FALSE) + val DEFAULT_HIGHLIGHTING_KEY = DefaultLanguageHighlighterColors.LOCAL_VARIABLE @JvmStatic val HIGHLIGHTING_KEYS: Set = setOf(PyHighlighter.PY_PARAMETER, DEFAULT_HIGHLIGHTING_KEY) @@ -59,7 +59,7 @@ class PyRainbowVisitor : RainbowVisitor() { private fun getReferenceContext(referenceExpression: PyReferenceExpression, visitedReferenceExpressions: MutableSet): PsiElement? { - if (referenceExpression.isQualified || referenceExpression.name in IGNORED_NAMES) return null + if (referenceExpression.isQualified || referenceExpression.name in Holder.IGNORED_NAMES) return null val resolved = referenceExpression.reference.resolve() return when (resolved) { @@ -74,7 +74,7 @@ class PyRainbowVisitor : RainbowVisitor() { } private fun getTargetContext(targetExpression: PyTargetExpression): PsiElement? { - if (targetExpression.isQualified || targetExpression.name in IGNORED_NAMES) return null + if (targetExpression.isQualified || targetExpression.name in Holder.IGNORED_NAMES) return null val parent = targetExpression.parent if (parent is PyGlobalStatement) return targetExpression.containingFile @@ -111,7 +111,7 @@ class PyRainbowVisitor : RainbowVisitor() { private fun updateNameIfGlobal(context: PsiElement, name: String?) = if (context is PyFile && name != null) "global_$name" else name - private fun addInfo(context: PsiElement, rainbowElement: PsiElement, name: String, key: TextAttributesKey? = DEFAULT_HIGHLIGHTING_KEY) { + private fun addInfo(context: PsiElement, rainbowElement: PsiElement, name: String, key: TextAttributesKey? = Holder.DEFAULT_HIGHLIGHTING_KEY) { addInfo(getInfo(context, rainbowElement, name, key)) } diff --git a/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java b/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java index 30d357eeafcf..ff956a70ecf8 100644 --- a/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java +++ b/python/src/com/jetbrains/python/highlighting/PythonColorsPage.java @@ -163,7 +163,7 @@ public class PythonColorsPage implements RainbowColorSettingsPage, InspectionCol @Override public boolean isRainbowType(TextAttributesKey type) { - return PyRainbowVisitor.getHIGHLIGHTING_KEYS().contains(type); + return PyRainbowVisitor.Holder.getHIGHLIGHTING_KEYS().contains(type); } @Nullable diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/RelaxNGReferenceContributor.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/RelaxNGReferenceContributor.java index 419d3edba87e..2fff61a07ae4 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/RelaxNGReferenceContributor.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/RelaxNGReferenceContributor.java @@ -15,18 +15,19 @@ import static com.intellij.patterns.XmlPatterns.*; * @author peter */ public class RelaxNGReferenceContributor extends PsiReferenceContributor { - private static final XmlNamedElementPattern RNG_TAG_PATTERN = xmlTag().withNamespace(RelaxNgMetaDataContributor.RNG_NAMESPACE); + private static class Holder { + private static final XmlNamedElementPattern RNG_TAG_PATTERN = xmlTag().withNamespace(RelaxNgMetaDataContributor.RNG_NAMESPACE); - private static final XmlNamedElementPattern.XmlAttributePattern NAME_ATTR_PATTERN = xmlAttribute("name"); - - private static final XmlNamedElementPattern.XmlAttributePattern NAME_PATTERN = NAME_ATTR_PATTERN.withParent( - RNG_TAG_PATTERN.withLocalName("element", "attribute")); + private static final XmlNamedElementPattern.XmlAttributePattern NAME_ATTR_PATTERN = xmlAttribute("name"); + private static final XmlNamedElementPattern.XmlAttributePattern NAME_PATTERN = NAME_ATTR_PATTERN.withParent( + RNG_TAG_PATTERN.withLocalName("element", "attribute")); + } @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { XmlUtil.registerXmlAttributeValueReferenceProvider(registrar, new String[]{ "name" - }, new PatternFilter(xmlAttributeValue().withParent(NAME_PATTERN)), true, new PrefixReferenceProvider()); + }, new PatternFilter(xmlAttributeValue().withParent(Holder.NAME_PATTERN)), true, new PrefixReferenceProvider()); // final XmlAttributeValuePattern id = xmlAttributeValue().withParent(xmlAttribute()).with(IdRefProvider.HAS_ID_REF_TYPE); // final XmlAttributeValuePattern idref = xmlAttributeValue().withParent(xmlAttribute()).with(IdRefProvider.HAS_ID_TYPE); diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java index d9d1fa70e41b..212609fb4d2d 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlHighlightVisitor.java @@ -49,12 +49,14 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV private static boolean ourDoJaxpTesting; - private static final TextAttributes NONEMPTY_TEXT_ATTRIBUTES = new TextAttributes() { - @Override - public boolean isEmpty() { - return false; - } - }; + private static class Holder { + private static final TextAttributes NONEMPTY_TEXT_ATTRIBUTES = new TextAttributes() { + @Override + public boolean isEmpty() { + return false; + } + }; + } private HighlightInfoHolder myHolder; public XmlHighlightVisitor() { @@ -187,7 +189,7 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(warning).range(childByRole, startOffset, startOffset + length).descriptionAndTooltip(localizedMessage).create(); if (highlightInfo == null) { - highlightInfo = HighlightInfo.newHighlightInfo(warning).range(new TextRange(startOffset, startOffset + length)).textAttributes(NONEMPTY_TEXT_ATTRIBUTES).descriptionAndTooltip(localizedMessage).create(); + highlightInfo = HighlightInfo.newHighlightInfo(warning).range(new TextRange(startOffset, startOffset + length)).textAttributes(Holder.NONEMPTY_TEXT_ATTRIBUTES).descriptionAndTooltip(localizedMessage).create(); } for (final IntentionAction quickFixAction : quickFixActions) { diff --git a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java index b03caab80143..da4ab6c69a72 100644 --- a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java +++ b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/XmlFileHighlighter.java @@ -35,51 +35,56 @@ import static com.intellij.psi.xml.XmlTokenType.*; public class XmlFileHighlighter extends SyntaxHighlighterBase { static final ExtensionPointName EMBEDDED_HIGHLIGHTERS = ExtensionPointName.create("com.intellij.embeddedTokenHighlighter"); - private static final MultiMap ourMap = MultiMap.create(); + private static class Holder { + private static final MultiMap ourMap = MultiMap.create(); - static { - ourMap.putValue(XML_DATA_CHARACTERS, XmlHighlighterColors.XML_TAG_DATA); + static { + ourMap.putValue(XML_DATA_CHARACTERS, XmlHighlighterColors.XML_TAG_DATA); - for (IElementType type : ContainerUtil.ar(XML_COMMENT_START, XML_COMMENT_END, XML_COMMENT_CHARACTERS, - XML_CONDITIONAL_COMMENT_END, XML_CONDITIONAL_COMMENT_END_START, - XML_CONDITIONAL_COMMENT_START, XML_CONDITIONAL_COMMENT_START_END)) { - ourMap.putValue(type, XmlHighlighterColors.XML_COMMENT); - } + for (IElementType type : ContainerUtil.ar(XML_COMMENT_START, XML_COMMENT_END, XML_COMMENT_CHARACTERS, + XML_CONDITIONAL_COMMENT_END, XML_CONDITIONAL_COMMENT_END_START, + XML_CONDITIONAL_COMMENT_START, XML_CONDITIONAL_COMMENT_START_END)) { + ourMap.putValue(type, XmlHighlighterColors.XML_COMMENT); + } - for (IElementType type : ContainerUtil.ar(XML_START_TAG_START, XML_END_TAG_START, XML_TAG_END, XML_EMPTY_ELEMENT_END, TAG_WHITE_SPACE)) { - ourMap.putValue(type, XmlHighlighterColors.XML_TAG); - } - for (IElementType type : ContainerUtil.ar(XML_TAG_NAME, XML_CONDITIONAL_IGNORE, XML_CONDITIONAL_INCLUDE)) { - ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_TAG_NAME)); - } - ourMap.putValues(XML_NAME, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_ATTRIBUTE_NAME)); - for (IElementType type : ContainerUtil.ar(XML_EQ, XML_TAG_CHARACTERS, - XML_ATTRIBUTE_VALUE_TOKEN, XML_ATTRIBUTE_VALUE_START_DELIMITER, XML_ATTRIBUTE_VALUE_END_DELIMITER)) { - ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_ATTRIBUTE_VALUE)); - } + for (IElementType type : ContainerUtil + .ar(XML_START_TAG_START, XML_END_TAG_START, XML_TAG_END, XML_EMPTY_ELEMENT_END, TAG_WHITE_SPACE)) { + ourMap.putValue(type, XmlHighlighterColors.XML_TAG); + } + for (IElementType type : ContainerUtil.ar(XML_TAG_NAME, XML_CONDITIONAL_IGNORE, XML_CONDITIONAL_INCLUDE)) { + ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_TAG_NAME)); + } + ourMap.putValues(XML_NAME, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_ATTRIBUTE_NAME)); + for (IElementType type : ContainerUtil.ar(XML_EQ, XML_TAG_CHARACTERS, + XML_ATTRIBUTE_VALUE_TOKEN, XML_ATTRIBUTE_VALUE_START_DELIMITER, + XML_ATTRIBUTE_VALUE_END_DELIMITER)) { + ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_ATTRIBUTE_VALUE)); + } - for (IElementType type : ContainerUtil.ar(XML_DECL_START, XML_DOCTYPE_START, XML_DOCTYPE_SYSTEM, XML_DOCTYPE_PUBLIC, - XML_ATTLIST_DECL_START, XML_ELEMENT_DECL_START, XML_ENTITY_DECL_START)) { - ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_TAG_NAME)); - } + for (IElementType type : ContainerUtil.ar(XML_DECL_START, XML_DOCTYPE_START, XML_DOCTYPE_SYSTEM, XML_DOCTYPE_PUBLIC, + XML_ATTLIST_DECL_START, XML_ELEMENT_DECL_START, XML_ENTITY_DECL_START)) { + ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_TAG, XmlHighlighterColors.XML_TAG_NAME)); + } - for (IElementType type : ContainerUtil.ar(XML_CONDITIONAL_SECTION_START, XML_CONDITIONAL_SECTION_END, XML_DECL_END, XML_DOCTYPE_END)) { - ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_PROLOGUE, XmlHighlighterColors.XML_TAG_NAME)); - } + for (IElementType type : ContainerUtil + .ar(XML_CONDITIONAL_SECTION_START, XML_CONDITIONAL_SECTION_END, XML_DECL_END, XML_DOCTYPE_END)) { + ourMap.putValues(type, Arrays.asList(XmlHighlighterColors.XML_PROLOGUE, XmlHighlighterColors.XML_TAG_NAME)); + } - ourMap.putValue(XML_PI_START, XmlHighlighterColors.XML_PROLOGUE); - ourMap.putValue(XML_PI_END, XmlHighlighterColors.XML_PROLOGUE); + ourMap.putValue(XML_PI_START, XmlHighlighterColors.XML_PROLOGUE); + ourMap.putValue(XML_PI_END, XmlHighlighterColors.XML_PROLOGUE); - ourMap.putValue(XML_CHAR_ENTITY_REF, XmlHighlighterColors.XML_ENTITY_REFERENCE); - ourMap.putValue(XML_ENTITY_REF_TOKEN, XmlHighlighterColors.XML_ENTITY_REFERENCE); + ourMap.putValue(XML_CHAR_ENTITY_REF, XmlHighlighterColors.XML_ENTITY_REFERENCE); + ourMap.putValue(XML_ENTITY_REF_TOKEN, XmlHighlighterColors.XML_ENTITY_REFERENCE); - ourMap.putValue(XML_BAD_CHARACTER, HighlighterColors.BAD_CHARACTER); + ourMap.putValue(XML_BAD_CHARACTER, HighlighterColors.BAD_CHARACTER); - for (EmbeddedTokenHighlighter highlighter : EMBEDDED_HIGHLIGHTERS.getExtensionList()) { - MultiMap attributes = highlighter.getEmbeddedTokenAttributes(); - for (Map.Entry> entry : attributes.entrySet()) { - if (!ourMap.containsKey(entry.getKey())) { - ourMap.putValues(entry.getKey(), entry.getValue()); + for (EmbeddedTokenHighlighter highlighter : EMBEDDED_HIGHLIGHTERS.getExtensionList()) { + MultiMap attributes = highlighter.getEmbeddedTokenAttributes(); + for (Map.Entry> entry : attributes.entrySet()) { + if (!ourMap.containsKey(entry.getKey())) { + ourMap.putValues(entry.getKey(), entry.getValue()); + } } } } @@ -118,7 +123,7 @@ public class XmlFileHighlighter extends SyntaxHighlighterBase { public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { //noinspection SynchronizationOnGetClass,SynchronizeOnThis synchronized (getClass()) { - return ourMap.get(tokenType).toArray(TextAttributesKey.EMPTY_ARRAY); + return Holder.ourMap.get(tokenType).toArray(TextAttributesKey.EMPTY_ARRAY); } } @@ -128,9 +133,9 @@ public class XmlFileHighlighter extends SyntaxHighlighterBase { @Deprecated public static synchronized void registerEmbeddedTokenAttributes(Map _keys1, Map _keys2) { - HashSet existingKeys = new HashSet<>(ourMap.keySet()); - addMissing(_keys1, existingKeys, ourMap); - addMissing(_keys2, existingKeys, ourMap); + HashSet existingKeys = new HashSet<>(Holder.ourMap.keySet()); + addMissing(_keys1, existingKeys, Holder.ourMap); + addMissing(_keys2, existingKeys, Holder.ourMap); } static void addMissing(Map from, Set existingKeys, MultiMap to) {