Examples of IMethodBinding


Examples of org.eclipse.jdt.core.dom.IMethodBinding

  {
    String name = mname;
    if( MockUtil.CTOR.equals(name) )
      name = type.getName();
   
    IMethodBinding origMethod = ASTUtil.findMethodInType(type, name, paramTypes);

    if( origMethod == null && type.isInterface() && ast != null ) // interfaces can mock Object.class methods
    {
      ITypeBinding objType = ast.resolveWellKnownType(Object.class.getName());
      origMethod = ASTUtil.findMethodInType(objType, name, paramTypes);
    }

    if (origMethod == null && type.getTypeArguments().length != 0)
    {
      // no method matches exactly, there could be type arguments (which we don't handle yet)
      origMethod = ASTUtil.findMethodInType(type, name, null); // match without params

      if (origMethod != null && origMethod.getParameterTypes().length != paramTypes.length)
      {
        origMethod = null;
      }
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

  }

  @Override
  public boolean visit(final MethodDeclaration node)
  {
    IMethodBinding meth = node.resolveBinding();
    ITypeBinding mockedType = MockUtil.findMockedType(node, meth); // new MockUp< MockedType >

    if ( mockedType != null )
    {
      boolean hasMockAnn = MockUtil.isMockMethod(meth);
      boolean methodExists = findRealMethod(node, meth, mockedType) != null;

      if (!hasMockAnn && methodExists )
      {
        addMarker(node.getName(), "Mocked method missing @Mock annotation", false);
      }

      if (hasMockAnn && !methodExists )
      {
        addMarker(node.getName(), "Mocked real method not found in type", true);
      }

      if (hasMockAnn && methodExists && isPrivate(meth.getModifiers()))
      {
        addMarker(node.getName(), "Mocked method should not be private", true);
      }
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

  }

  public IMethodBinding findRealMethod(final MethodDeclaration node,
      final IMethodBinding meth, final ITypeBinding mockedType)
  {
    IMethodBinding origMethod = null;

    if (mockedType != null)
      origMethod = MockUtil.findRealMethodInType(mockedType, new InvocationFilter(meth), node.getAST());

    return origMethod;
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

    boolean invokesGetInst = false;

    if (gparent instanceof MethodInvocation) // method invocation follows
    {
      MethodInvocation inv = (MethodInvocation) gparent;
      IMethodBinding meth = inv.resolveMethodBinding();

      if ( MockUtil.GET_INST.equals(meth.getName()))
      {
        invokesGetInst = true;
        if (gparent.getParent() instanceof ExpressionStatement)
        {
          addMarker(inv.getName(), "Returned mock instance is not being used.", false);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

  }

  @Override
  public boolean visit(final MethodInvocation node)
  {
    IMethodBinding meth = node.resolveMethodBinding();

    if (meth == null)
    {
      return false;
    }

    if ( MockUtil.isMockUpType(meth.getDeclaringClass()) && MockUtil.GET_INST.equals(meth.getName()))
    {
      ITypeBinding returnType = node.resolveTypeBinding();

      if (!returnType.isInterface())
      {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

      IBinding exprBinding = var.resolveBinding();

      if ( "it".equals(varName) && exprBinding instanceof IVariableBinding ) // call on 'it' field
      {
        IVariableBinding varBinding = (IVariableBinding) exprBinding;
        IMethodBinding mockMethod = getSurroundingMockMethod(node);

        if( mockMethod != null && varBinding.isField() && mockMethod.isSubsignature(meth)
            && varBinding.getDeclaringClass().equals(mockMethod.getDeclaringClass()) )
        {
          ITypeBinding mockedType = MockUtil.findMockedType(node);

          if( mockedType.equals(varBinding.getType()) // field type is correct mocked type
              && !MockUtil.isReentrantMockMethod(mockMethod) )
          {
            addMarker( node,
                "Method calls itself. Set @Mock(reentrant=true) on method '"
                    + mockMethod.getName() + "'", true);
          }
        }
      }
    }
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

  }

  private IMethodBinding getSurroundingMockMethod(final MethodInvocation node)
  {
    MethodDeclaration surroundingMeth = ASTUtil.findAncestor(node, MethodDeclaration.class);
    IMethodBinding mockMethod = null;

    if (surroundingMeth != null)
    {
      mockMethod = surroundingMeth.resolveBinding();
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

  }

  public static IMethodBinding findMethodInType(final ITypeBinding type, final String name,
      final ITypeBinding[] paramTypes)
  {
    IMethodBinding origMethod;

    if (type.isInterface())
    {
      origMethod = Bindings.findMethodInHierarchy(type, name, paramTypes);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

      return null;
    }

    ITypeBinding paramType = null;
    IRegion wordRegion = null;
    IMethodBinding mockMethod = null, realMethod = null;

    CompilationUnit astRoot = ASTUtil.getAstOrParse(input, null);
    if( astRoot == null )
    {
      return null;
View Full Code Here

Examples of org.eclipse.jdt.core.dom.IMethodBinding

      else if (node instanceof TypeDeclaration) {
        ITypeBinding binding = ((TypeDeclaration) node).resolveBinding();
        return bindingsResolver.resolveType(binding, true);
      }
      else if (node instanceof MethodDeclaration) {
        IMethodBinding binding = ((MethodDeclaration) node).resolveBinding();
          return bindingsResolver.resolveType(binding, true);
      }
      else if (node instanceof VariableDeclaration) {
        IVariableBinding binding = ((VariableDeclaration) node).resolveBinding();
        return bindingsResolver.resolveType(binding.getType(), false);
      }
    } catch (NullPointerException e) {
      System.err.println("Got NPE for node " + node);
    }
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.