@Test public void testHandleShortSyntaxNestedNestedMethods() { String line = "get(describe(1), find(\"name\", eq, \"foo\"))"; String expected = "concourse.get(concourse.describe(1), concourse.find(\"name\", eq, \"foo\"))"; Assert.assertEquals(expected, SyntaxTools.handleShortSyntax(line, options())); }
public static String handleShortSyntax(String line, List<String> options) { final String prepend = "concourse."; if(line.equalsIgnoreCase("time") || line.equalsIgnoreCase("date")) { return line + " \"now\""; } else if(!line.contains("(")) { if(line.startsWith(prepend)) { boolean hasArgs = line.split("\\s+").length > 1; if(!hasArgs) { line += "()"; } return line; } else { String[] query = line.split("\\s+"); String cmd = query[0]; if(cmd.contains("_")) { String replacement = CaseFormat.LOWER_UNDERSCORE .to(CaseFormat.LOWER_CAMEL, cmd); line = line.replaceFirst(cmd, replacement); } String expanded = prepend + line.trim(); Pattern pattern = Pattern.compile(expanded.split("\\s|\\(")[0]); for (String option : options) { if(pattern.matcher(option).matches()) { boolean hasArgs = expanded.split("\\s+").length > 1; if(!hasArgs) { expanded += "()"; } return expanded; } } } } else { Set<String> shortInvokedMethods = parseShortInvokedMethods(line); for (String method : shortInvokedMethods) { if(options.contains(prepend + method)) { line = line.replaceAll("(?<!\\_)" + method + "\\(", prepend + method + "\\("); } } } return line; }
SyntaxTools { public static String handleShortSyntax(String line, List<String> options) { final String prepend = "concourse."; if(line.equalsIgnoreCase("time") || line.equalsIgnoreCase("date")) { return line + " \"now\""; } else if(!line.contains("(")) { if(line.startsWith(prepend)) { boolean hasArgs = line.split("\\s+").length > 1; if(!hasArgs) { line += "()"; } return line; } else { String[] query = line.split("\\s+"); String cmd = query[0]; if(cmd.contains("_")) { String replacement = CaseFormat.LOWER_UNDERSCORE .to(CaseFormat.LOWER_CAMEL, cmd); line = line.replaceFirst(cmd, replacement); } String expanded = prepend + line.trim(); Pattern pattern = Pattern.compile(expanded.split("\\s|\\(")[0]); for (String option : options) { if(pattern.matcher(option).matches()) { boolean hasArgs = expanded.split("\\s+").length > 1; if(!hasArgs) { expanded += "()"; } return expanded; } } } } else { Set<String> shortInvokedMethods = parseShortInvokedMethods(line); for (String method : shortInvokedMethods) { if(options.contains(prepend + method)) { line = line.replaceAll("(?<!\\_)" + method + "\\(", prepend + method + "\\("); } } } return line; } }
SyntaxTools { public static String handleShortSyntax(String line, List<String> options) { final String prepend = "concourse."; if(line.equalsIgnoreCase("time") || line.equalsIgnoreCase("date")) { return line + " \"now\""; } else if(!line.contains("(")) { if(line.startsWith(prepend)) { boolean hasArgs = line.split("\\s+").length > 1; if(!hasArgs) { line += "()"; } return line; } else { String[] query = line.split("\\s+"); String cmd = query[0]; if(cmd.contains("_")) { String replacement = CaseFormat.LOWER_UNDERSCORE .to(CaseFormat.LOWER_CAMEL, cmd); line = line.replaceFirst(cmd, replacement); } String expanded = prepend + line.trim(); Pattern pattern = Pattern.compile(expanded.split("\\s|\\(")[0]); for (String option : options) { if(pattern.matcher(option).matches()) { boolean hasArgs = expanded.split("\\s+").length > 1; if(!hasArgs) { expanded += "()"; } return expanded; } } } } else { Set<String> shortInvokedMethods = parseShortInvokedMethods(line); for (String method : shortInvokedMethods) { if(options.contains(prepend + method)) { line = line.replaceAll("(?<!\\_)" + method + "\\(", prepend + method + "\\("); } } } return line; } private  SyntaxTools(); }
SyntaxTools { public static String handleShortSyntax(String line, List<String> options) { final String prepend = "concourse."; if(line.equalsIgnoreCase("time") || line.equalsIgnoreCase("date")) { return line + " \"now\""; } else if(!line.contains("(")) { if(line.startsWith(prepend)) { boolean hasArgs = line.split("\\s+").length > 1; if(!hasArgs) { line += "()"; } return line; } else { String[] query = line.split("\\s+"); String cmd = query[0]; if(cmd.contains("_")) { String replacement = CaseFormat.LOWER_UNDERSCORE .to(CaseFormat.LOWER_CAMEL, cmd); line = line.replaceFirst(cmd, replacement); } String expanded = prepend + line.trim(); Pattern pattern = Pattern.compile(expanded.split("\\s|\\(")[0]); for (String option : options) { if(pattern.matcher(option).matches()) { boolean hasArgs = expanded.split("\\s+").length > 1; if(!hasArgs) { expanded += "()"; } return expanded; } } } } else { Set<String> shortInvokedMethods = parseShortInvokedMethods(line); for (String method : shortInvokedMethods) { if(options.contains(prepend + method)) { line = line.replaceAll("(?<!\\_)" + method + "\\(", prepend + method + "\\("); } } } return line; } private  SyntaxTools(); static String handleMissingArgCommas(String line,
            List<String> methods); static String handleShortSyntax(String line, List<String> options); }
SyntaxTools { public static String handleShortSyntax(String line, List<String> options) { final String prepend = "concourse."; if(line.equalsIgnoreCase("time") || line.equalsIgnoreCase("date")) { return line + " \"now\""; } else if(!line.contains("(")) { if(line.startsWith(prepend)) { boolean hasArgs = line.split("\\s+").length > 1; if(!hasArgs) { line += "()"; } return line; } else { String[] query = line.split("\\s+"); String cmd = query[0]; if(cmd.contains("_")) { String replacement = CaseFormat.LOWER_UNDERSCORE .to(CaseFormat.LOWER_CAMEL, cmd); line = line.replaceFirst(cmd, replacement); } String expanded = prepend + line.trim(); Pattern pattern = Pattern.compile(expanded.split("\\s|\\(")[0]); for (String option : options) { if(pattern.matcher(option).matches()) { boolean hasArgs = expanded.split("\\s+").length > 1; if(!hasArgs) { expanded += "()"; } return expanded; } } } } else { Set<String> shortInvokedMethods = parseShortInvokedMethods(line); for (String method : shortInvokedMethods) { if(options.contains(prepend + method)) { line = line.replaceAll("(?<!\\_)" + method + "\\(", prepend + method + "\\("); } } } return line; } private  SyntaxTools(); static String handleMissingArgCommas(String line,
            List<String> methods); static String handleShortSyntax(String line, List<String> options);  }