mirror of https://github.com/apache/openjpa.git
OPENJPA-2156: Add support for generating a final class.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1303496 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7063dd5296
commit
1d71976c8f
|
@ -362,6 +362,7 @@ public class SourceCode {
|
|||
*/
|
||||
public class Class extends Element<Class> {
|
||||
private boolean isAbstract;
|
||||
private boolean isFinal;
|
||||
private ClassName superCls;
|
||||
private List<ClassName> interfaces = new ArrayList<ClassName>();
|
||||
private Set<Field> fields = new TreeSet<Field>();
|
||||
|
@ -384,10 +385,20 @@ public class SourceCode {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -23,3 +23,4 @@ src-invalid-type: "{0}" is not a valid type name. It must be a valid Java packag
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue