當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。