当前位置: 首页>>代码示例>>Java>>正文


Java VariableElement.getModifiers方法代码示例

本文整理汇总了Java中javax.lang.model.element.VariableElement.getModifiers方法的典型用法代码示例。如果您正苦于以下问题:Java VariableElement.getModifiers方法的具体用法?Java VariableElement.getModifiers怎么用?Java VariableElement.getModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.VariableElement的用法示例。


在下文中一共展示了VariableElement.getModifiers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeVariableString

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
 * Creates a String representation of a variable element with everything
 * necessary to track all public aspects of it in an API.
 * @param e Element to create String for.
 * @return String representation of element.
 */
protected String makeVariableString(VariableElement e) {
    StringBuilder result = new StringBuilder();
    for (Modifier modifier : e.getModifiers()) {
        result.append(modifier.toString());
        result.append(" ");
    }
    result.append(e.asType().toString());
    result.append(" ");
    result.append(e.toString());
    Object value = e.getConstantValue();
    if (value != null) {
        result.append(" = ");
        if (e.asType().toString().equals("char")) {
            int v = (int)value.toString().charAt(0);
            result.append("'\\u"+Integer.toString(v,16)+"'");
        } else {
            result.append(value.toString());
        }
    }
    return result.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:PubapiVisitor.java

示例2: getTypeColumn

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
 * Get the type column for the constant summary table row.
 *
 * @param member the field to be documented.
 * @return the type column of the constant table row
 */
private Content getTypeColumn(VariableElement member) {
    Content anchor = getMarkerAnchor(currentTypeElement.getQualifiedName() +
            "." + member.getSimpleName());
    Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor);
    Content code = new HtmlTree(HtmlTag.CODE);
    for (Modifier mod : member.getModifiers()) {
        Content modifier = new StringContent(mod.toString());
        code.addContent(modifier);
        code.addContent(Contents.SPACE);
    }
    Content type = getLink(new LinkInfoImpl(configuration,
            LinkInfoImpl.Kind.CONSTANT_SUMMARY, member.asType()));
    code.addContent(type);
    tdType.addContent(code);
    return tdType;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ConstantsSummaryWriterImpl.java

示例3: addConstant

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void addConstant(VariableElement v) {
    Set<Modifier> mods = v.getModifiers();
    if (!(mods.contains(Modifier.FINAL) && mods.contains(Modifier.STATIC))) {
        return;
    }
    
    boolean ok = false;
    
    // check that the return type is the same as this class' type
    if (!compilationInfo.getTypes().isSameType(
            v.asType(), classElement.asType())) {
        // the constant may be primitive & our type the wrapper
        TypeMirror t = v.asType();
        if (t instanceof PrimitiveType) {
            PrimitiveType p = (PrimitiveType)t;
            if (compilationInfo.getTypes().isSameType(
                    compilationInfo.getTypes().boxedClass(p).asType(),
                    classElement.asType())) {
                ok = true;
            }
        } 
        if (!ok) {
            return;
        }
    }
    
    addConstant(v.getSimpleName().toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:BeanModelBuilder.java

示例4: filterStaticFinal

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
public static List<VariableElement> filterStaticFinal(List<VariableElement> elements) {
    List<VariableElement> filtered = new ArrayList<>();
    for (VariableElement variableElement : elements) {
        final Set<Modifier> modifiers = variableElement.getModifiers();
        if (!modifiers.containsAll(Arrays.asList(Modifier.FINAL, Modifier.STATIC))) {
            filtered.add(variableElement);
        }
    } return filtered;
}
 
开发者ID:florent37,项目名称:RxAndroidOrm,代码行数:10,代码来源:ProcessUtils.java

示例5: 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

示例6: scanFields

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void scanFields(TypeElement node) {
    TypeElement currentClazz = node;
    do {
        for (VariableElement field : ElementFilter.fieldsIn(currentClazz.getEnclosedElements())) {
            Set<Modifier> modifiers = field.getModifiers();
            if (modifiers.contains(STATIC) || modifiers.contains(TRANSIENT)) {
                continue;
            }

            List<? extends AnnotationMirror> annotations = field.getAnnotationMirrors();

            boolean isNonOptionalInput = findAnnotationMirror(annotations, Input) != null;
            boolean isOptionalInput = findAnnotationMirror(annotations, OptionalInput) != null;
            boolean isSuccessor = findAnnotationMirror(annotations, Successor) != null;

            if (isNonOptionalInput || isOptionalInput) {
                if (findAnnotationMirror(annotations, Successor) != null) {
                    throw new ElementException(field, "Field cannot be both input and successor");
                } else if (isNonOptionalInput && isOptionalInput) {
                    throw new ElementException(field, "Inputs must be either optional or non-optional");
                } else if (isAssignableWithErasure(field, NodeInputList)) {
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Input list field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Input list field must not be public");
                    }
                } else {
                    if (!isAssignableWithErasure(field, Node) && field.getKind() == ElementKind.INTERFACE) {
                        throw new ElementException(field, "Input field type must be an interface or assignable to Node");
                    }
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Input field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Input field must not be public");
                    }
                }
            } else if (isSuccessor) {
                if (isAssignableWithErasure(field, NodeSuccessorList)) {
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Successor list field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Successor list field must not be public");
                    }
                } else {
                    if (!isAssignableWithErasure(field, Node)) {
                        throw new ElementException(field, "Successor field must be a Node type");
                    }
                    if (modifiers.contains(FINAL)) {
                        throw new ElementException(field, "Successor field must not be final");
                    }
                    if (modifiers.contains(PUBLIC)) {
                        throw new ElementException(field, "Successor field must not be public");
                    }
                }

            } else {
                if (isAssignableWithErasure(field, Node) && !field.getSimpleName().contentEquals("Null")) {
                    throw new ElementException(field, "Node field must be annotated with @" + Input.getSimpleName() + ", @" + OptionalInput.getSimpleName() + " or @" + Successor.getSimpleName());
                }
                if (isAssignableWithErasure(field, NodeInputList)) {
                    throw new ElementException(field, "NodeInputList field must be annotated with @" + Input.getSimpleName() + " or @" + OptionalInput.getSimpleName());
                }
                if (isAssignableWithErasure(field, NodeSuccessorList)) {
                    throw new ElementException(field, "NodeSuccessorList field must be annotated with @" + Successor.getSimpleName());
                }
                if (modifiers.contains(PUBLIC) && !modifiers.contains(FINAL)) {
                    throw new ElementException(field, "Data field must be final if public");
                }
            }
        }
        currentClazz = getSuperType(currentClazz);
    } while (!isObject(getSuperType(currentClazz).asType()));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:GraphNodeVerifier.java


注:本文中的javax.lang.model.element.VariableElement.getModifiers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。