Lines 25-30
Link Here
|
25 |
*/ |
25 |
*/ |
26 |
|
26 |
|
27 |
/* package */ class BinaryMethod extends BinaryMember implements IMethod { |
27 |
/* package */ class BinaryMethod extends BinaryMember implements IMethod { |
|
|
28 |
private static final char[] BOOLEAN = "boolean".toCharArray(); //$NON-NLS-1$ |
29 |
private static final char[] BYTE = "byte".toCharArray(); //$NON-NLS-1$ |
30 |
private static final char[] CHAR = "char".toCharArray(); //$NON-NLS-1$ |
31 |
private static final char[] DOUBLE = "double".toCharArray(); //$NON-NLS-1$ |
32 |
private static final char[] FLOAT = "float".toCharArray(); //$NON-NLS-1$ |
33 |
private static final char[] INT = "int".toCharArray(); //$NON-NLS-1$ |
34 |
private static final char[] LONG = "long".toCharArray(); //$NON-NLS-1$ |
35 |
private static final char[] SHORT = "short".toCharArray(); //$NON-NLS-1$ |
36 |
private static final char[] VOID = "void".toCharArray(); //$NON-NLS-1$ |
28 |
|
37 |
|
29 |
/** |
38 |
/** |
30 |
* The parameter type signatures of the method - stored locally |
39 |
* The parameter type signatures of the method - stored locally |
Lines 491-497
Link Here
|
491 |
if (this.isConstructor()) { |
500 |
if (this.isConstructor()) { |
492 |
methodName = typeQualifiedName; |
501 |
methodName = typeQualifiedName; |
493 |
} |
502 |
} |
494 |
String anchor = Signature.toString(this.getSignature().replace('/', '.'), methodName, null, true, false, Flags.isVarargs(this.getFlags())); |
503 |
IBinaryMethod info = (IBinaryMethod) getElementInfo(); |
|
|
504 |
char[] genericSignature = info.getGenericSignature(); |
505 |
String anchor = null; |
506 |
if (genericSignature != null) { |
507 |
CharOperation.replace(genericSignature, '/', '.'); |
508 |
anchor = toString(genericSignature, methodName, Flags.isVarargs(this.getFlags())); |
509 |
} else { |
510 |
anchor = Signature.toString(this.getSignature().replace('/', '.'), methodName, null, true, false, Flags.isVarargs(this.getFlags())); |
511 |
} |
495 |
if (declaringTypeIsMember) { |
512 |
if (declaringTypeIsMember) { |
496 |
|
513 |
|
497 |
int depth = 0; |
514 |
int depth = 0; |
Lines 544-547
Link Here
|
544 |
if (indexOfNextMethod == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, this)); |
561 |
if (indexOfNextMethod == -1) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.UNKNOWN_JAVADOC_FORMAT, this)); |
545 |
return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextMethod); |
562 |
return contents.substring(indexOfEndLink + JavadocConstants.ANCHOR_SUFFIX_LENGTH, indexOfNextMethod); |
546 |
} |
563 |
} |
|
|
564 |
public String toString(char[] methodSignature, String methodName, boolean isVarArgs) { |
565 |
return new String(toCharArray(methodSignature, methodName.toCharArray(), isVarArgs)); |
566 |
} |
567 |
public char[] toCharArray(char[] methodSignature, char[] methodName, boolean isVargArgs) { |
568 |
int firstParen = CharOperation.indexOf(Signature.C_PARAM_START, methodSignature); |
569 |
if (firstParen == -1) { |
570 |
throw new IllegalArgumentException(); |
571 |
} |
572 |
|
573 |
StringBuffer buffer = new StringBuffer(methodSignature.length + 10); |
574 |
|
575 |
// selector |
576 |
if (methodName != null) { |
577 |
buffer.append(methodName); |
578 |
} |
579 |
|
580 |
// parameters |
581 |
buffer.append('('); |
582 |
char[][] pts = getParameterTypes(methodSignature); |
583 |
for (int i = 0, max = pts.length; i < max; i++) { |
584 |
if (i == max - 1) { |
585 |
appendTypeSignature(pts[i], 0 , buffer, isVargArgs); |
586 |
} else { |
587 |
appendTypeSignature(pts[i], 0 , buffer, false); |
588 |
} |
589 |
if (i != pts.length - 1) { |
590 |
buffer.append(','); |
591 |
buffer.append(' '); |
592 |
} |
593 |
} |
594 |
buffer.append(')'); |
595 |
char[] result = new char[buffer.length()]; |
596 |
buffer.getChars(0, buffer.length(), result, 0); |
597 |
return result; |
598 |
} |
599 |
public char[][] getParameterTypes(char[] methodSignature) throws IllegalArgumentException { |
600 |
try { |
601 |
int count = getParameterCount(methodSignature); |
602 |
char[][] result = new char[count][]; |
603 |
if (count == 0) { |
604 |
return result; |
605 |
} |
606 |
int i = CharOperation.indexOf(Signature.C_PARAM_START, methodSignature); |
607 |
if (i < 0) { |
608 |
throw new IllegalArgumentException(); |
609 |
} else { |
610 |
i++; |
611 |
} |
612 |
int t = 0; |
613 |
for (;;) { |
614 |
if (methodSignature[i] == Signature.C_PARAM_END) { |
615 |
return result; |
616 |
} |
617 |
int e = Util.scanTypeSignature(methodSignature, i); |
618 |
if (e < 0) { |
619 |
throw new IllegalArgumentException(); |
620 |
} |
621 |
result[t] = CharOperation.subarray(methodSignature, i, e + 1); |
622 |
t++; |
623 |
i = e + 1; |
624 |
} |
625 |
} catch (ArrayIndexOutOfBoundsException e) { |
626 |
throw new IllegalArgumentException(); |
627 |
} |
628 |
} |
629 |
private int appendTypeSignature(char[] string, int start, StringBuffer buffer, boolean isVarArgs) { |
630 |
// need a minimum 1 char |
631 |
if (start >= string.length) { |
632 |
throw new IllegalArgumentException(); |
633 |
} |
634 |
char c = string[start]; |
635 |
if (isVarArgs) { |
636 |
switch (c) { |
637 |
case Signature.C_ARRAY : |
638 |
return appendArrayTypeSignature(string, start, buffer, true); |
639 |
case Signature.C_RESOLVED : |
640 |
case Signature.C_TYPE_VARIABLE : |
641 |
case Signature.C_BOOLEAN : |
642 |
case Signature.C_BYTE : |
643 |
case Signature.C_CHAR : |
644 |
case Signature.C_DOUBLE : |
645 |
case Signature.C_FLOAT : |
646 |
case Signature.C_INT : |
647 |
case Signature.C_LONG : |
648 |
case Signature.C_SHORT : |
649 |
case Signature.C_VOID : |
650 |
case Signature.C_STAR: |
651 |
case Signature.C_EXTENDS: |
652 |
case Signature.C_SUPER: |
653 |
case Signature.C_CAPTURE: |
654 |
default: |
655 |
throw new IllegalArgumentException(); // a var args is an array type |
656 |
} |
657 |
} else { |
658 |
switch (c) { |
659 |
case Signature.C_ARRAY : |
660 |
return appendArrayTypeSignature(string, start, buffer, false); |
661 |
case Signature.C_RESOLVED : |
662 |
return appendClassTypeSignature(string, start, buffer); |
663 |
case Signature.C_TYPE_VARIABLE : |
664 |
int e = Util.scanTypeVariableSignature(string, start); |
665 |
buffer.append(string, start + 1, e - start - 1); |
666 |
return e; |
667 |
case Signature.C_BOOLEAN : |
668 |
buffer.append(BOOLEAN); |
669 |
return start; |
670 |
case Signature.C_BYTE : |
671 |
buffer.append(BYTE); |
672 |
return start; |
673 |
case Signature.C_CHAR : |
674 |
buffer.append(CHAR); |
675 |
return start; |
676 |
case Signature.C_DOUBLE : |
677 |
buffer.append(DOUBLE); |
678 |
return start; |
679 |
case Signature.C_FLOAT : |
680 |
buffer.append(FLOAT); |
681 |
return start; |
682 |
case Signature.C_INT : |
683 |
buffer.append(INT); |
684 |
return start; |
685 |
case Signature.C_LONG : |
686 |
buffer.append(LONG); |
687 |
return start; |
688 |
case Signature.C_SHORT : |
689 |
buffer.append(SHORT); |
690 |
return start; |
691 |
case Signature.C_VOID : |
692 |
buffer.append(VOID); |
693 |
return start; |
694 |
case Signature.C_CAPTURE : |
695 |
return appendCaptureTypeSignature(string, start, buffer); |
696 |
case Signature.C_STAR: |
697 |
case Signature.C_EXTENDS: |
698 |
case Signature.C_SUPER: |
699 |
return appendTypeArgumentSignature(string, start, buffer); |
700 |
default : |
701 |
throw new IllegalArgumentException(); |
702 |
} |
703 |
} |
704 |
} |
705 |
public int getParameterCount(char[] methodSignature) throws IllegalArgumentException { |
706 |
try { |
707 |
int count = 0; |
708 |
int i = CharOperation.indexOf(Signature.C_PARAM_START, methodSignature); |
709 |
if (i < 0) { |
710 |
throw new IllegalArgumentException(); |
711 |
} else { |
712 |
i++; |
713 |
} |
714 |
for (;;) { |
715 |
if (methodSignature[i] == Signature.C_PARAM_END) { |
716 |
return count; |
717 |
} |
718 |
int e= Util.scanTypeSignature(methodSignature, i); |
719 |
if (e < 0) { |
720 |
throw new IllegalArgumentException(); |
721 |
} else { |
722 |
i = e + 1; |
723 |
} |
724 |
count++; |
725 |
} |
726 |
} catch (ArrayIndexOutOfBoundsException e) { |
727 |
throw new IllegalArgumentException(); |
728 |
} |
729 |
} |
730 |
private int appendArrayTypeSignature(char[] string, int start, StringBuffer buffer, boolean isVarArgs) { |
731 |
int length = string.length; |
732 |
// need a minimum 2 char |
733 |
if (start >= length - 1) { |
734 |
throw new IllegalArgumentException(); |
735 |
} |
736 |
char c = string[start]; |
737 |
if (c != Signature.C_ARRAY) { |
738 |
throw new IllegalArgumentException(); |
739 |
} |
740 |
|
741 |
int index = start; |
742 |
c = string[++index]; |
743 |
while(c == Signature.C_ARRAY) { |
744 |
// need a minimum 2 char |
745 |
if (index >= length - 1) { |
746 |
throw new IllegalArgumentException(); |
747 |
} |
748 |
c = string[++index]; |
749 |
} |
750 |
|
751 |
int e = appendTypeSignature(string, index, buffer, false); |
752 |
|
753 |
for(int i = 1, dims = index - start; i < dims; i++) { |
754 |
buffer.append('[').append(']'); |
755 |
} |
756 |
|
757 |
if (isVarArgs) { |
758 |
buffer.append('.').append('.').append('.'); |
759 |
} else { |
760 |
buffer.append('[').append(']'); |
761 |
} |
762 |
return e; |
763 |
} |
764 |
private int appendClassTypeSignature(char[] string, int start, StringBuffer buffer) { |
765 |
// need a minimum 3 chars "Lx;" |
766 |
if (start >= string.length - 2) { |
767 |
throw new IllegalArgumentException(); |
768 |
} |
769 |
// must start in "L" or "Q" |
770 |
char c = string[start]; |
771 |
if (c != Signature.C_RESOLVED && c != Signature.C_UNRESOLVED) { |
772 |
throw new IllegalArgumentException(); |
773 |
} |
774 |
int p = start + 1; |
775 |
while (true) { |
776 |
if (p >= string.length) { |
777 |
throw new IllegalArgumentException(); |
778 |
} |
779 |
c = string[p]; |
780 |
switch(c) { |
781 |
case Signature.C_SEMICOLON : |
782 |
// all done |
783 |
return p; |
784 |
case Signature.C_GENERIC_START : |
785 |
int e = searchGenericEnd(string, p + 1); |
786 |
// once we hit type arguments there are no more package prefixes |
787 |
p = e; |
788 |
break; |
789 |
case Signature.C_DOT : |
790 |
buffer.append('.'); |
791 |
break; |
792 |
case '/' : |
793 |
buffer.append('/'); |
794 |
break; |
795 |
case Signature.C_DOLLAR : |
796 |
// once we hit "$" there are no more package prefixes |
797 |
/** |
798 |
* Convert '$' in resolved type signatures into '.'. |
799 |
* NOTE: This assumes that the type signature is an inner type |
800 |
* signature. This is true in most cases, but someone can define a |
801 |
* non-inner type name containing a '$'. |
802 |
*/ |
803 |
buffer.append('.'); |
804 |
break; |
805 |
default : |
806 |
buffer.append(c); |
807 |
} |
808 |
p++; |
809 |
} |
810 |
} |
811 |
private int appendTypeArgumentSignature(char[] string, int start, StringBuffer buffer) { |
812 |
// need a minimum 1 char |
813 |
if (start >= string.length) { |
814 |
throw new IllegalArgumentException(); |
815 |
} |
816 |
char c = string[start]; |
817 |
switch(c) { |
818 |
case Signature.C_STAR : |
819 |
return start; |
820 |
case Signature.C_EXTENDS : |
821 |
return appendTypeSignature(string, start + 1, buffer, false); |
822 |
case Signature.C_SUPER : |
823 |
return appendTypeSignature(string, start + 1, buffer, false); |
824 |
default : |
825 |
return appendTypeSignature(string, start, buffer, false); |
826 |
} |
827 |
} |
828 |
private int appendCaptureTypeSignature(char[] string, int start, StringBuffer buffer) { |
829 |
// need a minimum 2 char |
830 |
if (start >= string.length - 1) { |
831 |
throw new IllegalArgumentException(); |
832 |
} |
833 |
char c = string[start]; |
834 |
if (c != Signature.C_CAPTURE) { |
835 |
throw new IllegalArgumentException(); |
836 |
} |
837 |
return appendTypeArgumentSignature(string, start + 1, buffer); |
838 |
} |
839 |
private int searchGenericEnd(char[] string, int start) { |
840 |
if (start >= string.length) { |
841 |
throw new IllegalArgumentException(); |
842 |
} |
843 |
if (string[start] == Signature.C_GENERIC_END) { |
844 |
return start; |
845 |
} |
846 |
int length = string.length; |
847 |
int balance = 1; |
848 |
start++; |
849 |
while (start <= length) { |
850 |
switch(string[start]) { |
851 |
case Signature.C_GENERIC_END : |
852 |
balance--; |
853 |
if (balance == 0) { |
854 |
return start; |
855 |
} |
856 |
break; |
857 |
case Signature.C_GENERIC_START : |
858 |
balance++; |
859 |
break; |
860 |
} |
861 |
start++; |
862 |
} |
863 |
return start; |
864 |
} |
547 |
} |
865 |
} |