private List<TypeMirror> extractListenerTypeMirrors(Element activityElement) { List<? extends AnnotationMirror> annotationMirrors = activityElement.getAnnotationMirrors(); String annotationName = RoboGuice.class.getName(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationName.equals(annotationMirror.getAnnotationType().toString())) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) { if ("value".equals(entry.getKey().getSimpleName().toString())) { AnnotationValue action = entry.getValue(); @SuppressWarnings("unchecked") List<AnnotationValue> elements = (List<AnnotationValue>) action.getValue(); List<TypeMirror> listenerTypeMirrors = new ArrayList<>(elements.size()); for (AnnotationValue annotationValue : elements) { listenerTypeMirrors.add((TypeMirror) annotationValue.getValue()); } return listenerTypeMirrors; } } } } return Collections.emptyList(); }
public static AnnotationSpec get(AnnotationMirror annotation) { TypeElement element = (TypeElement) annotation.getAnnotationType().asElement(); AnnotationSpec.Builder builder = AnnotationSpec.builder(ClassName.get(element)); Visitor visitor = new Visitor(builder); for (ExecutableElement executableElement : annotation.getElementValues().keySet()) { String name = executableElement.getSimpleName().toString(); AnnotationValue value = annotation.getElementValues().get(executableElement); value.accept(visitor, name); } return builder.build(); }
/** * 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; } }
if (!registration.getModifiers().contains(Modifier.PUBLIC)) { return "annotated elements must be public"; TypeMirror supertype = processingEnv.getElementUtils().getTypeElement("java.lang.Object").asType(); for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : indexable.getElementValues().entrySet()) { if (!entry.getKey().getSimpleName().contentEquals("type")) { continue; supertype = (TypeMirror) entry.getValue().getValue(); switch (registration.getKind()) { case CLASS: if (registration.getModifiers().contains(Modifier.ABSTRACT)) { return "annotated classes must not be abstract"; for (ExecutableElement constructor : ElementFilter.constructorsIn(registration.getEnclosedElements())) { if (constructor.getModifiers().contains(Modifier.PUBLIC) && constructor.getParameters().isEmpty()) { hasDefaultCtor = true; break;
TypeMirror dmc = type(DynamicMenuContent.class); for (Element e : roundEnv.getElementsAnnotatedWith(ActionRegistration.class)) { ActionRegistration ar = e.getAnnotation(ActionRegistration.class); if (ar == null) { continue; ActionID aid = e.getAnnotation(ActionID.class); if (aid == null) { throw new LayerGenerationException("@ActionRegistration can only be used together with @ActionID annotation", e, processingEnv, ar); if (e.getKind() == ElementKind.FIELD) { VariableElement var = (VariableElement)e; TypeMirror stringType = type(String.class); AnnotationMirror arMirror = null; for (AnnotationMirror m : e.getAnnotationMirrors()) { if (m.getAnnotationType().toString().equals(ActionRegistration.class.getCanonicalName())) { arMirror = m; for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : m.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals("lazy")) { direct = ! (Boolean) entry.getValue().getValue(); assert direct == !ar.lazy(); break;
for (AnnotationMirror m : e.getAnnotationMirrors()) { if (gradingName.equals(m.getAnnotationType().toString())) { for(Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : m.getElementValues().entrySet()) { if("value".equals(entry.getKey().getSimpleName().toString())) { AnnotationValue value = entry.getValue(); parseMeta(processingEnv.getElementUtils().getTypeElement(value.getValue().toString()), info); break; for (ExecutableElement method : ElementFilter.methodsIn(e.getEnclosedElements())) { if (method.getAnnotation(Actor.class) != null) { info.addActor(method); if (method.getAnnotation(Arbiter.class) != null) { info.setArbiter(method); for (VariableElement var : method.getParameters()) { TypeElement paramClass = (TypeElement) processingEnv.getTypeUtils().asElement(var.asType()); if (paramClass.getAnnotation(State.class) != null) { info.setState(paramClass); } else if (paramClass.getAnnotation(Result.class) != null) {
private static List<AnnotationSpec> getExternalAnnotations(VariableElement param) { final List<? extends AnnotationMirror> annotationMirrors = param.getAnnotationMirrors(); final List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationMirror.getAnnotationType().toString().startsWith(COMPONENTS_PACKAGE)) { continue; } final AnnotationSpec.Builder annotationSpec = AnnotationSpec.builder( ClassName.bestGuess(annotationMirror.getAnnotationType().toString())); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> elementValue : elementValues.entrySet()) { annotationSpec.addMember( elementValue.getKey().getSimpleName().toString(), elementValue.getValue().toString()); } annotations.add(annotationSpec.build()); } return annotations; }
if (e.getKind() == ElementKind.CLASS) { String className = ((TypeElement) e).getQualifiedName().toString(); Collection<AnnotationValue> targetTypes = null; List<? extends AnnotationMirror> annotationMirrors = e.getAnnotationMirrors(); for (AnnotationMirror am : annotationMirrors) { for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) { if ("targetType".equals(entry.getKey().getSimpleName().toString())) { //NOI18N targetTypes = (Collection<AnnotationValue>) entry.getValue().getValue(); if (!processingEnv.getTypeUtils().isSubtype(e.asType(), typeElement.asType())) { messager.printMessage(Kind.ERROR, className + " is not subtype of PropertyEditor", e); //NOI18N continue; int i = 1; for (AnnotationValue type : targetTypes) { String clsName = type.accept(new SimpleAnnotationValueVisitor6<String, Object>() {
if (e.getKind() != ElementKind.CLASS) { throw new IllegalStateException("" + e.getKind()); for (AnnotationMirror an : te.getAnnotationMirrors()) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : an.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals("properties")) { val = (List)entry.getValue().getValue(); break; AnnotationMirror am = (AnnotationMirror)val.get(i).getValue(); ret[i] = new Prprt(e, am, arr[i]);
private Void render(TemplateModel model, Element annotatedElement, TypeElement annotation) { parametersScanner.scan(annotatedElement, model); annotation.getEnclosedElements().forEach(new DefaultValueVisitor( method -> { if(nonNull(method.getDefaultValue())) { model.with(method.getSimpleName().toString(), factory.annotationValue(method.getDefaultValue())); annotatedElement.getAnnotationMirrors().stream().filter( mirror -> mirror.getAnnotationType().asElement().equals(annotation) ).forEach(mirror -> mirror.getElementValues().forEach( (name, value) -> model.with(name.getSimpleName().toString(), value.getValue()) )); for(String path : annotation.getAnnotation(Templates.class).value()) { String source = model.render(path); Matcher packageName = PACKAGE.matcher(source);
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())) { for (final String backstackActivityClassName : value.split(",")) {
private void processDeltaSpike(final Element e, final AnnotationMirror am) { final Map<? extends ExecutableElement, ? extends AnnotationValue> values = am.getElementValues(); String name = null; String defaultValue = null; for (final Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : values.entrySet()) { final Name simpleName = entry.getKey().getSimpleName(); if (simpleName.contentEquals("name")) { name = entry.getValue().getValue().toString(); } else if (simpleName.contentEquals("defaultValue")) { defaultValue = entry.getValue().getValue().toString(); if ("org.apache.deltaspike.NullValueMarker".equals(defaultValue)) { defaultValue = null; } } } onEntry(name, defaultValue, TypeElement.class.cast(DeclaredType.class.cast(e.asType()).asElement()).getQualifiedName().toString()); }
private Map<String, Object> getValueMap( Map<? extends ExecutableElement, ? extends AnnotationValue> values) { Map<String, Object> result = new HashMap<String, Object>(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : values .entrySet()) { String name = entry.getKey().getSimpleName().toString(); Object value = entry.getValue().getValue(); if (value instanceof TypeMirror) { TypeMirror tm = (TypeMirror) value; if (tm.getKind() == TypeKind.DECLARED) { DeclaredType declType = (DeclaredType) tm; TypeElement elem = (TypeElement) declType.asElement(); result.put(name, elem.getQualifiedName().toString()); } else { // TODO could this really happen? result.put(name, String.valueOf(value)); } } else { result.put(name, value); } } return result; }
private void init() { final Collection<ExecutableElement> methods = ElementFilter.methodsIn(interfaceElement.getEnclosedElements()); final MessageMethodBuilder builder = MessageMethodBuilder.create(elements, types); for (ExecutableElement param : methods) { for (AnnotationMirror mirror : interfaceElement.getAnnotationMirrors()) { final DeclaredType annotationType = mirror.getAnnotationType(); if (annotationType.toString().equals(types.getDeclaredType(elements.getTypeElement(annotations().messageLogger().getName())).toString())) { final Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues(); for (ExecutableElement key : map.keySet()) { if (key.getSimpleName().contentEquals("loggingClass")) { final String value = map.get(key).getValue().toString(); if (!value.equals(Void.class.getName())) fqcn = value.toString();
public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) { AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) { /* * "methodName" is unset when the default value is used */ if (methodName.equals(entry.getKey().getSimpleName().toString())) { AnnotationValue annotationValue = entry.getValue(); return (DeclaredType) annotationValue.getValue(); } } return null; }
@SuppressWarnings("unchecked") private static Collection<AnnotationMirror> getContainingAnnotations(final AnnotationMirror annotation) { final Collection<AnnotationMirror> result = new ArrayList<>(); // Return any child annotations final Map<? extends ExecutableElement, ? extends AnnotationValue> childAnnotations = annotation.getElementValues(); childAnnotations.entrySet().stream().filter(entry -> entry.getKey().getSimpleName().contentEquals("value")).forEach(entry -> { final Object value = entry.getValue().getValue(); if (value instanceof List) { final List<? extends AnnotationValue> values = (List<? extends AnnotationValue>) value; for (AnnotationValue subValue : values) { if (subValue instanceof AnnotationMirror) { result.add((AnnotationMirror) subValue); } else { result.add((AnnotationMirror) subValue.getValue()); } } } }); return result; } }
@SuppressWarnings("unchecked") public static Set<TypeElement> getAnnotationValuesAsElements(AnnotationMirror mirror, String method) { Set<TypeElement> elements = new HashSet<TypeElement>(); for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().toString().equals(method)) { List<AnnotationValue> values = ((List) entry.getValue().getValue()); for (AnnotationValue value : values) { DeclaredType type = (DeclaredType) value.getValue(); elements.add((TypeElement) type.asElement()); } } } return elements; }
private SimplifiedAST.Annotation createAnnotation(AnnotationMirror annotation) { val type = annotation.getAnnotationType().asElement().asType().toString(); val elementValues = annotation.getElementValues(); val values = new HashMap<String, Object>(); for (val e : elementValues.entrySet()) values.put( e.getKey().getSimpleName().toString(), e.getValue().toString() ); return new SimplifiedAST.Annotation() .setParameters(values).setType(type); }
private boolean isAbstract(final TypeElement annotationElement, final Element typeElement) { for (AnnotationMirror annotation : typeElement.getAnnotationMirrors()) { if (annotation.getAnnotationType().asElement().equals(annotationElement)) { Map<? extends ExecutableElement, ? extends AnnotationValue> annotationValues = processingEnv.getElementUtils().getElementValuesWithDefaults(annotation); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> element : annotationValues.entrySet()) { if ("isAbstract".contentEquals(element.getKey().getSimpleName())) { return element.getValue().getValue().equals(Boolean.TRUE); } } break; } } return false; } }
private BundlerWrapper getBundlerWrapper(Element field) { for (AnnotationMirror annotationMirror : field.getAnnotationMirrors()) { if (!isStateAnnotation(annotationMirror)) { continue; Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (ExecutableElement executableElement : elementValues.keySet()) { if ("value".equals(executableElement.getSimpleName().toString())) { Object value = elementValues.get(executableElement).getValue(); // bundler class if (value == null) { continue; List<? extends TypeMirror> interfaces = mElementUtils.getTypeElement(value.toString()).getInterfaces(); for (TypeMirror anInterface : interfaces) { if (isAssignable(mTypeUtils.erasure(anInterface), BUNDLER_CLASS_NAME)) { List<? extends TypeMirror> typeArguments = ((DeclaredType) anInterface).getTypeArguments(); if (typeArguments != null && typeArguments.size() >= 1) { TypeMirror genericTypeMirror = typeArguments.get(0);