Improve readability by using the isAnnotationPresent utility method

This commit is contained in:
Ruben Dijkstra 2014-09-25 21:44:29 +02:00
parent e99ba57543
commit a5e9e5d082
8 changed files with 14 additions and 17 deletions

View File

@ -113,7 +113,7 @@ public abstract class AbstractModule {
private <T> T createInstance(Class<? extends T> implementation) {
Constructor<?> constructor = null;
for (Constructor<?> c : implementation.getConstructors()) {
if (c.getAnnotation(Inject.class) != null) {
if (c.isAnnotationPresent(Inject.class)) {
constructor = c;
break;
}

View File

@ -361,7 +361,7 @@ public class GenericExporter {
private void addConstructors(Class<?> cl, EntityType type) {
for (Constructor<?> constructor : cl.getConstructors()) {
if (constructor.getAnnotation(QueryProjection.class) != null) {
if (constructor.isAnnotationPresent(QueryProjection.class)) {
List<Parameter> parameters = Lists.newArrayList();
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Type parameterType = typeFactory.get(
@ -507,15 +507,15 @@ public class GenericExporter {
private void handleClass(Class<?> cl) {
if (stopClasses.contains(cl) || cl.isAnnotationPresent(QueryExclude.class)) {
return;
} else if (cl.getAnnotation(entityAnnotation) != null) {
} else if (cl.isAnnotationPresent(entityAnnotation)) {
entityTypes.put(cl, null);
} else if (cl.getAnnotation(embeddableAnnotation) != null) {
} else if (cl.isAnnotationPresent(embeddableAnnotation)) {
embeddableTypes.put(cl, null);
} else if (cl.getAnnotation(supertypeAnnotation) != null) {
} else if (cl.isAnnotationPresent(supertypeAnnotation)) {
superTypes.put(cl, null);
} else {
for (Constructor<?> constructor : cl.getConstructors()) {
if (constructor.getAnnotation(QueryProjection.class) != null) {
if (constructor.isAnnotationPresent(QueryProjection.class)) {
projectionTypes.put(cl, null);
break;
}

View File

@ -214,7 +214,7 @@ public final class TypeFactory {
private boolean isEntityClass(Class<?> cl) {
for (Class<? extends Annotation> clazz : entityAnnotations) {
if (cl.getAnnotation(clazz) != null) {
if (cl.isAnnotationPresent(clazz)) {
return true;
}
}

View File

@ -413,7 +413,7 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
final List<Expression<?>> newArgs = new ArrayList<Expression<?>>(args);
final Class<?> cl = ((Class<?>) ((Constant<?>) newArgs.get(1)).getConstant());
// use discriminator value instead of fqnm
if (cl.getAnnotation(DiscriminatorValue.class) != null) {
if (cl.isAnnotationPresent(DiscriminatorValue.class)) {
newArgs.set(1, ConstantImpl.create(cl.getAnnotation(DiscriminatorValue.class).value()));
} else {
newArgs.set(1, ConstantImpl.create(cl.getSimpleName()));

View File

@ -66,7 +66,7 @@ public final class NativeSQLSerializer extends SQLSerializer {
protected void handleJoinTarget(JoinExpression je) {
SQLTemplates templates = getTemplates();
Class<?> type = je.getTarget().getType();
if (type.getAnnotation(Table.class) != null && templates.isSupportsAlias()) {
if (type.isAnnotationPresent(Table.class) && templates.isSupportsAlias()) {
Table table = type.getAnnotation(Table.class);
if (!table.schema().isEmpty() && templates.isPrintSchema()) {
appendSchemaName(table.schema());

View File

@ -37,11 +37,8 @@ public class JPAProviderRule implements MethodRule {
}
private <T extends Annotation> boolean hasAnnotation(FrameworkMethod method, Class<T> clazz) {
T rv = method.getMethod().getAnnotation(clazz);
if (rv == null) {
rv = method.getMethod().getDeclaringClass().getAnnotation(clazz);
}
return rv != null;
return method.getMethod().isAnnotationPresent(clazz)
|| method.getMethod().getDeclaringClass().isAnnotationPresent(clazz);
}
}

View File

@ -49,7 +49,7 @@ public class MorphiaSerializer extends MongodbSerializer {
@Override
protected boolean isReference(Path<?> arg) {
return arg.getAnnotatedElement().getAnnotation(Reference.class) != null;
return arg.getAnnotatedElement().isAnnotationPresent(Reference.class);
}
@Override

View File

@ -13,8 +13,8 @@ public class SkipForQuotedRule implements MethodRule {
public Statement apply(Statement base, FrameworkMethod method, Object target) {
SQLTemplates templates = Connections.getTemplates();
if (templates.isUseQuotes() || templates.isPrintSchema()) {
boolean run = method.getMethod().getAnnotation(SkipForQuoted.class) == null;
return run ? base : EmptyStatement.DEFAULT;
boolean skip = method.getMethod().isAnnotationPresent(SkipForQuoted.class);
return skip ? EmptyStatement.DEFAULT : base;
} else {
return base;
}