Skip to content

Commit 4b245de

Browse files
committed
Merge pull request #10 from tacianosilva/add-isfield-check
Add the checking for methods like isField.
2 parents fefca2c + b1b3303 commit 4b245de

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/main/java/br/edu/ufcg/splab/designtests/designrules/AbstractDesignRule.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ public abstract class AbstractDesignRule implements Rule {
2121
/**
2222
* ClassNode for represents the {@link Object} class.
2323
*/
24-
private final ClassNode objectClass = new ClassNode("java.lang.Object");
24+
private final ClassNode OBJECT_CLASS = new ClassNode("java.lang.Object");
25+
26+
/**
27+
* ClassNode for represents the boolean primitive type.
28+
*/
29+
private final ClassNode BOOLEAN_PRIMITIVE = new ClassNode("boolean");
30+
31+
/**
32+
* ClassNode for represents the {@link Boolean} class.
33+
*/
34+
private final ClassNode BOOLEAN_CLASS = new ClassNode("java.lang.Boolean");
2535

2636
/**
2737
* Facts of the Software Design.
@@ -95,7 +105,7 @@ public final String getName() {
95105
* @return A ClassNode for <code>java.lang.Object</code>.
96106
*/
97107
public final ClassNode getObjectClass() {
98-
return this.objectClass;
108+
return this.OBJECT_CLASS;
99109
}
100110

101111
/**
@@ -182,7 +192,15 @@ protected final boolean hasSetMethod(final FieldNode fieldNode, final ClassNode
182192
protected final boolean hasGetMethod(final FieldNode fieldNode, final ClassNode entityNode) {
183193
String shortFieldName = fieldNode.getShortName();
184194
ClassNode type = fieldNode.getType();
185-
String methodGetField = "get" + shortFieldName.substring(0, 1).toUpperCase()
195+
String strGetOrIs = "";
196+
197+
if (type != null && (type.equals(BOOLEAN_PRIMITIVE) || type.equals(BOOLEAN_CLASS))) {
198+
strGetOrIs = "is";
199+
} else {
200+
strGetOrIs = "get";
201+
}
202+
203+
String methodGetField = strGetOrIs + shortFieldName.substring(0, 1).toUpperCase()
186204
+ shortFieldName.substring(1) + "()";
187205

188206
MethodNode methodNode = entityNode.getDeclaredMethod(methodGetField);

src/test/java/tests/br/edu/ufcg/splab/designtests/entities/EntityA.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class EntityA implements Serializable {
3636
@Column
3737
private String name;
3838

39+
@Column
40+
private Boolean verified;
41+
42+
@Column
43+
private boolean confirmed;
44+
3945
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
4046
private Set<EntityB> entityBSet = new HashSet<EntityB>();
4147

@@ -109,4 +115,20 @@ public SortedSet<EntityE> getEntityESortedSet() {
109115
public void setEntityESortedSet(SortedSet<EntityE> entityESortedSet) {
110116
this.entityESortedSet = entityESortedSet;
111117
}
112-
}
118+
119+
public void setVerified(Boolean bool) {
120+
this.verified = bool;
121+
}
122+
123+
public Boolean isVerified() {
124+
return this.verified;
125+
}
126+
127+
public void setConfirmed(boolean bool) {
128+
this.verified = bool;
129+
}
130+
131+
public boolean isConfirmed() {
132+
return this.verified;
133+
}
134+
}

src/test/java/tests/br/edu/ufcg/splab/designtests/entities/EntityB.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public class EntityB implements Serializable {
2626
@Column(nullable=false, unique=true)
2727
private String name;
2828

29+
@Column
30+
private Boolean verified;
31+
32+
@Column
33+
private boolean confirmed;
34+
2935
@Column
3036
@ElementCollection(fetch=FetchType.EAGER)
3137
private List<String> collectionList;

0 commit comments

Comments
 (0)