本文整理汇总了Java中com.sun.tools.javac.code.Symbol.VarSymbol.getConstValue方法的典型用法代码示例。如果您正苦于以下问题:Java VarSymbol.getConstValue方法的具体用法?Java VarSymbol.getConstValue怎么用?Java VarSymbol.getConstValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.code.Symbol.VarSymbol
的用法示例。
在下文中一共展示了VarSymbol.getConstValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitVarDef
import com.sun.tools.javac.code.Symbol.VarSymbol; //导入方法依赖的package包/类
public void visitVarDef(JCVariableDecl tree) {
VarSymbol v = tree.sym;
code.newLocal(v);
if (tree.init != null) {
checkStringConstant(tree.init.pos(), v.getConstValue());
if (v.getConstValue() == null || varDebugInfo) {
genExpr(tree.init, v.erasure(types)).load();
items.makeLocalItem(v).store();
}
}
checkDimension(tree.pos(), v.type);
}
示例2: visitVarDef
import com.sun.tools.javac.code.Symbol.VarSymbol; //导入方法依赖的package包/类
public void visitVarDef(JCVariableDecl tree) {
VarSymbol v = tree.sym;
code.newLocal(v);
if (tree.init != null) {
checkStringConstant(tree.init.pos(), v.getConstValue());
if (v.getConstValue() == null || varDebugInfo) {
Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
genExpr(tree.init, v.erasure(types)).load();
items.makeLocalItem(v).store();
Assert.check(letExprDepth != 0 || code.state.stacksize == 0);
}
}
checkDimension(tree.pos(), v.type);
}
示例3: checkInit
import com.sun.tools.javac.code.Symbol.VarSymbol; //导入方法依赖的package包/类
/** Check that variable is initialized and evaluate the variable's
* initializer, if not yet done. Also check that variable is not
* referenced before it is defined.
* @param tree The tree making up the variable reference.
* @param env The current environment.
* @param v The variable's symbol.
*/
private void checkInit(JCTree tree,
Env<AttrContext> env,
VarSymbol v,
boolean onlyWarning) {
// System.err.println(v + " " + ((v.flags() & STATIC) != 0) + " " +
// tree.pos + " " + v.pos + " " +
// Resolve.isStatic(env));//DEBUG
// A forward reference is diagnosed if the declaration position
// of the variable is greater than the current tree position
// and the tree and variable definition occur in the same class
// definition. Note that writes don't count as references.
// This check applies only to class and instance
// variables. Local variables follow different scope rules,
// and are subject to definite assignment checking.
if ((env.info.enclVar == v || v.pos > tree.pos) &&
v.owner.kind == TYP &&
canOwnInitializer(env.info.scope.owner) &&
v.owner == env.info.scope.owner.enclClass() &&
((v.flags() & STATIC) != 0) == Resolve.isStatic(env) &&
(env.tree.getTag() != JCTree.ASSIGN ||
TreeInfo.skipParens(((JCAssign) env.tree).lhs) != tree)) {
String suffix = (env.info.enclVar == v) ?
"self.ref" : "forward.ref";
if (!onlyWarning || isStaticEnumField(v)) {
log.error(tree.pos(), "illegal." + suffix);
} else if (useBeforeDeclarationWarning) {
log.warning(tree.pos(), suffix, v);
}
}
v.getConstValue(); // ensure initializer is evaluated
checkEnumInitializer(tree, env, v);
}
示例4: checkSerialVersionUID
import com.sun.tools.javac.code.Symbol.VarSymbol; //导入方法依赖的package包/类
/** Check that an appropriate serialVersionUID member is defined. */
private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) {
// check for presence of serialVersionUID
Scope.Entry e = c.members().lookup(names.serialVersionUID);
while (e.scope != null && e.sym.kind != VAR) e = e.next();
if (e.scope == null) {
log.warning(LintCategory.SERIAL,
tree.pos(), "missing.SVUID", c);
return;
}
// check that it is static final
VarSymbol svuid = (VarSymbol)e.sym;
if ((svuid.flags() & (STATIC | FINAL)) !=
(STATIC | FINAL))
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c);
// check that it is long
else if (svuid.type.tag != TypeTags.LONG)
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c);
// check constant
else if (svuid.getConstValue() == null)
log.warning(LintCategory.SERIAL,
TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c);
}
示例5: visitVarDef
import com.sun.tools.javac.code.Symbol.VarSymbol; //导入方法依赖的package包/类
public void visitVarDef(JCVariableDecl tree) {
// Local variables have not been entered yet, so we need to do it now:
if (env.info.scope.owner.kind == MTH) {
if (tree.sym != null) {
// parameters have already been entered
env.info.scope.enter(tree.sym);
} else {
memberEnter.memberEnter(tree, env);
annotate.flush();
}
tree.sym.flags_field |= EFFECTIVELY_FINAL;
}
VarSymbol v = tree.sym;
Lint lint = env.info.lint.augment(v.attributes_field, v.flags());
Lint prevLint = chk.setLint(lint);
// Check that the variable's declared type is well-formed.
chk.validate(tree.vartype, env);
deferredLintHandler.flush(tree.pos());
try {
chk.checkDeprecatedAnnotation(tree.pos(), v);
if (tree.init != null) {
if ((v.flags_field & FINAL) != 0 && tree.init.getTag() != JCTree.NEWCLASS) {
// In this case, `v' is final. Ensure that it's initializer is
// evaluated.
v.getConstValue(); // ensure initializer is evaluated
} else {
// Attribute initializer in a new environment
// with the declared variable as owner.
// Check that initializer conforms to variable's declared type.
Env<AttrContext> initEnv = memberEnter.initEnv(tree, env);
initEnv.info.lint = lint;
// In order to catch self-references, we set the variable's
// declaration position to maximal possible value, effectively
// marking the variable as undefined.
initEnv.info.enclVar = v;
// de.so.ma
// perform sql query node transformation, if necessary
tree.init = SqlQueryNodeTransformer.getInstance()
.transformPotentialSqlQuery(tree.init, env, v.type, this, enter, memberEnter);
attribExpr(tree.init, initEnv, v.type);
}
}
result = tree.type = v.type;
chk.validateAnnotations(tree.mods.annotations, v);
}
finally {
chk.setLint(prevLint);
}
}