當前位置: 首頁>>代碼示例>>Java>>正文


Java VariableElement.getConstantValue方法代碼示例

本文整理匯總了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));
          }
        }
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:ButterKnifeProcessor.java

示例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));
                    }
                }
            }
        }
    }
}
 
開發者ID:hendraanggrian,項目名稱:r-parser,代碼行數:22,代碼來源:RParser.java

示例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));
                    }
                }
            }
        }
    }
}
 
開發者ID:WellingtonCosta,項目名稱:convalida,代碼行數:22,代碼來源:ConvalidaProcessor.java

示例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;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:19,代碼來源:PrintingProcessor.java

示例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();
}
 
開發者ID:skydoves,項目名稱:Kickback,代碼行數:26,代碼來源:KickbackElementClass.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:ValueType.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:GoToSupport.java

示例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();
    }
 
開發者ID:seasonfif,項目名稱:SwiftModule,代碼行數:29,代碼來源:ModuleProcessor.java

示例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;
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:15,代碼來源:AptResourceLoader.java

示例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()));
    }
}
 
開發者ID:skydoves,項目名稱:PreferenceRoom,代碼行數:37,代碼來源:PreferenceKeyField.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:ConstantsSummaryBuilder.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:SerializedFormBuilder.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:WebServiceVisitor.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:PubapiVisitor.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:ValueTaglet.java


注:本文中的javax.lang.model.element.VariableElement.getConstantValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。