/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jetbrains.python;

import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.psi.PyCallExpression;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.types.TypeEvalContext;

/**
 * Tests callee resolution in PyCallExpressionImpl.
 * User: dcheryasov
 * Date: Aug 21, 2008
 */
public class PyResolveCalleeTest extends PyTestCase {

  private PyCallExpression.PyMarkedCallee resolveCallee() {
    PsiReference ref = myFixture.getReferenceAtCaretPosition("/resolve/callee/" + getTestName(false) + ".py");
    PyCallExpression call = PsiTreeUtil.getParentOfType(ref.getElement(), PyCallExpression.class);
    final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), myFixture.getFile());
    return call.resolveCallee(PyResolveContext.noImplicits().withTypeEvalContext(context));
  }

  public void testInstanceCall() {
    PyCallExpression.PyMarkedCallee resolved = resolveCallee();
    assertNotNull(resolved.getCallable());
    assertEquals(1, resolved.getImplicitOffset());
  }

  public void testClassCall() {
    PyCallExpression.PyMarkedCallee resolved = resolveCallee();
    assertNotNull(resolved.getCallable());
    assertEquals(null, resolved.getModifier());
  }

  public void testDecoCall() {
    PyCallExpression.PyMarkedCallee resolved = resolveCallee();
    assertNotNull(resolved.getCallable());
    assertEquals(1, resolved.getImplicitOffset());
  }

  public void testDecoParamCall() {
    PyCallExpression.PyMarkedCallee resolved = resolveCallee();
    assertNotNull(resolved.getCallable());
    assertNull(resolved.getModifier());
  }
  
  public void testWrappedStaticMethod() {
    PyCallExpression.PyMarkedCallee resolved = resolveCallee();
    assertNotNull(resolved.getCallable());
    assertEquals(0, resolved.getImplicitOffset());
    assertEquals(resolved.getModifier(), PyFunction.Modifier.STATICMETHOD);
  }
}

@@ -21,9 +21,9 @@
 -201
-3
+7
  Jet
@@ -965,110 +965,74 @@
 xt;%0A
-%0A/**%0A * Tests callee resolution in PyCallExpressionImpl.%0A * User: dcheryasov%0A * Date: Aug 21, 2008%0A */
+import org.jetbrains.annotations.NotNull;%0A%0Aimport java.util.List;%0A
 %0Apub
@@ -1083,16 +1083,27 @@
 Case %7B%0A%0A
+  @NotNull%0A
   privat
@@ -1158,16 +1158,22 @@
 ) %7B%0A    
+final 
 PsiRefer
@@ -1271,24 +1271,30 @@
 %22.py%22);%0A    
+final 
 PyCallExpres
@@ -1376,16 +1376,17 @@
 class);%0A
+%0A
     fina
@@ -1496,34 +1496,48 @@
     
-return call.resolveCallee(
+final PyResolveContext resolveContext = 
 PyRe
@@ -1591,16 +1591,180 @@
 context)
+;%0A%0A    final List%3CPyCallExpression.PyMarkedCallee%3E callees = call.multiResolveCallee(resolveContext);%0A    assertEquals(1, callees.size());%0A%0A    return callees.get(0
 );%0A  %7D%0A%0A
@@ -1794,32 +1794,38 @@
 nceCall() %7B%0A    
+final 
 PyCallExpression
@@ -1995,32 +1995,38 @@
 assCall() %7B%0A    
+final 
 PyCallExpression
@@ -2192,32 +2192,38 @@
 ecoCall() %7B%0A    
+final 
 PyCallExpression
@@ -2397,32 +2397,38 @@
 ramCall() %7B%0A    
+final 
 PyCallExpression
@@ -2607,16 +2607,22 @@
 ) %7B%0A    
+final 
 PyCallEx
@@ -2788,32 +2788,8 @@
 als(
-resolved.getModifier(), 
 PyFu
@@ -2816,16 +2816,40 @@
 ICMETHOD
+, resolved.getModifier()
 );%0A  %7D%0A%7D

Update PyResolveCalleeTest to use multiresolve and fail when there are more than one resolved elements