1 11 package org.eclipse.jdt.internal.codeassist.select; 12 13 31 32 import org.eclipse.jdt.internal.compiler.ast.MessageSend; 33 import org.eclipse.jdt.internal.compiler.lookup.Binding; 34 import org.eclipse.jdt.internal.compiler.lookup.BlockScope; 35 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; 36 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; 37 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 38 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 39 40 public class SelectionOnMessageSend extends MessageSend { 41 42 46 private MethodBinding findNonDefaultAbstractMethod(MethodBinding methodBinding) { 47 48 ReferenceBinding[] itsInterfaces = methodBinding.declaringClass.superInterfaces(); 49 if (itsInterfaces != Binding.NO_SUPERINTERFACES) { 50 ReferenceBinding[] interfacesToVisit = itsInterfaces; 51 int nextPosition = interfacesToVisit.length; 52 53 for (int i = 0; i < nextPosition; i++) { 54 ReferenceBinding currentType = interfacesToVisit[i]; 55 MethodBinding[] methods = currentType.getMethods(methodBinding.selector); 56 if(methods != null) { 57 for (int k = 0; k < methods.length; k++) { 58 if(methodBinding.areParametersEqual(methods[k])) 59 return methods[k]; 60 } 61 } 62 63 if ((itsInterfaces = currentType.superInterfaces()) != Binding.NO_SUPERINTERFACES) { 64 int itsLength = itsInterfaces.length; 65 if (nextPosition + itsLength >= interfacesToVisit.length) 66 System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); 67 nextInterface : for (int a = 0; a < itsLength; a++) { 68 ReferenceBinding next = itsInterfaces[a]; 69 for (int b = 0; b < nextPosition; b++) 70 if (next == interfacesToVisit[b]) continue nextInterface; 71 interfacesToVisit[nextPosition++] = next; 72 } 73 } 74 } 75 } 76 return methodBinding; 77 } 78 79 public StringBuffer printExpression(int indent, StringBuffer output) { 80 81 output.append("<SelectOnMessageSend:"); if (!receiver.isImplicitThis()) receiver.printExpression(0, output).append('.'); 83 output.append(this.selector).append('('); 84 if (arguments != null) { 85 for (int i = 0; i < arguments.length; i++) { 86 if (i > 0) output.append(", "); arguments[i].printExpression(0, output); 88 } 89 } 90 return output.append(")>"); } 92 93 public TypeBinding resolveType(BlockScope scope) { 94 95 super.resolveType(scope); 96 97 if(binding == null || 99 !(binding.isValidBinding() || 100 binding.problemId() == ProblemReasons.NotVisible 101 || binding.problemId() == ProblemReasons.InheritedNameHidesEnclosingName 102 || binding.problemId() == ProblemReasons.NonStaticReferenceInConstructorInvocation 103 || binding.problemId() == ProblemReasons.NonStaticReferenceInStaticContext)) { 104 throw new SelectionNodeFound(); 105 } else { 106 if(binding.isDefaultAbstract()) { 107 throw new SelectionNodeFound(findNonDefaultAbstractMethod(binding)); } else { 109 throw new SelectionNodeFound(binding); 110 } 111 } 112 } 113 } 114 | Popular Tags |