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


Java TypeElement.getEnclosedElements方法代码示例

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


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

示例1: BundlerClassInfo

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public BundlerClassInfo(TypeElement te) {
    typeElement = te;
    className = ClassName.get(typeElement);

    for (Element e : te.getEnclosedElements()) {
        if (e.getKind() == ElementKind.FIELD) {
            VariableElement ve = (VariableElement) e;
            fields.add(ve);
        }

        if (e.getKind() == ElementKind.METHOD) {
            ExecutableElement ee = (ExecutableElement) e;
            methods.add(ee);
        }
    }
}
 
开发者ID:google,项目名称:easybundler,代码行数:17,代码来源:BundlerClassInfo.java

示例2: visitType

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public TypeElement visitType(TypeElement typeElement, String binaryName) {
    String bName = ElementUtilities.getBinaryName(typeElement);
    if(binaryName.equals(bName)) {
        return typeElement;
    } else if(binaryName.startsWith(bName)) {
        for(Element child : typeElement.getEnclosedElements()) {
            if(!child.getKind().isClass()) {
                continue;
            }
            
            TypeElement retVal = child.accept(this, binaryName);
            if(retVal != null) {
                return retVal;
            }
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:JavaUtils.java

示例3: overriddenMethod

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public ExecutableElement overriddenMethod(ExecutableElement method) {
    if (isStatic(method)) {
        return null;
    }
    final TypeElement origin = getEnclosingTypeElement(method);
    for (TypeMirror t = getSuperType(origin);
            t.getKind() == DECLARED;
            t = getSuperType(asTypeElement(t))) {
        TypeElement te = asTypeElement(t);
        if (te == null) {
            return null;
        }
        List<? extends Element> methods = te.getEnclosedElements();
        for (ExecutableElement ee : ElementFilter.methodsIn(methods)) {
            if (configuration.workArounds.overrides(method, ee, origin)) {
                return ee;
            }
        }
        if (t.equals(getObjectType()))
            return null;
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Utils.java

示例4: parseCompiledR

import javax.lang.model.element.TypeElement; //导入方法依赖的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

示例5: enumerateFieldElements

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static void enumerateFieldElements( @Nonnull final TypeElement element,
                                            @Nonnull final Map<String, VariableElement> fields )
{
  final TypeMirror superclass = element.getSuperclass();
  if ( TypeKind.NONE != superclass.getKind() )
  {
    enumerateFieldElements( (TypeElement) ( (DeclaredType) superclass ).asElement(), fields );
  }
  for ( final Element member : element.getEnclosedElements() )
  {
    if ( member.getKind() == ElementKind.FIELD )
    {
      fields.put( member.getSimpleName().toString(), (VariableElement) member );
    }
  }
}
 
开发者ID:arez,项目名称:arez,代码行数:17,代码来源:ProcessorUtil.java

示例6: parseCompiledR

import javax.lang.model.element.TypeElement; //导入方法依赖的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

示例7: hasTestableMethods

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 */
private boolean hasTestableMethods(TypeElement classElem) {
    List<? extends Element> enclosedElems = classElem.getEnclosedElements();
    if (enclosedElems.isEmpty()) {
        return false;
    }
    
    List<ExecutableElement> methods = ElementFilter.methodsIn(enclosedElems);
    if (methods.isEmpty()) {
        return false;
    }
    
    for (ExecutableElement method : methods) {
        if (isMethodTestable(method)) {
            return true;
        }
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TestGeneratorSetup.java

示例8: createInitialObjects

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public List<ResourceImpl> createInitialObjects() {
    final List<ResourceImpl> result = new ArrayList<ResourceImpl>();
    TypeElement departmentType = helper.getCompilationController().getElements().getTypeElement("foo.Department");
    for (Element element : departmentType.getEnclosedElements()) {
        if (isResource(element)) {
            result.add(new ResourceImpl(helper, departmentType, element));
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:PersistentObjectManagerMultipleTest.java

示例9: getExistingMethods

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
 * Returns a list of methods contained directly in the given class.
 * 
 * @param  classElem  class whose methods should be returned
 * @return  list of methods in the given class
 */
private static List<ExecutableElement> getExistingMethods(
                                final TypeElement classElem) {
    List<? extends Element> elements = classElem.getEnclosedElements();
    if (elements.isEmpty()) {
        return Collections.<ExecutableElement>emptyList();
    }

    List<ExecutableElement> methods = ElementFilter.methodsIn(elements);
    return !methods.isEmpty() ? methods
                              : Collections.<ExecutableElement>emptyList();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TestMethodNameGenerator.java

示例10: AttributesHelper

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public AttributesHelper(AnnotationModelHelper helper, TypeElement typeElement, PropertyHandler propertyHandler) {
    this.helper = helper;
    this.typeElement = typeElement;
    this.propertyHandler = propertyHandler;
    if (typeElement == null) {
        fieldAccess = true;
        return;
    }
    List<? extends Element> elements = typeElement.getEnclosedElements();
    fieldAccess = EntityMappingsUtilities.hasFieldAccess(helper, elements);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AttributesHelper.java

示例11: getFields

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
List<Element> getFields(TypeElement klass) {
    List<Element> out = new ArrayList<>();
    for (Element e : klass.getEnclosedElements()) {
        if (e.getKind() == ElementKind.FIELD) {
            out.add(e);
        }
    }
    return out;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:DupOk.java

示例12: findMethod

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/** Gets the method we are looking for
 */
private static ElementHandle findMethod(CompilationController ctrl, TypeElement ce, String member) {
    TreeUtilities utils = ctrl.getTreeUtilities();

    int pi = member.indexOf( '(' );
    String name = member.substring( 0, pi );

    StringTokenizer tokenizer = new StringTokenizer( member.substring( pi ), " ,()" ); // NOI18N
    List<TypeMirror> paramList = new ArrayList<TypeMirror>();

    while( tokenizer.hasMoreTokens() ) {
        String token = tokenizer.nextToken();
        if (token.endsWith("...")) { // NOI18N
            // translate varargs to array
            token = token.substring(0, token.length() - 3);
            token += "[]"; // NOI18N
        }
        TypeMirror type = utils.parseType(token, ce);
        paramList.add(type);
    }
    
    // search method or constructor
    for (Element e: ce.getEnclosedElements()) {
        if (e.getKind() == ElementKind.METHOD
                && name.equals(e.getSimpleName().toString())
                && compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
            return ElementHandle.create(e);
        } else if (e.getKind() == ElementKind.CONSTRUCTOR
                && name.equals(ce.getSimpleName().toString())
                && compareTypes(ctrl, paramList, ((ExecutableElement) e).getParameters())) {
            return ElementHandle.create(e);
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:SrcFinder.java

示例13: create

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public List<? extends CodeGenerator> create(Lookup context) {
    ArrayList<CodeGenerator> ret = new ArrayList<>();
    JTextComponent component = context.lookup(JTextComponent.class);
    CompilationController controller = context.lookup(CompilationController.class);
    if (component == null || controller == null) {
        return ret;
    }
    TreePath path = context.lookup(TreePath.class);
    path = path != null ? controller.getTreeUtilities().getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, path) : null;
    if (path == null) {
        return ret;
    }
    try {
        controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
    } catch (IOException ioe) {
        return ret;
    }
    TypeElement typeElement = (TypeElement) controller.getTrees().getElement(path);
    if (typeElement == null || !typeElement.getKind().isClass()) {
        return ret;
    }
    List<ElementNode.Description> descriptions = new ArrayList<>();
    for (Element element : typeElement.getEnclosedElements()) {
        switch (element.getKind()) {
            case METHOD:
                if (element.getSimpleName().contentEquals("toString") && ((ExecutableElement) element).getParameters().isEmpty()) { //NOI18N
                    return ret;
                }
                break;
            case FIELD:
                if (!ERROR.contentEquals(element.getSimpleName()) && !element.getModifiers().contains(Modifier.STATIC)) {
                    descriptions.add(ElementNode.Description.create(controller, element, null, true, true));
                }
        }
    }
    ret.add(new ToStringGenerator(component, ElementNode.Description.create(controller, typeElement, descriptions, false, false)));
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:ToStringGenerator.java

示例14: buildAnnotatedClass

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private AnnotatedClass buildAnnotatedClass(TypeElement typeElement) throws
        NoPackageNameException, IOException {

    HashMap<String, TypeMirror> variableMap = new HashMap<>();
    ArrayList<String> variableNames = new ArrayList<>();
    for (Element element : typeElement.getEnclosedElements()) {
        //过滤 字段 的Element
        if (!(element instanceof VariableElement)) {
            continue;
        }
        //过滤 static final 字段
        if (element.getModifiers().contains(STATIC) || element.getModifiers().contains(FINAL)) {
            continue;
        }
        VariableElement variableElement = (VariableElement) element;
        variableNames.add(variableElement.getSimpleName().toString());
        variableMap.put(
                variableElement.getSimpleName().toString(),
                variableElement.asType()
        );
    }

    //打印 用于测试 是否为 parcelable
    if (isParcelable(typeElement)) {
        String message = String.format("Classes %s is parceleble.", ANNOTATION);
        //messager.printMessage(Diagnostic.Kind.OTHER, message, typeElement);
    }
    return new AnnotatedClass(typeElement, variableNames, variableMap,
            isParcelable(typeElement));
}
 
开发者ID:weizongwei5,项目名称:GeneratorX,代码行数:31,代码来源:GeneratorProcessor.java

示例15: isCallbackMethodAnnotationValid

import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public boolean isCallbackMethodAnnotationValid(Element element, String annotationName) {
    TypeElement enclosingElement = (TypeElement)element.getEnclosingElement();

    if (enclosingElement.getAnnotation(JsonObject.class) == null) {
        error(enclosingElement, "%s: @%s methods can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), annotationName, JsonObject.class.getSimpleName());
        return false;
    }

    ExecutableElement executableElement = (ExecutableElement)element;
    if (executableElement.getParameters().size() > 0) {
        error(element, "%s: @%s methods must not take any parameters.", enclosingElement.getQualifiedName(), annotationName);
        return false;
    }

    List<? extends Element> allElements = enclosingElement.getEnclosedElements();
    int methodInstances = 0;
    for (Element enclosedElement : allElements) {
        for (AnnotationMirror am : enclosedElement.getAnnotationMirrors()) {
            if (am.getAnnotationType().asElement().getSimpleName().toString().equals(annotationName)) {
                methodInstances++;
            }
        }
    }
    if (methodInstances != 1) {
        error(element, "%s: There can only be one @%s method per class.", enclosingElement.getQualifiedName(), annotationName);
        return false;
    }

    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:MethodProcessor.java


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