本文整理匯總了Java中javax.lang.model.element.VariableElement.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java VariableElement.toString方法的具體用法?Java VariableElement.toString怎麽用?Java VariableElement.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.element.VariableElement
的用法示例。
在下文中一共展示了VariableElement.toString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitVariable
import javax.lang.model.element.VariableElement; //導入方法依賴的package包/類
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Void visitVariable(VariableElement e, Void p) {
if (isNonPrivate(e)) {
Object constVal = e.getConstantValue();
String constValStr = null;
// TODO: This doesn't seem to be entirely accurate. What if I change
// from, say, 0 to 0L? (And the field is public final static so that
// it could get inlined.)
if (constVal != null) {
if (e.asType().toString().equals("char")) {
// What type is 'value'? Is it already a char?
char c = constVal.toString().charAt(0);
constValStr = "'" + encodeChar(c) + "'";
} else {
constValStr = constVal.toString()
.chars()
.mapToObj(PubapiVisitor::encodeChar)
.collect(Collectors.joining("", "\"", "\""));
}
}
PubVar v = new PubVar(e.getModifiers(),
TypeDesc.fromType(e.asType()),
e.toString(),
constValStr);
collectedApi.variables.put(v.identifier, v);
}
// Safe to not recurse here, because the only thing
// to visit here is the constructor of a variable declaration.
// If it happens to contain an anonymous inner class (which it might)
// then this class is never visible outside of the package anyway, so
// we are allowed to ignore it here.
return null;
}