@Test(expected = IllegalArgumentException.class) public void testValidatePackageNameStartsWithDigit() { Utils.validatePackageName("2foo"); }
static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; }
Utils { static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; } }
Utils { static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; } private  Utils(); }
Utils { static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; } private  Utils();  }
Utils { static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; } private  Utils();   }