本文整理汇总了Java中javax.lang.model.element.VariableElement.getConstantValue方法的典型用法代码示例。如果您正苦于以下问题:Java VariableElement.getConstantValue方法的具体用法?Java VariableElement.getConstantValue怎么用?Java VariableElement.getConstantValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.VariableElement
的用法示例。
在下文中一共展示了VariableElement.getConstantValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseCompiledR
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (SUPPORTED_TYPES.contains(innerClassName)) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName =
ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R",
innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
示例2: parseCompiledR
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (supportedTypes.contains(innerClassName)) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
示例3: parseCompiledR
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void parseCompiledR(String respectivePackageName, TypeElement rClass) {
for (Element element : rClass.getEnclosedElements()) {
String innerClassName = element.getSimpleName().toString();
if (innerClassName.equals("string")) {
for (Element enclosedElement : element.getEnclosedElements()) {
if (enclosedElement instanceof VariableElement) {
VariableElement variableElement = (VariableElement) enclosedElement;
Object value = variableElement.getConstantValue();
if (value instanceof Integer) {
int id = (Integer) value;
ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
String resourceName = variableElement.getSimpleName().toString();
QualifiedId qualifiedId = new QualifiedId(respectivePackageName, id);
symbols.put(qualifiedId, new Id(id, rClassName, resourceName));
}
}
}
}
}
}
示例4: visitVariable
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@Override
public PrintingElementVisitor visitVariable(VariableElement e, Boolean newLine) {
ElementKind kind = e.getKind();
defaultAction(e, newLine);
if (kind == ENUM_CONSTANT)
writer.print(e.getSimpleName());
else {
writer.print(e.asType().toString() + " " + e.getSimpleName() );
Object constantValue = e.getConstantValue();
if (constantValue != null) {
writer.print(" = ");
writer.print(elementUtils.getConstantExpression(constantValue));
}
writer.println(";");
}
return this;
}
示例5: KickbackElementClass
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
public KickbackElementClass(VariableElement variableElement, Elements elementUtils) throws VerifyException {
KickbackElement kickbackElement = variableElement.getAnnotation(KickbackElement.class);
Weak weak = variableElement.getAnnotation(Weak.class);
Soft soft = variableElement.getAnnotation(Soft.class);
PackageElement packageElement = elementUtils.getPackageOf(variableElement);
this.variableElement = variableElement;
this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
this.typeName = TypeName.get(variableElement.asType());
this.clazzName = variableElement.getSimpleName().toString();
this.value = variableElement.getConstantValue();
if(weak != null) this.isWeak = true;
else this.isWeak = false;
if(soft != null) this.isSoft = true;
else this.isSoft = false;
if(kickbackElement != null) {
this.elementName = StringUtils.toUpperCamel(Strings.isNullOrEmpty(kickbackElement.name()) ? this.clazzName : kickbackElement.name());
} else {
this.elementName = StringUtils.toUpperCamel(this.clazzName);
}
checkPrimitiveType();
checkModifierValidate();
checkAnnotationValidate();
}
示例6: findSerialVersionUID
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private Long findSerialVersionUID() {
for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) {
if (field.getSimpleName().contentEquals(SERIAL_VERSION_FIELD_NAME)
&& field.asType().getKind() == TypeKind.LONG) {
return (Long) field.getConstantValue();
}
}
return null;
}
示例7: visitVariable
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@Override
public Void visitVariable(VariableElement e, Boolean highlightName) {
modifier(e.getModifiers());
result.append(getTypeName(info, e.asType(), true));
result.append(' ');
boldStartCheck(highlightName);
result.append(e.getSimpleName());
boldStopCheck(highlightName);
if (highlightName) {
if (e.getConstantValue() != null) {
result.append(" = ");
result.append(StringEscapeUtils.escapeHtml(e.getConstantValue().toString()));
}
Element enclosing = e.getEnclosingElement();
if (e.getKind() != ElementKind.PARAMETER && e.getKind() != ElementKind.LOCAL_VARIABLE
&& e.getKind() != ElementKind.RESOURCE_VARIABLE && e.getKind() != ElementKind.EXCEPTION_PARAMETER) {
result.append(" in ");
//short typename:
result.append(getTypeName(info, enclosing.asType(), true));
}
}
return null;
}
示例8: generateJava
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void generateJava(TypeElement elements, List<VariableElement> fields) throws IOException {
JavaFileObject javaFileObject = mFiler.createSourceFile("ThroughConstant", elements);
PrintWriter writer = new PrintWriter(javaFileObject.openWriter());
writer.println("//Automatic generation, please do not modify ");
writer.println("package com.seasonfif.swiftrouter;");
writer.println("public class ThroughConstant {");
for (VariableElement field : fields) {
String fieldValue;
if (field.getConstantValue() instanceof String){
fieldValue = '"'+field.getConstantValue().toString()+'"';
}else {
fieldValue = field.getConstantValue().toString();
}
writer.println("public static final " + field.asType().toString() + " "
+ field.getSimpleName().toString()+ "="
+ fieldValue
+ ";");
}
writer.println("}");
writer.flush();
writer.close();
}
示例9: getEntries
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@Override
public List<Resource> getEntries(String name) {
List<Resource> resources = new ArrayList<>();
String location = name + "_" + FileStore.STANDARD.getPath();
TypeElement element = elements.getTypeElement(location);
if (element != null) {
VariableElement dataField = (VariableElement) element.getEnclosedElements().stream()
.filter(e -> FIELD_NAME.equals(e.getSimpleName().toString())
&& e.getKind() == ElementKind.FIELD).findFirst().orElse(null);
String data = (String) dataField.getConstantValue();
resources.add(new StringResource(location, data));
}
return resources;
}
示例10: PreferenceKeyField
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
public PreferenceKeyField(@NonNull VariableElement variableElement, @NonNull Elements elementUtils) throws IllegalAccessException {
KeyName annotation_keyName = variableElement.getAnnotation(KeyName.class);
this.variableElement = variableElement;
PackageElement packageElement = elementUtils.getPackageOf(variableElement);
this.packageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
this.typeName = TypeName.get(variableElement.asType());
this.clazzName = variableElement.getSimpleName().toString();
this.value = variableElement.getConstantValue();
setTypeStringName();
if(annotation_keyName != null)
this.keyName = Strings.isNullOrEmpty(annotation_keyName.name()) ? StringUtils.toUpperCamel(this.clazzName) : annotation_keyName.name();
else
this.keyName = StringUtils.toUpperCamel(this.clazzName);
if(this.isObjectField) {
variableElement.getAnnotationMirrors().stream()
.filter(annotationMirror -> TypeName.get(annotationMirror.getAnnotationType()).equals(TypeName.get(TypeConverter.class)))
.forEach(annotationMirror -> {
annotationMirror.getElementValues().forEach((type, value) -> {
String[] split = value.getValue().toString().split("\\.");
StringBuilder builder = new StringBuilder();
for (int i=0; i<split.length-1; i++)
builder.append(split[i] + ".");
this.converterPackage = builder.toString().substring(0, builder.toString().length()-1);
this.converter = split[split.length-1];
});
});
}
if(variableElement.getModifiers().contains(Modifier.PRIVATE)) {
throw new IllegalAccessException(String.format("Field \'%s\' should not be private.", variableElement.getSimpleName()));
} else if(!this.isObjectField && !variableElement.getModifiers().contains(Modifier.FINAL)) {
throw new IllegalAccessException(String.format("Field \'%s\' should be final.", variableElement.getSimpleName()));
}
}
示例11: hasConstantField
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
* Return true if the given class has constant fields to document.
*
* @param typeElement the class being checked.
* @return true if the given package has constant fields to document.
*/
private boolean hasConstantField (TypeElement typeElement) {
VisibleMemberMap visibleMemberMapFields = configuration.getVisibleMemberMap(typeElement,
VisibleMemberMap.Kind.FIELDS);
List<Element> fields = visibleMemberMapFields.getLeafMembers();
for (Element f : fields) {
VariableElement field = (VariableElement)f;
if (field.getConstantValue() != null) {
typeElementsWithConstFields.add(typeElement);
return true;
}
}
return false;
}
示例12: buildSerialUIDInfo
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
* Build the serial UID information for the given class.
*
* @param classTree content tree to which the serial UID information will be added
*/
protected void buildSerialUIDInfo(Content classTree) {
Content serialUidTree = writer.getSerialUIDInfoHeader();
for (Element e : utils.getFieldsUnfiltered(currentTypeElement)) {
VariableElement field = (VariableElement)e;
if (field.getSimpleName().toString().compareTo(SERIAL_VERSION_UID) == 0 &&
field.getConstantValue() != null) {
writer.addSerialUIDInfo(SERIAL_VERSION_UID_HEADER,
utils.constantValueExpresion(field), serialUidTree);
break;
}
}
classTree.addContent(serialUidTree);
}
示例13: isLegalSei
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
protected boolean isLegalSei(TypeElement interfaceElement) {
for (VariableElement field : ElementFilter.fieldsIn(interfaceElement.getEnclosedElements()))
if (field.getConstantValue() != null) {
builder.processError(WebserviceapMessages.WEBSERVICEAP_SEI_CANNOT_CONTAIN_CONSTANT_VALUES(
interfaceElement.getQualifiedName(), field.getSimpleName()));
return false;
}
return methodsAreLegal(interfaceElement);
}
示例14: 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;
}
示例15: getTagletOutput
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public Content getTagletOutput(Element holder, DocTree tag, TagletWriter writer) {
Utils utils = writer.configuration().utils;
Messages messages = writer.configuration().getMessages();
VariableElement field = getVariableElement(holder, writer.configuration(), tag);
if (field == null) {
if (tag.toString().isEmpty()) {
//Invalid use of @value
messages.warning(holder,
"doclet.value_tag_invalid_use");
} else {
//Reference is unknown.
messages.warning(holder,
"doclet.value_tag_invalid_reference", tag.toString());
}
} else if (field.getConstantValue() != null) {
return writer.valueTagOutput(field,
utils.constantValueExpresion(field),
// TODO: investigate and cleanup
// in the j.l.m world, equals will not be accurate
// !field.equals(tag.holder())
!utils.elementsEqual(field, holder)
);
} else {
//Referenced field is not a constant.
messages.warning(holder,
"doclet.value_tag_invalid_constant", utils.getSimpleName(field));
}
return writer.getOutputInstance();
}