StringUtils { public static int findEndOfMethodArgsIndex(CharSequence string, int startOfMethodArgsIndex) { boolean isDoubleQuoted = false; boolean isSingleQuoted = false; int nestingLevel = 0; for (int charIndex = startOfMethodArgsIndex; charIndex < string.length(); charIndex++) { boolean isCurrentCharEscaped = charIndex > 0 && string.charAt(charIndex - 1) == '\\'; switch (string.charAt(charIndex)) { case '(': if (!isDoubleQuoted && !isSingleQuoted) { nestingLevel++; } break; case ')': if (!isDoubleQuoted && !isSingleQuoted) { nestingLevel--; if (nestingLevel == 0) { return charIndex; } } break; case '"': if (isCurrentCharEscaped || isSingleQuoted) { continue; } isDoubleQuoted = !isDoubleQuoted; break; case '\'': if (isCurrentCharEscaped || isDoubleQuoted) { continue; } isSingleQuoted = !isSingleQuoted; break; default: } } return -1; } StringUtils(); static String ucFirst(final String s); static String lcFirst(String s); static String lcFirstForBean(String s); static boolean isEmpty(final CharSequence str); static String repeat(final String str,
                                final int repeat); static String[] splitPreserveAllTokens(final String str,
                                                  final String separatorChars); static String padding(final int repeat,
                                 final char padChar); static String readFileAsString(Reader reader); static String unescapeJava(String str); static void unescapeJava(Writer out, String str); static String cleanPath(String path); static String collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix); static String collectionToDelimitedString(Collection coll, String delim); static String replace(String inString, String oldPattern, String newPattern); static URI toURI(String location); static String escapeXmlString(String string); static String[] delimitedListToStringArray(String str, String delimiter); static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete); static String[] toStringArray(Collection collection); static String deleteAny(String inString, String charsToDelete); static String toString(Reader reader); static String toString(InputStream is); static String toString(BufferedReader reader); static String getPkgUUID(ReleaseId releaseId, String packageName); static String getPkgUUID(String gav, String packageName); static String md5Hash(String s); static String bytesToHex(byte[] bytes); static String generateUUID(); static String extractFirstIdentifier(String string, int start); static int extractFirstIdentifier(String string, StringBuilder builder, int start); static int skipBlanks(String string, int start); static List<String> splitStatements(CharSequence string); static List<String> splitArgumentsList(CharSequence string); static List<String> splitArgumentsList(CharSequence string, boolean trimArgs); static boolean codeAwareEqualsIgnoreSpaces(String in1, String in2); static int findEndOfMethodArgsIndex(CharSequence string, int startOfMethodArgsIndex); static int indexOfOutOfQuotes(String str, String searched); static int indexOfOutOfQuotes(String str, String searched, int fromIndex); static int codeAwareIndexOf(String str, String searched); static int codeAwareIndexOf(String str, String searched, int fromIndex); static String replaceOutOfQuotes( String s, String oldValue, String newValue ); static int indexOfOutOfQuotes(String str, char searched); static boolean isIdentifier(String expr); static boolean isDereferencingIdentifier(String expr); static double stringSimilarity( String s1, String s2, SIMILARITY_STRATS method ); static boolean equalsIgnoreSpaces(String s1, String s2); static String uuid(); static final String[] EMPTY_STRING_ARRAY; static final String EMPTY; static final int INDEX_NOT_FOUND; }
@Test public void testFindEndOfMethodArgsIndex() { findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"myId\")", 12); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"myId\").call()", 12); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('myId')", 12); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('myId').call()", 12); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id\")", 13); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id\").call()", 13); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id'\")", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id'\").call()", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('my\"Id\"')", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('my\"Id\"').call()", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('my\"Id')", 13); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('my\"Id').call()", 13); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my\\\"Id\")", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my\\\"Id\").call()", 14); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId('myId', 'something')", 25); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"myId\", \"something\")", 25); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id\", \"somet'hing\")", 27); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'Id'\", \"somet'hing\")", 28); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setId(\"my'(Id\", \"somet'(hing'\")", 30); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setObject(new Object())", 22); findEndOfMethodArgsIndexAndAssertItEqualsToExpected("setObject(new Object(\"string param\"))", 36); }