本文整理汇总了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;
}
示例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
}
}
示例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;
}
示例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);
}
示例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;
}
};
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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<CompilationInfo> 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();
}
});
}
示例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;
}
示例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;
}
示例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;
}
}