NamesUtil { public static boolean matchingOverloads(String overloadNamesSpecifier1, String overloadNamesSpecifier2, boolean ignoreAllPackages) { overloadNamesSpecifier1=overloadNamesSpecifier1.trim(); overloadNamesSpecifier2=overloadNamesSpecifier2.trim(); int nameQualifierPos1 = overloadNamesSpecifier1.indexOf("("); int nameQualifierPos2 = overloadNamesSpecifier2.indexOf("("); String name1 = nameQualifierPos1>=0 ? overloadNamesSpecifier1.substring(0, nameQualifierPos1) : overloadNamesSpecifier1; String name2 = nameQualifierPos2>=0 ? overloadNamesSpecifier2.substring(0, nameQualifierPos2) : overloadNamesSpecifier2; if (!name1.equals("*") && !name2.equals("*") && !name1.equals(name2)) return false; String nameTypes1String=nameQualifierPos1>=0 ? overloadNamesSpecifier1.substring(nameQualifierPos1+1, overloadNamesSpecifier1.length()-1) : ""; String nameTypes2String = nameQualifierPos2>=0 ? overloadNamesSpecifier2.substring(nameQualifierPos2+1, overloadNamesSpecifier2.length()-1) : ""; if (nameTypes1String.equals("**") || nameTypes2String.equals("**")) return true; String[] nameTypes1 = !nameTypes1String.isEmpty() ? nameTypes1String.split(",") : new String[0]; String[] nameTypes2 = !nameTypes2String.isEmpty() ? nameTypes2String.split(",") : new String[0]; if (nameTypes1.length!=nameTypes2.length) return false; String defaultPackage = "java.lang"; for (int i=0; i<nameTypes1.length; ++i) { String type1 = nameTypes1[i].trim(); if (ignoreAllPackages || hasPackage(type1, defaultPackage)) type1=getUnqualifiedName(type1); String type2 = nameTypes2[i].trim(); if (ignoreAllPackages || hasPackage(type2, defaultPackage)) type2=getUnqualifiedName(type2); if (!type1.equals("*") && !type2.equals("*") && !type1.equals(type2)) return false; } return true; } private  NamesUtil(); static boolean isJavaLangClassName(String identifier); static boolean isJavaUtilClassName(String identifier); static String makeSafeJavaIdentifier(String identifier); static String createNewClassNameFromInterfaceName(String interfaceName); static String getGenericQualifier(String className); static String[] getGenericQualifierNames(String className); static boolean hasGenericQualifier(String name); static String stripGenericQualifier(String className); static String stripArrrayQualifier(String className); static String ensureQualifedName(String name, String defaultPackage); static boolean isQualifiedName(String name); static String getUnqualifiedName(String name); static String getPackageFromQualifiedName(String name); static boolean hasPackage(String qualifiedName, String packageName); static boolean isGetterMethod(String methodName, String[] getterPrefixes); static boolean isSetterMethod(String methodName, String[] setterPrefixes); static String getWrapperTypeName(String typeName); static boolean hasWilcard(String wildcardSpecifier); static boolean matchingOverloads(String overloadNamesSpecifier1, String overloadNamesSpecifier2, boolean ignoreAllPackages); static final String ImplClassSuffix; }
@Test public void testMatchingOverloadsNoMethodsAndNoArgs() { Assert.assertTrue(NamesUtil.matchingOverloads("()", "()", false)); }
@Test public void testMatchingOverloadsNoMethodsAndArgs() { Assert.assertTrue(NamesUtil.matchingOverloads("(int)", "(int)", false)); }
@Test public void testMatchingOverloadsNoArgs() { Assert.assertTrue(NamesUtil.matchingOverloads("test()", "test()", false)); }
@Test public void testMatchingOverloadsNoArgsOmitParenthesis() { Assert.assertTrue(NamesUtil.matchingOverloads("test", "test()", false)); }
@Test public void testMatchingOverloadsWithArgs() { Assert.assertTrue(NamesUtil.matchingOverloads("test(int,String)", "test(int,String)", false)); }
@Test public void testMatchingOverloadsWithJavaLangPrefix() { Assert.assertTrue(NamesUtil.matchingOverloads("test(String)", "test(java.lang.String)", false)); }
@Test public void testMatchingOverloadsWithWildcards() { Assert.assertTrue(NamesUtil.matchingOverloads("test(*,String)", "test(int,*)", false)); }
@Test public void testNotMatchingOverloadsWithMethodWildcards() { Assert.assertTrue(NamesUtil.matchingOverloads("*(*,*)", "test(int,String)", false)); }
@Test public void testNotMatchingOverloadsWithArgumentWildcards() { Assert.assertFalse(NamesUtil.matchingOverloads("test(int,Double)", "test(int,String)", false)); }
@Test public void testNotMatchingDifferentNumberArgsOverloads() { Assert.assertFalse(NamesUtil.matchingOverloads("*(*,*)", "test(int)", false)); }
@Test public void testNotMatchingDifferentNumberArgsOverloads2() { Assert.assertFalse(NamesUtil.matchingOverloads("*(*)", "test()", false)); }
@Test public void testDoubleStarMatchesAllArgs1() { Assert.assertTrue(NamesUtil.matchingOverloads("test(**)", "test(int,String)", false)); }
@Test public void testDoubleStarMatchesAllArgs2() { Assert.assertTrue(NamesUtil.matchingOverloads("test(int,String)", "test(**)", false)); }
@Test public void testDoubleStarMatchesAllArgs3() { Assert.assertTrue(NamesUtil.matchingOverloads("test()", "test(**)", false)); }