Package org.eclipse.php.internal.core.ast.nodes

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


    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);
    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);
View Full Code Here


    char indentChar = FormatterUtils
        .getFormatterCommonPrferences().getIndentationChar(document);
    String indent = String.valueOf(indentChar);
   
    ClassDeclaration clazz = (ClassDeclaration) node;
    Block body = clazz.getBody();
    List<Statement> bodyStatements = body.statements();
       

    int end = bodyStatements.get(bodyStatements.size()-1).getEnd();
   
    if (insertFirst) {
View Full Code Here

    List<FormalParameter> formalParameters = new ArrayList<FormalParameter>();
    formalParameters.add(ast.newFormalParameter(null, ast.newVariable("a"),
        ast.newScalar("5"), false));
    formalParameters.add(ast.newFormalParameter(null, ast.newVariable("b"),
        ast.newScalar("'boobo'"), true));
    Block body = ast.newBlock();
    program.statements()
        .add(0,
            ast.newFunctionDeclaration(name, formalParameters,
                body, false));
    rewrite();
View Full Code Here

    List<FormalParameter> formalParameters = new ArrayList<FormalParameter>();
    formalParameters.add(ast.newFormalParameter(ast.newIdentifier("int"),
        ast.newVariable("a"), ast.newScalar("5"), false));
    formalParameters.add(ast.newFormalParameter(null, ast.newVariable("b"),
        ast.newScalar("'boobo'"), false));
    Block body = ast.newBlock();
    program.statements().add(0,
        ast.newFunctionDeclaration(name, formalParameters, body, true));
    rewrite();
    checkResult("<?php function &foo(int $a = 5,  $b = 'boobo') {\n}\n?> ");
  }
View Full Code Here

    String str = "<?php ?>";
    initialize(str);

    List<Statement> trueStatement = new ArrayList<Statement>(1);
    trueStatement.add(ast.newEchoStatement(ast.newScalar("'Boobo'")));
    Block block = ast.newBlock(trueStatement);
    block.setIsCurly(true);
    program.statements().add(0,
        ast.newIfStatement(ast.newVariable("a"), block, null));
    rewrite();
    checkResult("<?php if ($a) {\n  echo 'Boobo';\n}\n?>");
  }
View Full Code Here

    String str = "<?php ?>";
    initialize(str);

    List<Statement> trueStatement = new ArrayList<Statement>(1);
    trueStatement.add(ast.newEchoStatement(ast.newScalar("'Boobo'")));
    Block block = ast.newBlock(trueStatement);
    block.setIsCurly(false);
    program.statements().add(0,
        ast.newIfStatement(ast.newVariable("a"), block, null));
    rewrite();
    checkResult("<?php if ($a) :\n  echo 'Boobo';\n\nendif;\n?>");
  }
View Full Code Here

    initialize(str);

    List<TryStatement> statements = getAllOfType(program,
        TryStatement.class);
    Assert.assertTrue("Unexpected list size.", statements.size() == 1);
    Block newBlock = ast.newBlock();
    newBlock.statements().add(
        ast.newEchoStatement(ast.newScalar("'Hello'")));
    statements
        .get(0)
        .catchClauses()
        .add(ast.newCatchClause(ast.newIdentifier("Boobo"),
View Full Code Here

    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);
View Full Code Here

    String expected = "<?php if ($a) { $b = 4; $c = 4; }  ?>";
    parseAndCompare(str, expected, new ICodeManiplator() {
      public void manipulate(Program program) {
        IfStatement statement = (IfStatement) program.statements().get(
            0);
        Block block = (Block) statement.getTrueStatement();
        block.statements().remove(0);
      }
    });
  }
View Full Code Here

    String expected = "<?php if ($a) { $a = 5; }  ?>";
    parseAndCompare(str, expected, new ICodeManiplator() {
      public void manipulate(Program program) {
        IfStatement statement = (IfStatement) program.statements().get(
            0);
        Block block = (Block) statement.getTrueStatement();
        block.statements().remove(1);
      }
    });
  }
View Full Code Here

TOP

Related Classes of org.eclipse.php.internal.core.ast.nodes.Block

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.