Skip to content

Commit c446ad5

Browse files
committed
added javaDoc and codeBeforeClass to Entity, freemarker:2.3.23
1 parent e002b2c commit c446ad5

File tree

6 files changed

+42
-10
lines changed

6 files changed

+42
-10
lines changed

DaoGenerator/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ apply plugin: 'signing'
44

55
group = 'de.greenrobot'
66
archivesBaseName = 'greendao-generator'
7-
version = '2.0.0'
8-
sourceCompatibility = 1.6
7+
version = '2.1.0-SNAPSHOT'
8+
sourceCompatibility = 1.7
99

1010
def isSnapshot = version.endsWith('-SNAPSHOT')
1111
def sonatypeRepositoryUrl
@@ -27,7 +27,7 @@ configurations {
2727
}
2828

2929
dependencies {
30-
compile 'org.freemarker:freemarker:2.3.22'
30+
compile 'org.freemarker:freemarker:2.3.23'
3131
testCompile 'junit:junit:4.12'
3232
// deployerJars 'org.apache.maven.wagon:wagon-webdav-jackrabbit:2.4'
3333
deployerJars 'org.apache.maven.wagon:wagon-webdav:1.0-beta-2'

DaoGenerator/src-template/entity.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ import ${additionalImport};
4444
<#else>
4545
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
4646
</#if>
47+
<#if entity.javaDoc ??>
48+
${entity.javaDoc}
49+
<#else>
4750
/**
4851
* Entity mapped to table "${entity.tableName}".
4952
*/
53+
</#if>
54+
<#if entity.codeBeforeClass ??>
55+
${entity.codeBeforeClass}
56+
</#if>
5057
public class ${entity.className}<#if
5158
entity.superclass?has_content> extends ${entity.superclass} </#if><#if
5259
entity.interfacesToImplement?has_content> implements <#list entity.interfacesToImplement

DaoGenerator/src/de/greenrobot/daogenerator/DaoGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.regex.Pattern;
2929

3030
import freemarker.template.Configuration;
31-
import freemarker.template.DefaultObjectWrapper;
3231
import freemarker.template.Template;
3332

3433
/**
@@ -58,9 +57,8 @@ public DaoGenerator() throws IOException {
5857
patternKeepFields = compilePattern("FIELDS");
5958
patternKeepMethods = compilePattern("METHODS");
6059

61-
Configuration config = new Configuration();
60+
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
6261
config.setClassForTemplateLoading(this.getClass(), "/");
63-
config.setObjectWrapper(new DefaultObjectWrapper());
6462

6563
templateDao = config.getTemplate("dao.ftl");
6664
templateDaoMaster = config.getTemplate("dao-master.ftl");

DaoGenerator/src/de/greenrobot/daogenerator/Entity.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*/
1818
package de.greenrobot.daogenerator;
1919

20-
import de.greenrobot.daogenerator.Property.PropertyBuilder;
21-
2220
import java.util.ArrayList;
2321
import java.util.Collection;
2422
import java.util.HashSet;
2523
import java.util.List;
2624
import java.util.Set;
2725
import java.util.TreeSet;
2826

27+
import de.greenrobot.daogenerator.Property.PropertyBuilder;
28+
2929
/**
3030
* Model class for an entity: a Java data object mapped to a data base table. A new entity is added to a {@link Schema}
3131
* by the method {@link Schema#addEntity(String)} (there is no public constructor for {@link Entity} itself). <br/>
@@ -64,6 +64,8 @@ public class Entity {
6464
private Property pkProperty;
6565
private String pkType;
6666
private String superclass;
67+
private String javaDoc;
68+
private String codeBeforeClass;
6769

6870
private boolean protobuf;
6971
private boolean constructors;
@@ -463,7 +465,27 @@ public void setSuperclass(String classToExtend) {
463465
this.superclass = classToExtend;
464466
}
465467

468+
public String getJavaDoc() {
469+
return javaDoc;
470+
}
471+
472+
public void setJavaDoc(String javaDoc) {
473+
this.javaDoc = javaDoc;
474+
}
475+
476+
public String getCodeBeforeClass() {
477+
return codeBeforeClass;
478+
}
479+
480+
public void setCodeBeforeClass(String codeBeforeClass) {
481+
this.codeBeforeClass = codeBeforeClass;
482+
}
483+
466484
void init2ndPass() {
485+
if (javaDoc != null && !javaDoc.trim().startsWith("/**")) {
486+
javaDoc = javaDoc.replace("\n", "\n * ");
487+
javaDoc = "/**\n * " + javaDoc + "\n*/";
488+
}
467489
init2ndPassNamesWithDefaults();
468490

469491
for (int i = 0; i < properties.size(); i++) {

DaoTest/src-gen/de/greenrobot/daotest/TestEntity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.
44
/**
5-
* Entity mapped to table "TEST_ENTITY".
6-
*/
5+
* This entity is used by internal tests of greenDAO.
6+
* (This JavaDoc is defined in the generator project.)
7+
*/
8+
// This is another test comment, you could also apply annotations like this
79
public class TestEntity {
810

911
private Long id;

DaoTestGenerator/src/de/greenrobot/daogenerator/gentest/TestDaoGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ protected void createSimpleNotNull() {
105105

106106
protected Entity createTest() {
107107
Entity testEntity = schema.addEntity("TestEntity");
108+
testEntity.setJavaDoc("This entity is used by internal tests of greenDAO.\n" +
109+
"(This JavaDoc is defined in the generator project.)");
110+
testEntity.setCodeBeforeClass("// This is another test comment, you could also apply annotations like this");
108111
testEntity.addIdProperty();
109112
testEntity.addIntProperty("simpleInt").notNull();
110113
testEntity.addIntProperty("simpleInteger");

0 commit comments

Comments
 (0)