[Title] JSDT : Added VariableBinding for Anonymous function.
authorSujin Kim <sujin921.kim@samsung.com>
Fri, 21 Dec 2012 02:07:41 +0000 (11:07 +0900)
committerhyukmin kwon <hyukmin0530.kwon@samsung.com>
Fri, 28 Dec 2012 09:11:37 +0000 (18:11 +0900)
[Desc.] 1) If anonymous function was assigned to a variable,
binding of MessageSend is not MethodBinding but VariableBinding.
Added a checking about it.
[Issue] REDMINE-7711
Change-Id: Iac128274a5adb80cbff963bc7b2e4d72557f4fe3

org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/codeassist/select/SelectionOnMessageSend.java
org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/ast/SingleNameReference.java
org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/lookup/BlockScope.java
org.eclipse.wst.jsdt.core/src/org/eclipse/wst/jsdt/internal/compiler/lookup/MethodBinding.java

index b4d14b1..bf5b8f1 100644 (file)
@@ -74,6 +74,8 @@ public class SelectionOnMessageSend extends MessageSend {
                } else {
                        if(binding.isDefaultAbstract()) {
                                throw new SelectionNodeFound(findNonDefaultAbstractMethod(binding)); // 23594
+                       } else if (binding.variableBinding != null) {
+                               throw new SelectionNodeFound(binding.variableBinding);
                        } else {
                                throw new SelectionNodeFound(binding);
                        }
index daf541a..c5b982b 100644 (file)
@@ -412,6 +412,7 @@ public int nullStatus(FlowInfo flowInfo) {
                                                                        if (useType.isFunctionType())   // add method binding if function
                                                                        {
                                                                                MethodBinding methodBinding = ((FunctionTypeBinding)useType).functionBinding.createNamedMethodBinding(this.token);
+                                                                               methodBinding.variableBinding = variable;
                                                                                MethodScope methodScope = scope.enclosingMethodScope();
                                                                                if (methodScope!=null)
                                                                                        methodScope.addLocalMethod(methodBinding);
index 9d41c6f..e9fe948 100644 (file)
@@ -118,7 +118,7 @@ public  void addLocalVariable(LocalVariableBinding binding) {
                        (binding.declaration.inferredType != null && binding.declaration.inferredType.isFunction())) {
 
                MethodBinding methodBinding=
-                       new MethodBinding(0, binding.name, TypeBinding.UNKNOWN, null,this.enclosingTypeBinding());
+                       new MethodBinding(0, binding.name, TypeBinding.UNKNOWN, null,this.enclosingTypeBinding(), binding);
                methodBinding.createFunctionTypeBinding(this);
                addLocalMethod(methodBinding);
 
@@ -278,13 +278,13 @@ public MethodBinding findMethod(char[] methodName,TypeBinding[]argumentTypes, bo
                if (variable!=null)
                {
                        MethodBinding binding;
-                       if (!(variable.type.isAnyType() || variable.type.isFunctionType()))
-                       {
-                         binding=new ProblemMethodBinding(methodName,null,ProblemReasons.NotAFunction);        
-                       }
-                       else    
+//                     if (!(variable.type.isAnyType() || variable.type.isFunctionType()))
+//                     {
+//                       binding=new ProblemMethodBinding(methodName,null,ProblemReasons.NotAFunction);        
+//                     }
+//                     else    
                         binding = new MethodBinding(ClassFileConstants.AccPublic,
-                                       methodName,TypeBinding.UNKNOWN,null,variable.declaringScope.enclosingTypeBinding());
+                                       methodName,TypeBinding.UNKNOWN,null,variable.declaringScope.enclosingTypeBinding(), variable);
                        
                        addLocalMethod(binding);
                        return binding;
index 78a9255..0ed3678 100644 (file)
@@ -26,17 +26,34 @@ public class MethodBinding extends Binding {
        public FunctionTypeBinding functionTypeBinding;
        public ReferenceBinding allocationType;
        public Method oaaMethod;
+       public VariableBinding variableBinding;
        
 
 protected MethodBinding() {
        // for creating problem or synthetic method
 }
+public MethodBinding(int modifiers, char[] selector, TypeBinding returnType, TypeBinding[] parameters, ReferenceBinding declaringClass, VariableBinding variable) {
+       this.modifiers = modifiers;
+       this.selector = selector;
+       this.returnType = returnType;
+       this.parameters = (parameters == null || parameters.length == 0) ? Binding.NO_PARAMETERS : parameters;
+       this.declaringClass = declaringClass;
+       this.variableBinding = variable;
+
+       // propagate the strictfp & deprecated modifiers
+       if (this.declaringClass != null) {
+               if (this.declaringClass.isStrictfp())
+                       if (!(isAbstract()))
+                               this.modifiers |= ClassFileConstants.AccStrictfp;
+       }
+}
 public MethodBinding(int modifiers, char[] selector, TypeBinding returnType, TypeBinding[] parameters, ReferenceBinding declaringClass) {
        this.modifiers = modifiers;
        this.selector = selector;
        this.returnType = returnType;
        this.parameters = (parameters == null || parameters.length == 0) ? Binding.NO_PARAMETERS : parameters;
        this.declaringClass = declaringClass;
+       this.variableBinding = null;
 
        // propagate the strictfp & deprecated modifiers
        if (this.declaringClass != null) {
@@ -55,6 +72,7 @@ public MethodBinding(MethodBinding initialMethodBinding, ReferenceBinding declar
        this.returnType = initialMethodBinding.returnType;
        this.parameters = initialMethodBinding.parameters;
        this.declaringClass = declaringClass;
+       this.variableBinding = null;
 }
 /* Answer true if the argument types & the receiver's parameters are equal
 */