Examples of MethodDeclaration


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

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

     * @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

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

  }

  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

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

    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

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

      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

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

  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

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

    }
  }

  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

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

    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

Examples of org.eclipse.jdt.internal.compiler.ast.MethodDeclaration

    if (methodDeclarations != null) {
      TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext;
      int typeDeclarationSourceStart = currentDeclaration.sourceStart();
      int typeDeclarationSourceEnd = currentDeclaration.sourceEnd();
      for (int i = 0, max = methodDeclarations.length; i < max; i++) {
        MethodDeclaration methodDeclaration = methodDeclarations[i];
        MethodBinding methodBinding = methodDeclaration.binding;
         String readableName = new String(methodBinding.readableName());
         CategorizedProblem[] problems = compilationResult.problems;
         int problemsCount = compilationResult.problemCount;
        for (int j = 0; j < problemsCount; j++) {
View Full Code Here

Examples of org.eclipse.php.internal.core.ast.nodes.MethodDeclaration

    anotherChange.addTextEditGroup(newMethodEdit);
    anotherChange.addTextEditGroup(inlineReplacementEdit);
    anotherChange.addTextEditGroup(additionalInlineReplacementEdit);
   
    AST ast = fProgram.getAST();
    MethodDeclaration method = ast.newMethodDeclaration();
    Block extractedMethodBody = ast.newBlock();
       
    FunctionDeclaration functionDec = ast.newFunctionDeclaration(ast.newIdentifier(fMethodName), computeArguments(ast), extractedMethodBody, false);
    method.setModifier(fModifierAccessFlag);
    method.setFunction(functionDec);
   
    ASTRewrite rewriter = ASTRewrite.create(ast);
   
    ListRewrite classListRewrite = rewriter.getListRewrite( fCoveringDeclarationFinder.getCoveringClassDeclaration().getBody(), Block.STATEMENTS_PROPERTY);
    VariableBase dispatcher = ast.newVariable(THIS_VARIABLE_NAME);
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.