openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1303498 - in /openjpa/branches/2.2.x/openjpa-persistence/src/main: java/org/apache/openjpa/persistence/util/SourceCode.java resources/org/apache/openjpa/persistence/util/localizer.properties
Date Wed, 21 Mar 2012 18:46:10 GMT
Author: curtisr7
Date: Wed Mar 21 18:46:09 2012
New Revision: 1303498

URL: http://svn.apache.org/viewvc?rev=1303498&view=rev
Log:
OPENJPA-2156: Add support for generating a final class.

Modified:
    openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
    openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties

Modified: openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java?rev=1303498&r1=1303497&r2=1303498&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
Wed Mar 21 18:46:09 2012
@@ -361,7 +361,8 @@ public class SourceCode {
 	 *
 	 */
 	public class Class extends Element<Class> {
-		private boolean isAbstract;
+        private boolean isAbstract;
+		private boolean isFinal;
 		private ClassName superCls;
 		private List<ClassName> interfaces = new ArrayList<ClassName>();
 	    private Set<Field> fields   = new TreeSet<Field>();
@@ -383,10 +384,20 @@ public class SourceCode {
 			return this;
 		}
 		
-		public Class makeAbstract() {
-			isAbstract = true;
-			return this;
-		}
+        public Class makeAbstract() {
+            if (isFinal)
+                throw new IllegalArgumentException(_loc.get("src-invalid-modifier").toString());
+
+            isAbstract = true;
+            return this;
+        }
+
+        public Class makeFinal() {
+            if (isAbstract)
+                throw new IllegalArgumentException(_loc.get("src-invalid-modifier").toString());
+            isFinal = true;
+            return this;
+        }
 		
 	    /**
 	     * Adds getters and setters to every non-public field.
@@ -449,6 +460,8 @@ public class SourceCode {
 			super.write(out, tab);
 			if (isAbstract) 
 			    out.append("abstract ");
+			if(isFinal)
+			    out.append("final ");
 			out.print("class ");
 			out.print(type.simpleName);
 			writeList(out, BLANK, params, PARAMS_DELIMITER, false);

Modified: openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties?rev=1303498&r1=1303497&r2=1303498&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/util/localizer.properties
Wed Mar 21 18:46:09 2012
@@ -23,3 +23,4 @@ src-invalid-type: "{0}" is not a valid t
 Java type or token and a valid Java identifier.
 src-invalid-field: "{0}" is not a valid field name. \
 It must be a non-reserved Java token and a valid Java identifier.
+src-invalid-modifier: Unable to declare a class as abstract and final.



Mime
View raw message