@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 Collection<ExecutableElement> findByName(final Collection<ExecutableElement> methods, final ExecutableElement method) { final Name methodName = method.getSimpleName(); final List<ExecutableElement> result = new ArrayList<>(); final int paramCount = parameterCount(method.getParameters()); for (ExecutableElement m : methods) { if (methodName.equals(m.getSimpleName()) && parameterCount(m.getParameters()) == paramCount) { result.add(m); } } return result; }
@Nullable private static Tree suppressibleNode(TreePath path) { return StreamSupport.stream(path.spliterator(), false) .filter( tree -> tree instanceof MethodTree || (tree instanceof ClassTree && ((ClassTree) tree).getSimpleName().length() != 0) || tree instanceof VariableTree) .findFirst() .orElse(null); }
@Value.Lazy @Override public JacksonMode jacksonSerializeMode() { boolean wasJacksonSerialize = false; for (AnnotationMirror a : element().getAnnotationMirrors()) { TypeElement e = (TypeElement) a.getAnnotationType().asElement(); if (!wasJacksonSerialize && e.getQualifiedName().contentEquals(JACKSON_SERIALIZE)) { wasJacksonSerialize = true; } if (e.getQualifiedName().contentEquals(JACKSON_DESERIALIZE)) { for (ExecutableElement attr : a.getElementValues().keySet()) { if (attr.getSimpleName().contentEquals("builder")) { // If builder attribute is specified, we don't consider this as // our, immutables, business to generate anything. return JacksonMode.BUILDER; } } return JacksonMode.DELEGATED; } } return wasJacksonSerialize ? JacksonMode.DELEGATED : JacksonMode.NONE; }
/** * Retrieves the attribute value from the annotation and assumes it's a {@link Class class} type. * * @param element the element the annotation is on * @param annotation the annotation to get the value from * @param attributeName the name of the attribute to retrieve the class value for * * @return a {@link TypeElement} representing the value for the annotation attribute or {@code null} if the * attribute was not found */ @SuppressWarnings({"StaticMethodOnlyUsedInOneClass", "SameParameterValue"}) public static TypeElement getClassAnnotationValue(final Element element, final Class<? extends Annotation> annotation, final String attributeName) { for (AnnotationMirror mirror : element.getAnnotationMirrors()) { final DeclaredType annotationType = mirror.getAnnotationType(); if (annotationType.toString().equals(annotation.getName())) { final Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues(); for (ExecutableElement key : map.keySet()) { if (key.getSimpleName().contentEquals(attributeName)) { return ((TypeElement) (((DeclaredType) map.get(key).getValue()).asElement())); } } } } 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) {
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; }
final TypeSpec.Builder traversalSourceClass = TypeSpec.classBuilder(ctx.traversalSourceClazz) .addModifiers(Modifier.PUBLIC) .superclass(TypeName.get(graphTraversalSourceElement.asType())); final Predicate<ExecutableElement> ignore = e -> !(e.getReturnType().getKind() == TypeKind.DECLARED && ((DeclaredType) e.getReturnType()).asElement().getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())); for (ExecutableElement elementOfGraphTraversalSource : findMethodsOfElement(tinkerPopsGraphTraversalSource, ignore)) { if (!graphTraversalSourceElement.getSimpleName().contentEquals(GraphTraversalSource.class.getSimpleName())) { for (ExecutableElement templateMethod : findMethodsOfElement(graphTraversalSourceElement, null)) { final MethodSpec.Builder methodToAdd = MethodSpec.methodBuilder(templateMethod.getSimpleName().toString()) .addModifiers(Modifier.PUBLIC) .addAnnotation(Override.class);
private void setClosestRequiredAncestor( ExtraBindingTarget extraBindingTarget, TypeElement superIntentBuilder) { for (ExecutableElement method : methodsIn(superIntentBuilder.getEnclosedElements())) { if (method.getSimpleName().contentEquals(NEXT_STATE_METHOD)) { final TypeMirror returnTypeMirror = method.getReturnType(); if (compilerUtil.isAssignable(returnTypeMirror, "dart.henson.AllRequiredSetState")) { return; } final Element reqElement = ((DeclaredType) typeUtils.erasure(returnTypeMirror)).asElement(); final TypeElement intentBuilderTypeElement = (TypeElement) reqElement.getEnclosingElement(); extraBindingTarget.closestRequiredAncestorPackage = compilerUtil.getPackageName(intentBuilderTypeElement); final String intentBuilderClass = compilerUtil.getClassName( intentBuilderTypeElement, extraBindingTarget.closestRequiredAncestorPackage); extraBindingTarget.closestRequiredAncestorClass = intentBuilderClass.substring(0, intentBuilderClass.indexOf(BUNDLE_BUILDER_SUFFIX)); } } }
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();
static boolean isKotlinSingleton(TypeElement element) { return element.getKind() == ElementKind.CLASS && element .getEnclosedElements() .stream() .anyMatch( e -> { final CharSequence instanceFieldName = "INSTANCE"; return e.getSimpleName().contentEquals(instanceFieldName) && e.asType().toString().equals(((Symbol.ClassSymbol) element).className()) && e.getModifiers() .containsAll( ImmutableList.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)); }); }
|| !type.getModifiers().contains(Modifier.STATIC)) { reporter.withElement(type) .error("@Encoding.Builder class '%s' should be static with" + " the same type parameters as encoding type: %s", type.getSimpleName(), typesReader.parameters); for (Element member : type.getEnclosedElements()) { if ((member.getKind() == ElementKind.FIELD || member.getKind() == ElementKind.METHOD) && !memberNames.add(memberPath(member))) { reporter.withElement(member) + " @Encoding.Naming annotation could be used so that actually generated methods might have the same name" + " if they are not conflicting as per JLS overload rules", member.getSimpleName()); continue; if (member.getSimpleName().contentEquals("<init>")) { continue;
private P2<HktEffectiveVisibility, String> genCoerceMethod(TypeElement typeConstructor, DeclaredType hktInterface, String coerceMethodName, String typeEqMethodName, HktEffectiveVisibility visibility) { String packageNamePrefix = Elts.getPackageOf(typeConstructor).getQualifiedName().toString() + "."; String typeAsString = typeConstructor.asType() .toString() .substring(packageNamePrefix.length(), typeConstructor.asType().toString().length()); TypeElement packageRelativeTypeElement = packageRelativeTypeElement(typeConstructor); CharSequence typeParams = typeConstructor.asType().toString().substring(typeConstructor.getQualifiedName().length()); String hktInterfaceAsString = hktInterface.toString() .replace(Visitors.asTypeElement.visit(hktInterface.asElement()).get().getQualifiedName(), hktInterface .asElement().getSimpleName()) .replace(packageRelativeTypeElement.getQualifiedName(), packageRelativeTypeElement.getSimpleName()); return _P2.of(visibility, MessageFormat.format(METHODS_TEMPLATE, visibility.prefix(), typeAsString, typeParams, hktInterfaceAsString, coerceMethodName, typeEqMethodName)); }
private AnnotationValue getAnnotationValue(AnnotationMirror mirror, String key) { for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals(key)) { return entry.getValue(); } } 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; }
private boolean isOptionalType(DeclaredType parametrizedType) { return parametrizedType.asElement().getSimpleName().contentEquals(OPTIONAL_TYPE_SIMPLE_NAME) && parametrizedType.getTypeArguments().size() == 1; } }
Name name = clientMethodElement.getSimpleName(); if (currentTypeIsProxy && name.contentEquals("stableId") && clientMethodElement.getParameters().isEmpty()) { return null; new MethodFinder(name, domainElement.asType(), lookFor, false, state).scan( domainElement, state); if (!domainMethod.getModifiers().contains(Modifier.PUBLIC)) { state.poison(clientMethodElement, Messages.domainMethodNotPublic( domainMethod.getSimpleName()));
static boolean overridesMethod(Types types, TypeElement element, String methodName) { while (element != null) { if (ElementFilter.methodsIn(element.getEnclosedElements()).stream() .anyMatch(method -> method.getSimpleName().contentEquals(methodName))) { return true; } TypeMirror superType = element.getSuperclass(); if (superType.getKind() == TypeKind.NONE) { break; } else { element = (TypeElement) types.asElement(superType); } if (namesEqual(element, Object.class.getCanonicalName())) { break; } } return false; }
private TypeMirror extractSpecificType(TypeMirror type) { TypeMirror specificType = removeWildcard(type); return typeUtils.asElement(specificType).getAnnotationMirrors().stream() .filter(a -> a.getAnnotationType().toString().equals(GenerateDiffFunction.class.getName())) .findFirst() .map(annotation -> annotation.getElementValues().entrySet().stream() .filter(entry -> "defaultImpl".equals(entry.getKey().getSimpleName().toString())) .map(Map.Entry::getValue) .map(AnnotationValue::getValue) .filter(val -> !val.equals(Object.class.getName())) .findFirst() .map(val -> elementUtils.getTypeElement(val.toString()).asType()) .orElse(specificType)) .orElse(specificType); }
@Override public Void visitType(TypeElement e, Void aVoid) { if(!e.getModifiers().contains(Modifier.ABSTRACT)) { Element sc = asElement(e.getSuperclass()); if (sc!=null && ((TypeElement)sc).getQualifiedName().contentEquals("hudson.Plugin")) { try { write(e); } catch (IOException x) { processingEnv.getMessager().printMessage(Kind.ERROR, Functions.printThrowable(x), e); } } } return super.visitType(e, aVoid); }