IDEA-127533 int field is displayed as char
This commit is contained in:
@@ -442,6 +442,11 @@ public class ClassWriter {
|
||||
}
|
||||
else {
|
||||
buffer.append(" = ");
|
||||
|
||||
if (initializer.type == Exprent.EXPRENT_CONST) {
|
||||
((ConstExprent) initializer).adjustConstType(fieldType);
|
||||
}
|
||||
|
||||
// FIXME: special case field initializer. Can map to more than one method (constructor) and bytecode intruction.
|
||||
buffer.append(initializer.toJava(indent, tracer));
|
||||
}
|
||||
|
||||
@@ -885,6 +885,10 @@ public class ExprProcessor implements CodeConstants {
|
||||
|
||||
if (quote) buffer.append('(');
|
||||
|
||||
if (exprent.type == Exprent.EXPRENT_CONST) {
|
||||
((ConstExprent) exprent).adjustConstType(leftType);
|
||||
}
|
||||
|
||||
buffer.append(exprent.toJava(indent, tracer));
|
||||
|
||||
if (quote) buffer.append(')');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -138,6 +138,10 @@ public class AssignmentExprent extends Exprent {
|
||||
buffer.append(left.toJava(indent, tracer));
|
||||
}
|
||||
|
||||
if (right.type == EXPRENT_CONST) {
|
||||
((ConstExprent) right).adjustConstType(leftType);
|
||||
}
|
||||
|
||||
TextBuffer res = right.toJava(indent, tracer);
|
||||
|
||||
if (condType == CONDITION_NONE &&
|
||||
|
||||
@@ -367,6 +367,21 @@ public class ConstExprent extends Exprent {
|
||||
this.constType = constType;
|
||||
}
|
||||
|
||||
public void adjustConstType(VarType expectedType) {
|
||||
// BYTECHAR and SHORTCHAR => CHAR in the CHAR context
|
||||
if (expectedType.equals(VarType.VARTYPE_CHAR) &&
|
||||
(constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) {
|
||||
if (getIntValue() != 0) {
|
||||
setConstType(VarType.VARTYPE_CHAR);
|
||||
}
|
||||
}
|
||||
// CHAR => INT in the INT context
|
||||
else if (expectedType.equals(VarType.VARTYPE_INT) &&
|
||||
constType.equals(VarType.VARTYPE_CHAR)) {
|
||||
setConstType(VarType.VARTYPE_INT);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -459,7 +459,20 @@ public class FunctionExprent extends Exprent {
|
||||
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
|
||||
}
|
||||
|
||||
// try to determine more accurate type for 'char' literals
|
||||
if (funcType >= FUNCTION_EQ) {
|
||||
if (funcType <= FUNCTION_LE) {
|
||||
Exprent left = lstOperands.get(0);
|
||||
Exprent right = lstOperands.get(1);
|
||||
|
||||
if (right.type == EXPRENT_CONST) {
|
||||
((ConstExprent) right).adjustConstType(left.getExprType());
|
||||
}
|
||||
else if (left.type == EXPRENT_CONST) {
|
||||
((ConstExprent) left).adjustConstType(right.getExprType());
|
||||
}
|
||||
}
|
||||
|
||||
return wrapOperandString(lstOperands.get(0), false, indent, tracer)
|
||||
.append(OPERATORS[funcType - FUNCTION_EQ + 11])
|
||||
.append(wrapOperandString(lstOperands.get(1), true, indent, tracer));
|
||||
|
||||
Reference in New Issue
Block a user