NamesUtil { public static String makeSafeJavaIdentifier(String identifier) { if (identifier==null || identifier.isEmpty()) throw new IllegalArgumentException("non-null/empty name must be specified"); if (isReserved(identifier) || !Character.isJavaIdentifierStart(identifier.charAt(0))) return "_"+identifier; else return identifier; } 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 testMakeSafeJavaIdentifier_Escaped() { String actual = NamesUtil.makeSafeJavaIdentifier("int"); Assert.assertEquals("keyword is not allowed", "_int", actual); }
@Test public void testMakeSafeJavaIdentifier_NotEscaped() { String actual = NamesUtil.makeSafeJavaIdentifier("x"); Assert.assertEquals("non-keyword is allowed", "x", actual); }