Package org.eclipse.jdt.core.dom

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


     *
     * @param name simple class name
     * @return constructor builder
     */
    public MethodBuilder addConstructor(String name) {
        MethodDeclaration constr = getAST().newMethodDeclaration();
        constr.setName(getAST().newSimpleName(name));
        constr.setConstructor(true);
        m_methods.add(constr);
        return new MethodBuilder(this, constr);
    }
View Full Code Here


     * @param name
     * @param type
     * @return method builder
     */
    public MethodBuilder addMethod(String name, Type type) {
        MethodDeclaration meth = getAST().newMethodDeclaration();
        meth.setName(getAST().newSimpleName(name));
        meth.setConstructor(false);
        meth.setReturnType2(type);
        if (m_class instanceof AnonymousClassDeclaration) {
            ((AnonymousClassDeclaration)m_class).bodyDeclarations().add(meth);       
        } else {
            m_methods.add(meth);
        }
View Full Code Here

  }

  private void addMethods(JClass cls, TypeDeclaration object) {
    MethodDeclaration[] met = object.getMethods();
    for (int i = 0; i < met.length; i++) {
      MethodDeclaration dec = met[i];
      JMethod method = new JMethod();
      method.setMethodName(dec.getName().toString());
      Type returnType = dec.getReturnType2();
      if (returnType != null) {
        method.setReturnType(returnType.toString());
      }
      Block d = dec.getBody();
      if (d == null) {
        continue;
      }
      method.setCodeBlock(d.toString());
      List param = dec.parameters();
      ListIterator paramList = param.listIterator();
      while (paramList.hasNext()) {
        SingleVariableDeclaration sin = (SingleVariableDeclaration) paramList.next();
        method.getParameters().add(sin.getType().toString());
      }
View Full Code Here

    return declaringClass != null && declaringClass.getQualifiedName().startsWith(MOCK_UP);
  }

  public static ITypeBinding findMockedType(final MethodInvocation node)
  {
    MethodDeclaration surroundingMeth = ASTUtil.findAncestor(node, MethodDeclaration.class);

    if (surroundingMeth != null)
    {
      return findMockedType(surroundingMeth, surroundingMeth.resolveBinding());
    }
    else
    {
      return null;
    }
View Full Code Here

      AST ast = unit.getAST();
      ASTRewrite rewrite = ASTRewrite.create(ast);

      CodeGenerationSettings settings = getCodeGenSettings();

      MethodDeclaration stub = createMockMethodStub(ast, rewrite, settings);

      String methodDeclarationText = generateMethodDeclaration(document, recoveredDocument,
          node, rewrite, settings, stub);

      setReplacementString(methodDeclarationText);
View Full Code Here

  private MethodDeclaration createMockMethodStub(final AST ast, final ASTRewrite rewrite,
      final CodeGenerationSettings settings) throws CoreException, JavaModelException
  {
    ITypeBinding declaringType = method.getDeclaringClass();

    MethodDeclaration stub = StubUtility2.createImplementationStub(fCompilationUnit, rewrite,
        importRewrite, context, method, declaringType.getName(), settings, false);

    if( !Object.class.getName().equals( method.getDeclaringClass().getQualifiedName() ) )
    {
      stub.modifiers().clear();
    }

    ASTUtil.addAnnotation("Mock", fJavaProject, rewrite, stub, method);
    importRewrite.addImport(MockUtil.MOCK, context);

    if( method.isConstructor() )
    {
      stub.setName( ast.newSimpleName(MockUtil.CTOR) );
      stub.getBody().statements().clear();
    }
    else
    {
      setReturnStatement(stub, method, declaringType, ast, rewrite);
    }
   
    if( "void".equals(method.getReturnType().getName()) )
    {
      stub.getBody().statements().clear();
    }
   
    return stub;
  }
View Full Code Here

    }
  }

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

    if (surroundingMeth != null)
    {
      mockMethod = surroundingMeth.resolveBinding();
    }

    if( mockMethod != null && MockUtil.isMockMethod(mockMethod) )
    {
      return mockMethod;
View Full Code Here

    ASTNode node = NodeFinder.perform(astRoot, region.getOffset(), 1);

    if( node instanceof SimpleName && node.getParent() instanceof MethodDeclaration )
    {
      MethodDeclaration mdec = (MethodDeclaration) node.getParent();
      mockMethod = mdec.resolveBinding();

      paramType = MockUtil.findMockedType(mdec, mockMethod);

      wordRegion = new Region(node.getStartPosition(), node.getLength());
View Full Code Here

      switch (result) {
      case THROW:
        return THROW;
      }
    } else {
      MethodDeclaration mi = getMethodDeclaration();
      if (mi != null) {
        return evaluateMethodInvocation(context, mi);
      } else {
        stack.push(context.getThisObject());
      }
View Full Code Here

    String name = invocation.getName().getIdentifier();
    ASTNode root = invocation.getRoot();
    CompilationUnit unit = (CompilationUnit) root;
    TypeDeclaration typeDec = (TypeDeclaration) unit.types().get(0);
    MethodDeclaration[] methods = typeDec.getMethods();
    MethodDeclaration mi = null;
con:    for (MethodDeclaration method : methods) {
      String methodName = method.getName().getIdentifier();
      if (name.equals(methodName)) {
        List<Type> mParamTypes = getMethodParamTypes(method);
        List<Type> argTypes = inferArgumentTypes();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.MethodDeclaration

Copyright © 2018 www.massapicom. 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.