Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Commit

Permalink
METAGEN-79 Unified skipGeneratedAnnotation and addGeneratedAnnotation
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Jan 25, 2012
1 parent 3e168e3 commit df68192
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 32 deletions.
24 changes: 7 additions & 17 deletions src/main/docbook/en-US/master.xml
Expand Up @@ -550,22 +550,12 @@ cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
<row>
<entry>addGeneratedAnnotation</entry>

<entry>this option is deprecated and has no effect. The
<classname>@Generation</classname> annotation is added per
default.</entry>
</row>

<row>
<entry>skipGeneratedAnnotation</entry>

<entry>If set to <literal>true</literal> the processor will
not the <classname>@Generated</classname> to the generated
Java source file. The default for this option is
<constant>false</constant> and the
<classname>@Generated</classname> annotation is added to the
source code. Adding this annotation using JDK 5will cause a
compilation error. In this case set the flag to
<constant>true</constant>.</entry>
add the <classname>@Generated</classname> to the generated
Java source file. Adding this annotation using JDK 5will cause
a compilation error. In this case set the flag to
<constant>false</constant>. The default for this option is
<constant>true</constant></entry>
</row>

<row>
Expand All @@ -575,8 +565,8 @@ cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
of the metamodel class will be inserted in the date parameter
of the <classname>@Generated</classname> annotation. The
default is <constant>false</constant>. This parameter is
ignored if <constant>skipGeneratedAnnotation</constant> is
specified.</entry>
ignored if <constant>addGeneratedAnnotation</constant> is set
to <constant>false</constant>.</entry>
</row>

<row>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
Expand Up @@ -106,7 +106,7 @@ private static StringBuffer generateBody(MetaEntity entity, Context context) {
try {
pw = new PrintWriter( sw );

if ( !context.skipGeneratedAnnotation() ) {
if ( context.addGeneratedAnnotation() ) {
pw.println( writeGeneratedAnnotation( entity, context ) );
}
if ( context.isAddSuppressWarningsAnnotation() ) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/hibernate/jpamodelgen/Context.java
Expand Up @@ -61,7 +61,7 @@ public final class Context {
private final List<String> ormXmlFiles;

private boolean isPersistenceUnitCompletelyXmlConfigured;
private boolean skipGeneratedAnnotation;
private boolean addGeneratedAnnotation = true;
private boolean addGenerationDate;
private boolean addSuppressWarningsAnnotation;
private AccessType persistenceUnitDefaultAccessType;
Expand Down Expand Up @@ -102,12 +102,12 @@ public ProcessingEnvironment getProcessingEnvironment() {
return pe;
}

public boolean skipGeneratedAnnotation() {
return skipGeneratedAnnotation;
public boolean addGeneratedAnnotation() {
return addGeneratedAnnotation;
}

public void setSkipGeneratedAnnotation(boolean skipGeneratedAnnotation) {
this.skipGeneratedAnnotation = skipGeneratedAnnotation;
public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) {
this.addGeneratedAnnotation = addGeneratedAnnotation;
}

public boolean addGeneratedDate() {
Expand Down
Expand Up @@ -63,7 +63,6 @@
JPAMetaModelEntityProcessor.ORM_XML_OPTION,
JPAMetaModelEntityProcessor.FULLY_ANNOTATION_CONFIGURED_OPTION,
JPAMetaModelEntityProcessor.LAZY_XML_PARSING,
JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION,
JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION,
JPAMetaModelEntityProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION
})
Expand All @@ -73,11 +72,7 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
public static final String ORM_XML_OPTION = "ormXml";
public static final String FULLY_ANNOTATION_CONFIGURED_OPTION = "fullyAnnotationConfigured";
public static final String LAZY_XML_PARSING = "lazyXmlParsing";
public static final String SKIP_GENERATED_ANNOTATION = "skipGeneratedAnnotation";
public static final String ADD_GENERATION_DATE = "addGenerationDate";
/**
* @deprecated since 1.2
*/
public static final String ADD_GENERATED_ANNOTATION = "addGeneratedAnnotation";
public static final String ADD_SUPPRESS_WARNINGS_ANNOTATION = "addSuppressWarningsAnnotation";

Expand All @@ -93,9 +88,11 @@ public void init(ProcessingEnvironment env) {
Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString()
);

String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION );
boolean addGeneratedAnnotation = Boolean.parseBoolean( tmp );
context.setSkipGeneratedAnnotation( addGeneratedAnnotation );
String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION );
if ( tmp != null ) {
boolean addGeneratedAnnotation = Boolean.parseBoolean( tmp );
context.setAddGeneratedAnnotation( addGeneratedAnnotation );
}

tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATION_DATE );
boolean addGenerationDate = Boolean.parseBoolean( tmp );
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void testGeneratedAnnotationGenerated() {
@Override
protected Map<String, String> getProcessorOptions() {
Map<String, String> properties = new HashMap<String, String>();
properties.put( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION, "true" );
properties.put( JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION, "false" );
return properties;
}

Expand Down

0 comments on commit df68192

Please sign in to comment.