mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Merge pull request #1481 from DaSilva2010/use-fieldtypes
Added an option to switch between field and getter return types.
This commit is contained in:
commit
46c880ce5c
@ -99,6 +99,8 @@ public class GenericExporter {
|
||||
|
||||
private boolean handleFields = true, handleMethods = true;
|
||||
|
||||
private boolean useFieldTypes = false;
|
||||
|
||||
@Nullable
|
||||
private File targetFolder;
|
||||
|
||||
@ -391,7 +393,7 @@ public class GenericExporter {
|
||||
AnnotatedElement annotated = ReflectionUtils.getAnnotatedElement(cl, field.getName(), field.getType());
|
||||
Method method = ReflectionUtils.getGetterOrNull(cl, field.getName(), field.getType());
|
||||
Type propertyType = null;
|
||||
if (method != null) {
|
||||
if (method != null && !useFieldTypes) {
|
||||
propertyType = getPropertyType(cl, annotated, method.getReturnType(), method.getGenericReturnType());
|
||||
} else {
|
||||
propertyType = getPropertyType(cl, annotated, field.getType(), field.getGenericType());
|
||||
@ -707,6 +709,15 @@ public class GenericExporter {
|
||||
handleMethods = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether field types should be used instead of getter return types (default false)
|
||||
*
|
||||
* @param b
|
||||
*/
|
||||
public void setUseFieldTypes(boolean b) {
|
||||
useFieldTypes = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a stop class to be used (default Object.class and Enum.class)
|
||||
*
|
||||
|
||||
@ -130,4 +130,17 @@ public class GenericExporterTest {
|
||||
assertTrue(new File("target/gen7/com/querydsl/codegen/sub/QExampleEntity2.java").exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Export_UseFieldTypes() {
|
||||
exporter.setTargetFolder(new File("target/gen8"));
|
||||
exporter.export(getClass().getPackage());
|
||||
exporter.setUseFieldTypes(true);
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/QExampleEmbeddable.java").exists());
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/QExampleEmbedded.java").exists());
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/QExampleEntity.java").exists());
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/QExampleEntityInterface.java").exists());
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/QExampleSupertype.java").exists());
|
||||
assertTrue(new File("target/gen8/com/querydsl/codegen/sub/QExampleEntity2.java").exists());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -76,6 +76,13 @@ public abstract class AbstractExporterMojo extends AbstractMojo {
|
||||
*/
|
||||
private boolean handleMethods = true;
|
||||
|
||||
/**
|
||||
* switch for usage of field types instead of getter types
|
||||
*
|
||||
* @parameter default-value=false
|
||||
*/
|
||||
private boolean useFieldTypes = false;
|
||||
|
||||
/**
|
||||
* maven project
|
||||
*
|
||||
@ -154,6 +161,7 @@ public abstract class AbstractExporterMojo extends AbstractMojo {
|
||||
protected void configure(GenericExporter exporter) {
|
||||
exporter.setHandleFields(handleFields);
|
||||
exporter.setHandleMethods(handleMethods);
|
||||
exporter.setUseFieldTypes(useFieldTypes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -226,4 +234,8 @@ public abstract class AbstractExporterMojo extends AbstractMojo {
|
||||
public void setHandleMethods(boolean handleMethods) {
|
||||
this.handleMethods = handleMethods;
|
||||
}
|
||||
|
||||
public void setUseFieldTypes(boolean useFieldTypes) {
|
||||
this.useFieldTypes = useFieldTypes;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user