mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
updated version to 0.2.7
This commit is contained in:
parent
a638e01173
commit
fa81781584
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.mysema.codegen</groupId>
|
||||
<artifactId>codegen</artifactId>
|
||||
<version>0.2.6-SNAPSHOT</version>
|
||||
<version>0.2.7</version>
|
||||
<name>Codegen</name>
|
||||
<description>Code generation and compilation for Java</description>
|
||||
<parent>
|
||||
|
||||
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@ -102,7 +103,10 @@ public class ScalaWriter extends AbstractCodeWriter<ScalaWriter>{
|
||||
for (Method method : methods){
|
||||
try {
|
||||
Object value = method.invoke(annotation);
|
||||
if (value == null || value.equals(method.getDefaultValue())){
|
||||
if (value == null
|
||||
|| value.equals(method.getDefaultValue())
|
||||
|| (value.getClass().isArray()
|
||||
&& Arrays.equals((Object[])value, (Object[])method.getDefaultValue()))){
|
||||
continue;
|
||||
}else if (!first){
|
||||
append(COMMA);
|
||||
@ -134,19 +138,32 @@ public class ScalaWriter extends AbstractCodeWriter<ScalaWriter>{
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void annotationConstant(Object value) throws IOException{
|
||||
if (value instanceof Class){
|
||||
appendType((Class)value).append(".class");
|
||||
}else if (value instanceof Number || value instanceof Boolean){
|
||||
append(value.toString());
|
||||
}else if (value instanceof Enum){
|
||||
Enum enumValue = (Enum)value;
|
||||
append(enumValue.getDeclaringClass().getName()+DOT+enumValue.name());
|
||||
}else if (value instanceof String){
|
||||
append(QUOTE + StringEscapeUtils.escapeJava(value.toString()) + QUOTE);
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unsupported annotation value : " + value);
|
||||
}
|
||||
}
|
||||
if (value.getClass().isArray()){
|
||||
append("Array(");
|
||||
boolean first = true;
|
||||
for (Object o : (Object[])value){
|
||||
if (!first){
|
||||
append(", ");
|
||||
}
|
||||
annotationConstant(o);
|
||||
first = false;
|
||||
}
|
||||
append(")");
|
||||
}else if (value instanceof Class){
|
||||
append("classOf[");
|
||||
appendType((Class)value);
|
||||
append("]");
|
||||
}else if (value instanceof Number || value instanceof Boolean){
|
||||
append(value.toString());
|
||||
}else if (value instanceof Enum){
|
||||
Enum enumValue = (Enum)value;
|
||||
append(enumValue.getDeclaringClass().getName()+DOT+enumValue.name());
|
||||
}else if (value instanceof String){
|
||||
append(QUOTE + StringEscapeUtils.escapeJava(value.toString()) + QUOTE);
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unsupported annotation value : " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private ScalaWriter appendType(Class<?> type) throws IOException{
|
||||
if (classes.contains(type.getName()) || packages.contains(type.getPackage().getName())){
|
||||
|
||||
@ -9,6 +9,8 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
|
||||
import org.apache.commons.collections15.Transformer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -172,6 +174,18 @@ public class ScalaWriterTest {
|
||||
System.out.println(w);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void AnnotationConstant() throws IOException{
|
||||
Max annotation = new MaxImpl(0l){
|
||||
@Override
|
||||
public Class<?>[] groups() {
|
||||
return new Class[]{Object.class, String.class};
|
||||
}
|
||||
};
|
||||
writer.annotation(annotation);
|
||||
|
||||
System.out.println(w);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Annotations() throws IOException{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user