mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Add CodeWriter.getClassConstant() to abstract the difference between A.class in Java and classOf[A] in Scala. To be used in querydsl-codegen shortly.
This commit is contained in:
parent
7493e1af30
commit
8ff357f6d0
@ -33,6 +33,8 @@ public interface CodeWriter extends Appendable {
|
||||
|
||||
String getGenericName(boolean asArgType, Type type);
|
||||
|
||||
String getClassConstant(String className);
|
||||
|
||||
CodeWriter annotation(Annotation annotation) throws IOException;
|
||||
|
||||
CodeWriter annotation(Class<? extends Annotation> annotation) throws IOException;
|
||||
|
||||
@ -303,6 +303,12 @@ public final class JavaWriter extends AbstractCodeWriter<JavaWriter> {
|
||||
+ value + SEMICOLON).nl();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getClassConstant(String className) {
|
||||
return className + ".class";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenericName(boolean asArgType, Type type) {
|
||||
return type.getGenericName(asArgType, packages, classes);
|
||||
|
||||
@ -352,6 +352,11 @@ public class ScalaWriter extends AbstractCodeWriter<ScalaWriter> {
|
||||
return compact ? this : nl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassConstant(String className) {
|
||||
return "classOf[" + className + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenericName(boolean asArgType, Type type) {
|
||||
if (type.getParameters().isEmpty()) {
|
||||
|
||||
@ -223,6 +223,11 @@ public class JavaWriterTest {
|
||||
assertTrue(w.toString().contains("@Target({FIELD, METHOD})"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ClassConstants() {
|
||||
assertEquals("SomeClass.class", writer.getClassConstant("SomeClass"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Fields() throws IOException {
|
||||
writer.beginClass(testType);
|
||||
@ -330,5 +335,4 @@ public class JavaWriterTest {
|
||||
|
||||
match("/testSuppressWarnings", w.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -366,6 +366,11 @@ public class ScalaWriterTest {
|
||||
assertEquals("case class TestType(a: String, b: String)\n", w.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ClassConstants() {
|
||||
assertEquals("classOf[SomeClass]", writer.getClassConstant("SomeClass"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Primitive() throws IOException {
|
||||
writer.beginClass(testType);
|
||||
@ -381,7 +386,7 @@ public class ScalaWriterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Primive_Types() throws IOException {
|
||||
public void Primitive_Types() throws IOException {
|
||||
writer.field(Types.BOOLEAN_P, "field");
|
||||
writer.field(Types.BYTE_P, "field");
|
||||
writer.field(Types.CHAR, "field");
|
||||
@ -417,5 +422,4 @@ public class ScalaWriterTest {
|
||||
assertTrue(w.toString().contains("`class`: JavaWriterTest"));
|
||||
assertTrue(w.toString().contains("`var`(): JavaWriterTest"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user