< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/CheckClassAdapter.java

Print this page

 616     }
 617 
 618     /**
 619       * Checks a class signature.
 620       *
 621       * @param signature a string containing the signature that must be checked.
 622       */
 623     public static void checkClassSignature(final String signature) {
 624         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 625         // ClassSignature:
 626         //   [TypeParameters] SuperclassSignature SuperinterfaceSignature*
 627         // SuperclassSignature:
 628         //   ClassTypeSignature
 629         // SuperinterfaceSignature:
 630         //   ClassTypeSignature
 631         int pos = 0;
 632         if (getChar(signature, 0) == '<') {
 633             pos = checkTypeParameters(signature, pos);
 634         }
 635         pos = checkClassTypeSignature(signature, pos);
 636         while (getChar(signature, pos) == 'L') {
 637             pos = checkClassTypeSignature(signature, pos);
 638         }
 639         if (pos != signature.length()) {
 640             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 641         }
 642     }
 643 
 644     /**
 645       * Checks a method signature.
 646       *
 647       * @param signature a string containing the signature that must be checked.
 648       */
 649     public static void checkMethodSignature(final String signature) {
 650         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 651         // MethodSignature:
 652         //   [TypeParameters] ( JavaTypeSignature* ) Result ThrowsSignature*
 653         // Result:
 654         //   JavaTypeSignature
 655         //   VoidDescriptor
 656         // ThrowsSignature:
 657         //   ^ ClassTypeSignature
 658         //   ^ TypeVariableSignature
 659         int pos = 0;
 660         if (getChar(signature, 0) == '<') {
 661             pos = checkTypeParameters(signature, pos);
 662         }
 663         pos = checkChar('(', signature, pos);
 664         while ("ZCBSIFJDL[T".indexOf(getChar(signature, pos)) != -1) {
 665             pos = checkJavaTypeSignature(signature, pos);
 666         }
 667         pos = checkChar(')', signature, pos);
 668         if (getChar(signature, pos) == 'V') {
 669             ++pos;
 670         } else {
 671             pos = checkJavaTypeSignature(signature, pos);
 672         }
 673         while (getChar(signature, pos) == '^') {
 674             ++pos;
 675             if (getChar(signature, pos) == 'L') {
 676                 pos = checkClassTypeSignature(signature, pos);
 677             } else {
 678                 pos = checkTypeVariableSignature(signature, pos);
 679             }
 680         }
 681         if (pos != signature.length()) {
 682             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 683         }
 684     }
 685 
 686     /**
 687       * Checks a field signature.
 688       *
 689       * @param signature a string containing the signature that must be checked.
 690       */
 691     public static void checkFieldSignature(final String signature) {
 692         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 693         // FieldSignature:
 694         //   ReferenceTypeSignature
 695         int pos = checkReferenceTypeSignature(signature, 0);

 771     }
 772 
 773     /**
 774       * Checks a class type signature.
 775       *
 776       * @param signature a string containing the signature that must be checked.
 777       * @param startPos index of first character to be checked.
 778       * @return the index of the first character after the checked part.
 779       */
 780     private static int checkClassTypeSignature(final String signature, final int startPos) {
 781         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 782         // ClassTypeSignature:
 783         //   L [PackageSpecifier] SimpleClassTypeSignature ClassTypeSignatureSuffix* ;
 784         // PackageSpecifier:
 785         //   Identifier / PackageSpecifier*
 786         // SimpleClassTypeSignature:
 787         //   Identifier [TypeArguments]
 788         // ClassTypeSignatureSuffix:
 789         //   . SimpleClassTypeSignature
 790         int pos = startPos;
 791         pos = checkChar('L', signature, pos);





 792         pos = checkSignatureIdentifier(signature, pos);
 793         while (getChar(signature, pos) == '/') {
 794             pos = checkSignatureIdentifier(signature, pos + 1);
 795         }
 796         if (getChar(signature, pos) == '<') {
 797             pos = checkTypeArguments(signature, pos);
 798         }
 799         while (getChar(signature, pos) == '.') {
 800             pos = checkSignatureIdentifier(signature, pos + 1);
 801             if (getChar(signature, pos) == '<') {
 802                 pos = checkTypeArguments(signature, pos);
 803             }
 804         }
 805         return checkChar(';', signature, pos);
 806     }
 807 
 808     /**
 809       * Checks the type arguments in a class type signature.
 810       *
 811       * @param signature a string containing the signature that must be checked.

 616     }
 617 
 618     /**
 619       * Checks a class signature.
 620       *
 621       * @param signature a string containing the signature that must be checked.
 622       */
 623     public static void checkClassSignature(final String signature) {
 624         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 625         // ClassSignature:
 626         //   [TypeParameters] SuperclassSignature SuperinterfaceSignature*
 627         // SuperclassSignature:
 628         //   ClassTypeSignature
 629         // SuperinterfaceSignature:
 630         //   ClassTypeSignature
 631         int pos = 0;
 632         if (getChar(signature, 0) == '<') {
 633             pos = checkTypeParameters(signature, pos);
 634         }
 635         pos = checkClassTypeSignature(signature, pos);
 636         while (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 637             pos = checkClassTypeSignature(signature, pos);
 638         }
 639         if (pos != signature.length()) {
 640             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 641         }
 642     }
 643 
 644     /**
 645       * Checks a method signature.
 646       *
 647       * @param signature a string containing the signature that must be checked.
 648       */
 649     public static void checkMethodSignature(final String signature) {
 650         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 651         // MethodSignature:
 652         //   [TypeParameters] ( JavaTypeSignature* ) Result ThrowsSignature*
 653         // Result:
 654         //   JavaTypeSignature
 655         //   VoidDescriptor
 656         // ThrowsSignature:
 657         //   ^ ClassTypeSignature
 658         //   ^ TypeVariableSignature
 659         int pos = 0;
 660         if (getChar(signature, 0) == '<') {
 661             pos = checkTypeParameters(signature, pos);
 662         }
 663         pos = checkChar('(', signature, pos);
 664         while ("ZCBSIFJDLQ[T".indexOf(getChar(signature, pos)) != -1) {
 665             pos = checkJavaTypeSignature(signature, pos);
 666         }
 667         pos = checkChar(')', signature, pos);
 668         if (getChar(signature, pos) == 'V') {
 669             ++pos;
 670         } else {
 671             pos = checkJavaTypeSignature(signature, pos);
 672         }
 673         while (getChar(signature, pos) == '^') {
 674             ++pos;
 675             if (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 676                 pos = checkClassTypeSignature(signature, pos);
 677             } else {
 678                 pos = checkTypeVariableSignature(signature, pos);
 679             }
 680         }
 681         if (pos != signature.length()) {
 682             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 683         }
 684     }
 685 
 686     /**
 687       * Checks a field signature.
 688       *
 689       * @param signature a string containing the signature that must be checked.
 690       */
 691     public static void checkFieldSignature(final String signature) {
 692         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 693         // FieldSignature:
 694         //   ReferenceTypeSignature
 695         int pos = checkReferenceTypeSignature(signature, 0);

 771     }
 772 
 773     /**
 774       * Checks a class type signature.
 775       *
 776       * @param signature a string containing the signature that must be checked.
 777       * @param startPos index of first character to be checked.
 778       * @return the index of the first character after the checked part.
 779       */
 780     private static int checkClassTypeSignature(final String signature, final int startPos) {
 781         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 782         // ClassTypeSignature:
 783         //   L [PackageSpecifier] SimpleClassTypeSignature ClassTypeSignatureSuffix* ;
 784         // PackageSpecifier:
 785         //   Identifier / PackageSpecifier*
 786         // SimpleClassTypeSignature:
 787         //   Identifier [TypeArguments]
 788         // ClassTypeSignatureSuffix:
 789         //   . SimpleClassTypeSignature
 790         int pos = startPos;
 791         if (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 792             pos = pos + 1;
 793         } else {
 794             throw new IllegalArgumentException(signature + ": 'L' or 'Q' expected at index " + pos);
 795         }
 796 
 797         pos = checkSignatureIdentifier(signature, pos);
 798         while (getChar(signature, pos) == '/') {
 799             pos = checkSignatureIdentifier(signature, pos + 1);
 800         }
 801         if (getChar(signature, pos) == '<') {
 802             pos = checkTypeArguments(signature, pos);
 803         }
 804         while (getChar(signature, pos) == '.') {
 805             pos = checkSignatureIdentifier(signature, pos + 1);
 806             if (getChar(signature, pos) == '<') {
 807                 pos = checkTypeArguments(signature, pos);
 808             }
 809         }
 810         return checkChar(';', signature, pos);
 811     }
 812 
 813     /**
 814       * Checks the type arguments in a class type signature.
 815       *
 816       * @param signature a string containing the signature that must be checked.
< prev index next >