< prev index next >

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

Print this page




 579     }
 580 
 581     /**
 582       * Checks a class signature.
 583       *
 584       * @param signature a string containing the signature that must be checked.
 585       */
 586     public static void checkClassSignature(final String signature) {
 587         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 588         // ClassSignature:
 589         //   [TypeParameters] SuperclassSignature SuperinterfaceSignature*
 590         // SuperclassSignature:
 591         //   ClassTypeSignature
 592         // SuperinterfaceSignature:
 593         //   ClassTypeSignature
 594         int pos = 0;
 595         if (getChar(signature, 0) == '<') {
 596             pos = checkTypeParameters(signature, pos);
 597         }
 598         pos = checkClassTypeSignature(signature, pos);
 599         while (getChar(signature, pos) == 'L') {
 600             pos = checkClassTypeSignature(signature, pos);
 601         }
 602         if (pos != signature.length()) {
 603             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 604         }
 605     }
 606 
 607     /**
 608       * Checks a method signature.
 609       *
 610       * @param signature a string containing the signature that must be checked.
 611       */
 612     public static void checkMethodSignature(final String signature) {
 613         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 614         // MethodSignature:
 615         //   [TypeParameters] ( JavaTypeSignature* ) Result ThrowsSignature*
 616         // Result:
 617         //   JavaTypeSignature
 618         //   VoidDescriptor
 619         // ThrowsSignature:
 620         //   ^ ClassTypeSignature
 621         //   ^ TypeVariableSignature
 622         int pos = 0;
 623         if (getChar(signature, 0) == '<') {
 624             pos = checkTypeParameters(signature, pos);
 625         }
 626         pos = checkChar('(', signature, pos);
 627         while ("ZCBSIFJDL[T".indexOf(getChar(signature, pos)) != -1) {
 628             pos = checkJavaTypeSignature(signature, pos);
 629         }
 630         pos = checkChar(')', signature, pos);
 631         if (getChar(signature, pos) == 'V') {
 632             ++pos;
 633         } else {
 634             pos = checkJavaTypeSignature(signature, pos);
 635         }
 636         while (getChar(signature, pos) == '^') {
 637             ++pos;
 638             if (getChar(signature, pos) == 'L') {
 639                 pos = checkClassTypeSignature(signature, pos);
 640             } else {
 641                 pos = checkTypeVariableSignature(signature, pos);
 642             }
 643         }
 644         if (pos != signature.length()) {
 645             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 646         }
 647     }
 648 
 649     /**
 650       * Checks a field signature.
 651       *
 652       * @param signature a string containing the signature that must be checked.
 653       */
 654     public static void checkFieldSignature(final String signature) {
 655         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 656         // FieldSignature:
 657         //   ReferenceTypeSignature
 658         int pos = checkReferenceTypeSignature(signature, 0);


 734     }
 735 
 736     /**
 737       * Checks a class type signature.
 738       *
 739       * @param signature a string containing the signature that must be checked.
 740       * @param startPos index of first character to be checked.
 741       * @return the index of the first character after the checked part.
 742       */
 743     private static int checkClassTypeSignature(final String signature, final int startPos) {
 744         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 745         // ClassTypeSignature:
 746         //   L [PackageSpecifier] SimpleClassTypeSignature ClassTypeSignatureSuffix* ;
 747         // PackageSpecifier:
 748         //   Identifier / PackageSpecifier*
 749         // SimpleClassTypeSignature:
 750         //   Identifier [TypeArguments]
 751         // ClassTypeSignatureSuffix:
 752         //   . SimpleClassTypeSignature
 753         int pos = startPos;
 754         pos = checkChar('L', signature, pos);





 755         pos = checkSignatureIdentifier(signature, pos);
 756         while (getChar(signature, pos) == '/') {
 757             pos = checkSignatureIdentifier(signature, pos + 1);
 758         }
 759         if (getChar(signature, pos) == '<') {
 760             pos = checkTypeArguments(signature, pos);
 761         }
 762         while (getChar(signature, pos) == '.') {
 763             pos = checkSignatureIdentifier(signature, pos + 1);
 764             if (getChar(signature, pos) == '<') {
 765                 pos = checkTypeArguments(signature, pos);
 766             }
 767         }
 768         return checkChar(';', signature, pos);
 769     }
 770 
 771     /**
 772       * Checks the type arguments in a class type signature.
 773       *
 774       * @param signature a string containing the signature that must be checked.




 579     }
 580 
 581     /**
 582       * Checks a class signature.
 583       *
 584       * @param signature a string containing the signature that must be checked.
 585       */
 586     public static void checkClassSignature(final String signature) {
 587         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 588         // ClassSignature:
 589         //   [TypeParameters] SuperclassSignature SuperinterfaceSignature*
 590         // SuperclassSignature:
 591         //   ClassTypeSignature
 592         // SuperinterfaceSignature:
 593         //   ClassTypeSignature
 594         int pos = 0;
 595         if (getChar(signature, 0) == '<') {
 596             pos = checkTypeParameters(signature, pos);
 597         }
 598         pos = checkClassTypeSignature(signature, pos);
 599         while (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 600             pos = checkClassTypeSignature(signature, pos);
 601         }
 602         if (pos != signature.length()) {
 603             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 604         }
 605     }
 606 
 607     /**
 608       * Checks a method signature.
 609       *
 610       * @param signature a string containing the signature that must be checked.
 611       */
 612     public static void checkMethodSignature(final String signature) {
 613         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 614         // MethodSignature:
 615         //   [TypeParameters] ( JavaTypeSignature* ) Result ThrowsSignature*
 616         // Result:
 617         //   JavaTypeSignature
 618         //   VoidDescriptor
 619         // ThrowsSignature:
 620         //   ^ ClassTypeSignature
 621         //   ^ TypeVariableSignature
 622         int pos = 0;
 623         if (getChar(signature, 0) == '<') {
 624             pos = checkTypeParameters(signature, pos);
 625         }
 626         pos = checkChar('(', signature, pos);
 627         while ("ZCBSIFJDLQ[T".indexOf(getChar(signature, pos)) != -1) {
 628             pos = checkJavaTypeSignature(signature, pos);
 629         }
 630         pos = checkChar(')', signature, pos);
 631         if (getChar(signature, pos) == 'V') {
 632             ++pos;
 633         } else {
 634             pos = checkJavaTypeSignature(signature, pos);
 635         }
 636         while (getChar(signature, pos) == '^') {
 637             ++pos;
 638             if (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 639                 pos = checkClassTypeSignature(signature, pos);
 640             } else {
 641                 pos = checkTypeVariableSignature(signature, pos);
 642             }
 643         }
 644         if (pos != signature.length()) {
 645             throw new IllegalArgumentException(signature + ERROR_AT + pos);
 646         }
 647     }
 648 
 649     /**
 650       * Checks a field signature.
 651       *
 652       * @param signature a string containing the signature that must be checked.
 653       */
 654     public static void checkFieldSignature(final String signature) {
 655         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 656         // FieldSignature:
 657         //   ReferenceTypeSignature
 658         int pos = checkReferenceTypeSignature(signature, 0);


 734     }
 735 
 736     /**
 737       * Checks a class type signature.
 738       *
 739       * @param signature a string containing the signature that must be checked.
 740       * @param startPos index of first character to be checked.
 741       * @return the index of the first character after the checked part.
 742       */
 743     private static int checkClassTypeSignature(final String signature, final int startPos) {
 744         // From https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.9.1:
 745         // ClassTypeSignature:
 746         //   L [PackageSpecifier] SimpleClassTypeSignature ClassTypeSignatureSuffix* ;
 747         // PackageSpecifier:
 748         //   Identifier / PackageSpecifier*
 749         // SimpleClassTypeSignature:
 750         //   Identifier [TypeArguments]
 751         // ClassTypeSignatureSuffix:
 752         //   . SimpleClassTypeSignature
 753         int pos = startPos;
 754         if (getChar(signature, pos) == 'L' || getChar(signature, pos) == 'Q') {
 755             pos = pos + 1;
 756         } else {
 757             throw new IllegalArgumentException(signature + ": 'L' or 'Q' expected at index " + pos);
 758         }
 759 
 760         pos = checkSignatureIdentifier(signature, pos);
 761         while (getChar(signature, pos) == '/') {
 762             pos = checkSignatureIdentifier(signature, pos + 1);
 763         }
 764         if (getChar(signature, pos) == '<') {
 765             pos = checkTypeArguments(signature, pos);
 766         }
 767         while (getChar(signature, pos) == '.') {
 768             pos = checkSignatureIdentifier(signature, pos + 1);
 769             if (getChar(signature, pos) == '<') {
 770                 pos = checkTypeArguments(signature, pos);
 771             }
 772         }
 773         return checkChar(';', signature, pos);
 774     }
 775 
 776     /**
 777       * Checks the type arguments in a class type signature.
 778       *
 779       * @param signature a string containing the signature that must be checked.


< prev index next >