private void setConstField(ConstantExpression constantExpression) {
final Object n = constantExpression.getValue();
if (!(n instanceof Number || n instanceof Character)) return;
if (n instanceof Integer || n instanceof Double) return;
FieldNode field = (FieldNode) const2Var.get(n);
if (field!=null) {
constantExpression.setConstantName(field.getName());
return;
}
final String name = "$const$" + const2Var.size();
//TODO: this part here needs a bit of rethinking. If it can happen that the field is defined already,
// then is this code still valid?
field = currentClass.getDeclaredField(name);
if (field==null) {
field = new FieldNode(name,
Opcodes.ACC_PRIVATE|Opcodes.ACC_STATIC|Opcodes.ACC_SYNTHETIC| Opcodes.ACC_FINAL,
constantExpression.getType(),
currentClass,
constantExpression
);
field.setSynthetic(true);
missingFields.add(field);
}
constantExpression.setConstantName(field.getName());
const2Var.put(n, field);
}