private Expression getCompileTimeConstantExpression() { // Must be static constant if (!isStatic() || !isFinal()) { return null; } IType type = getFeatureType(); // Must be either primitive, String, or Enum constant if (type != JavaTypes.STRING() && !type.isPrimitive() && !type.isEnum()) { return null; } // // Field must be initialized directly // if (getOwnersType().isDeclarationsCompiled()) { getOwnersType().isValid(); // barf } for (VarStatement varStmt : getOwnersType().getParseInfo().getStaticFields().values()) { // barf if (varStmt.getIdentifierName().toString().equals(getName())) { Expression initiazerExpr = varStmt.getAsExpression(); if (initiazerExpr != null) { return varStmt.isEnumConstant() || initiazerExpr.isCompileTimeConstant() ? initiazerExpr : null; } } } return null; }
@Override public Object doCompileTimeEvaluation() { Expression expr = getCompileTimeConstantExpression(); return expr instanceof INewExpression ? getName() // Enum constant field name : expr.evaluate(); }