/** * Checks a field signature. * * @param signature a string containing the signature that must be checked. */ public static void checkFieldSignature(final String signature) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // FieldSignature: // ReferenceTypeSignature int pos = checkReferenceTypeSignature(signature, 0); if (pos != signature.length()) { throw new IllegalArgumentException(signature + ERROR_AT + pos); } }
/** * Checks a field signature. * * @param signature a string containing the signature that must be checked. */ public static void checkFieldSignature(final String signature) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // FieldSignature: // ReferenceTypeSignature int pos = checkReferenceTypeSignature(signature, 0); if (pos != signature.length()) { throw new IllegalArgumentException(signature + ERROR_AT + 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 Java 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 checkJavaTypeSignature(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // JavaTypeSignature: // ReferenceTypeSignature // BaseType // BaseType: // (one of) // B C D F I J S Z int pos = startPos; switch (getChar(signature, pos)) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'J': case 'S': case 'Z': return pos + 1; default: return checkReferenceTypeSignature(signature, pos); } }
/** * Checks a Java 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 checkJavaTypeSignature(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // JavaTypeSignature: // ReferenceTypeSignature // BaseType // BaseType: // (one of) // B C D F I J S Z int pos = startPos; switch (getChar(signature, pos)) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'J': case 'S': case 'Z': return pos + 1; default: return checkReferenceTypeSignature(signature, pos); } }
/** * Checks a type parameter 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 checkTypeParameter(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeParameter: // Identifier ClassBound InterfaceBound* // ClassBound: // : [ReferenceTypeSignature] // InterfaceBound: // : ReferenceTypeSignature int pos = startPos; pos = checkSignatureIdentifier(signature, pos); pos = checkChar(':', signature, pos); if ("L[T".indexOf(getChar(signature, pos)) != -1) { pos = checkReferenceTypeSignature(signature, pos); } while (getChar(signature, pos) == ':') { pos = checkReferenceTypeSignature(signature, pos + 1); } return pos; }
/** * Checks a type parameter 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 checkTypeParameter(final String signature, final int startPos) { // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1: // TypeParameter: // Identifier ClassBound InterfaceBound* // ClassBound: // : [ReferenceTypeSignature] // InterfaceBound: // : ReferenceTypeSignature int pos = startPos; pos = checkSignatureIdentifier(signature, pos); pos = checkChar(':', signature, pos); if ("L[T".indexOf(getChar(signature, pos)) != -1) { pos = checkReferenceTypeSignature(signature, pos); } while (getChar(signature, pos) == ':') { pos = checkReferenceTypeSignature(signature, pos + 1); } return pos; }