Skip to content

Commit 4a11208

Browse files
committed
Re-use GrailsNameUtils property logic instead of separate logic
Re-use GrailsNameUtils.getPropertyForGetter from ClassPropertyFetcher instead of having separate (and wrong) logic. This commit has a small behavioral change in that the old code would register both "Property" and "property" for a static property with a getter "getProperty" in ClassPropertyFetcher. With improved property name derivation that should not be necessary anymore.
1 parent f3f0c89 commit 4a11208

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

grails-core/src/main/groovy/org/grails/core/util/ClassPropertyFetcher.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,24 @@ public void doWith(CachedMethod method) throws IllegalArgumentException,
126126
if (!method.isPublic()) {
127127
return;
128128
}
129-
if (returnType != Void.class && returnType != void.class) {
130-
if (method.getParameterTypes().length == 0) {
131-
String name = method.getName();
132-
if (name.indexOf('$') == -1) {
133-
if (name.length() > 3 && name.startsWith("get") && (
134-
Character.isUpperCase(name.charAt(3))
135-
|| (name.length() > 4 && Character.isUpperCase(name.charAt(4)))
136-
)) {
137-
name = name.substring(3);
138-
} else if (name.length() > 2
139-
&& name.startsWith("is")
140-
&& Character.isUpperCase(name.charAt(2))
141-
&& (returnType == Boolean.class ||
142-
returnType == boolean.class)) {
143-
name = name.substring(2);
144-
}
145-
if (method.isStatic()) {
146-
GetterPropertyFetcher fetcher = new GetterPropertyFetcher(method, true);
147-
staticFetchers.put(name, fetcher);
148-
staticFetchers.put(StringUtils.uncapitalize(name),
149-
fetcher);
150-
} else {
151-
instanceFetchers.put(StringUtils.uncapitalize(name),
152-
new GetterPropertyFetcher(method, false));
153-
}
154-
}
155-
}
129+
if (returnType == Void.class || returnType == void.class || method.getParameterTypes().length != 0) {
130+
return;
131+
}
132+
133+
String propertyName = GrailsClassUtils.getPropertyForGetter(method.getName());
134+
if(propertyName == null || propertyName.indexOf('$') != -1) {
135+
return;
136+
}
137+
138+
if (method.getName().startsWith("is") &&
139+
!(returnType == Boolean.class || returnType == boolean.class)) {
140+
return;
141+
}
142+
143+
if (method.isStatic()) {
144+
staticFetchers.put(propertyName, new GetterPropertyFetcher(method, true));
145+
} else {
146+
instanceFetchers.put(propertyName, new GetterPropertyFetcher(method, false));
156147
}
157148
}
158149
};

0 commit comments

Comments
 (0)