rzo1 commented on code in PR #334:
URL: https://github.com/apache/openjpa/pull/334#discussion_r4766808935
##########
openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java:
##########
@@ -2214,6 +2228,47 @@ private Value getPathOrConstant(JPQLNode node) {
}
}
+ /**
+ * Whether the given path starts with an identification variable whose
+ * type has a field named like the second path element (or whose type is
+ * unknown).
+ */
+ private boolean isTraversablePath(JPQLNode node) {
+ String name = firstChild(node).text;
+ if (name == null || node.getChildCount() < 2) {
+ return true;
+ }
+ ClassMetaData meta = getMetaDataForAlias(name);
+ if (meta == null) {
+ Context c = ctx().findContext(name.toLowerCase(Locale.ROOT));
+ if (c == null) {
+ return false;
+ }
+ Value var = c.getVariable(name);
+ meta = var.getMetaData() != null ? var.getMetaData() :
c.getSchema(name);
+ if (meta == null) {
+ return true;
+ }
+ }
+ return meta.getField(node.children[1].text) != null;
+ }
+
+ /**
+ * Resolve a dotted name such as <code>pkg.Outer.Inner</code> to a nested
+ * class by replacing dots with <code>$</code> from the right.
+ */
+ private Class<?> nestedClassForName(String className) {
+ StringBuilder buf = new StringBuilder(className);
+ for (int dot = className.lastIndexOf('.'); dot > 0; dot =
className.lastIndexOf('.', dot - 1)) {
Review Comment:
A single `lastIndexOf` only covers one level (`pkg.Outer$Inner`). The loop
keeps replacing dots from the right, so deeper nesting resolves too:
`pkg.A.B.C` tries `pkg.A.B$C`, then `pkg.A$B$C`. The text alone doesn't tell
where the package name ends, so each candidate is tried with the class
resolver. `TestNestedEnumLiteral` covers the doubly nested case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]