mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Improve readability by using the isAnnotationPresent utility method
This commit is contained in:
parent
e99ba57543
commit
a5e9e5d082
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()));
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user