1 11 package org.eclipse.jdt.internal.codeassist; 12 13 import org.eclipse.jdt.core.IAccessRule; 14 import org.eclipse.jdt.core.IMethod; 15 import org.eclipse.jdt.core.IType; 16 import org.eclipse.jdt.core.JavaModelException; 17 import org.eclipse.jdt.core.compiler.CharOperation; 18 import org.eclipse.jdt.internal.core.BinaryType; 19 import org.eclipse.jdt.internal.core.NameLookup; 20 21 25 public class InternalCompletionProposal { 26 private static Object NO_ATTACHED_SOURCE = new Object (); 27 28 static final char[] ARG = "arg".toCharArray(); static final char[] ARG0 = "arg0".toCharArray(); static final char[] ARG1 = "arg1".toCharArray(); static final char[] ARG2 = "arg2".toCharArray(); static final char[] ARG3 = "arg3".toCharArray(); static final char[][] ARGS1 = new char[][]{ARG0}; 34 static final char[][] ARGS2 = new char[][]{ARG0, ARG1}; 35 static final char[][] ARGS3 = new char[][]{ARG0, ARG1, ARG2}; 36 static final char[][] ARGS4 = new char[][]{ARG0, ARG1, ARG2, ARG3}; 37 38 protected CompletionEngine completionEngine; 39 protected NameLookup nameLookup; 40 41 protected char[] declarationPackageName; 42 protected char[] declarationTypeName; 43 protected char[] packageName; 44 protected char[] typeName; 45 protected char[][] parameterPackageNames; 46 protected char[][] parameterTypeNames; 47 48 protected char[] originalSignature; 49 50 protected int accessibility = IAccessRule.K_ACCESSIBLE; 51 52 protected boolean isConstructor = false; 53 54 protected char[][] createDefaultParameterNames(int length) { 55 char[][] parameterNames; 56 switch (length) { 57 case 0 : 58 parameterNames = new char[length][]; 59 break; 60 case 1 : 61 parameterNames = ARGS1; 62 break; 63 case 2 : 64 parameterNames = ARGS2; 65 break; 66 case 3 : 67 parameterNames = ARGS3; 68 break; 69 case 4 : 70 parameterNames = ARGS4; 71 break; 72 default : 73 parameterNames = new char[length][]; 74 for (int i = 0; i < length; i++) { 75 parameterNames[i] = CharOperation.concat(ARG, String.valueOf(i).toCharArray()); 76 } 77 break; 78 } 79 return parameterNames; 80 } 81 protected char[][] findMethodParameterNames(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, char[][] paramTypeNames){ 82 if(paramTypeNames == null || declaringTypeName == null) return null; 83 84 char[][] parameterNames = null; 85 int length = paramTypeNames.length; 86 87 char[] tName = CharOperation.concat(declaringTypePackageName,declaringTypeName,'.'); 88 Object cachedType = this.completionEngine.typeCache.get(tName); 89 90 IType type = null; 91 if(cachedType != null) { 92 if(cachedType != NO_ATTACHED_SOURCE && cachedType instanceof BinaryType) { 93 type = (BinaryType)cachedType; 94 } 95 } else { 96 NameLookup.Answer answer = this.nameLookup.findType(new String (tName), 98 false, 99 NameLookup.ACCEPT_CLASSES & NameLookup.ACCEPT_INTERFACES, 100 true, 101 false, 102 false, 103 null); 104 type = answer == null ? null : answer.type; 105 if(type instanceof BinaryType){ 106 this.completionEngine.typeCache.put(tName, type); 107 } else { 108 type = null; 109 } 110 } 111 112 if(type != null) { 113 String [] args = new String [length]; 114 for(int i = 0; i< length ; i++){ 115 args[i] = new String (paramTypeNames[i]); 116 } 117 IMethod method = type.getMethod(new String (selector),args); 118 try{ 119 parameterNames = new char[length][]; 120 String [] params = method.getParameterNames(); 121 for(int i = 0; i< length ; i++){ 122 parameterNames[i] = params[i].toCharArray(); 123 } 124 } catch(JavaModelException e){ 125 parameterNames = null; 126 } 127 } 128 129 if(parameterNames == null) { 131 parameterNames = createDefaultParameterNames(length); 132 } 133 134 return parameterNames; 135 } 136 137 protected char[] getDeclarationPackageName() { 138 return this.declarationPackageName; 139 } 140 141 protected char[] getDeclarationTypeName() { 142 return this.declarationTypeName; 143 } 144 145 protected char[] getPackageName() { 146 return this.packageName; 147 } 148 149 protected char[] getTypeName() { 150 return this.typeName; 151 } 152 153 protected char[][] getParameterPackageNames() { 154 return this.parameterPackageNames; 155 } 156 157 158 protected char[][] getParameterTypeNames() { 159 return this.parameterTypeNames; 160 } 161 162 protected void setDeclarationPackageName(char[] declarationPackageName) { 163 this.declarationPackageName = declarationPackageName; 164 } 165 166 protected void setDeclarationTypeName(char[] declarationTypeName) { 167 this.declarationTypeName = declarationTypeName; 168 } 169 170 protected void setPackageName(char[] packageName) { 171 this.packageName = packageName; 172 } 173 174 protected void setTypeName(char[] typeName) { 175 this.typeName = typeName; 176 } 177 178 protected void setParameterPackageNames(char[][] parameterPackageNames) { 179 this.parameterPackageNames = parameterPackageNames; 180 } 181 182 protected void setParameterTypeNames(char[][] parameterTypeNames) { 183 this.parameterTypeNames = parameterTypeNames; 184 } 185 186 protected void setAccessibility(int kind) { 187 this.accessibility = kind; 188 } 189 190 protected void setIsContructor(boolean isConstructor) { 191 this.isConstructor = isConstructor; 192 } 193 public void setOriginalSignature(char[] originalSignature) { 194 this.originalSignature = originalSignature; 195 } 196 } 197 | Popular Tags |