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


Java Elements.getTypeElement方法代码示例

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


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

示例1: RequestManagerGenerator

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
RequestManagerGenerator(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) {
  this.processingEnv = processingEnv;
  this.processorUtil = processorUtil;

  Elements elementUtils = processingEnv.getElementUtils();

  requestManagerType = elementUtils.getTypeElement(REQUEST_MANAGER_QUALIFIED_NAME);
  requestManagerClassName = ClassName.get(requestManagerType);

  lifecycleType = elementUtils.getTypeElement(LIFECYCLE_QUALIFIED_NAME);
  requestManagerTreeNodeType =
      elementUtils.getTypeElement(REQUEST_MANAGER_TREE_NODE_QUALIFIED_NAME);

  requestBuilderType =
      elementUtils.getTypeElement(RequestBuilderGenerator.REQUEST_BUILDER_QUALIFIED_NAME);

  glideType = elementUtils.getTypeElement(GLIDE_QUALIFIED_NAME);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RequestManagerGenerator.java

示例2: resolve

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public Element resolve(ASTService ast, Elements elements, String what, ModuleElement modle) {
    Element result = null;
    
    if (classes.containsKey(what)) {
        result = createElement(ast, elements, what, null, modle);
    }

    if (result == null) {
        result = modle != null ? elements.getTypeElement(modle, what) : elements.getTypeElement(what);
    }

    if (result == null) {
        result = modle != null ? elements.getPackageElement(modle, what) : elements.getPackageElement(what);
    }

    result = createElement(ast, elements, what, result, modle);

    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ElementOverlay.java

示例3: testFieldSignatureFromElement

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public void testFieldSignatureFromElement () throws Exception {
InputStream in = this.prepareData(TEST_CLASS);
try {
    JavacTask jt = prepareJavac ();
    Elements elements = jt.getElements();
    TypeElement be = elements.getTypeElement(TEST_CLASS);
    ClassFile cf = new ClassFile (in, true);
    String className = cf.getName().getInternalName().replace('/','.');	    //NOI18N
    List<? extends Element> members = be.getEnclosedElements();
    for (Element e : members) {
	if (e.getKind() == ElementKind.FIELD) {
	    String[] msig = ClassFileUtil.createFieldDescriptor((VariableElement) e);
	    assertEquals (className,msig[0]);
	    assertEquals (e.getSimpleName().toString(),msig[1]);
	    Variable v = cf.getVariable (e.getSimpleName().toString());		    
	    assertNotNull (v);		    
	    assertEquals (v.getDescriptor(), msig[2]);
	}
    }
} finally {
    in.close ();
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CompromiseSATest.java

示例4: process

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver())
        return false;

    Elements elements = processingEnv.getElementUtils();
    TypeElement test = elements.getTypeElement("test.Test");
    List<? extends Element> members = new ArrayList<>(test.getEnclosedElements());

    Collections.sort(members,
                     (e1, e2) -> e1.getSimpleName().toString().compareTo(e2.getSimpleName().toString()));

    for (Element el : members) {
        System.out.println(el.getSimpleName() + ":" + elements.getOrigin(el));
    }

    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TestOrigin.java

示例5: RequestManagerFactoryGenerator

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
RequestManagerFactoryGenerator(ProcessingEnvironment processingEnv) {
  Elements elementUtils = processingEnv.getElementUtils();
  glideType = elementUtils.getTypeElement(GLIDE_QUALIFIED_NAME);
  lifecycleType = elementUtils.getTypeElement(LIFECYCLE_QUALIFIED_NAME);
  requestManagerTreeNodeType =
      elementUtils.getTypeElement(REQUEST_MANAGER_TREE_NODE_QUALIFIED_NAME);

  requestManagerFactoryInterface =
      elementUtils.getTypeElement(REQUEST_MANAGER_FACTORY_QUALIFIED_NAME);

  TypeElement requestManagerType = elementUtils.getTypeElement(REQUEST_MANAGER_QUALIFIED_NAME);
  requestManagerClassName = ClassName.get(requestManagerType);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:RequestManagerFactoryGenerator.java

示例6: findBestIndex

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private static int findBestIndex(Elements elements){
    int index = 0;
    do{
        index ++;
    }while(elements.getTypeElement(getClassName(index)) != null);
    return index;
}
 
开发者ID:LightSun,项目名称:data-mediator,代码行数:8,代码来源:SharedPropertiesNGenerator.java

示例7: generateOverrideSetRequestOptions

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
/**
 * The {@link com.bumptech.glide.request.RequestOptions} subclass should always be our
 * generated subclass type to avoid inadvertent errors where a different subclass is applied that
 * accidentally wipes out some logic in overidden methods in our generated subclass.
 */
@Nullable
private MethodSpec generateOverrideSetRequestOptions(
    String generatedCodePackageName, @Nullable TypeSpec generatedRequestOptions) {
  if (generatedRequestOptions == null) {
    return null;
  }

  Elements elementUtils = processingEnv.getElementUtils();
  TypeElement requestOptionsType =
          elementUtils.getTypeElement(
              RequestOptionsGenerator.REQUEST_OPTIONS_QUALIFIED_NAME);
  TypeElement androidNonNullType =
          elementUtils.getTypeElement("android.support.annotation.NonNull");

  // This class may have just been generated and therefore may not be found if we try to obtain
  // it via Elements, so use just the String version instead.
  String generatedRequestOptionsQualifiedName =
      generatedCodePackageName + "." + generatedRequestOptions.name;

  String methodName = "setRequestOptions";
  String parameterName = "toSet";

  return MethodSpec.methodBuilder(methodName)
      .addAnnotation(Override.class)
      .addModifiers(Modifier.PROTECTED)
      .addParameter(
          ParameterSpec.builder(ClassName.get(requestOptionsType), parameterName)
              .addAnnotation(ClassName.get(androidNonNullType))
              .build())
      .beginControlFlow("if ($N instanceof $L)",
          parameterName, generatedRequestOptionsQualifiedName)
      .addStatement("super.$N($N)", methodName, parameterName)
      .nextControlFlow("else")
      .addStatement("super.setRequestOptions(new $L().apply($N))",
          generatedRequestOptionsQualifiedName, parameterName)
      .endControlFlow()
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:44,代码来源:RequestManagerGenerator.java

示例8: isParcelableArray

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public static boolean isParcelableArray(Types typeUtils, Elements elementUtils, Element element) {
    if (element.asType().getKind() != TypeKind.ARRAY) {
        return false;
    }

    ArrayType arrayType = (ArrayType) element.asType();
    TypeMirror componentType = arrayType.getComponentType();

    TypeElement typeParcelable = elementUtils.getTypeElement(Parcelable.class.getName());
    return typeUtils.isSubtype(componentType, typeParcelable.asType());
}
 
开发者ID:srym,项目名称:vulture,代码行数:12,代码来源:TypeUtils.java

示例9: getElemForClassName

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
/**
 */
protected static TypeElement getElemForClassName(String className,
                                                 Elements elements) {
    TypeElement elem = elements.getTypeElement(className);
    if (elem == null) {
        ErrorManager.getDefault().log(
                ErrorManager.ERROR,
                "Could not find TypeElement for " + className);     //NOI18N
    }
    return elem;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:AbstractTestGenerator.java

示例10: run

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public void run(WorkingCopy copy) throws Exception {
    copy.toPhase(JavaSource.Phase.RESOLVED);
    CompilationUnitTree cut = copy.getCompilationUnit();
    Elements elements = copy.getElements();
    Set<Element> imports = new HashSet<Element>();
    for (String imp : toImport) {
        if (imp.endsWith(".*"))
            imp = imp.substring(0, imp.length() - 2);
        Element el = elements.getTypeElement(imp);
        if (el == null)
            el = elements.getPackageElement(imp);
        if (el == null) {
            int idx = imp.lastIndexOf('.');
            if (idx >= 0) {
                el = elements.getTypeElement(imp.substring(0, idx));
                if (el != null) {
                    String name = imp.substring(idx + 1);
                    for (Element ee : el.getEnclosedElements()) {
                        if (name.contentEquals(ee.getSimpleName())) {                                
                            el = ee;
                            break;
                        }
                    }
                }
            }
        }
        assertNotNull(el);
        imports.add(el);
    }
    GeneratorUtilities utilities = GeneratorUtilities.get(copy);
    assertNotNull(utilities);
    CompilationUnitTree newCut = utilities.addImports(cut, imports);
    copy.rewrite(cut, newCut);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:GeneratorUtilitiesTest.java

示例11: run

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    Elements elementUtils = root.getElementUtils();
    TypeElement klass = elementUtils.getTypeElement("baz.Foo");
    if (!root.isIncluded(klass)) {
        throw new AssertionError("Base class is not included: baz.Foo");
    }

    for (TypeElement te : ElementFilter.typesIn(root.getSpecifiedElements())) {
        if (te.getKind() == ElementKind.CLASS &&
                te.getSimpleName().contentEquals("Bar")) {
            klass = te;
        }
    }
    if (klass == null) {
        throw new AssertionError("class Bar not found");
    }
    List<? extends Element> members = klass.getEnclosedElements();


    boolean foundPublic = false;
    boolean foundProtected = false;

    boolean foundPackagePrivate = false;
    boolean foundPrivate = false;

    List<Element> included = members.stream()
            .filter(cls -> root.isIncluded(cls))
            .collect(Collectors.toList());

    for (Element e : included) {
        System.out.println("element: " + e);
        if (e.getSimpleName().toString().equals("aPublicMethod")) {
            foundPublic = true;
        }
        if (e.getSimpleName().toString().equals("aProtectedMethod")) {
            foundProtected = true;
        }
        if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {
            foundPackagePrivate = true;
        }
        if (e.getSimpleName().toString().equals("aPackagePrivateMethod")) {
            foundPrivate = true;
        }
    }
    if (!foundPublic || !foundProtected) {
        throw new AssertionError("selected methods not found");
    }

    if (foundPrivate || foundPackagePrivate) {
         throw new AssertionError("unselected methods found");
    }

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:BaseClass.java

示例12: generateCode

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
public void generateCode(Elements elementUtils, Filer filer) throws IOException {
    TypeElement className = elementUtils.getTypeElement(annotatedClassName);
    TypeElement itemType = elementUtils.getTypeElement(adapterItemType);
    new ViewHolderClass(elementUtils, filer, className, itemType, SUFFIX).generate();
    new AdapterClass(elementUtils, filer, className, itemType, SUFFIX).generate();
}
 
开发者ID:mitrejcevski,项目名称:gendapter,代码行数:7,代码来源:AdapterGroupedClass.java

示例13: getModuleBase

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
private static final TypeMirror getModuleBase(Types typeUtils, Elements elementUtils) {
    TypeElement moduleBaseTypeElement = elementUtils.getTypeElement(ModuleBase.class.getCanonicalName());
    WildcardType wildcard = typeUtils.getWildcardType(null, null);
    return typeUtils.getDeclaredType(moduleBaseTypeElement, wildcard);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:6,代码来源:ModelContext.java

示例14: visitThrows

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
@Override
    public Void visitThrows(ThrowsTree tree, List<ErrorDescription> errors) {
        boolean oldInheritDoc = foundInheritDoc;
        ReferenceTree exName = tree.getExceptionName();
        DocTreePath refPath = new DocTreePath(getCurrentPath(), tree.getExceptionName());
        Element ex = javac.getDocTrees().getElement(refPath);
        Types types = javac.getTypes();
        Elements elements = javac.getElements();
        final TypeElement throwableEl = elements.getTypeElement("java.lang.Throwable");
        final TypeElement errorEl = elements.getTypeElement("java.lang.Error");
        final TypeElement runtimeEl = elements.getTypeElement("java.lang.RuntimeException");
        if(throwableEl == null || errorEl == null || runtimeEl == null) {
            LOG.warning("Broken java-platform, cannot resolve " + throwableEl == null? "java.lang.Throwable" : errorEl == null? "java.lang.Error" : "java.lang.RuntimeException"); //NOI18N
            return null;
        }
        TypeMirror throwable = throwableEl.asType();
        TypeMirror error = errorEl.asType();
        TypeMirror runtime = runtimeEl.asType();
        DocTreePath currentDocPath = getCurrentPath();
        DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
        if(dtph == null) {
            return null;
        }
        DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
        int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
        int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
        if (ex == null || (ex.asType().getKind() == TypeKind.DECLARED
                && types.isAssignable(ex.asType(), throwable))) {
            switch (currentElement.getKind()) {
                case CONSTRUCTOR:
                case METHOD:
                    if (ex == null || !(types.isAssignable(ex.asType(), error)
                            || types.isAssignable(ex.asType(), runtime))) {
                        ExecutableElement ee = (ExecutableElement) currentElement;
                        String fqn;
                        if (ex != null) {
                            fqn = ((TypeElement) ex).getQualifiedName().toString();
                        } else {
                            ExpressionTree referenceClass = javac.getTreeUtilities().getReferenceClass(new DocTreePath(currentDocPath, exName));
                            if(referenceClass == null) break;
                            fqn = referenceClass.toString();
                        }
                        checkThrowsDeclared(tree, ex, fqn, ee.getThrownTypes(), dtph, start, end, errors);
                    }
                    break;
                default:
//                        env.messages.error(REFERENCE, tree, "dc.invalid.throws");
            }
        } else {
//                env.messages.error(REFERENCE, tree, "dc.invalid.throws");
        }
        warnIfEmpty(tree, tree.getDescription());
        super.visitThrows(tree, errors);
        foundInheritDoc = oldInheritDoc;
        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:Analyzer.java

示例15: handleProcess

import javax.lang.model.util.Elements; //导入方法依赖的package包/类
@Override
protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
    for (Element e : roundEnv.getElementsAnnotatedWith(ProjectConvertor.Registration.class)) {
        if (!e.getKind().isClass()) {
            throw new LayerGenerationException("Annotated element is not a class", e);   //NOI18N
        }
        final ProjectConvertor.Registration reg = e.getAnnotation(ProjectConvertor.Registration.class);
        final Elements elements = processingEnv.getElementUtils();
        final Types types = processingEnv.getTypeUtils();
        final TypeElement projectConvertor = elements.getTypeElement(ProjectConvertor.class.getName());
        if (types.isSubtype(((TypeElement)e).asType(), projectConvertor.asType())) {
            final LayerBuilder.File f = layer(e).instanceFile("Services/ProjectConvertors", null, null);    //NOI18N
            f.stringvalue("instanceOf", ProjectConvertorAcceptor.class.getName());   //NOI18N
            f.stringvalue("instanceClass", ProjectConvertorAcceptor.class.getName());   //NOI18N
            f.methodvalue("instanceCreate", ProjectConvertor.Result.class.getName(), "create");    //NOI18N
            final int position = reg.position();
            if (position >= 0) {
                f.intvalue("position", position);   //NOI18N
            }
            f.instanceAttribute(ProjectConvertorAcceptor.ATTR_DELEGATE, ProjectConvertor.class);
            final String pattern = reg.requiredPattern();
            if (pattern == null || pattern.isEmpty()) {
                throw new LayerGenerationException(
                    String.format("The %s has to be non empty string.", ProjectConvertorAcceptor.ATTR_PATTERN), //NOI18N
                    e);
            }
            try {
                Pattern.compile(pattern);
            } catch (PatternSyntaxException ex) {
                throw new LayerGenerationException(
                    String.format(
                        "The %s is not valid regular expression: %s.",  //NOI18N
                        ProjectConvertorAcceptor.ATTR_PATTERN,
                        ex.getMessage()),
                    e);
            }
            f.stringvalue(ProjectConvertorAcceptor.ATTR_PATTERN, pattern);
            f.write();
        } else {
            throw new LayerGenerationException("Annoated element is not a subclass of ProjectConvertor.",e); //NOI18N
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:ProjectConvertorProcessor.java


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