ObjectPathExpressionParser { @SuppressWarnings("unchecked") public static <T> T parsePathExpression(Object root, String path, final PathEntry pathEntry) { ParseState parseState = (ParseState) TL_EL_PARSE_STATE.get(); boolean recycle; if (parseState == null) { TL_EL_PARSE_STATE.set(new ParseState()); parseState = TL_EL_PARSE_STATE.get(); recycle = true; } else if (parseState.isActive()) { ProcessLogger.ntrace("el-parse:", ":nested", 100); parseState = new ParseState(); recycle = false; } else { recycle = true; } try { parseState.originalPath = path; parseState.originalPathIndex = 0; parseState.parentPath = null; parseState.currentContinuation = pathEntry.parse(null, root, null); while (path != null) { path = parseState.prepareNextScan(path); parseState.scan(path); path = parseState.step(path, pathEntry); } return (T) parseState.currentContinuation; } finally { assert !recycle || parseState == TL_EL_PARSE_STATE.get(); parseState.reset(); } } private  ObjectPathExpressionParser(); static int indexOfCloseBracket(String path, int leftBracketIndex); static boolean isPath(String propertyName); @SuppressWarnings("unchecked") static T parsePathExpression(Object root, String path, final PathEntry pathEntry);  }
@Test public void testParsePathExpression() { assertEquals("foo+bar", ObjectPathExpressionParser.parsePathExpression(null, "foo.bar", new DoIt()) .toString()); assertEquals("foo+bar", ObjectPathExpressionParser.parsePathExpression(null, "foo[bar]", new DoIt()) .toString()); assertEquals("foo+bar+baz", ObjectPathExpressionParser .parsePathExpression(null, "foo[bar].baz", new DoIt()) .toString()); assertEquals( "foo+bar[baz]", ObjectPathExpressionParser.parsePathExpression(null, "foo[bar[baz]]", new DoIt()).toString()); assertEquals( "foo+bar-bar.baz+fez", ObjectPathExpressionParser.parsePathExpression(null, "foo[bar-bar.baz]+fez", new DoIt()).toString()); }
@Test public void testJoinParsePathExpression() { @SuppressWarnings("unchecked") List<String> l1 = (List<String>) ObjectPathExpressionParser.parsePathExpression(null, "foo.bar", new JoinIt()); assertEquals(2, l1.size()); assertEquals("foo", l1.get(0)); assertEquals("bar", l1.get(1)); @SuppressWarnings("unchecked") List<String> l2 = (List<String>) ObjectPathExpressionParser.parsePathExpression(null, "foo[bar]", new JoinIt()); assertEquals(2, l2.size()); assertEquals("foo", l2.get(0)); assertEquals("bar", l2.get(1)); @SuppressWarnings("unchecked") List<String> l3 = (List<String>) ObjectPathExpressionParser.parsePathExpression(null, "foo[bar-bar.baz].fez", new JoinIt()); assertEquals(3, l3.size()); assertEquals("foo", l3.get(0)); assertEquals("bar-bar.baz", l3.get(1)); assertEquals("fez", l3.get(2)); }