Refine search
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; }
return true; if (typeMirror.getKind() != TypeKind.DECLARED) { return false; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments.size() > 0) { StringBuilder typeString = new StringBuilder(declaredType.asElement().toString()); typeString.append('<'); for (int i = 0; i < typeArguments.size(); i++) { Element element = declaredType.asElement(); if (!(element instanceof TypeElement)) { return false; TypeMirror superType = typeElement.getSuperclass(); if (isSubtypeOfType(superType, otherType)) { return true; for (TypeMirror interfaceType : typeElement.getInterfaces()) { if (isSubtypeOfType(interfaceType, otherType)) { return true;
@Override public TypeName visitDeclared(DeclaredType t, Void p) { ClassName rawType = ClassName.get((TypeElement) t.asElement()); TypeMirror enclosingType = t.getEnclosingType(); TypeName enclosing = (enclosingType.getKind() != TypeKind.NONE) && !t.asElement().getModifiers().contains(Modifier.STATIC) ? enclosingType.accept(this, null) : null; if (t.getTypeArguments().isEmpty() && !(enclosing instanceof ParameterizedTypeName)) { return rawType; } List<TypeName> typeArgumentNames = new ArrayList<>(); for (TypeMirror mirror : t.getTypeArguments()) { typeArgumentNames.add(get(mirror, typeVariables)); } return enclosing instanceof ParameterizedTypeName ? ((ParameterizedTypeName) enclosing).nestedClass( rawType.simpleName(), typeArgumentNames) : new ParameterizedTypeName(null, rawType, typeArgumentNames); }
private boolean isOptionalType(DeclaredType parametrizedType) { return parametrizedType.asElement().getSimpleName().contentEquals(OPTIONAL_TYPE_SIMPLE_NAME) && parametrizedType.getTypeArguments().size() == 1; } }
private void collectIfSimpleType(TypeMirror type, Map<String, TypeMirror> collected) { if (type.getKind() == TypeKind.DECLARED) { DeclaredType declared = (DeclaredType) type; if (declared.getTypeArguments().isEmpty()) { collected.put(declared.asElement().getSimpleName().toString(), declared); } } }
public boolean isCallbackMethodAnnotationValid(Element element, String annotationName) { TypeElement enclosingElement = (TypeElement)element.getEnclosingElement(); if (enclosingElement.getAnnotation(JsonObject.class) == null) { error(enclosingElement, "%s: @%s methods can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), annotationName, JsonObject.class.getSimpleName()); return false; } ExecutableElement executableElement = (ExecutableElement)element; if (executableElement.getParameters().size() > 0) { error(element, "%s: @%s methods must not take any parameters.", enclosingElement.getQualifiedName(), annotationName); return false; } List<? extends Element> allElements = enclosingElement.getEnclosedElements(); int methodInstances = 0; for (Element enclosedElement : allElements) { for (AnnotationMirror am : enclosedElement.getAnnotationMirrors()) { if (am.getAnnotationType().asElement().getSimpleName().toString().equals(annotationName)) { methodInstances++; } } } if (methodInstances != 1) { error(element, "%s: There can only be one @%s method per class.", enclosingElement.getQualifiedName(), annotationName); return false; } return true; }
public void validateRestSimpleParameter(Element element, String requiredClass, String parameterName, ElementValidation validation) { TypeMirror requiredType = annotationHelper.typeElementFromQualifiedName(requiredClass).asType(); DeclaredType paramterType = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), parameterName); if (paramterType != null) { if (annotationHelper.isSubtype(paramterType, requiredType)) { Element parameterElement = paramterType.asElement(); if (parameterElement.getKind().isClass()) { if (!annotationHelper.isAbstract(parameterElement)) { if (parameterElement.getAnnotation(EBean.class) != null) { typeIsValid(EBean.class, paramterType, validation); return; } List<ExecutableElement> constructors = ElementFilter.constructorsIn(parameterElement.getEnclosedElements()); for (ExecutableElement constructor : constructors) { if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) { return; } } validation.addError(element, "The " + parameterName + " class must have a public no argument constructor or must be annotated with @EBean"); } else { validation.addError(element, "The " + parameterName + " class must not be abstract"); } } else { validation.addError(element, "The " + parameterName + " class must be a class"); } } else { validation.addError(element, "The " + parameterName + " class must be a subtype of " + requiredClass); } } }
@Override public Iterable<? extends Completion> getCompletions(Element annotated, AnnotationMirror annotation, ExecutableElement attr, String userText) { if (processingEnv == null || annotated == null || !annotated.getKind().isClass()) { return Collections.emptyList(); || !"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")); parents.add(c.getSuperclass()); parents.addAll(c.getInterfaces()); if (tm == null || tm.getKind() != TypeKind.DECLARED) { continue;
private void parseBindViews(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); } else if (LIST_TYPE.equals(erasedType)) { DeclaredType declaredType = (DeclaredType) elementType; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments.size() != 1) { error(element, "@%s List must have a generic component. (%s.%s)", BindViews.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; } else { } else { error(element, "@%s must be a List or array. (%s.%s)", BindViews.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; if (viewType != null && viewType.getKind() == TypeKind.TYPEVAR) { TypeVariable typeVariable = (TypeVariable) viewType; viewType = typeVariable.getUpperBound(); if (viewType.getKind() == TypeKind.ERROR) { note(element, "@%s List or array with unresolved type (%s) " + "must elsewhere be generated as a View or interface. (%s.%s)", BindViews.class.getSimpleName(), viewType, enclosingElement.getQualifiedName(),
protected boolean isOverride(TypeElement typeElement, ExecutableElement methodElement) { TypeElement currentTypeElement = typeElement; do { if (currentTypeElement != typeElement) { List<? extends Element> enclosedElements = currentTypeElement.getEnclosedElements(); for (Element enclosedElement : enclosedElements) { if (enclosedElement.getSimpleName().equals(methodElement.getSimpleName()) && enclosedElement.getAnnotation(Inject.class) != null && enclosedElement.getKind() == ElementKind.METHOD) { return true; } } } TypeMirror superclass = currentTypeElement.getSuperclass(); if (superclass.getKind() == TypeKind.DECLARED) { DeclaredType superType = (DeclaredType) superclass; currentTypeElement = (TypeElement) superType.asElement(); } else { currentTypeElement = null; } } while (currentTypeElement != null); return false; }
TypeElement drawableType = elements.getTypeElement(ClassNames.DRAWABLE_NAME); for (Element enclosedElement : element.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; OnCreateMountContent annotation = enclosedElement.getAnnotation(OnCreateMountContent.class); if (annotation != null) { if (annotation.mountingType() == MountingType.VIEW) { while (returnType.getKind() != TypeKind.NONE && returnType.getKind() != TypeKind.VOID) { final TypeElement returnElement = (TypeElement) ((DeclaredType) returnType).asElement(); returnType = returnElement.getSuperclass(); } catch (RuntimeException e) { throw new ComponentsProcessingException(
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) {
/** * Retrieve the string value inside an @Contract annotation without statically depending on the * type. * * @param sym A method which has an @Contract annotation. * @return The string value spec inside the annotation. */ private static @Nullable String getContractFromAnnotation(Symbol.MethodSymbol sym) { for (AnnotationMirror annotation : sym.getAnnotationMirrors()) { Element element = annotation.getAnnotationType().asElement(); assert element.getKind().equals(ElementKind.ANNOTATION_TYPE); if (((TypeElement) element) .getQualifiedName() .contentEquals("org.jetbrains.annotations.Contract")) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e : annotation.getElementValues().entrySet()) { if (e.getKey().getSimpleName().contentEquals("value")) { String value = e.getValue().toString(); if (value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } return value; } } } } return null; } }
private void debugType(TypeMirror typeMirror, Element element, String indent) { if (indent.length() > 20) { return; } if (typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; logger.finest(format("%stype=%s, asElement=%s, (elementKind=%s, elementClass=%s), typeArgs=%s, enclosing=%s", indent, declaredType, declaredType.asElement(), declaredType.asElement().getKind(), declaredType.asElement().getClass(), declaredType.getTypeArguments(), declaredType.getEnclosingType())); for (TypeMirror tm : declaredType.getTypeArguments()) { if (!tm.equals(typeMirror)) { debugType(tm, element, indent + " "); if (declaredType.asElement().getKind() == ENUM && !element.equals(declaredType.asElement())) { debugElement(declaredType.asElement(), indent + " --> "); } else if (typeMirror.getKind() == TypeKind.EXECUTABLE) { ExecutableType type = (ExecutableType) typeMirror; logger.finest(format("%stype=%s, typeArgs=%s, paramTypes=%s, returnType=%s",
/** 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; } } }
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 void handleEmbeddedType(Element element, Set<TypeElement> elements) { TypeMirror type = element.asType(); if (element.getKind() == ElementKind.METHOD) { type = ((ExecutableElement) element).getReturnType(); } String typeName = type.toString(); if (typeName.startsWith(Collection.class.getName()) || typeName.startsWith(List.class.getName()) || typeName.startsWith(Set.class.getName())) { type = ((DeclaredType) type).getTypeArguments().get(0); } else if (typeName.startsWith(Map.class.getName())) { type = ((DeclaredType) type).getTypeArguments().get(1); } TypeElement typeElement = typeExtractor.visit(type); if (typeElement != null && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) { if (!typeElement.getQualifiedName().toString().startsWith("java.")) { elements.add(typeElement); } } }
ElementType elementType, @Nullable NullabilityAnnotationInfo nullability) { String qualifiedName = annotationElement.getQualifiedName().toString(); && hasJacksonPackagePrefix(Iterables.getOnlyElement(includeAnnotations)))) { if (Proto.isAnnotatedWith(annotationElement, Proto.JACKSON_ANNOTATIONS_INSIDE)) { for (AnnotationMirror metaAnnotation : annotationElement.getAnnotationMirrors()) { TypeElement metaAnnotationElement = (TypeElement) metaAnnotation.getAnnotationType().asElement(); String qname = metaAnnotationElement.getQualifiedName().toString(); if (nullability != null && annotationElement.getQualifiedName().contentEquals(nullability.qualifiedName())) { if (element.getKind() != ElementKind.METHOD) { if (qualifiedName.equals(Proto.JACKSON_DESERIALIZE) || qualifiedName.equals(Proto.JACKSON_SERIALIZE)) { return false; for (AnnotationMirror parentAnnotation : annotationElement.getAnnotationMirrors()) { TypeElement parentElement = (TypeElement) parentAnnotation.getAnnotationType().asElement();
if (!(mte.getTypeMirror() instanceof NoType)) { DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror(); TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement(); String targetActivityClassName = classTypeElement.getQualifiedName().toString(); blockBuilder.add(".setActivity(new $T(context, $T.class))\n", componentName, ClassName.bestGuess(targetActivityClassName)); final List<? extends AnnotationMirror> annotationMirrors = annotatedElement.getElement().getAnnotationMirrors(); for (final AnnotationMirror annotationMirror : annotationMirrors) { if (annotationMirror.getAnnotationType().toString().equals(Shortcut.class.getName())) { for (Map.Entry<? extends Element, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) { if ("backStack".equals(entry.getKey().getSimpleName().toString())) { final String value = entry.getValue().getValue().toString(); if (!"".equals(value.trim())) {
Set<Type> superTypes = Collections.emptySet(); typeMirror = normalize(typeMirror); if (typeMirror.getKind() == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; TypeElement e = (TypeElement) declaredType.asElement(); if (e.getKind() == ElementKind.CLASS) { if (e.getSuperclass().getKind() != TypeKind.NONE) { TypeMirror supertype = normalize(e.getSuperclass()); if (supertype instanceof DeclaredType && ((DeclaredType) supertype).asElement().getAnnotation(QueryExclude.class) != null) { return Collections.emptySet(); } else {