IDEA-201267 Color icon is not correct for JBColor objects

This commit is contained in:
Egor Ushakov
2018-10-26 11:58:17 +03:00
parent 468434ddb5
commit 5ceda3102a
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.debugger.ui.tree.render;
import com.intellij.debugger.engine.evaluation.EvaluateException;
@@ -25,6 +11,7 @@ import com.sun.jdi.*;
import javax.swing.*;
import java.awt.*;
import java.util.Collections;
class ColorObjectRenderer extends CompoundReferenceRenderer {
ColorObjectRenderer(final NodeRendererSettings rendererSettings) {
@@ -35,17 +22,26 @@ class ColorObjectRenderer extends CompoundReferenceRenderer {
@Override
public Icon calcValueIcon(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener) throws EvaluateException {
final Value value = descriptor.getValue();
Value value = descriptor.getValue();
if (value instanceof ObjectReference) {
try {
final ObjectReference objRef = (ObjectReference)value;
final ReferenceType refType = objRef.referenceType();
final Field valueField = refType.fieldByName("value");
if (valueField != null) {
final Value rgbValue = objRef.getValue(valueField);
ObjectReference objRef = (ObjectReference)value;
ReferenceType refType = objRef.referenceType();
if (refType instanceof ClassType) {
Value rgbValue = null;
Method getRGBMethod = ((ClassType)refType).concreteMethodByName("getRGB", "()I");
if (getRGBMethod == null || getRGBMethod.declaringType().name().equals(getClassName())) { // getRGB is not overridden
Field valueField = refType.fieldByName("value");
if (valueField != null) {
rgbValue = objRef.getValue(valueField);
}
}
if (rgbValue == null && getRGBMethod != null) {
rgbValue = evaluationContext.getDebugProcess().invokeMethod(evaluationContext, objRef, getRGBMethod, Collections.emptyList());
}
if (rgbValue instanceof IntegerValue) {
@SuppressWarnings("UseJBColor")
final Color color = new Color(((IntegerValue)rgbValue).value(), true);
Color color = new Color(((IntegerValue)rgbValue).value(), true);
return JBUI.scale(new ColorIcon(16, 12, color, true));
}
}