mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-40398 fixed class loading order issues that caused NPEs in syntax highlighters due to EditorColorsManager not initialized on time [r=cdr]
This commit is contained in:
@@ -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<TextAttributesKey>, JDOMExternalizable {
|
||||
private static final TextAttributes NULL_ATTRIBUTES = new TextAttributes();
|
||||
private static final ConcurrentHashMap<String, TextAttributesKey> ourRegistry = new ConcurrentHashMap<String, TextAttributesKey>();
|
||||
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<TextAttributesKey>, 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<TextAttributesKey>, J
|
||||
public interface TextAttributeKeyDefaultsProvider {
|
||||
TextAttributes getDefaultAttributes(TextAttributesKey key);
|
||||
}
|
||||
|
||||
public static TextAttributeKeyDefaultsProvider myDefaultsProvider;
|
||||
}
|
||||
|
||||
+8
-11
@@ -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() {
|
||||
|
||||
+30
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,8 @@
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager"
|
||||
serviceImplementation="com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.editor.colors.TextAttributesKey$TextAttributeKeyDefaultsProvider"
|
||||
serviceImplementation="com.intellij.openapi.editor.colors.impl.TextAttributeKeyDefaultsProviderImpl"/>
|
||||
<applicationService serviceInterface="com.intellij.openapi.editor.colors.EditorColorsManager"
|
||||
serviceImplementation="com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl"/>
|
||||
<exportable serviceInterface="com.intellij.openapi.editor.colors.EditorColorsManager"/>
|
||||
|
||||
Reference in New Issue
Block a user