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


Java VariableElement.getKind方法代码示例

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


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

示例1: createHtmlHeader

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private String createHtmlHeader(CompilationInfo info, VariableElement e, boolean isDeprecated,boolean isInherited, boolean fqn) {

        StringBuilder sb = new StringBuilder();

        if ( isDeprecated ) {
            sb.append("<s>"); // NOI18N
        }
        if( isInherited ) {
            sb.append( "<font color=" + ui.getInheritedColor() + ">" ); // NOI18N
        }
        sb.append(Utils.escape(e.getSimpleName().toString()));
        if ( isDeprecated ) {
            sb.append("</s>"); // NOI18N
        }

        if ( e.getKind() != ElementKind.ENUM_CONSTANT ) {
            sb.append( " : " ); // NOI18N
            sb.append( "<font color=" + ui.getTypeColor() + ">" ); // NOI18N
            sb.append(print(info, e.asType(), fqn));
            sb.append("</font>"); // NOI18N
        }

        return sb.toString();            
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ElementScanningTask.java

示例2: stripVariableName

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
     * Strips the variable name off prefixes and suffixes configured in the coding style. Handles 
     * fields, local variables, parameters and constants.
     * 
     * @param style the code style
     * @param el the variable element 
     * @return name stripped of prefixes/suffices
     */
    public static String stripVariableName(CodeStyle style, VariableElement el) {
        String n = el.getSimpleName().toString();
        switch (el.getKind()) {
            case PARAMETER:
                return stripVariableName(n, style.getParameterNamePrefix(), style.getParameterNameSuffix());
                
            case LOCAL_VARIABLE:
            case RESOURCE_VARIABLE:
            case EXCEPTION_PARAMETER:
                return stripVariableName(n, style.getLocalVarNamePrefix(), style.getLocalVarNameSuffix());
                
            case FIELD: {
//                boolean c = el.getModifiers().containsAll(EnumSet.of(Modifier.FINAL, Modifier.STATIC));
//                if (!c) {
//                    break;
//                }
                // fall through to enum constant
            }
            case ENUM_CONSTANT:
                return stripVariableName(n, style.getFieldNamePrefix(), style.getFieldNameSuffix());
                
            default:
                return n;
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:Utilities.java

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

示例4: createHtmlHeader

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private static String createHtmlHeader(boolean deprecated, VariableElement e) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    if (deprecated) sb.append("<s>");
    sb.append(e.getSimpleName());
    if (deprecated) sb.append("</s>");
    if ( e.getKind() != ElementKind.ENUM_CONSTANT ) {
        sb.append( " : " ); // NOI18N
        sb.append(translateToHTML(print(e.asType())));
    }
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ElementNode.java

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

示例6: checkNoLoggers

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
@TriggerTreeKind({Tree.Kind.ANNOTATION_TYPE, Tree.Kind.CLASS, Tree.Kind.ENUM, Tree.Kind.INTERFACE})
public static Iterable<ErrorDescription> checkNoLoggers(HintContext ctx) {
    Element cls = ctx.getInfo().getTrees().getElement(ctx.getPath());
    if (cls == null || cls.getKind() != ElementKind.CLASS || cls.getModifiers().contains(Modifier.ABSTRACT) ||
        (cls.getEnclosingElement() != null && cls.getEnclosingElement().getKind() != ElementKind.PACKAGE)
    ) {
        return null;
    }

    TypeElement loggerTypeElement = ctx.getInfo().getElements().getTypeElement("java.util.logging.Logger"); // NOI18N
    if (loggerTypeElement == null) {
        return null;
    }
    TypeMirror loggerTypeElementAsType = loggerTypeElement.asType();
    if (loggerTypeElementAsType == null || loggerTypeElementAsType.getKind() != TypeKind.DECLARED) {
        return null;
    }

    List<TypeMirror> customLoggersList = new ArrayList<>();
    if (isCustomEnabled(ctx.getPreferences())) {
        List<String> customLoggerClasses = getCustomLoggers(ctx.getPreferences());
        if (customLoggerClasses != null) {
            for (String className : customLoggerClasses) {
                TypeElement customTypeElement = ctx.getInfo().getElements().getTypeElement(className);
                if (customTypeElement == null) {
                    continue;
                }
                TypeMirror customTypeMirror = customTypeElement.asType();
                if (customTypeMirror == null || customTypeMirror.getKind() != TypeKind.DECLARED) {
                    continue;
                }
                customLoggersList.add(customTypeMirror);
            }
        }
    }

    List<VariableElement> loggerFields = new LinkedList<VariableElement>();
    List<VariableElement> fields = ElementFilter.fieldsIn(cls.getEnclosedElements());
    for(VariableElement f : fields) {
        if (f.getKind() != ElementKind.FIELD) {
            continue;
        }

        if (f.asType().equals(loggerTypeElementAsType)) {
            loggerFields.add(f);
        } else if (customLoggersList.contains(f.asType())) {
            loggerFields.add(f);
        }
    }

    if (loggerFields.size() == 0) {
        return Collections.singleton(ErrorDescriptionFactory.forName(
                ctx,
                ctx.getPath(),
                NbBundle.getMessage(NoLoggers.class, "MSG_NoLoggers_checkNoLoggers", cls), //NOI18N
                new NoLoggersFix(NbBundle.getMessage(NoLoggers.class, "MSG_NoLoggers_checkNoLoggers_Fix", cls), TreePathHandle.create(cls, ctx.getInfo())).toEditorFix() //NOI18N
        ));
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:NoLoggers.java

示例7: isNotVariable

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private static boolean isNotVariable(VariableElement variableElement) {
    return variableElement.getKind() == ElementKind.ENUM ||
            variableElement.getKind() == ElementKind.INTERFACE ||
            variableElement.getKind() == ElementKind.CLASS;
}
 
开发者ID:florent37,项目名称:RxAndroidOrm,代码行数:6,代码来源:ProcessUtils.java

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

示例9: getOrdinalValue

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
public int getOrdinalValue(VariableElement member) {
    if (member == null || member.getKind() != ENUM_CONSTANT) {
        throw new IllegalArgumentException("must be an enum constant: " + member);
    }
    return member.getEnclosingElement().getEnclosedElements().indexOf(member);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:Utils.java

示例10: isConstant

import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
 * Static helper method to determine if the given {@link VariableElement}
 * refers to a constant, i.e. a static final field.
 *
 * @param element
 * @return
 */
static boolean isConstant(final VariableElement element) {
	return element.getKind() == ElementKind.FIELD
			&& IS_STATIC_FINAL.test(element);
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:12,代码来源:Util.java


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