use of java.lang.annotation.Annotation in project requery by requery.
the class EntityType method typeName.
@Override
public QualifiedName typeName() {
String entityName = Stream.of(Mirrors.findAnnotationMirror(element(), Entity.class), Mirrors.findAnnotationMirror(element(), javax.persistence.Entity.class)).filter(Optional::isPresent).map(Optional::get).map(mirror -> Mirrors.findAnnotationValue(mirror, "name")).filter(Optional::isPresent).map(Optional::get).map(value -> value.getValue().toString()).filter(name -> !Names.isEmpty(name)).findAny().orElse("");
Elements elements = processingEnvironment.getElementUtils();
String packageName = elements.getPackageOf(element()).getQualifiedName().toString();
// if set in the annotation just use that
if (!Names.isEmpty(entityName)) {
return new QualifiedName(packageName, entityName);
}
String typeName = element().getSimpleName().toString();
if (element().getKind().isInterface()) {
// maybe I<Something> style
if (typeName.startsWith("I") && Character.isUpperCase(typeName.charAt(1))) {
entityName = typeName.substring(1);
} else {
entityName = typeName + "Entity";
}
} else {
entityName = Names.removeClassPrefixes(typeName);
if (entityName.equals(typeName)) {
entityName = typeName + (isImmutable() || isUnimplementable() ? "Type" : "Entity");
}
}
return new QualifiedName(packageName, entityName);
}
use of java.lang.annotation.Annotation in project roboguice by roboguice.
the class Annotations method getKey.
/** Gets a key for the given type, member and annotations. */
public static Key<?> getKey(TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors) throws ErrorsException {
int numErrorsBefore = errors.size();
Annotation found = findBindingAnnotation(errors, member, annotations);
errors.throwIfNewErrors(numErrorsBefore);
return found == null ? Key.get(type) : Key.get(type, found);
}
use of java.lang.annotation.Annotation in project roboguice by roboguice.
the class FactoryProvider method createMethodMapping.
private static Map<Method, AssistedConstructor<?>> createMethodMapping(TypeLiteral<?> factoryType, TypeLiteral<?> implementationType) {
List<AssistedConstructor<?>> constructors = Lists.newArrayList();
for (Constructor<?> constructor : implementationType.getRawType().getDeclaredConstructors()) {
if (constructor.isAnnotationPresent(AssistedInject.class)) {
AssistedConstructor<?> assistedConstructor = AssistedConstructor.create(constructor, implementationType.getParameterTypes(constructor));
constructors.add(assistedConstructor);
}
}
if (constructors.isEmpty()) {
return ImmutableMap.of();
}
Method[] factoryMethods = factoryType.getRawType().getMethods();
if (constructors.size() != factoryMethods.length) {
throw newConfigurationException("Constructor mismatch: %s has %s @AssistedInject " + "constructors, factory %s has %s creation methods", implementationType, constructors.size(), factoryType, factoryMethods.length);
}
Map<ParameterListKey, AssistedConstructor<?>> paramsToConstructor = Maps.newHashMap();
for (AssistedConstructor<?> c : constructors) {
if (paramsToConstructor.containsKey(c.getAssistedParameters())) {
throw new RuntimeException("Duplicate constructor, " + c);
}
paramsToConstructor.put(c.getAssistedParameters(), c);
}
Map<Method, AssistedConstructor<?>> result = Maps.newHashMap();
for (Method method : factoryMethods) {
if (!method.getReturnType().isAssignableFrom(implementationType.getRawType())) {
throw newConfigurationException("Return type of method %s is not assignable from %s", method, implementationType);
}
List<Type> parameterTypes = Lists.newArrayList();
for (TypeLiteral<?> parameterType : factoryType.getParameterTypes(method)) {
parameterTypes.add(parameterType.getType());
}
ParameterListKey methodParams = new ParameterListKey(parameterTypes);
if (!paramsToConstructor.containsKey(methodParams)) {
throw newConfigurationException("%s has no @AssistInject constructor that takes the " + "@Assisted parameters %s in that order. @AssistInject constructors are %s", implementationType, methodParams, paramsToConstructor.values());
}
method.getParameterAnnotations();
for (Annotation[] parameterAnnotations : method.getParameterAnnotations()) {
for (Annotation parameterAnnotation : parameterAnnotations) {
if (parameterAnnotation.annotationType() == Assisted.class) {
throw newConfigurationException("Factory method %s has an @Assisted parameter, which " + "is incompatible with the deprecated @AssistedInject annotation. Please replace " + "@AssistedInject with @Inject on the %s constructor.", method, implementationType);
}
}
}
AssistedConstructor<?> matchingConstructor = paramsToConstructor.remove(methodParams);
result.put(method, matchingConstructor);
}
return result;
}
use of java.lang.annotation.Annotation in project roboguice by roboguice.
the class Parameter method getBindingAnnotation.
/**
* Returns the unique binding annotation from the specified list, or
* {@code null} if there are none.
*
* @throws IllegalStateException if multiple binding annotations exist.
*/
private Annotation getBindingAnnotation(Annotation[] annotations) {
Annotation bindingAnnotation = null;
for (Annotation annotation : annotations) {
if (Annotations.isBindingAnnotation(annotation.annotationType())) {
checkArgument(bindingAnnotation == null, "Parameter has multiple binding annotations: %s and %s", bindingAnnotation, annotation);
bindingAnnotation = annotation;
}
}
return bindingAnnotation;
}
use of java.lang.annotation.Annotation in project android-saripaar by ragunathjawahar.
the class Validator method getSaripaarAnnotatedFields.
private List<Field> getSaripaarAnnotatedFields(final Class<?> controllerClass) {
Set<Class<? extends Annotation>> saripaarAnnotations = SARIPAAR_REGISTRY.getRegisteredAnnotations();
List<Field> annotatedFields = new ArrayList<Field>();
List<Field> controllerViewFields = getControllerViewFields(controllerClass);
for (int i = 0, n = controllerViewFields.size(); i < n; i++) {
Field field = controllerViewFields.get(i);
if (isSaripaarAnnotatedField(field, saripaarAnnotations)) {
annotatedFields.add(field);
}
}
// Sort
SaripaarFieldsComparator comparator = new SaripaarFieldsComparator();
Collections.sort(annotatedFields, comparator);
mOrderedFields = annotatedFields.size() == 1 ? annotatedFields.get(0).getAnnotation(Order.class) != null : annotatedFields.size() != 0 && comparator.areOrderedFields();
return annotatedFields;
}
Aggregations