/** * Checks a single character. * * @param c a character. * @param signature a string containing the signature that must be checked. * @param pos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkChar(final char c, final String signature, final int pos) { if (getChar(signature, pos) == c) { return pos + 1; } throw new IllegalArgumentException(signature + ": '" + c + "' expected at index " + pos); }
/** * Checks a single character. * * @param c a character. * @param signature a string containing the signature that must be checked. * @param pos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkChar(final char c, final String signature, final int pos) { if (getChar(signature, pos) == c) { return pos + 1; } throw new IllegalArgumentException(signature + ": '" + c + "' expected at index " + pos); }
/** * Checks a single character. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkChar(final char c, final String signature, int pos) { if (getChar(signature, pos) == c) { return pos + 1; } throw new IllegalArgumentException(signature + ": '" + c + "' expected at index " + pos); }
/** * Checks an identifier. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkIdentifier(final String signature, int pos) { if (!Character.isJavaIdentifierStart(getChar(signature, pos))) { throw new IllegalArgumentException(signature + ": identifier expected at index " + pos); } ++pos; while (Character.isJavaIdentifierPart(getChar(signature, pos))) { ++pos; } return pos; }
/** * Checks a type argument in a class type signature. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArgument(final String signature, int pos) { // TypeArgument: // * | ( ( + | - )? FieldTypeSignature ) char c = getChar(signature, pos); if (c == '*') { return pos + 1; } else if (c == '+' || c == '-') { pos++; } return checkFieldTypeSignature(signature, pos); }
/** * Checks a type argument in a class type signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArgument(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeArgument: // [WildcardIndicator] ReferenceTypeSignature // * // WildcardIndicator: // + // - int pos = startPos; char c = getChar(signature, pos); if (c == '*') { return pos + 1; } else if (c == '+' || c == '-') { pos++; } return checkReferenceTypeSignature(signature, pos); }
/** * Checks a type argument in a class type signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArgument(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeArgument: // [WildcardIndicator] ReferenceTypeSignature // * // WildcardIndicator: // + // - int pos = startPos; char c = getChar(signature, pos); if (c == '*') { return pos + 1; } else if (c == '+' || c == '-') { pos++; } return checkReferenceTypeSignature(signature, pos); }
/** * Checks a class signature. * * @param signature * a string containing the signature that must be checked. */ public static void checkClassSignature(final String signature) { // ClassSignature: // FormalTypeParameters? ClassTypeSignature ClassTypeSignature* int pos = 0; if (getChar(signature, 0) == '<') { pos = checkFormalTypeParameters(signature, pos); } pos = checkClassTypeSignature(signature, pos); while (getChar(signature, pos) == 'L') { pos = checkClassTypeSignature(signature, pos); } if (pos != signature.length()) { throw new IllegalArgumentException(signature + ": error at index " + pos); } }
/** * Checks a class signature. * * @param signature a string containing the signature that must be checked. */ public static void checkClassSignature(final String signature) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // ClassSignature: // [TypeParameters] SuperclassSignature SuperinterfaceSignature* // SuperclassSignature: // ClassTypeSignature // SuperinterfaceSignature: // ClassTypeSignature int pos = 0; if (getChar(signature, 0) == '<') { pos = checkTypeParameters(signature, pos); } pos = checkClassTypeSignature(signature, pos); while (getChar(signature, pos) == 'L') { pos = checkClassTypeSignature(signature, pos); } if (pos != signature.length()) { throw new IllegalArgumentException(signature + ERROR_AT + pos); } }
/** * Checks a class signature. * * @param signature a string containing the signature that must be checked. */ public static void checkClassSignature(final String signature) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // ClassSignature: // [TypeParameters] SuperclassSignature SuperinterfaceSignature* // SuperclassSignature: // ClassTypeSignature // SuperinterfaceSignature: // ClassTypeSignature int pos = 0; if (getChar(signature, 0) == '<') { pos = checkTypeParameters(signature, pos); } pos = checkClassTypeSignature(signature, pos); while (getChar(signature, pos) == 'L') { pos = checkClassTypeSignature(signature, pos); } if (pos != signature.length()) { throw new IllegalArgumentException(signature + ERROR_AT + pos); } }
/** * Checks a formal type parameter of a class or method signature. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkFormalTypeParameter(final String signature, int pos) { // FormalTypeParameter: // Identifier : FieldTypeSignature? (: FieldTypeSignature)* pos = checkIdentifier(signature, pos); pos = checkChar(':', signature, pos); if ("L[T".indexOf(getChar(signature, pos)) != -1) { pos = checkFieldTypeSignature(signature, pos); } while (getChar(signature, pos) == ':') { pos = checkFieldTypeSignature(signature, pos + 1); } return pos; }
/** * Checks the type arguments in a class type signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArguments(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeArguments: // < TypeArgument TypeArgument* > int pos = startPos; pos = checkChar('<', signature, pos); pos = checkTypeArgument(signature, pos); while (getChar(signature, pos) != '>') { pos = checkTypeArgument(signature, pos); } return pos + 1; }
/** * Checks the formal type parameters of a class or method signature. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkFormalTypeParameters(final String signature, int pos) { // FormalTypeParameters: // < FormalTypeParameter+ > pos = checkChar('<', signature, pos); pos = checkFormalTypeParameter(signature, pos); while (getChar(signature, pos) != '>') { pos = checkFormalTypeParameter(signature, pos); } return pos + 1; }
/** * Checks the type arguments in a class type signature. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArguments(final String signature, int pos) { // TypeArguments: // < TypeArgument+ > pos = checkChar('<', signature, pos); pos = checkTypeArgument(signature, pos); while (getChar(signature, pos) != '>') { pos = checkTypeArgument(signature, pos); } return pos + 1; }
/** * Checks the type parameters of a class or method signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeParameters(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeParameters: // < TypeParameter TypeParameter* > int pos = startPos; pos = checkChar('<', signature, pos); pos = checkTypeParameter(signature, pos); while (getChar(signature, pos) != '>') { pos = checkTypeParameter(signature, pos); } return pos + 1; }
/** * Checks the type arguments in a class type signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeArguments(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeArguments: // < TypeArgument TypeArgument* > int pos = startPos; pos = checkChar('<', signature, pos); pos = checkTypeArgument(signature, pos); while (getChar(signature, pos) != '>') { pos = checkTypeArgument(signature, pos); } return pos + 1; }
/** * Checks the type parameters of a class or method signature. * * @param signature a string containing the signature that must be checked. * @param startPos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkTypeParameters(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeParameters: // < TypeParameter TypeParameter* > int pos = startPos; pos = checkChar('<', signature, pos); pos = checkTypeParameter(signature, pos); while (getChar(signature, pos) != '>') { pos = checkTypeParameter(signature, pos); } return pos + 1; }
/** * Checks a field type signature. * * @param signature * a string containing the signature that must be checked. * @param pos * index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkFieldTypeSignature(final String signature, int pos) { // FieldTypeSignature: // ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature // // ArrayTypeSignature: // [ TypeSignature switch (getChar(signature, pos)) { case 'L': return checkClassTypeSignature(signature, pos); case '[': return checkTypeSignature(signature, pos + 1); default: return checkTypeVariableSignature(signature, pos); } }
/** * Checks a reference type signature. * * @param signature a string containing the signature that must be checked. * @param pos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkReferenceTypeSignature(final String signature, final int pos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // ReferenceTypeSignature: // ClassTypeSignature // TypeVariableSignature // ArrayTypeSignature // ArrayTypeSignature: // [ JavaTypeSignature switch (getChar(signature, pos)) { case 'L': return checkClassTypeSignature(signature, pos); case '[': return checkJavaTypeSignature(signature, pos + 1); default: return checkTypeVariableSignature(signature, pos); } }
/** * Checks a reference type signature. * * @param signature a string containing the signature that must be checked. * @param pos index of first character to be checked. * @return the index of the first character after the checked part. */ private static int checkReferenceTypeSignature(final String signature, final int pos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // ReferenceTypeSignature: // ClassTypeSignature // TypeVariableSignature // ArrayTypeSignature // ArrayTypeSignature: // [ JavaTypeSignature switch (getChar(signature, pos)) { case 'L': return checkClassTypeSignature(signature, pos); case '[': return checkJavaTypeSignature(signature, pos + 1); default: return checkTypeVariableSignature(signature, pos); } }