made fields final to prevent some nasty bugs like EA-52519 - IAE: TObjectHash.throwObjectContractViolation

This commit is contained in:
Alexey Kudravtsev
2013-12-19 13:43:52 +04:00
parent 47267dc998
commit d0eb1689f4
12 changed files with 233 additions and 250 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -15,10 +15,7 @@
*/
package com.intellij.lang.annotation;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -30,9 +27,9 @@ import org.jetbrains.annotations.NotNull;
* @see com.intellij.lang.annotation.Annotation
*/
public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExternalizable {
public String myName;
public int myVal;
public class HighlightSeverity implements Comparable<HighlightSeverity> {
public final String myName;
public final int myVal;
/**
* The standard severity level for information annotations.
@@ -86,7 +83,9 @@ public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExt
//read external only
public HighlightSeverity() {
public HighlightSeverity(@NotNull Element element) {
myName = JDOMExternalizerUtil.readField(element, "myName");
myVal = Integer.valueOf(JDOMExternalizerUtil.readField(element, "myVal"));
}
public String toString() {
@@ -98,17 +97,10 @@ public class HighlightSeverity implements Comparable<HighlightSeverity>, JDOMExt
return myVal - highlightSeverity.myVal;
}
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
}
@Override
public void writeExternal(final Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element);
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -26,7 +26,6 @@ import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
@@ -101,14 +100,14 @@ public interface HighlightInfoType {
TextAttributesKey getAttributesKey();
class HighlightInfoTypeImpl implements HighlightInfoType, JDOMExternalizable {
class HighlightInfoTypeImpl implements HighlightInfoType {
private final HighlightSeverity mySeverity;
private final TextAttributesKey myAttributesKey;
//read external only
public HighlightInfoTypeImpl() {
mySeverity = new HighlightSeverity();
myAttributesKey = new TextAttributesKey();
HighlightInfoTypeImpl(@NotNull Element element) throws InvalidDataException {
mySeverity = new HighlightSeverity(element);
myAttributesKey = new TextAttributesKey(element);
}
public HighlightInfoTypeImpl(@NotNull HighlightSeverity severity, TextAttributesKey attributesKey) {
@@ -132,19 +131,11 @@ public interface HighlightInfoType {
return "HighlightInfoTypeImpl[severity=" + mySeverity + ", key=" + myAttributesKey + "]";
}
@Override
public void readExternal(Element element) throws InvalidDataException {
mySeverity.readExternal(element);
myAttributesKey.readExternal(element);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
mySeverity.writeExternal(element);
myAttributesKey.writeExternal(element);
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -46,10 +46,10 @@ import java.util.List;
* Date: 24-Feb-2006
*/
public class SeverityRegistrar implements JDOMExternalizable, Comparator<HighlightSeverity> {
@NonNls private static final String INFO = "info";
@NonNls private static final String INFO_TAG = "info";
@NonNls private static final String COLOR_ATTRIBUTE = "color";
private final Map<String, SeverityBasedTextAttributes> myMap = new THashMap<String, SeverityBasedTextAttributes>();
private final Map<String, Color> myRendererColors = new THashMap<String, Color>();
@NonNls private static final String COLOR = "color";
private final OrderMap myOrder = new OrderMap();
private JDOMExternalizableStringList myReadOrder;
@@ -120,15 +120,14 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
public void readExternal(Element element) throws InvalidDataException {
myMap.clear();
myRendererColors.clear();
final List children = element.getChildren(INFO);
final List children = element.getChildren(INFO_TAG);
for (Object child : children) {
final Element infoElement = (Element)child;
final SeverityBasedTextAttributes highlightInfo = new SeverityBasedTextAttributes();
highlightInfo.readExternal(infoElement);
final SeverityBasedTextAttributes highlightInfo = new SeverityBasedTextAttributes(infoElement);
Color color = null;
final String colorStr = infoElement.getAttributeValue(COLOR);
final String colorStr = infoElement.getAttributeValue(COLOR_ATTRIBUTE);
if (colorStr != null){
color = new Color(Integer.parseInt(colorStr, 16));
}
@@ -178,14 +177,14 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
public void writeExternal(Element element) throws WriteExternalException {
List<HighlightSeverity> list = getOrderAsList();
for (HighlightSeverity s : list) {
Element info = new Element(INFO);
Element info = new Element(INFO_TAG);
String severity = s.toString();
final SeverityBasedTextAttributes infoType = myMap.get(severity);
if (infoType != null) {
infoType.writeExternal(info);
final Color color = myRendererColors.get(severity);
if (color != null) {
info.setAttribute(COLOR, Integer.toString(color.getRGB() & 0xFFFFFF, 16));
info.setAttribute(COLOR_ATTRIBUTE, Integer.toString(color.getRGB() & 0xFFFFFF, 16));
}
element.addContent(info);
}
@@ -343,14 +342,14 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
}
}
public static class SeverityBasedTextAttributes implements JDOMExternalizable {
public static class SeverityBasedTextAttributes {
private final TextAttributes myAttributes;
private final HighlightInfoType.HighlightInfoTypeImpl myType;
//read external
public SeverityBasedTextAttributes() {
myAttributes = new TextAttributes();
myType = new HighlightInfoType.HighlightInfoTypeImpl();
public SeverityBasedTextAttributes(@NotNull Element element) throws InvalidDataException {
myAttributes = new TextAttributes(element);
myType = new HighlightInfoType.HighlightInfoTypeImpl(element);
}
public SeverityBasedTextAttributes(final TextAttributes attributes, final HighlightInfoType.HighlightInfoTypeImpl type) {
@@ -366,14 +365,7 @@ public class SeverityRegistrar implements JDOMExternalizable, Comparator<Highlig
return myType;
}
@Override
public void readExternal(Element element) throws InvalidDataException {
myAttributes.readExternal(element);
myType.readExternal(element);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
private void writeExternal(Element element) throws WriteExternalException {
myAttributes.writeExternal(element);
myType.writeExternal(element);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
/**
* A type of item with a distinct highlighting in an editor or in other views.
*/
public final class TextAttributesKey implements Comparable<TextAttributesKey>, JDOMExternalizable {
public final class TextAttributesKey implements Comparable<TextAttributesKey> {
private static final TextAttributes NULL_ATTRIBUTES = new TextAttributes();
private static final ConcurrentHashMap<String, TextAttributesKey> ourRegistry = new ConcurrentHashMap<String, TextAttributesKey>();
private static final NullableLazyValue<TextAttributeKeyDefaultsProvider> ourDefaultsProvider = new VolatileNullableLazyValue<TextAttributeKeyDefaultsProvider>() {
@@ -39,9 +39,8 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
}
};
public String myExternalName;
public TextAttributes myDefaultAttributes = NULL_ATTRIBUTES;
private final String myExternalName;
private TextAttributes myDefaultAttributes = NULL_ATTRIBUTES;
private TextAttributesKey myFallbackAttributeKey;
private TextAttributesKey(String externalName) {
@@ -49,10 +48,16 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
}
//read external only
public TextAttributesKey() {
public TextAttributesKey(@NotNull Element element) throws InvalidDataException {
this(JDOMExternalizerUtil.readField(element, "myExternalName"));
Element myDefaultAttributesElement = JDOMExternalizerUtil.getOption(element, "myDefaultAttributes");
if (myDefaultAttributesElement != null) {
myDefaultAttributes = new TextAttributes(myDefaultAttributesElement);
}
}
@NotNull public static TextAttributesKey find(@NotNull @NonNls String externalName) {
@NotNull
public static TextAttributesKey find(@NotNull @NonNls String externalName) {
return ourRegistry.cacheOrGet(externalName, new TextAttributesKey(externalName));
}
@@ -80,14 +85,13 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
return find(externalName);
}
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element);
JDOMExternalizerUtil.writeField(element, "myExternalName", myExternalName);
if (myDefaultAttributes != NULL_ATTRIBUTES) {
Element option = JDOMExternalizerUtil.writeOption(element, "myDefaultAttributes");
myDefaultAttributes.writeExternal(option);
}
}
@@ -115,8 +119,9 @@ public final class TextAttributesKey implements Comparable<TextAttributesKey>, J
if (myDefaultAttributes == NULL_ATTRIBUTES) {
myDefaultAttributes = null;
final TextAttributeKeyDefaultsProvider provider = ourDefaultsProvider.getValue();
if (provider != null)
if (provider != null) {
myDefaultAttributes = provider.getDefaultAttributes(this);
}
}
else if (myDefaultAttributes == null) {
myDefaultAttributes = NULL_ATTRIBUTES;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -20,26 +20,31 @@
package com.intellij.openapi.editor.markup;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizerUtil;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.StripedLockConcurrentHashMap;
import org.intellij.lang.annotations.JdkConstants;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.concurrent.ConcurrentMap;
public class AttributesFlyweight {
private static final StripedLockConcurrentHashMap<FlyweightKey, AttributesFlyweight> entries = new StripedLockConcurrentHashMap<FlyweightKey, AttributesFlyweight>();
private static final ConcurrentMap<FlyweightKey, AttributesFlyweight> entries = new StripedLockConcurrentHashMap<FlyweightKey, AttributesFlyweight>();
private static final ThreadLocal<FlyweightKey> ourKey = new ThreadLocal<FlyweightKey>();
private final int myHashCode;
private final Color myForeground;
private final Color myBackground;
private final Color myForeground;
private final Color myBackground;
@JdkConstants.FontStyle
private final int myFontType;
private final Color myEffectColor;
private final int myFontType;
private final Color myEffectColor;
private final EffectType myEffectType;
private final Color myErrorStripeColor;
private final Color myErrorStripeColor;
private static class FlyweightKey implements Cloneable {
private Color foreground;
@@ -128,6 +133,86 @@ public class AttributesFlyweight {
myHashCode = calcHashCode(foreground, background, fontType, effectColor, effectType, errorStripeColor);
}
@NotNull
public static AttributesFlyweight create(@NotNull Element element) throws InvalidDataException {
Color FOREGROUND = DefaultJDOMExternalizer.toColor(JDOMExternalizerUtil.readField(element, "FOREGROUND"));
Color BACKGROUND = DefaultJDOMExternalizer.toColor(JDOMExternalizerUtil.readField(element, "BACKGROUND"));
Color EFFECT_COLOR = DefaultJDOMExternalizer.toColor(JDOMExternalizerUtil.readField(element, "EFFECT_COLOR"));
Color ERROR_STRIPE_COLOR = DefaultJDOMExternalizer.toColor(JDOMExternalizerUtil.readField(element, "ERROR_STRIPE_COLOR"));
int fontType = DefaultJDOMExternalizer.toInt(JDOMExternalizerUtil.readField(element, "FONT_TYPE", "0"));
if (fontType < 0 || fontType > 3) {
fontType = 0;
}
int FONT_TYPE = fontType;
int EFFECT_TYPE = DefaultJDOMExternalizer.toInt(JDOMExternalizerUtil.readField(element, "EFFECT_TYPE", "0"));
return new AttributesFlyweight(FOREGROUND, BACKGROUND, FONT_TYPE, EFFECT_COLOR, toEffectType(EFFECT_TYPE), ERROR_STRIPE_COLOR);
}
private static void writeColor(Element element, String fieldName, Color color) {
if (color != null) {
String string = Integer.toString(color.getRGB() & 0xFFFFFF, 16);
JDOMExternalizerUtil.writeField(element, fieldName, string);
}
}
void writeExternal(@NotNull Element element) {
writeColor(element, "FOREGROUND", getForeground());
writeColor(element, "BACKGROUND", getBackground());
int fontType = getFontType();
if (fontType != 0) {
JDOMExternalizerUtil.writeField(element, "FONT_TYPE", String.valueOf(fontType));
}
writeColor(element, "EFFECT_COLOR", getEffectColor());
writeColor(element, "ERROR_STRIPE_COLOR", getErrorStripeColor());
JDOMExternalizerUtil.writeField(element, "EFFECT_TYPE", String.valueOf(fromEffectType(getEffectType())));
}
private static final int EFFECT_BORDER = 0;
private static final int EFFECT_LINE = 1;
private static final int EFFECT_WAVE = 2;
private static final int EFFECT_STRIKEOUT = 3;
private static final int EFFECT_BOLD_LINE = 4;
private static final int EFFECT_BOLD_DOTTED_LINE = 5;
private static int fromEffectType(EffectType effectType) {
int EFFECT_TYPE;
if (effectType == EffectType.BOXED) {
EFFECT_TYPE = EFFECT_BORDER;
}
else if (effectType == EffectType.LINE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_LINE;
}
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_BOLD_LINE;
}
else if (effectType == EffectType.STRIKEOUT) {
EFFECT_TYPE = EFFECT_STRIKEOUT;
}
else if (effectType == EffectType.WAVE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_WAVE;
}
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
EFFECT_TYPE = EFFECT_BOLD_DOTTED_LINE;
}
else {
EFFECT_TYPE = -1;
}
return EFFECT_TYPE;
}
private static EffectType toEffectType(int effectType) {
switch (effectType) {
case EFFECT_BORDER: return EffectType.BOXED;
case EFFECT_BOLD_LINE: return EffectType.BOLD_LINE_UNDERSCORE;
case EFFECT_LINE: return EffectType.LINE_UNDERSCORE;
case EFFECT_STRIKEOUT: return EffectType.STRIKEOUT;
case EFFECT_WAVE: return EffectType.WAVE_UNDERSCORE;
case EFFECT_BOLD_DOTTED_LINE: return EffectType.BOLD_DOTTED_LINE;
default: return null;
}
}
private static int calcHashCode(Color foreground,
Color background,
int fontType,
@@ -16,7 +16,6 @@
package com.intellij.openapi.editor.markup;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
@@ -27,7 +26,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.lang.reflect.Field;
/**
* Defines the visual representation (colors and effects) of text.
@@ -37,7 +35,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
public static final TextAttributes ERASE_MARKER = new TextAttributes();
private boolean myEnforcedDefaults = false;
private boolean myEnforcedDefaults;
@NotNull
private AttributesFlyweight myAttrs;
@@ -70,103 +68,19 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
return attrs;
}
private static class Externalizable implements Cloneable, JDOMExternalizable {
public Color FOREGROUND = null;
public Color BACKGROUND = null;
@JdkConstants.FontStyle
public int FONT_TYPE = Font.PLAIN;
public Color EFFECT_COLOR = null;
public int EFFECT_TYPE = EFFECT_BORDER;
public Color ERROR_STRIPE_COLOR = null;
private static final int EFFECT_BORDER = 0;
private static final int EFFECT_LINE = 1;
private static final int EFFECT_WAVE = 2;
private static final int EFFECT_STRIKEOUT = 3;
private static final int EFFECT_BOLD_LINE = 4;
private static final int EFFECT_BOLD_DOTTED_LINE = 5;
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
if (FONT_TYPE < 0 || FONT_TYPE > 3) {
LOG.info("Wrong font type: " + FONT_TYPE);
FONT_TYPE = 0;
}
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
DefaultJDOMExternalizer.writeExternal(this, element, new DefaultJDOMExternalizer.JDOMFilter() {
@Override
public boolean isAccept(@NotNull Field field) {
try {
if (field.getType().equals(Color.class) && field.get(Externalizable.this) == null) return false;
if (field.getType().equals(int.class) && field.getInt(Externalizable.this) == 0) return false;
}
catch (IllegalAccessException e) {
LOG.error("Can not access: " + field.getName());
}
return true;
}
});
}
private EffectType getEffectType() {
switch (EFFECT_TYPE) {
case EFFECT_BORDER:
return EffectType.BOXED;
case EFFECT_BOLD_LINE:
return EffectType.BOLD_LINE_UNDERSCORE;
case EFFECT_LINE:
return EffectType.LINE_UNDERSCORE;
case EFFECT_STRIKEOUT:
return EffectType.STRIKEOUT;
case EFFECT_WAVE:
return EffectType.WAVE_UNDERSCORE;
case EFFECT_BOLD_DOTTED_LINE:
return EffectType.BOLD_DOTTED_LINE;
default:
return null;
}
}
private void setEffectType(EffectType effectType) {
if (effectType == EffectType.BOXED) {
EFFECT_TYPE = EFFECT_BORDER;
}
else if (effectType == EffectType.LINE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_LINE;
}
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_BOLD_LINE;
}
else if (effectType == EffectType.STRIKEOUT) {
EFFECT_TYPE = EFFECT_STRIKEOUT;
}
else if (effectType == EffectType.WAVE_UNDERSCORE) {
EFFECT_TYPE = EFFECT_WAVE;
}
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
EFFECT_TYPE = EFFECT_BOLD_DOTTED_LINE;
}
else {
EFFECT_TYPE = -1;
}
}
}
public TextAttributes() {
this(null, null, null, EffectType.BOXED, Font.PLAIN);
}
private TextAttributes(@NotNull AttributesFlyweight attributesFlyweight, boolean enforced) {
myAttrs = attributesFlyweight;
myEnforcedDefaults = enforced;
}
public TextAttributes(@NotNull Element element) throws InvalidDataException {
readExternal(element);
}
public TextAttributes(@Nullable Color foregroundColor, @Nullable Color backgroundColor, @Nullable Color effectColor, EffectType effectType, @JdkConstants.FontStyle int fontType) {
setAttributes(foregroundColor, backgroundColor, effectColor, null, effectType, fontType);
}
@@ -262,10 +176,7 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
@Override
public TextAttributes clone() {
TextAttributes cloned = new TextAttributes();
cloned.myAttrs = myAttrs;
cloned.myEnforcedDefaults = myEnforcedDefaults;
return cloned;
return new TextAttributes(myAttrs, myEnforcedDefaults);
}
public boolean equals(Object obj) {
@@ -282,24 +193,13 @@ public class TextAttributes implements JDOMExternalizable, Cloneable {
@Override
public void readExternal(Element element) throws InvalidDataException {
Externalizable ext = new Externalizable();
ext.readExternal(element);
myAttrs = AttributesFlyweight.create(ext.FOREGROUND, ext.BACKGROUND, ext.FONT_TYPE, ext.EFFECT_COLOR, ext.getEffectType(), ext.ERROR_STRIPE_COLOR);
myAttrs = AttributesFlyweight.create(element);
if (isEmpty()) myEnforcedDefaults = true;
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
Externalizable ext = new Externalizable();
ext.FOREGROUND = myAttrs.getForeground();
ext.BACKGROUND = myAttrs.getBackground();
ext.FONT_TYPE = myAttrs.getFontType();
ext.EFFECT_COLOR = myAttrs.getEffectColor();
ext.ERROR_STRIPE_COLOR = myAttrs.getErrorStripeColor();
ext.setEffectType(myAttrs.getEffectType());
ext.writeExternal(element);
myAttrs.writeExternal(element);
}
@Override
@@ -331,9 +331,8 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme {
Element e = (Element)o;
String key = e.getAttributeValue(NAME_ATTR);
TextAttributesKey name = TextAttributesKey.find(key);
TextAttributes attr = new TextAttributes();
Element value = e.getChild(VALUE_ELEMENT);
attr.readExternal(value);
TextAttributes attr = new TextAttributes(value);
myAttributesMap.put(name, attr);
migrateErrorStripeColorFrom45(name, attr);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -31,7 +31,7 @@ import javax.swing.*;
public class TodoAttributes implements Cloneable {
private Icon myIcon;
private TextAttributes myTextAttributes = new TextAttributes();
private TextAttributes myTextAttributes;
private boolean myShouldUseCustomColors;
@NonNls private static final String ATTRIBUTE_ICON = "icon";
@@ -56,10 +56,12 @@ public class TodoAttributes implements Cloneable {
else{
throw new InvalidDataException(icon);
}
myTextAttributes.readExternal(element);
if (element.getChild(ELEMENT_OPTION) == null) {
myTextAttributes = defaultTodoAttributes;
}
else {
myTextAttributes = new TextAttributes(element);
}
// default color setting
final String useCustomColors = element.getAttributeValue(USE_CUSTOM_COLORS_ATT);
@@ -1,5 +1,17 @@
/*
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
* Copyright 2000-2013 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.
*/
/*
@@ -15,28 +27,10 @@ import junit.framework.TestCase;
import org.jdom.Element;
public class HighlightSeveritiesTest extends TestCase {
private int myOldSeverity;
@Override
protected void setUp() throws Exception {
super.setUp();
myOldSeverity = HighlightSeverity.ERROR.myVal;
}
@Override
protected void tearDown() throws Exception {
HighlightSeverity.ERROR.myVal = myOldSeverity;
super.tearDown();
}
public void testSeveritiesMigration() throws Exception{
HighlightSeverity.ERROR.myVal = 200;
final Element element = new Element("temp");
new HighlightSeverity(HighlightSeverity.ERROR.myName, 500).writeExternal(element);
HighlightSeverity.ERROR.readExternal(element);
assertEquals(500, HighlightSeverity.ERROR.myVal);
HighlightSeverity newSeverity = new HighlightSeverity(element);
assertEquals(500, newSeverity.myVal);
}
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.EffectType;
@@ -345,7 +346,8 @@ public class ExpectedHighlightingData {
return toContinueFrom;
}
private static final HighlightInfoType WHATEVER = new HighlightInfoType.HighlightInfoTypeImpl();
private static final HighlightInfoType WHATEVER = new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION,
HighlighterColors.TEXT);
public void checkLineMarkers(Collection<LineMarkerInfo> markerInfos, String text) {
String fileName = myFile == null ? "" : myFile.getName() + ": ";
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -202,12 +202,8 @@ public class DefaultJDOMExternalizer {
}
}
else if (type.equals(int.class)) {
try {
field.setInt(data, Integer.parseInt(value));
}
catch (NumberFormatException ex) {
throw new InvalidDataException();
}
int i = toInt(value);
field.setInt(data, i);
}
else if (type.equals(long.class)) {
try {
@@ -259,19 +255,8 @@ public class DefaultJDOMExternalizer {
field.set(data, value);
}
else if (type.equals(Color.class)) {
if (value != null) {
try {
int rgb = Integer.parseInt(value, 16);
field.set(data, new Color(rgb));
}
catch (NumberFormatException ex) {
LOG.debug("Wrong color value: " + value, ex);
throw new InvalidDataException();
}
}
else {
field.set(data, null);
}
Color color = toColor(value);
field.set(data, color);
}
else if (ReflectionCache.isAssignable(JDOMExternalizable.class, type)) {
final List children = e.getChildren("value");
@@ -305,4 +290,33 @@ public class DefaultJDOMExternalizer {
}
}
}
public static int toInt(@NotNull String value) throws InvalidDataException {
int i;
try {
i = Integer.parseInt(value);
}
catch (NumberFormatException ex) {
throw new InvalidDataException(value, ex);
}
return i;
}
public static Color toColor(@Nullable String value) throws InvalidDataException {
Color color;
if (value == null) {
color = null;
}
else {
try {
int rgb = Integer.parseInt(value, 16);
color = new Color(rgb);
}
catch (NumberFormatException ex) {
LOG.debug("Wrong color value: " + value, ex);
throw new InvalidDataException("Wrong color value: " + value, ex);
}
}
return color;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -15,19 +15,14 @@
*/
package com.intellij.openapi.util;
import com.intellij.openapi.diagnostic.Logger;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@SuppressWarnings({"HardCodedStringLiteral"})
public class JDOMExternalizerUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.JDOMExternalizerUtil");
public static void writeField(Element root, @NonNls String fieldName, String value) {
public static void writeField(@NotNull Element root, @NotNull @NonNls String fieldName, String value) {
Element element = new Element("option");
element.setAttribute("name", fieldName);
element.setAttribute("value", value == null ? "" : value);
@@ -35,20 +30,14 @@ public class JDOMExternalizerUtil {
}
@NotNull
public static String readField(Element parent, @NonNls String fieldName, @NotNull String defaultValue) {
public static String readField(@NotNull Element parent, @NotNull @NonNls String fieldName, @NotNull String defaultValue) {
String val = readField(parent, fieldName);
if (val != null) {
return val;
} else {
return defaultValue;
}
return val == null ? defaultValue : val;
}
@Nullable
public static String readField(Element parent, @NonNls String fieldName) {
List list = parent.getChildren("option");
for (int i = 0; i < list.size(); i++) {
Element element = (Element)list.get(i);
public static String readField(@NotNull Element parent, @NotNull @NonNls String fieldName) {
for (Element element : JDOMUtil.getChildren(parent, "option")) {
String childName = element.getAttributeValue("name");
if (Comparing.strEqual(childName, fieldName)) {
return element.getAttributeValue("value");
@@ -56,4 +45,22 @@ public class JDOMExternalizerUtil {
}
return null;
}
public static Element getOption(@NotNull Element parent, @NotNull @NonNls String fieldName) {
for (Element element : JDOMUtil.getChildren(parent, "option")) {
String childName = element.getAttributeValue("name");
if (Comparing.strEqual(childName, fieldName)) {
return element;
}
}
return null;
}
@NotNull
public static Element writeOption(@NotNull Element root, @NotNull @NonNls String fieldName) {
Element element = new Element("option");
element.setAttribute("name", fieldName);
root.addContent(element);
return element;
}
}