當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeElement類代碼示例

本文整理匯總了Java中javax.lang.model.element.TypeElement的典型用法代碼示例。如果您正苦於以下問題:Java TypeElement類的具體用法?Java TypeElement怎麽用?Java TypeElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeElement類屬於javax.lang.model.element包,在下文中一共展示了TypeElement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
@Override
public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

  if (roundEnv.processingOver()) {
    return false;
  }

  for (ProcessorPipeline processorPipeline : processorPipelines) {
    try {
      processorPipeline.process(annotations, roundEnv);
    } catch (Throwable e) {
      errorReporter.reportError(
          String.format(
              Locale.getDefault(),
              "Fatal error running %s processor: %s",
              processorPipeline.getAnnotationType().getSimpleName(),
              e.getMessage()));
    }
  }
  return false;
}
 
開發者ID:uber,項目名稱:RIBs,代碼行數:22,代碼來源:RibProcessor.java

示例2: visitDeclared

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
@Override
public StringBuilder visitDeclared(DeclaredType t, Boolean p) {
    Element e = t.asElement();
    if (e instanceof TypeElement) {
        TypeElement te = (TypeElement)e;
        DEFAULT_VALUE.append((p ? te.getQualifiedName() : te.getSimpleName()).toString());
        Iterator<? extends TypeMirror> it = t.getTypeArguments().iterator();
        if (it.hasNext()) {
            DEFAULT_VALUE.append("<"); //NOI18N
            while(it.hasNext()) {
                visit(it.next(), p);
                if (it.hasNext())
                    DEFAULT_VALUE.append(", "); //NOI18N
            }
            DEFAULT_VALUE.append(">"); //NOI18N
        }
        return DEFAULT_VALUE;
    } else {
        return DEFAULT_VALUE.append(UNKNOWN); //NOI18N
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:SpringXMLConfigCompletionItem.java

示例3: detectKind

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
private static KindOfType detectKind(CompilationInfo info, TypeMirror tm) {
    if (tm.getKind().isPrimitive()) {
        return KindOfType.valueOf(tm.getKind().name());
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        return ((ArrayType) tm).getComponentType().getKind().isPrimitive() ? KindOfType.ARRAY_PRIMITIVE : KindOfType.ARRAY;
    }

    if (tm.getKind() == TypeKind.DECLARED) {
        Types t = info.getTypes();
        TypeElement en = info.getElements().getTypeElement("java.lang.Enum");

        if (en != null) {
            if (t.isSubtype(tm, t.erasure(en.asType()))) {
                return KindOfType.ENUM;
            }
        }

        if (((DeclaredType)tm).asElement().getKind().isClass() && ((TypeElement) ((DeclaredType) tm).asElement()).getQualifiedName().contentEquals("java.lang.String")) {
            return KindOfType.STRING;
        }
    }

    return KindOfType.OTHER;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:EqualsHashCodeGenerator.java

示例4: buildPackageSerializedForm

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
/**
 * Build the package serialized form for the current package being processed.
 *
 * @param serializedSummariesTree content tree to which the documentation will be added
 * @throws DocletException if there is a problem while building the documentation
 */
protected void buildPackageSerializedForm(Content serializedSummariesTree) throws DocletException {
    Content packageSerializedTree = writer.getPackageSerializedHeader();
    SortedSet<TypeElement> classes = utils.getAllClassesUnfiltered(currentPackage);
    if (classes.isEmpty()) {
        return;
    }
    if (!serialInclude(utils, currentPackage)) {
        return;
    }
    if (!serialClassFoundToDocument(classes)) {
        return;
    }

    buildPackageHeader(packageSerializedTree);
    buildClassSerializedForm(packageSerializedTree);

    writer.addPackageSerializedTree(serializedSummariesTree, packageSerializedTree);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:SerializedFormBuilder.java

示例5: createAccessibilityFilter

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
private Predicate<Element> createAccessibilityFilter(AnalyzeTask at, TreePath tp) {
    Scope scope = at.trees().getScope(tp);
    return el -> {
        switch (el.getKind()) {
            case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE:
                return at.trees().isAccessible(scope, (TypeElement) el);
            case PACKAGE:
            case EXCEPTION_PARAMETER: case PARAMETER: case LOCAL_VARIABLE: case RESOURCE_VARIABLE:
                return true;
            default:
                TypeMirror type = el.getEnclosingElement().asType();
                if (type.getKind() == TypeKind.DECLARED)
                    return at.trees().isAccessible(scope, el, (DeclaredType) type);
                else
                    return true;
        }
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:SourceCodeAnalysisImpl.java

示例6: findClassElementByBinaryName

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
public static TypeElement findClassElementByBinaryName(final String binaryName, CompilationController cc) {
    if (!binaryName.contains("$")) { // NOI18N
        // fast search based on fqn
        return cc.getElements().getTypeElement(binaryName);
    } else {
        // get containing package
        String packageName = ""; // NOI18N
        int dotIndex = binaryName.lastIndexOf("."); // NOI18N
        if (dotIndex != -1) {
            packageName = binaryName.substring(0, dotIndex);
        }
        PackageElement packElem = cc.getElements().getPackageElement(packageName);
        if (packElem == null) {
            return null;
        }

        // scan for element matching the binaryName
        return new BinaryNameTypeScanner().visit(packElem, binaryName);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JavaUtils.java

示例7: getTypeElementByBinaryName

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
public static TypeElement getTypeElementByBinaryName(JavacTask task, String name) {
    Set<? extends ModuleElement> allModules = task.getElements().getAllModuleElements();
    
    if (allModules.isEmpty()) {
        Context ctx = ((JavacTaskImpl) task).getContext();
        Symtab syms = Symtab.instance(ctx);
        
        return getTypeElementByBinaryName(task, syms.noModule, name);
    }
    
    TypeElement result = null;
    
    for (ModuleElement me : allModules) {
        TypeElement found = getTypeElementByBinaryName(task, me, name);
        
        if (found != null) {
            if (result != null) return null;
            result = found;
        }
    }
    
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:ElementUtils.java

示例8: findImplementors

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
public static Set<ElementHandle<TypeElement>> findImplementors(final ClasspathInfo cpInfo, final ElementHandle<TypeElement> baseType) {
    final Set<ClassIndex.SearchKind> kind = EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS);
    final Set<ClassIndex.SearchScope> scope = EnumSet.allOf(ClassIndex.SearchScope.class);
    
    final Set<ElementHandle<TypeElement>> allImplementors = new HashSet<ElementHandle<TypeElement>>();

    ParsingUtils.invokeScanSensitiveTask(cpInfo, new ScanSensitiveTask<CompilationController>(true) {
        @Override
        public void run(CompilationController cc) {
            Set<ElementHandle<TypeElement>> implementors = cpInfo.getClassIndex().getElements(baseType, kind, scope);
            do {
                Set<ElementHandle<TypeElement>> tmpImplementors = new HashSet<ElementHandle<TypeElement>>();
                allImplementors.addAll(implementors);

                for (ElementHandle<TypeElement> element : implementors) {
                    tmpImplementors.addAll(cpInfo.getClassIndex().getElements(element, kind, scope));
                }

                implementors = tmpImplementors;
            } while (!implementors.isEmpty());
        }
    });
    
    return allImplementors;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ElementUtilitiesEx.java

示例9: visitWildcard

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
@Override
public StringBuilder visitWildcard(WildcardType t, Boolean p) {
    int len = DEFAULT_VALUE.length();
    DEFAULT_VALUE.append("?"); //NOI18N
    TypeMirror bound = t.getSuperBound();
    if (bound == null) {
        bound = t.getExtendsBound();
        if (bound != null) {
            DEFAULT_VALUE.append(" extends "); //NOI18N
            if (bound.getKind() == TypeKind.WILDCARD)
                bound = ((WildcardType)bound).getSuperBound();
            visit(bound, p);
        } else if (len == 0) {
            bound = SourceUtils.getBound(t);
            if (bound != null && (bound.getKind() != TypeKind.DECLARED || !((TypeElement)((DeclaredType)bound).asElement()).getQualifiedName().contentEquals("java.lang.Object"))) { //NOI18N
                DEFAULT_VALUE.append(" extends "); //NOI18N
                visit(bound, p);
            }
        }
    } else {
        DEFAULT_VALUE.append(" super "); //NOI18N
        visit(bound, p);
    }
    return DEFAULT_VALUE;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:TypeUtilities.java

示例10: getName

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
@Override
public String getName() {
    if(typeName == null){
        Element elt = po != null ? getTypeElement(po) : element;
        if(elt != null){
            if(elt instanceof TypeElement) {
                typeName = ((TypeElement) elt).getQualifiedName().toString();
            }
            else {
                typeName = elt.asType().toString();
            }
        } else if (type != null) {
            typeName = type.getName();
        }
    }
    return typeName;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:Type.java

示例11: extend

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
/** The super qualifier user to extend this property metadata. */
@Override public @Nullable PropertyReference extend() {
    if (mixinMetamodel != null && mixinProperty != null) {
        return new PropertyReference(mixinMetamodel, mixinProperty);
    }

    // apply bean Qualify(mixin) if this property has no explicit @Extend
    if (isProperty()) {
        Qualify beanQualify = beanElement.getAnnotation(Qualify.class);
        TypeElement classRepresenter = qualifyExtendValue(beanQualify);
        if (classRepresenter != null && !classRepresenter.equals(typeElementFor(Object.class))) {
            return new PropertyReference(
                    ClassName.bestGuess(getQualifierName(getFlatName(classRepresenter))),
                    isNullOrEmpty(mixinProperty) ? name : mixinProperty);
        }
    }

    return null;
}
 
開發者ID:intendia-oss,項目名稱:qualifier,代碼行數:20,代碼來源:StaticQualifierMetamodelProcessor.java

示例12: getElementsForPackage

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
/**
 * Returns a set of {@link ElementHandle}s containing reference(s) to given package element.
 * @param element the {@link ElementHandle} of a {@link PackageElement} for which usages should be found
 * @param searchKind type of reference, {@see SearchKind}
 * @param scope to search in {@see SearchScope}
 * @return set of {@link ElementHandle}s containing the reference(s)
 * It may return null when the caller is a CancellableTask&lt;CompilationInfo&gt; and is cancelled
 * inside call of this method.
 * @since 0.89
 */
public @NullUnknown Set<ElementHandle<TypeElement>> getElementsForPackage (
        final @NonNull ElementHandle<PackageElement> element,
        final @NonNull Set<SearchKind> searchKind,
        final @NonNull Set<? extends SearchScopeType> scope) {
    return searchImpl(
        element,
        searchKind,
        scope,
        new Convertor<ClassIndexImpl, Convertor<Document,ElementHandle<TypeElement>>>(){
            @NonNull
            @Override
            public Convertor<Document, ElementHandle<TypeElement>> convert(@NonNull final ClassIndexImpl p) {
                return DocumentUtil.typeElementConvertor();
            }
        });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ClassIndex.java

示例13: findBuilderClass

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
@Override
public String findBuilderClass(CompilationInfo cinfo, Source source, String beanClassName) {
    TypeElement classElement = cinfo.getElements().getTypeElement(beanClassName);
    if (classElement == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder(((PackageElement)classElement.getEnclosingElement()).getQualifiedName().toString());
    if (sb.length() > 0) {
        sb.append("."); // NOI18N
    }
    sb.append(classElement.getSimpleName().toString()).append("Builder"); // NOI18N
    
    TypeElement builderEl = cinfo.getElements().getTypeElement(sb.toString());
    return builderEl != null ?
            sb.toString() :
            null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:SimpleBuilderResolver.java

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

示例15: ClassBuilder

import javax.lang.model.element.TypeElement; //導入依賴的package包/類
/**
 * Construct a new ClassBuilder.
 *
 * @param context  the build context
 * @param typeElement the class being documented.
 * @param writer the doclet specific writer.
 */
private ClassBuilder(Context context, TypeElement typeElement, ClassWriter writer) {
    super(context);
    this.typeElement = typeElement;
    this.writer = writer;
    this.utils = configuration.utils;
    if (utils.isInterface(typeElement)) {
        isInterface = true;
        isEnum = false;
    } else if (utils.isEnum(typeElement)) {
        isInterface = false;
        isEnum = true;
        utils.setEnumDocumentation(typeElement);
    } else {
        isInterface = false;
        isEnum = false;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ClassBuilder.java


注:本文中的javax.lang.model.element.TypeElement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。