My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 1 attachment: primitive-boolean-getter.patch (4.1 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Index: src/main/java/com/nebulent/xjc/addons/booleangetter/PluginImpl.java
===================================================================
--- src/main/java/com/nebulent/xjc/addons/booleangetter/PluginImpl.java (revision 8)
+++ src/main/java/com/nebulent/xjc/addons/booleangetter/PluginImpl.java (working copy)
@@ -106,7 +106,7 @@
private CPropertyInfo prop;
private JType implType;
private JType exposedType;
- private JCodeModel codeModel;
+// private JCodeModel codeModel;

/**
* Field declaration of the actual
@@ -146,6 +146,11 @@
declareMethod((ClassOutlineImpl) co, (SingleField) fo[i]);
}
}
+ else if (fo[i] instanceof UnboxedField && ((UnboxedField)fo[i]).getRawType() instanceof JType){
+ if ((((JType)((UnboxedField)fo[i]).getRawType()).name().equals("boolean"))) {
+ declareMethod((ClassOutlineImpl) co, (UnboxedField) fo[i]);
+ }
+ }
}
}
}
@@ -169,12 +174,9 @@
*/
private void declareMethod(ClassOutlineImpl context, SingleField field){

- MethodWriter writer = context.createMethodWriter();
Map <String,JFieldVar> fields = null;
- NameConverter nc = context.parent().getModel().getNameConverter();
-
outline = context;
- codeModel = context.parent().getCodeModel();
+// codeModel = context.parent().getCodeModel();
prop = field.getPropertyInfo();

// Retrieve the Map that contains the field name
@@ -184,15 +186,57 @@
// Obtains a reference to the collection-based field
this.field = fields.get(field.getPropertyInfo().getName(false));

+ declareMethod(outline);
+ }
+
+ private void declareMethod(ClassOutlineImpl context, UnboxedField field) {
+ Map <String,JFieldVar> fields = null;
+
+ outline = context;
+ prop = field.getPropertyInfo();
+
+ fields = outline.implClass.fields();
+
+ // Obtains a reference to the collection-based field
+ this.field = fields.get(field.getPropertyInfo().getName(false));
+
+ declareMethod(outline);
+ }
+
+ private void declareMethod(ClassOutlineImpl context){
+
+ MethodWriter writer = context.createMethodWriter();
+
+ boolean getExists = false;
+ boolean isExists = false;
+ JMethod $is = null;
+ for ( JMethod method : outline.implClass.methods() ) {
+ if ( method.name().equals("get" + prop.getName(true)) ) {
+ //System.out.println(String.format("Method %s.%s already exists", outline.implClass.fullName(), method.name()));
+ getExists = true;
+ }
+ if ( method.name().equals("is" + prop.getName(true)) ) {
+ //System.out.println(String.format("Method %s.%s exists", outline.implClass.fullName(), method.name()));
+ isExists = true;
+ $is = method;
+ }
+ }
+ if ( getExists ) { return; }
+
// Creates the method
JMethod $set = writer.declareMethod(this.field.type(), "get" + prop.getName(true));
+ //System.out.println(String.format("Creating method %s.%s", outline.implClass.fullName(), $set.name()));
// Creates the JVar that will hold the method's parameter
//JVar $value = writer.addParameter( this.field.type(), prop.getName(false));
// Creates the methods's JBlock
JBlock body = $set.body();
// Creates the assignment (method parameter to instance variable)
//body.assign(JExpr._this().ref(ref()), castToImplType($value));
- body._return(JExpr._this().ref(ref()));
+ if ( isExists ) {
+ body._return(JExpr._this().invoke($is));
+ } else {
+ body._return(JExpr._this().ref(ref()));
+ }

// Writes javadoc for the methods
// String javadoc = prop.javadoc;
Powered by Google Project Hosting