/** * Checks that the given string is a valid unqualified name. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ static void checkUnqualifiedName(final int version, final String name, final String message) { checkIdentifier(version, name, 0, -1, message); }
/** * Checks that the given string is a valid Java identifier. * * @param name * the string to be checked. * @param msg * a message to be used in case of error. */ static void checkIdentifier(final String name, final String msg) { checkIdentifier(name, 0, -1, msg); }
/** * Checks that the given string is a valid unqualified name. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ static void checkUnqualifiedName(final int version, final String name, final String message) { checkIdentifier(version, name, 0, -1, message); }
/** * Checks that the given name is a fully qualified name, using dots. * * @param version the class version. * @param name the name to be checked. * @param source the source of 'name' (e.g 'module' for a module name). */ static void checkFullyQualifiedName(final int version, final String name, final String source) { try { int startIndex = 0; int dotIndex; while ((dotIndex = name.indexOf('.', startIndex + 1)) != -1) { CheckMethodAdapter.checkIdentifier(version, name, startIndex, dotIndex, null); startIndex = dotIndex + 1; } CheckMethodAdapter.checkIdentifier(version, name, startIndex, name.length(), null); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Invalid " + source + " (must be a fully qualified name): " + name, e); } }
/** * Checks that the given string is a valid internal class name. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ private static void checkInternalClassName( final int version, final String name, final String message) { try { int startIndex = 0; int slashIndex; while ((slashIndex = name.indexOf('/', startIndex + 1)) != -1) { CheckMethodAdapter.checkIdentifier(version, name, startIndex, slashIndex, null); startIndex = slashIndex + 1; } CheckMethodAdapter.checkIdentifier(version, name, startIndex, name.length(), null); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( INVALID + message + " (must be an internal class name): " + name, e); } }
/** * Checks that the given string is a valid internal class name. * * @param version the class version. * @param name the string to be checked. * @param message the message to use in case of error. */ private static void checkInternalClassName( final int version, final String name, final String message) { try { int startIndex = 0; int slashIndex; while ((slashIndex = name.indexOf('/', startIndex + 1)) != -1) { CheckMethodAdapter.checkIdentifier(version, name, startIndex, slashIndex, null); startIndex = slashIndex + 1; } CheckMethodAdapter.checkIdentifier(version, name, startIndex, name.length(), null); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( INVALID + message + " (must be an internal class name): " + name, e); } }
/** * Checks that the given name is a fully qualified name, using dots. * * @param version the class version. * @param name the name to be checked. * @param source the source of 'name' (e.g 'module' for a module name). */ static void checkFullyQualifiedName(final int version, final String name, final String source) { try { int startIndex = 0; int dotIndex; while ((dotIndex = name.indexOf('.', startIndex + 1)) != -1) { CheckMethodAdapter.checkIdentifier(version, name, startIndex, dotIndex, null); startIndex = dotIndex + 1; } CheckMethodAdapter.checkIdentifier(version, name, startIndex, name.length(), null); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "Invalid " + source + " (must be a fully qualified name): " + name, e); } }
@Override public void visitTypeVariable(final String name) { if (type != TYPE_SIGNATURE || state != EMPTY) { throw new IllegalStateException(); } CheckMethodAdapter.checkIdentifier(name, "type variable"); state = SIMPLE_TYPE; if (sv != null) { sv.visitTypeVariable(name); } }
@Override public void visitInnerClassType(final String name) { if (state != CLASS_TYPE) { throw new IllegalStateException(); } CheckMethodAdapter.checkIdentifier(name, "inner class name"); if (sv != null) { sv.visitInnerClassType(name); } }
@Override public void visitFormalTypeParameter(final String name) { if (type == TYPE_SIGNATURE || (state != EMPTY && state != FORMAL && state != BOUND)) { throw new IllegalStateException(); } CheckMethodAdapter.checkIdentifier(name, "formal type parameter"); state = FORMAL; if (sv != null) { sv.visitFormalTypeParameter(name); } }
/** * Checks that the given string is a valid unqualified name. * * @param version * the class version. * @param name * the string to be checked. * @param msg * a message to be used in case of error. */ static void checkUnqualifiedName(int version, final String name, final String msg) { if ((version & 0xFFFF) < Opcodes.V1_5) { checkIdentifier(name, msg); } else { for (int i = 0; i < name.length(); ++i) { if (".;[/".indexOf(name.charAt(i)) != -1) { throw new IllegalArgumentException("Invalid " + msg + " (must be a valid unqualified name): " + name); } } } }
slash = max; checkIdentifier(name, begin, slash, null); begin = slash + 1; } while (slash != max);
@Override public void visitInnerClass(final String name, final String outerName, final String innerName, final int access) { checkState(); CheckMethodAdapter.checkInternalName(name, "class name"); if (outerName != null) { CheckMethodAdapter.checkInternalName(outerName, "outer class name"); } if (innerName != null) { int start = 0; while (start < innerName.length() && Character.isDigit(innerName.charAt(start))) { start++; } if (start == 0 || start < innerName.length()) { CheckMethodAdapter.checkIdentifier(innerName, start, -1, "inner class name"); } } checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE + Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL + Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_ANNOTATION + Opcodes.ACC_ENUM); super.visitInnerClass(name, outerName, innerName, access); }
CheckMethodAdapter.checkIdentifier(version, innerName, startIndex, -1, "inner class name");
CheckMethodAdapter.checkIdentifier(version, innerName, startIndex, -1, "inner class name");