1 11 package org.eclipse.jdt.core; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.jdt.core.compiler.CharOperation; 15 import org.eclipse.jdt.internal.codeassist.InternalCompletionProposal; 16 17 53 public final class CompletionProposal extends InternalCompletionProposal { 54 private boolean updateCompletion = false; 55 56 86 public static final int ANONYMOUS_CLASS_DECLARATION = 1; 87 88 116 public static final int FIELD_REF = 2; 117 118 138 public static final int KEYWORD = 3; 139 140 157 public static final int LABEL_REF = 4; 158 159 182 public static final int LOCAL_VARIABLE_REF = 5; 183 184 210 public static final int METHOD_REF = 6; 211 212 250 public static final int METHOD_DECLARATION = 7; 251 252 269 public static final int PACKAGE_REF = 8; 270 271 298 public static final int TYPE_REF = 9; 299 300 321 public static final int VARIABLE_DECLARATION = 10; 322 323 353 public static final int POTENTIAL_METHOD_DECLARATION = 11; 354 355 382 public static final int METHOD_NAME_REFERENCE = 12; 383 384 413 public static final int ANNOTATION_ATTRIBUTE_REF = 13; 414 415 444 public static final int JAVADOC_FIELD_REF = 14; 445 446 473 public static final int JAVADOC_METHOD_REF = 15; 474 475 503 public static final int JAVADOC_TYPE_REF = 16; 504 505 534 public static final int JAVADOC_VALUE_REF = 17; 535 536 569 public static final int JAVADOC_PARAM_REF = 18; 570 571 600 public static final int JAVADOC_BLOCK_TAG = 19; 601 602 631 public static final int JAVADOC_INLINE_TAG = 20; 632 633 664 public static final int FIELD_IMPORT = 21; 665 666 695 public static final int METHOD_IMPORT = 22; 696 697 726 public static final int TYPE_IMPORT = 23; 727 728 733 protected static final int FIRST_KIND = ANONYMOUS_CLASS_DECLARATION; 734 735 740 protected static final int LAST_KIND = TYPE_IMPORT; 741 742 745 private int completionKind; 746 747 751 private int completionLocation; 752 753 758 private int tokenStart = 0; 759 760 765 private int tokenEnd = 0; 766 767 770 private char[] completion = CharOperation.NO_CHAR; 771 772 777 private int replaceStart = 0; 778 779 784 private int replaceEnd = 0; 785 786 790 private int relevance = 1; 791 792 797 private char[] declarationSignature = null; 798 799 804 private char[] declarationKey = null; 805 806 812 private char[] name = null; 813 814 819 private char[] signature = null; 820 821 826 private char[] key = null; 827 828 833 private CompletionProposal[] requiredProposals; 834 835 840 private int flags = Flags.AccDefault; 841 842 847 private int additionalFlags = CompletionFlags.Default; 848 849 854 private char[][] parameterNames = null; 855 856 859 private boolean parameterNamesComputed = false; 860 861 874 public static CompletionProposal create(int kind, int completionOffset) { 875 return new CompletionProposal(kind, completionOffset); 876 } 877 878 890 CompletionProposal(int kind, int completionLocation) { 891 if ((kind < CompletionProposal.FIRST_KIND) 892 || (kind > CompletionProposal.LAST_KIND)) { 893 throw new IllegalArgumentException (); 894 } 895 if (this.completion == null || completionLocation < 0) { 896 if(this.completion == null || completionLocation != -1) { 900 throw new IllegalArgumentException (); 901 } 902 completionLocation = 0; 903 } 904 this.completionKind = kind; 905 this.completionLocation = completionLocation; 906 } 907 908 935 public int getAdditionalFlags() { 936 return this.additionalFlags; 937 } 938 939 954 public void setAdditionalFlags(int additionalFlags) { 955 this.additionalFlags = additionalFlags; 956 } 957 958 972 public int getKind() { 973 return this.completionKind; 974 } 975 976 985 public int getCompletionLocation() { 987 return this.completionLocation; 988 } 989 990 1003 public int getTokenStart() { 1004 return this.tokenStart; 1005 } 1006 1007 1016 public int getTokenEnd() { 1017 return this.tokenEnd; 1018 } 1019 1020 1036 public void setTokenRange(int startIndex, int endIndex) { 1037 if (startIndex < 0 || endIndex < startIndex) { 1038 throw new IllegalArgumentException (); 1039 } 1040 this.tokenStart = startIndex; 1041 this.tokenEnd = endIndex; 1042 } 1043 1044 1055 public char[] getCompletion() { 1056 if(this.completionKind == METHOD_DECLARATION) { 1057 this.findParameterNames(null); 1058 if(this.updateCompletion) { 1059 this.updateCompletion = false; 1060 1061 if(this.parameterNames != null) { 1062 int length = this.parameterNames.length; 1063 StringBuffer completionBuffer = new StringBuffer (this.completion.length); 1064 1065 int start = 0; 1066 int end = CharOperation.indexOf('%', this.completion); 1067 1068 completionBuffer.append(this.completion, start, end - start); 1069 1070 for(int i = 0 ; i < length ; i++){ 1071 completionBuffer.append(this.parameterNames[i]); 1072 start = end + 1; 1073 end = CharOperation.indexOf('%', this.completion, start); 1074 if(end > -1){ 1075 completionBuffer.append(this.completion, start, end - start); 1076 } else { 1077 completionBuffer.append(this.completion, start, this.completion.length - start); 1078 } 1079 } 1080 int nameLength = completionBuffer.length(); 1081 this.completion = new char[nameLength]; 1082 completionBuffer.getChars(0, nameLength, this.completion, 0); 1083 } 1084 } 1085 } 1086 return this.completion; 1087 } 1088 1089 1104 public void setCompletion(char[] completion) { 1105 this.completion = completion; 1106 } 1107 1108 1129 public int getReplaceStart() { 1130 return this.replaceStart; 1131 } 1132 1133 1143 public int getReplaceEnd() { 1144 return this.replaceEnd; 1145 } 1146 1147 1165 public void setReplaceRange(int startIndex, int endIndex) { 1166 if (startIndex < 0 || endIndex < startIndex) { 1167 throw new IllegalArgumentException (); 1168 } 1169 this.replaceStart = startIndex; 1170 this.replaceEnd = endIndex; 1171 } 1172 1173 1178 public int getRelevance() { 1179 return this.relevance; 1180 } 1181 1182 1194 public void setRelevance(int rating) { 1195 if (rating <= 0) { 1196 throw new IllegalArgumentException (); 1197 } 1198 this.relevance = rating; 1199 } 1200 1201 1241 public char[] getDeclarationSignature() { 1242 return this.declarationSignature; 1243 } 1244 1245 1267 public char[] getDeclarationKey() { 1268 return this.declarationKey; 1269 } 1270 1271 1285 public void setDeclarationSignature(char[] signature) { 1286 this.declarationSignature = signature; 1287 } 1288 1289 1304 public void setDeclarationKey(char[] key) { 1305 this.declarationKey = key; 1306 } 1307 1308 1336 public char[] getName() { 1337 return this.name; 1338 } 1339 1340 1341 1356 public void setName(char[] name) { 1357 this.name = name; 1358 } 1359 1360 1400 public char[] getSignature() { 1401 return this.signature; 1402 } 1403 1404 1426 public char[] getKey() { 1427 return this.key; 1428 } 1429 1430 1635 1648 public void setSignature(char[] signature) { 1649 this.signature = signature; 1650 } 1651 1652 1666 public void setKey(char[] key) { 1667 this.key = key; 1668 } 1669 1670 1726 public int getFlags() { 1727 return this.flags; 1728 } 1729 1730 1743 public void setFlags(int flags) { 1744 this.flags = flags; 1745 } 1746 1747 1787 public CompletionProposal[] getRequiredProposals() { 1788 return this.requiredProposals; 1789 } 1790 1791 1792 1806 public void setRequiredProposals(CompletionProposal[] proposals) { 1807 this.requiredProposals = proposals; 1808 } 1809 1810 1827 public char[][] findParameterNames(IProgressMonitor monitor) { 1828 if (!this.parameterNamesComputed) { 1829 this.parameterNamesComputed = true; 1830 1831 switch(this.completionKind) { 1832 case ANONYMOUS_CLASS_DECLARATION: 1833 try { 1834 this.parameterNames = this.findMethodParameterNames( 1835 this.declarationPackageName, 1836 this.declarationTypeName, 1837 CharOperation.lastSegment(this.declarationTypeName, '.'), 1838 Signature.getParameterTypes(this.originalSignature == null ? this.signature : this.originalSignature)); 1839 } catch(IllegalArgumentException e) { 1840 if(this.parameterTypeNames != null) { 1842 this.parameterNames = this.createDefaultParameterNames(this.parameterTypeNames.length); 1843 } else { 1844 this.parameterNames = null; 1845 } 1846 } 1847 break; 1848 case METHOD_REF: 1849 try { 1850 this.parameterNames = this.findMethodParameterNames( 1851 this.declarationPackageName, 1852 this.declarationTypeName, 1853 this.name, 1854 Signature.getParameterTypes(this.originalSignature == null ? this.signature : this.originalSignature)); 1855 } catch(IllegalArgumentException e) { 1856 if(this.parameterTypeNames != null) { 1858 this.parameterNames = this.createDefaultParameterNames(this.parameterTypeNames.length); 1859 } else { 1860 this.parameterNames = null; 1861 } 1862 } 1863 break; 1864 case METHOD_DECLARATION: 1865 try { 1866 this.parameterNames = this.findMethodParameterNames( 1867 this.declarationPackageName, 1868 this.declarationTypeName, 1869 this.name, 1870 Signature.getParameterTypes(this.originalSignature == null ? this.signature : this.originalSignature)); 1871 } catch(IllegalArgumentException e) { 1872 if(this.parameterTypeNames != null) { 1874 this.parameterNames = this.createDefaultParameterNames(this.parameterTypeNames.length); 1875 } else { 1876 this.parameterNames = null; 1877 } 1878 } 1879 if(this.parameterNames != null) { 1880 this.updateCompletion = true; 1881 } 1882 break; 1883 } 1884 } 1885 return this.parameterNames; 1886 } 1887 1888 1899 public void setParameterNames(char[][] parameterNames) { 1900 this.parameterNames = parameterNames; 1901 this.parameterNamesComputed = true; 1902 } 1903 1904 1924 public int getAccessibility() { 1925 return this.accessibility; 1926 } 1927 1928 1946 public boolean isConstructor() { 1947 return this.isConstructor; 1948 } 1949 1950 public String toString() { 1951 StringBuffer buffer = new StringBuffer (); 1952 buffer.append('['); 1953 switch(this.completionKind) { 1954 case CompletionProposal.ANONYMOUS_CLASS_DECLARATION : 1955 buffer.append("ANONYMOUS_CLASS_DECLARATION"); break; 1957 case CompletionProposal.FIELD_REF : 1958 buffer.append("FIELD_REF"); break; 1960 case CompletionProposal.KEYWORD : 1961 buffer.append("KEYWORD"); break; 1963 case CompletionProposal.LABEL_REF : 1964 buffer.append("LABEL_REF"); break; 1966 case CompletionProposal.LOCAL_VARIABLE_REF : 1967 buffer.append("LOCAL_VARIABLE_REF"); break; 1969 case CompletionProposal.METHOD_DECLARATION : 1970 buffer.append("METHOD_DECLARATION"); if(this.isConstructor) { 1972 buffer.append("<CONSTRUCTOR>"); } 1974 break; 1975 case CompletionProposal.METHOD_REF : 1976 buffer.append("METHOD_REF"); if(this.isConstructor) { 1978 buffer.append("<CONSTRUCTOR>"); } 1980 break; 1981 case CompletionProposal.PACKAGE_REF : 1982 buffer.append("PACKAGE_REF"); break; 1984 case CompletionProposal.TYPE_REF : 1985 buffer.append("TYPE_REF"); break; 1987 case CompletionProposal.VARIABLE_DECLARATION : 1988 buffer.append("VARIABLE_DECLARATION"); break; 1990 case CompletionProposal.POTENTIAL_METHOD_DECLARATION : 1991 buffer.append("POTENTIAL_METHOD_DECLARATION"); break; 1993 case CompletionProposal.METHOD_NAME_REFERENCE : 1994 buffer.append("METHOD_IMPORT"); break; 1996 case CompletionProposal.ANNOTATION_ATTRIBUTE_REF : 1997 buffer.append("ANNOTATION_ATTRIBUTE_REF"); break; 1999 case CompletionProposal.JAVADOC_BLOCK_TAG : 2000 buffer.append("JAVADOC_BLOCK_TAG"); break; 2002 case CompletionProposal.JAVADOC_INLINE_TAG : 2003 buffer.append("JAVADOC_INLINE_TAG"); break; 2005 case CompletionProposal.JAVADOC_FIELD_REF: 2006 buffer.append("JAVADOC_FIELD_REF"); break; 2008 case CompletionProposal.JAVADOC_METHOD_REF : 2009 buffer.append("JAVADOC_METHOD_REF"); break; 2011 case CompletionProposal.JAVADOC_TYPE_REF : 2012 buffer.append("JAVADOC_TYPE_REF"); break; 2014 case CompletionProposal.JAVADOC_PARAM_REF : 2015 buffer.append("JAVADOC_PARAM_REF"); break; 2017 case CompletionProposal.JAVADOC_VALUE_REF : 2018 buffer.append("JAVADOC_VALUE_REF"); break; 2020 case CompletionProposal.FIELD_IMPORT : 2021 buffer.append("FIELD_IMPORT"); break; 2023 case CompletionProposal.METHOD_IMPORT : 2024 buffer.append("METHOD_IMPORT"); break; 2026 case CompletionProposal.TYPE_IMPORT : 2027 buffer.append("TYPE_IMPORT"); break; 2029 default : 2030 buffer.append("PROPOSAL"); break; 2032 2033 } 2034 buffer.append("]{completion:"); if (this.completion != null) buffer.append(this.completion); 2036 buffer.append(", declSign:"); if (this.declarationSignature != null) buffer.append(this.declarationSignature); 2038 buffer.append(", sign:"); if (this.signature != null) buffer.append(this.signature); 2040 buffer.append(", declKey:"); if (this.declarationKey != null) buffer.append(this.declarationKey); 2042 buffer.append(", key:"); if (this.key != null) buffer.append(key); 2044 buffer.append(", name:"); if (this.name != null) buffer.append(this.name); 2046 buffer.append(", ["); buffer.append(this.replaceStart); 2048 buffer.append(','); 2049 buffer.append(this.replaceEnd); 2050 buffer.append("], relevance="); buffer.append(this.relevance); 2052 buffer.append('}'); 2053 return buffer.toString(); 2054 } 2055} 2056 | Popular Tags |