Java 类com.intellij.psi.impl.PsiConstantEvaluationHelperImpl 实例源码

项目:consulo-java    文件:PsiLocalVariableImpl.java   
@Override
public Object computeConstantValue(Set<PsiVariable> visitedVars) {
  if (!hasModifierProperty(PsiModifier.FINAL)) return null;

  PsiType type = getType();
  // javac rejects all non primitive and non String constants, although JLS states constants "variables whose initializers are constant expressions"
  if (!(type instanceof PsiPrimitiveType) && !type.equalsToText("java.lang.String")) return null;

  PsiExpression initializer = getInitializer();
  if (initializer == null) return null;
  return PsiConstantEvaluationHelperImpl.computeCastTo(initializer, getType(), visitedVars);
}
项目:consulo-java    文件:PsiFieldImpl.java   
@Nullable
private Object _computeConstantValue(Set<PsiVariable> visitedVars)
{
    PsiType type = getType();
    // javac rejects all non primitive and non String constants, although JLS states constants "variables whose initializers are constant expressions"
    if(!(type instanceof PsiPrimitiveType) && !type.equalsToText("java.lang.String"))
    {
        return null;
    }

    PsiExpression initializer = getDetachedInitializer();

    return PsiConstantEvaluationHelperImpl.computeCastTo(initializer, type, visitedVars);
}