use of javax.lang.model.element.AnnotationMirror in project glide by bumptech.
the class RequestBuilderGenerator method generateRequestBuilderOverride.
/**
* Generates an override of a particular method in {@code com.bumptech.glide.RequestBuilder} that
* returns {@code com.bumptech.glide.RequestBuilder} so that it returns our generated subclass
* instead.
*/
private MethodSpec generateRequestBuilderOverride(ExecutableElement methodToOverride) {
// We've already verified that this method returns a RequestBuilder and RequestBuilders have
// exactly one type argument, so this is safe unless those assumptions change.
TypeMirror typeArgument = ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);
ParameterizedTypeName generatedRequestBuilderOfType = ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));
MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride).returns(generatedRequestBuilderOfType);
builder.addCode(CodeBlock.builder().add("return ($T) super.$N(", generatedRequestBuilderOfType, methodToOverride.getSimpleName()).add(FluentIterable.from(builder.build().parameters).transform(new Function<ParameterSpec, String>() {
@Override
public String apply(ParameterSpec input) {
return input.name;
}
}).join(Joiner.on(", "))).add(");\n").build());
for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
builder = builder.addAnnotation(AnnotationSpec.get(mirror));
}
if (methodToOverride.isVarArgs()) {
builder = builder.addModifiers(Modifier.FINAL).addAnnotation(SafeVarargs.class).addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "varargs").build());
}
return builder.build();
}
use of javax.lang.model.element.AnnotationMirror in project arez by arez.
the class ComponentDescriptor method analyzeMethod.
private boolean analyzeMethod(@Nonnull final ExecutableElement method, @Nonnull final ExecutableType methodType) throws ArezProcessorException {
verifyNoDuplicateAnnotations(method);
final AnnotationMirror action = ProcessorUtil.findAnnotationByType(method, Constants.ACTION_ANNOTATION_CLASSNAME);
final AnnotationMirror autorun = ProcessorUtil.findAnnotationByType(method, Constants.AUTORUN_ANNOTATION_CLASSNAME);
final AnnotationMirror observable = ProcessorUtil.findAnnotationByType(method, Constants.OBSERVABLE_ANNOTATION_CLASSNAME);
final AnnotationMirror observableRef = ProcessorUtil.findAnnotationByType(method, Constants.OBSERVABLE_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror computed = ProcessorUtil.findAnnotationByType(method, Constants.COMPUTED_ANNOTATION_CLASSNAME);
final AnnotationMirror computedValueRef = ProcessorUtil.findAnnotationByType(method, Constants.COMPUTED_VALUE_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror contextRef = ProcessorUtil.findAnnotationByType(method, Constants.CONTEXT_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror componentRef = ProcessorUtil.findAnnotationByType(method, Constants.COMPONENT_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror componentId = ProcessorUtil.findAnnotationByType(method, Constants.COMPONENT_ID_ANNOTATION_CLASSNAME);
final AnnotationMirror componentTypeName = ProcessorUtil.findAnnotationByType(method, Constants.COMPONENT_TYPE_NAME_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror componentName = ProcessorUtil.findAnnotationByType(method, Constants.COMPONENT_NAME_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror postConstruct = ProcessorUtil.findAnnotationByType(method, Constants.POST_CONSTRUCT_ANNOTATION_CLASSNAME);
final AnnotationMirror ejbPostConstruct = ProcessorUtil.findAnnotationByType(method, Constants.EJB_POST_CONSTRUCT_ANNOTATION_CLASSNAME);
final AnnotationMirror preDispose = ProcessorUtil.findAnnotationByType(method, Constants.PRE_DISPOSE_ANNOTATION_CLASSNAME);
final AnnotationMirror postDispose = ProcessorUtil.findAnnotationByType(method, Constants.POST_DISPOSE_ANNOTATION_CLASSNAME);
final AnnotationMirror onActivate = ProcessorUtil.findAnnotationByType(method, Constants.ON_ACTIVATE_ANNOTATION_CLASSNAME);
final AnnotationMirror onDeactivate = ProcessorUtil.findAnnotationByType(method, Constants.ON_DEACTIVATE_ANNOTATION_CLASSNAME);
final AnnotationMirror onStale = ProcessorUtil.findAnnotationByType(method, Constants.ON_STALE_ANNOTATION_CLASSNAME);
final AnnotationMirror onDispose = ProcessorUtil.findAnnotationByType(method, Constants.ON_DISPOSE_ANNOTATION_CLASSNAME);
final AnnotationMirror track = ProcessorUtil.findAnnotationByType(method, Constants.TRACK_ANNOTATION_CLASSNAME);
final AnnotationMirror onDepsChanged = ProcessorUtil.findAnnotationByType(method, Constants.ON_DEPS_CHANGED_ANNOTATION_CLASSNAME);
final AnnotationMirror observerRef = ProcessorUtil.findAnnotationByType(method, Constants.OBSERVER_REF_ANNOTATION_CLASSNAME);
final AnnotationMirror memoize = ProcessorUtil.findAnnotationByType(method, Constants.MEMOIZE_ANNOTATION_CLASSNAME);
final AnnotationMirror dependency = ProcessorUtil.findAnnotationByType(method, Constants.DEPENDENCY_ANNOTATION_CLASSNAME);
if (null != observable) {
addObservable(observable, method, methodType);
return true;
} else if (null != observableRef) {
addObservableRef(observableRef, method, methodType);
return true;
} else if (null != action) {
addAction(action, method, methodType);
return true;
} else if (null != autorun) {
addAutorun(autorun, method, methodType);
return true;
} else if (null != track) {
addTracked(track, method, methodType);
return true;
} else if (null != onDepsChanged) {
addOnDepsChanged(onDepsChanged, method);
return true;
} else if (null != observerRef) {
addObserverRef(observerRef, method, methodType);
return true;
} else if (null != contextRef) {
setContextRef(method);
return true;
} else if (null != computed) {
addComputed(computed, method, methodType);
return true;
} else if (null != computedValueRef) {
addComputedValueRef(computedValueRef, method, methodType);
return true;
} else if (null != memoize) {
addMemoize(memoize, method, methodType);
return true;
} else if (null != componentRef) {
setComponentRef(method);
return true;
} else if (null != componentId) {
setComponentId(method, methodType);
return true;
} else if (null != componentName) {
setComponentNameRef(method);
return true;
} else if (null != componentTypeName) {
setComponentTypeNameRef(method);
return true;
} else if (null != ejbPostConstruct) {
throw new ArezProcessorException("@" + Constants.EJB_POST_CONSTRUCT_ANNOTATION_CLASSNAME + " annotation " + "not supported in components annotated with @ArezComponent, use the @" + Constants.POST_CONSTRUCT_ANNOTATION_CLASSNAME + " annotation instead.", method);
} else if (null != postConstruct) {
setPostConstruct(method);
return true;
} else if (null != preDispose) {
setPreDispose(method);
return true;
} else if (null != postDispose) {
setPostDispose(method);
return true;
} else if (null != onActivate) {
addOnActivate(onActivate, method);
return true;
} else if (null != onDeactivate) {
addOnDeactivate(onDeactivate, method);
return true;
} else if (null != onStale) {
addOnStale(onStale, method);
return true;
} else if (null != onDispose) {
addOnDispose(onDispose, method);
return true;
} else if (null != dependency) {
addDependency(method);
return false;
} else {
return false;
}
}
use of javax.lang.model.element.AnnotationMirror in project scout.rt by eclipse.
the class EntryPointDefinition method getAuthMethod.
/**
* @return qualified name of the {@link IAuthenticationMethod} used.
*/
public String getAuthMethod() {
final AnnotationMirror authenticationAnnotation = (AnnotationMirror) AnnotationUtil.getAnnotationValue(m_annotationMirror, "authentication", m_env.getElementUtils()).getValue();
final AnnotationMirror clazzAnnotation = (AnnotationMirror) AnnotationUtil.getAnnotationValue(authenticationAnnotation, "method", m_env.getElementUtils()).getValue();
return AnnotationUtil.resolveClass(clazzAnnotation, m_env);
}
use of javax.lang.model.element.AnnotationMirror in project scout.rt by eclipse.
the class EntryPointDefinition method getHandlerChain.
/**
* @return {@link List} of declared handlers.
*/
public List<HandlerDefinition> getHandlerChain() {
final List<HandlerDefinition> handlerChain = new ArrayList<>();
@SuppressWarnings("unchecked") final List<AnnotationValue> handlerAnnotationValues = (List<AnnotationValue>) AnnotationUtil.getAnnotationValue(m_annotationMirror, "handlerChain", m_env.getElementUtils()).getValue();
for (final AnnotationValue handlerAnnotationValue : handlerAnnotationValues) {
final AnnotationMirror handlerAnnotation = (AnnotationMirror) handlerAnnotationValue.getValue();
handlerChain.add(new HandlerDefinition(handlerAnnotation));
}
return handlerChain;
}
use of javax.lang.model.element.AnnotationMirror in project scout.rt by eclipse.
the class AnnotationUtil method createExpression.
/**
* Creates an expression for the given annotation value. Thereby, all annotation member types as specified by JLS are
* supported: primitive, String, Class, Enum, annotation, 1-dimensional array.
*/
public static JExpression createExpression(final JCodeModel model, final AnnotationValue _paramValue) {
final Object _rawParamValue = _paramValue.getValue();
// Class member type.
if (_rawParamValue instanceof TypeMirror) {
final TypeMirror _clazz = (TypeMirror) _rawParamValue;
return JExpr.dotclass(model.ref(_clazz.toString()));
} else // Enum member type.
if (_rawParamValue instanceof VariableElement) {
final VariableElement _enum = (VariableElement) _rawParamValue;
final JClass enumType = model.ref(_enum.asType().toString());
final String enumValue = _enum.getSimpleName().toString();
return new JExpressionImpl() {
@Override
public void generate(final JFormatter f) {
f.t(enumType).p('.').p(enumValue);
}
};
} else // Annotation member type.
if (_rawParamValue instanceof AnnotationMirror) {
final AnnotationMirror _refAnnotation = (AnnotationMirror) _rawParamValue;
final JClass refAnnotationClazz = model.ref(_refAnnotation.getAnnotationType().toString());
final P_AnnotationExpression refAnnotationExpression = new P_AnnotationExpression(refAnnotationClazz);
for (final Entry<? extends ExecutableElement, ? extends AnnotationValue> _annotationParamEntry : _refAnnotation.getElementValues().entrySet()) {
final String paramName = _annotationParamEntry.getKey().getSimpleName().toString();
refAnnotationExpression.param(paramName, AnnotationUtil.createExpression(model, _annotationParamEntry.getValue()));
}
return refAnnotationExpression;
} else // Array member type.
if (_rawParamValue instanceof List<?>) {
final List<JExpression> expressions = new ArrayList<>();
for (final Object _arrayElementValue : (List<?>) _rawParamValue) {
expressions.add(AnnotationUtil.createExpression(model, (AnnotationValue) _arrayElementValue));
}
return new JExpressionImpl() {
@Override
public void generate(final JFormatter f) {
if (expressions.size() == 1) {
f.g(expressions.get(0));
} else {
f.p("{").g(expressions).p("}");
}
}
};
} else if (_rawParamValue instanceof String) {
return JExpr.lit((String) _rawParamValue);
} else if (_rawParamValue instanceof Integer) {
return JExpr.lit((Integer) _rawParamValue);
} else if (_rawParamValue instanceof Float) {
return JExpr.lit((Float) _rawParamValue);
} else if (_rawParamValue instanceof Double) {
return JExpr.lit((Double) _rawParamValue);
} else if (_rawParamValue instanceof Boolean) {
return JExpr.lit((Boolean) _rawParamValue);
} else if (_rawParamValue instanceof Character) {
return JExpr.lit((Character) _rawParamValue);
} else if (_rawParamValue instanceof Byte) {
return JExpr.lit((Byte) _rawParamValue);
} else {
return JExpr._null();
}
}
Aggregations