From ed058a92e19223be39219dc7b415786deea9ba36 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Wed, 12 Dec 2012 15:21:56 +0400 Subject: [PATCH] EA-40398 fixed class loading order issues that caused NPEs in syntax highlighters due to EditorColorsManager not initialized on time [r=cdr] --- .../editor/colors/TextAttributesKey.java | 8 ++--- .../colors/impl/EditorColorsManagerImpl.java | 19 +++++------- .../TextAttributeKeyDefaultsProviderImpl.java | 30 +++++++++++++++++++ .../src/META-INF/PlatformExtensions.xml | 2 ++ 4 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/TextAttributeKeyDefaultsProviderImpl.java diff --git a/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java b/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java index 11aa05788bf2..55aecc97ed97 100644 --- a/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java +++ b/platform/core-api/src/com/intellij/openapi/editor/colors/TextAttributesKey.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.editor.colors; +import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.DefaultJDOMExternalizer; import com.intellij.openapi.util.InvalidDataException; @@ -32,6 +33,7 @@ import org.jetbrains.annotations.NotNull; public final class TextAttributesKey implements Comparable, JDOMExternalizable { private static final TextAttributes NULL_ATTRIBUTES = new TextAttributes(); private static final ConcurrentHashMap ourRegistry = new ConcurrentHashMap(); + private static final TextAttributeKeyDefaultsProvider OUR_DEFAULTS_PROVIDER = ServiceManager.getService(TextAttributeKeyDefaultsProvider.class); public String myExternalName; public TextAttributes myDefaultAttributes = NULL_ATTRIBUTES; @@ -106,8 +108,8 @@ public final class TextAttributesKey implements Comparable, J if (myDefaultAttributes == NULL_ATTRIBUTES) { // E.g. if one text key reuse default attributes of some other predefined key myDefaultAttributes = null; - if (myDefaultsProvider != null) - myDefaultAttributes = myDefaultsProvider.getDefaultAttributes(this); + if (OUR_DEFAULTS_PROVIDER != null) + myDefaultAttributes = OUR_DEFAULTS_PROVIDER.getDefaultAttributes(this); } return myDefaultAttributes; } @@ -147,6 +149,4 @@ public final class TextAttributesKey implements Comparable, J public interface TextAttributeKeyDefaultsProvider { TextAttributes getDefaultAttributes(TextAttributesKey key); } - - public static TextAttributeKeyDefaultsProvider myDefaultsProvider; } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java index 48e29b6bd380..d5f2035042bd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java @@ -118,18 +118,15 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Name loadAllSchemes(); setGlobalScheme(myDefaultColorSchemesManager.getAllSchemes()[0]); + } - TextAttributesKey.myDefaultsProvider = new TextAttributesKey.TextAttributeKeyDefaultsProvider() { - final boolean dark = UIUtil.isUnderDarcula() && getScheme("Darcula") != null; - @Override - public TextAttributes getDefaultAttributes(TextAttributesKey key) { - // It is reasonable to fetch attributes from Default color scheme. Otherwise if we launch IDE and then - // try switch from custom colors scheme (e.g. with dark background) to default one. Editor will show - // incorrect highlighting with "traces" of color scheme which was active during IDE startup. - final EditorColorsScheme defaultColorScheme = getScheme(dark ? "Darcula" : EditorColorsScheme.DEFAULT_SCHEME_NAME); - return defaultColorScheme.getAttributes(key); - } - }; + public TextAttributes getDefaultAttributes(TextAttributesKey key) { + final boolean dark = UIUtil.isUnderDarcula() && getScheme("Darcula") != null; + // It is reasonable to fetch attributes from Default color scheme. Otherwise if we launch IDE and then + // try switch from custom colors scheme (e.g. with dark background) to default one. Editor will show + // incorrect highlighting with "traces" of color scheme which was active during IDE startup. + final EditorColorsScheme defaultColorScheme = getScheme(dark ? "Darcula" : EditorColorsScheme.DEFAULT_SCHEME_NAME); + return defaultColorScheme.getAttributes(key); } private void extendDefaultScheme() { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/TextAttributeKeyDefaultsProviderImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/TextAttributeKeyDefaultsProviderImpl.java new file mode 100644 index 000000000000..5cd49f1568eb --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/TextAttributeKeyDefaultsProviderImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2012 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.openapi.editor.colors.impl; + +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.editor.markup.TextAttributes; + +/** + * @author Dennis.Ushakov + */ +public class TextAttributeKeyDefaultsProviderImpl implements TextAttributesKey.TextAttributeKeyDefaultsProvider { + @Override + public TextAttributes getDefaultAttributes(TextAttributesKey key) { + return ((EditorColorsManagerImpl)EditorColorsManager.getInstance()).getDefaultAttributes(key); + } +} diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index c2adba48c555..a1b54ee3d271 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -132,6 +132,8 @@ +