@Override public String apply(AnnotationMirror input) { return input.getAnnotationType().asElement().toString(); } })
private static boolean hasAnnotationWithName(Element element, String simpleName) { for (AnnotationMirror mirror : element.getAnnotationMirrors()) { String annotationName = mirror.getAnnotationType().asElement().getSimpleName().toString(); if (simpleName.equals(annotationName)) { return true; } } return false; }
/** Finds the parent binder type in the supplied set, if any. */ private @Nullable TypeElement findParentType(TypeElement typeElement, Set<TypeElement> parents) { TypeMirror type; while (true) { type = typeElement.getSuperclass(); if (type.getKind() == TypeKind.NONE) { return null; } typeElement = (TypeElement) ((DeclaredType) type).asElement(); if (parents.contains(typeElement)) { return typeElement; } } }
public AnnotationMirror getAnnotationMirror() { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (annotationElement.getQualifiedName().toString().equals(annotationName)) { return annotationMirror; } } return null; }
private static boolean find(String interfaceName, TypeElement typeElement, Set<Element> visited) { if (visited.contains(typeElement)) { return false; } visited.add(typeElement); //logger.finest("trying to find " + interfaceName + " in " + typeElement); if (typeElement.getQualifiedName().contentEquals(interfaceName)) { return true; } for (TypeMirror implemented : typeElement.getInterfaces()) { if (find(interfaceName, (TypeElement) ((DeclaredType) implemented).asElement())) { return true; } } while (typeElement.getSuperclass().getKind() != TypeKind.NONE) { typeElement = (TypeElement) ((DeclaredType) typeElement.getSuperclass()).asElement(); if (find(interfaceName, typeElement)) { return true; } } return false; }
public static MetaAnnotated from(AnnotationMirror mirror, Environment environment) { TypeElement element = (TypeElement) mirror.getAnnotationType().asElement(); String name = element.getQualifiedName().toString(); @Nullable MetaAnnotated metaAnnotated = cache.get(name); if (metaAnnotated == null) { metaAnnotated = ImmutableProto.MetaAnnotated.of(element, name, environment); @Nullable MetaAnnotated existing = cache.putIfAbsent(name, metaAnnotated); if (existing != null) { metaAnnotated = existing; } } return metaAnnotated; } }
private String qualifiedNameOf(DeclaredType t) { return ((TypeElement) t.asElement()).getQualifiedName().toString(); }
private static String findMappedSuperClass(MetaEntity entity, Context context) { TypeMirror superClass = entity.getTypeElement().getSuperclass(); //superclass of Object is of NoType which returns some other kind while ( superClass.getKind() == TypeKind.DECLARED ) { //F..king Ch...t Have those people used their horrible APIs even once? final Element superClassElement = ( (DeclaredType) superClass ).asElement(); String superClassName = ( (TypeElement) superClassElement ).getQualifiedName().toString(); if ( extendsSuperMetaModel( superClassElement, entity.isMetaComplete(), context ) ) { return superClassName; } superClass = ( (TypeElement) superClassElement ).getSuperclass(); } return null; }
|| !"org.openide.util.lookup.ServiceProvider".contentEquals(((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName())) { return Collections.emptyList(); TypeElement c = toProcess.remove(0); result.add(new TypeCompletion(c.getQualifiedName().toString() + ".class")); if (tm == null || tm.getKind() != TypeKind.DECLARED) { continue;
@Override public String apply(VariableTree variableTree) { for (Compound c : ASTHelpers.getSymbol(variableTree).getAnnotationMirrors()) { if (((TypeElement) c.getAnnotationType().asElement()) .getQualifiedName() .contentEquals(ASSISTED_ANNOTATION)) { // Assisted only has 'value', and value can only contain 1 element. Collection<Attribute> valueEntries = c.getElementValues().values(); if (!valueEntries.isEmpty()) { return Iterables.getOnlyElement(valueEntries).getValue().toString(); } } } return ""; } };
/** * Check for the presence of an annotation with a specific simple name directly on this symbol. * Does *not* consider annotation inheritance. * * @param sym the symbol to check for the presence of the annotation * @param simpleName the simple name of the annotation to look for, e.g. "Nullable" or * "CheckReturnValue" */ public static boolean hasDirectAnnotationWithSimpleName(Symbol sym, String simpleName) { for (AnnotationMirror annotation : sym.getAnnotationMirrors()) { if (annotation.getAnnotationType().asElement().getSimpleName().contentEquals(simpleName)) { return true; } } return false; }
private static <T> T findAnnotationValue(Element element, String annotationClass, String valueName, Class<T> expectedType) { T ret = null; for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) { DeclaredType annotationType = annotationMirror.getAnnotationType(); TypeElement annotationElement = (TypeElement) annotationType .asElement(); if (annotationElement.getQualifiedName().contentEquals( annotationClass)) { ret = extractValue(annotationMirror, valueName, expectedType); break; } } return ret; } private static <T> T extractValue(AnnotationMirror annotationMirror, String valueName, Class<T> expectedType) { Map<ExecutableElement, AnnotationValue> elementValues = new HashMap<ExecutableElement, AnnotationValue>( annotationMirror.getElementValues()); for (Entry<ExecutableElement, AnnotationValue> entry : elementValues .entrySet()) { if (entry.getKey().getSimpleName().contentEquals(valueName)) { Object value = entry.getValue().getValue(); return expectedType.cast(value); } } return null; }
private TypeMirror createStringTypeMirror() { TypeElement element = typeElement; while (element.getSuperclass().getKind() != TypeKind.NONE) { logger.finest("finding toString in " + element); element = (TypeElement) ((DeclaredType) element.getSuperclass()).asElement(); } for (Element enclosed : typeElement.getEnclosedElements()) { if (enclosed.getKind() == ElementKind.METHOD) { ExecutableElement method = (ExecutableElement) enclosed; if (method.getSimpleName().contentEquals("toString")) { return method.getReturnType(); } } } throw new IllegalStateException("Cannot find toString method in Object"); } private static boolean find(String interfaceName, TypeElement typeElement) {
private boolean isOptionalType(DeclaredType parametrizedType) { return parametrizedType.asElement().getSimpleName().contentEquals(OPTIONAL_TYPE_SIMPLE_NAME) && parametrizedType.getTypeArguments().size() == 1; } }
@Nullable public static AnnotationMirror findAnnotation( List<? extends AnnotationMirror> annotationMirrors, String annotationTypeName) { for (AnnotationMirror annotation : annotationMirrors) { if (((TypeElement) annotation.getAnnotationType().asElement()) .getQualifiedName() .contentEquals(annotationTypeName)) { return annotation; } } return null; }
private boolean isJavaLangObject(TypeMirror type) { if (type.getKind() != TypeKind.DECLARED) { return false; } DeclaredType declaredType = (DeclaredType) type; TypeElement typeElement = (TypeElement) declaredType.asElement(); return typeElement.getQualifiedName().contentEquals("java.lang.Object"); } };
public static TypeElement getSuperclassTypeElement(TypeElement element) { final TypeMirror superClass = element.getSuperclass(); //superclass of Object is of NoType which returns some other kind if ( superClass.getKind() == TypeKind.DECLARED ) { //F..king Ch...t Have those people used their horrible APIs even once? final Element superClassElement = ( (DeclaredType) superClass ).asElement(); return (TypeElement) superClassElement; } else { return null; } }
public AnnotationMirror findAnnotationMirror(Element annotatedElement, String annotationName) { List<? extends AnnotationMirror> annotationMirrors = annotatedElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : annotationMirrors) { TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (isAnnotation(annotationElement, annotationName)) { return annotationMirror; } } return null; }
private Name getAnnotationQualifiedName(AnnotationMirror annotationMirror) { return ( (TypeElement) annotationMirror.getAnnotationType().asElement() ).getQualifiedName(); }
private TypeElement getIntentBuilder(TypeMirror dartModelMirror) { final TypeElement dartModel = (TypeElement) ((DeclaredType) dartModelMirror).asElement(); final String modelFQN = dartModel.getQualifiedName().toString(); final int indexOfSuffix = modelFQN.indexOf(DART_MODEL_SUFFIX); if (indexOfSuffix == -1) { return null; } final String targetComponentFQN = modelFQN.substring(0, indexOfSuffix); return elementUtils.getTypeElement(targetComponentFQN + BUNDLE_BUILDER_SUFFIX); } }