Examples of ListRewrite


Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

    }
    else {
      property = MethodDeclaration.MODIFIERS2_PROPERTY;
    }

    ListRewrite listRewrite = astRewrite.getListRewrite(decl, property);
    listRewrite.insertFirst(annotation, null);

    return astRewrite;
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

    StringLiteral pathVariableName = ast.newStringLiteral();
    pathVariableName.setLiteralValue(variable.getVariableName());
    annotation.setValue(pathVariableName);
    addLinkedPosition(new StringLiteralTrackedPosition(astRewrite.track(pathVariableName)), false, "variableName");

    ListRewrite listRewrite = astRewrite.getListRewrite(paramDecl, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    listRewrite.insertFirst(annotation, null);

    listRewrite = astRewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    listRewrite.insertLast(paramDecl, null);

    return astRewrite;
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

    CompilationUnit astRoot = ASTResolving.findParentCompilationUnit(typeDecl);
    AST ast = astRoot.getAST();
    ASTRewrite astRewrite = ASTRewrite.create(ast);
    ImportRewrite importRewrite = StubUtility.createImportRewrite(astRoot, true);
    ListRewrite listRewriter = astRewrite.getListRewrite(typeDecl, (typeDecl).getBodyDeclarationsProperty());

    if (listRewriter != null) {
      IJavaProject javaProject = compilationUnit.getJavaProject();
      CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(javaProject);
      MethodDeclaration methodDecl = createNewConstructor(typeDecl, ast);
      IMethodBinding constructorBinding = ASTNodes.getMethodBinding(methodDecl.getName());
      ITypeBinding typeBinding = ASTNodes.getTypeBinding(typeDecl.getName());
      ImportRewriteContext context = new ContextSensitiveImportRewriteContext(typeDecl, importRewrite);

      MethodDeclaration stub = StubUtility2.createConstructorStub(compilationUnit, astRewrite, importRewrite,
          context, typeBinding, constructorBinding, this.variableBindings, Modifier.PUBLIC, settings);
      if (stub != null) {

        IType type = null;
        // Getting the IType in question turned out to be much more
        // difficult than one would hope. At this point, it appears that
        // typeDecl "belongs to" a different compilation unit than the
        // one which we can get at from here. Thus, we have to look
        // through *this* compilation unit for the IType with the name
        // we are looking for.
        for (Object type2 : compilationUnit.getAllTypes()) {
          if (type2 instanceof IType) {

            // Allegedly, getFullyQualifiedName will return the
            // fully qualified name (e.g. a.b.c.Foo), but I have
            // seen it return a name without the package type.
            String typeName = typeDecl.getName().getFullyQualifiedName();
            String type2Name = ((IType) type2).getFullyQualifiedName();
            if (type2Name.endsWith(typeName)) {
              type = (IType) type2;
              break;
            }
          }
        }
        if (type == null) {
          return astRewrite; // this should never get hit
        }

        IJavaElement[] fields = type.getChildren();
        IJavaElement firstField;
        if (fields.length == 0) {
          firstField = null;
        }
        else {
          firstField = fields[0];
        }

        ASTNode insertion = StubUtility2.getNodeToInsertBefore(listRewriter, firstField);

        if (insertion != null && insertion.getParent() == typeDecl) {
          listRewriter.insertBefore(stub, insertion, null);
        }
        else {
          listRewriter.insertLast(stub, null);
        }

        constructorBinding = ASTNodes.getMethodBinding(stub.getName());
        addAutowiredAnnotation(javaProject, astRewrite, stub, constructorBinding);

View Full Code Here

Examples of org.eclipse.jdt.core.dom.rewrite.ListRewrite

        importEdit = JdtQuickfixUtils.getTextEditForImport(cu, REQUEST_METHOD_IMPORT);
        if (importEdit != null) {
          edit.addChild(importEdit);
        }

        ListRewrite listRewrite = astRewrite.getListRewrite(annotation, NormalAnnotation.VALUES_PROPERTY);
        AST annotationAST = annotation.getAST();
        MemberValuePair pair = annotationAST.newMemberValuePair();
        pair.setName(annotationAST.newSimpleName("method"));

        QualifiedName valueName = annotationAST.newQualifiedName(annotationAST.newSimpleName("RequestMethod"),
            annotationAST.newSimpleName(methodTypeString));
        pair.setValue(valueName);
        listRewrite.insertFirst(pair, null);
      }

      astRewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, null);

      edit.addChild(astRewrite.rewriteAST());
View Full Code Here

Examples of org.eclipse.php.internal.core.ast.rewrite.ListRewrite

    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);
    FunctionInvocation calledExtractedMethod = ast.newFunctionInvocation(ast.newFunctionName(ast.newIdentifier(fMethodName)), computeParameters(ast));
    MethodInvocation inlineMethodCall = ast.newMethodInvocation(dispatcher, calledExtractedMethod);

    List<List<ASTNode>> Occurences = new ArrayList<List<ASTNode>>();
   
    if(fReplaceDuplicates) {
      for(Match replace : fDuplicates) {
        Occurences.add(Arrays.asList(replace.getNodes()));
      }
    } else {
      Occurences.add(fSelectedNodesFinder.getNodes());
    }
   
    boolean createdMethodBody = false;
   
    TextEditGroup inlineReplacementEditGroup = inlineReplacementEdit;
   
    for(List<ASTNode> selectedNodeOccurence : Occurences) {
   
      // this is also an indicator, whether this loop was already gone through
      if(createdMethodBody) {
        inlineReplacementEditGroup = additionalInlineReplacementEdit;
      }
     
      ASTNode parent = selectedNodeOccurence.get(0).getParent();
     
      inlineMethodCall = ASTNode.copySubtree(ast, inlineMethodCall);
     
      ListRewrite lrw;
           
      if(parent instanceof Block) {
       
        if(!createdMethodBody) {
          extractedMethodBody.statements().addAll(ASTNode.copySubtrees(ast, selectedNodeOccurence));
          addReturnStatement(ast, extractedMethodBody, fReturnStatement);
          createdMethodBody = true;
        }
       
        lrw = rewriter.getListRewrite(parent, Block.STATEMENTS_PROPERTY);
       
        ExpressionStatement inlineReplacement;
        if (fReturnStatement != null) {
          inlineReplacement = ast.newExpressionStatement(ast.newAssignment(
              ast.newVariable(fReturnStatement.getParameterName()),
              Assignment.OP_EQUAL, inlineMethodCall));
        } else {
          inlineReplacement = ast.newExpressionStatement(inlineMethodCall);
        }
       
        lrw.replace(selectedNodeOccurence.get(0),inlineReplacement, inlineReplacementEditGroup);
 
        for (int i = 1; i < selectedNodeOccurence.size(); ++i) {
          lrw.remove(selectedNodeOccurence.get(i), inlineReplacementEditGroup);
        }
       
      } else {
        if(!createdMethodBody) {
          addReturnStatement(ast, extractedMethodBody, ASTNode.copySubtree(ast, selectedNodeOccurence.get(0)));
View Full Code Here

Examples of org.eclipse.php.internal.core.ast.rewrite.ListRewrite

    List<Block> blocks = getAllOfType(program, Block.class);
    Assert.assertTrue("Unexpected list size.", blocks.size() == 2);
    AST astRoot = program.getAST();
    ASTRewrite rewrite = ASTRewrite.create(astRoot);
    Block block = blocks.get(0);
    ListRewrite listRewrite = rewrite.getListRewrite(block,
        Block.STATEMENTS_PROPERTY);
    ASTNode placeHolder = rewrite.createStringPlaceholder("//mycomment",
        ASTNode.COMMENT);
    listRewrite.insertFirst(placeHolder, null);

    TextEdit textEdits = rewrite.rewriteAST(document, null);
    textEdits.apply(document);
    checkResult("<?php\n class A { \n  //mycomment\n  public function foo(int $a){}\n }?> ");
  }
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.