@Test public void testHandleMissingArgsCommasSingleArg() { String line = "foo 1"; String expected = line; Assert.assertEquals(expected, SyntaxTools.handleMissingArgCommas(line, METHODS)); }
public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if(hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if(Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(Character.isWhitespace(c) && foundMethod) { if(transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if(c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if(c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if(c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if(c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if(c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if(foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); }
SyntaxTools { public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if(hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if(Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(Character.isWhitespace(c) && foundMethod) { if(transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if(c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if(c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if(c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if(c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if(c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if(foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); } }
SyntaxTools { public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if(hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if(Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(Character.isWhitespace(c) && foundMethod) { if(transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if(c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if(c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if(c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if(c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if(c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if(foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); } private  SyntaxTools(); }
SyntaxTools { public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if(hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if(Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(Character.isWhitespace(c) && foundMethod) { if(transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if(c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if(c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if(c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if(c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if(c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if(foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); } private  SyntaxTools(); static String handleMissingArgCommas(String line,
            List<String> methods); static String handleShortSyntax(String line, List<String> options); }
SyntaxTools { public static String handleMissingArgCommas(String line, List<String> methods) { int hashCode = methods.hashCode(); Set<String> hashedMethods = CACHED_METHODS.get(hashCode); if(hashedMethods == null) { hashedMethods = Sets.newHashSetWithExpectedSize(methods.size()); hashedMethods.addAll(methods); CACHED_METHODS.put(hashCode, hashedMethods); } char[] chars = line.toCharArray(); StringBuilder transformed = new StringBuilder(); StringBuilder gather = new StringBuilder(); boolean foundMethod = false; boolean inSingleQuotes = false; boolean inDoubleQuotes = false; int parenCount = 0; for (char c : chars) { if(Character.isWhitespace(c) && !foundMethod) { transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(Character.isWhitespace(c) && foundMethod) { if(transformed.charAt(transformed.length() - 1) != ',' && !inSingleQuotes && !inDoubleQuotes && c != '\n') { transformed.append(","); } transformed.append(c); } else if(c == '(' && !foundMethod) { parenCount++; transformed.append(gather); transformed.append(c); foundMethod = hashedMethods.contains(gather.toString()); gather.setLength(0); } else if(c == '(' && foundMethod) { parenCount++; transformed.append(c); } else if(c == ';') { transformed.append(c); foundMethod = false; parenCount = 0; } else if(c == ')') { parenCount--; transformed.append(c); foundMethod = parenCount == 0 ? false : foundMethod; } else if(c == '"') { transformed.append(c); inSingleQuotes = !inSingleQuotes; } else if(c == '\'') { transformed.append(c); inDoubleQuotes = !inDoubleQuotes; } else if(foundMethod) { transformed.append(c); } else { gather.append(c); } } transformed.append(gather); return transformed.toString(); } private  SyntaxTools(); static String handleMissingArgCommas(String line,
            List<String> methods); static String handleShortSyntax(String line, List<String> options);  }