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; }
@Override public Boolean visitType( TypeElement element, Void aVoid ) { return element.getQualifiedName().contentEquals( annotationType.getName() ); } }
private TypeElement getSuperclass(TypeElement type) { if (type.getSuperclass().getKind() == TypeKind.DECLARED) { TypeElement superclass = (TypeElement) processingEnv.getTypeUtils().asElement(type.getSuperclass()); String name = superclass.getQualifiedName().toString(); if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) { // Skip system classes, this just degrades performance return null; } else { return superclass; } } else { return null; } }
@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 void findMapping(Set<? extends Element> set, Map<TypeElement, List<ExecutableElement>> controllerMap) { for (Element element : set) { if (element instanceof ExecutableElement) { ExecutableElement execute = (ExecutableElement)element; Element enclosing = element.getEnclosingElement(); if (!(enclosing instanceof TypeElement)) continue; TypeElement type = (TypeElement)enclosing; Annotation restController = type.getAnnotation(RestController.class); Annotation controller = type.getAnnotation(Controller.class); if (restController == null && controller == null) { mLog.w(String.format("Controller/RestController annotations may be missing on %s.", type.getQualifiedName())); continue; } String host = type.getQualifiedName() + "#" + execute.getSimpleName() + "()"; Set<Modifier> modifiers = execute.getModifiers(); Validate.isTrue(!modifiers.contains(Modifier.PRIVATE), "The modifier private is redundant on %s.", host); if (modifiers.contains(Modifier.STATIC)) { mLog.w(String.format("The modifier static is redundant on %s.", host)); } List<ExecutableElement> elementList = controllerMap.get(type); if (CollectionUtils.isEmpty(elementList)) { elementList = new ArrayList<>(); controllerMap.put(type, elementList); } elementList.add(execute); } } }
private String qualifiedNameOf(DeclaredType t) { return ((TypeElement) t.asElement()).getQualifiedName().toString(); }
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; }
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; }
@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 ""; } };
public Model(DeclaredType type) { this.type = type; for (ExecutableElement e : ElementFilter.methodsIn(type.asElement().getEnclosedElements())) { Metadata im = e.getAnnotation(Metadata.class); if(im==null) continue; String name = im.value(); if (name.length() == 0) name = ((TypeElement) type.asElement()).getQualifiedName().toString() + '.' + e.getSimpleName(); metadataProperties.put(e,name); } }
.add("\n"); String host = type.getQualifiedName().toString() + "#" + execute.getSimpleName().toString() + "()"; StringBuilder paramBuild = new StringBuilder(); List<? extends VariableElement> parameters = execute.getParameters(); String executeName = execute.getSimpleName().toString(); TypeMirror returnMirror = execute.getReturnType(); handleCode.add("\n").addStatement("Object o = null", type, executeName).beginControlFlow("try"); if (!TypeKind.VOID.equals(returnMirror.getKind())) { handleCode.addStatement("o = (($T)mHost).$L($L)", type, executeName, paramBuild.toString()); } else {
static AttributeTypeKind from(TypeMirror type) { if (type.getKind() == TypeKind.DECLARED) { TypeElement typeElement = toElement(type); if (typeElement.getKind() == ElementKind.ENUM) { return ENUM; } if (typeElement.getKind() == ElementKind.ANNOTATION_TYPE) { return ANNOTATION; } Name qualifiedName = typeElement.getQualifiedName(); if (qualifiedName.contentEquals(Class.class.getName())) { return TYPE; } if (qualifiedName.contentEquals(String.class.getName())) { return STRING; } } else if (type.getKind().isPrimitive()) { return PRIMITIVE; } throw new AssertionError(); } }
public static ImmutableList<TypeMirror> getTypesFromMirrors( String annotationQualifiedName, String annotationAttributeName, List<? extends AnnotationMirror> annotationMirrors) { ImmutableList.Builder<TypeMirror> builder = ImmutableList.builder(); for (AnnotationMirror annotationMirror : annotationMirrors) { TypeElement element = (TypeElement) annotationMirror.getAnnotationType().asElement(); if (element.getQualifiedName().contentEquals(annotationQualifiedName)) { collectTypesFromAnnotationAttribute(annotationAttributeName, builder, annotationMirror); } } return builder.build(); }
private void extractAnnotations(AnnotationElementsHolder extractedModel, Set<String> annotationTypesToCheck, TypeElement rootTypeElement, Element ancestorEnclosedElement) { List<? extends AnnotationMirror> ancestorEnclosedElementAnnotations = ancestorEnclosedElement.getAnnotationMirrors(); for (AnnotationMirror annotationMirror : ancestorEnclosedElementAnnotations) { DeclaredType annotationType = annotationMirror.getAnnotationType(); if (annotationTypesToCheck.contains(annotationType.toString())) { TypeElement annotation = (TypeElement) annotationType.asElement(); /* * rootTypeElement is one of the types that are being compiled * * ancestorEnclosedElement is the annotated element in an ancestor of * rootTypeElement * * annotation is a type representing the annotation on ancestorEnclosedElement */ extractedModel.putAncestorAnnotatedElement(annotation.getQualifiedName().toString(), ancestorEnclosedElement, rootTypeElement); } } }
public RInnerClass(TypeElement rInnerTypeElement) { if (rInnerTypeElement != null) { rInnerQualifiedName = rInnerTypeElement.getQualifiedName().toString(); List<? extends Element> idEnclosedElements = rInnerTypeElement.getEnclosedElements(); List<VariableElement> idFields = ElementFilter.fieldsIn(idEnclosedElements); for (VariableElement idField : idFields) { TypeKind fieldType = idField.asType().getKind(); if (fieldType.isPrimitive() && fieldType.equals(TypeKind.INT)) { String idQualifiedName = rInnerQualifiedName + "." + idField.getSimpleName(); idQualifiedNames.add(idQualifiedName); Integer idFieldId = (Integer) idField.getConstantValue(); if (idFieldId != null) { idQualifiedNamesByIdValues.put(idFieldId, idQualifiedName); } } } } else { rInnerQualifiedName = ""; } }
if (duplicateId != null) { error(element, "@%s annotation for method contains duplicate ID %d. (%s.%s)", annotationClass.getSimpleName(), duplicateId, enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; if (!required) { error(element, "ID-free binding must not be annotated with @Optional. (%s.%s)", enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; annotationClass.getSimpleName(), id, enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; error(element, "@%s methods can have at most %s parameter(s). (%s.%s)", annotationClass.getSimpleName(), method.parameters().length, enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; error(element, "@%s methods must have a '%s' return type. (%s.%s)", annotationClass.getSimpleName(), method.returnType(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; .append(annotationClass.getSimpleName()) .append(" method arguments. (") .append(enclosingElement.getQualifiedName()) .append('.')
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); } }
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"); } };
private static boolean namesEqual(TypeElement element, String qualifiedName) { return element != null && element.getQualifiedName().contentEquals(qualifiedName); } }
@Override public TypeSpec visitDeclared(DeclaredType t, Void aVoid) { final TypeElement typeElement = (TypeElement) t.asElement(); final String qualifiedName = typeElement.getQualifiedName().toString(); final Supplier<TypeSpec> superclass = new SimpleMemoizingSupplier<>( () -> { final TypeMirror mirror = typeElement.getSuperclass(); return mirror.getKind() != TypeKind.DECLARED ? null : generateTypeSpec(mirror); ? mirrors .stream() .filter(mirror -> mirror.getKind() == TypeKind.DECLARED) .map(SpecModelUtils::generateTypeSpec) .collect(Collectors.toList())