List of usage examples for org.eclipse.jdt.core.dom Block statements
ASTNode.NodeList statements
To view the source code for org.eclipse.jdt.core.dom Block statements.
Click Source Link
From source file:net.sf.eclipsecs.ui.quickfixes.blocks.AvoidNestedBlocksQuickfix.java
License:Open Source License
/** * {@inheritDoc}/*ww w . j a v a 2 s .c o m*/ */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { public boolean visit(Block node) { if (containsPosition(lineInfo, node.getStartPosition())) { if (node.getParent() instanceof Block) { List statements = ((Block) node.getParent()).statements(); int index = statements.indexOf(node); statements.remove(node); statements.addAll(index, ASTNode.copySubtrees(node.getAST(), node.statements())); } else if (node.getParent() instanceof SwitchStatement) { List statements = ((SwitchStatement) node.getParent()).statements(); int index = statements.indexOf(node); statements.remove(node); statements.addAll(index, ASTNode.copySubtrees(node.getAST(), node.statements())); } } return true; } }; }
From source file:net.sf.eclipsecs.ui.quickfixes.blocks.NeedBracesQuickfix.java
License:Open Source License
/** * {@inheritDoc}//from w w w .j a va2s.co m */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { public boolean visit(IfStatement node) { int nodePos = node.getStartPosition(); int nodeEnd = nodePos + node.getLength(); if ((nodePos >= lineInfo.getOffset() && nodePos <= (lineInfo.getOffset() + lineInfo.getLength())) || (nodePos <= lineInfo.getOffset() && nodeEnd >= lineInfo.getOffset() + lineInfo.getLength())) { bracifyIfStatement(node); } return true; } /** * Helper method to recursivly bracify a if-statement. * * @param ifStatement the if statement */ private void bracifyIfStatement(IfStatement ifStatement) { // change the then statement to a block if necessary if (!(ifStatement.getThenStatement() instanceof Block)) { if (ifStatement.getThenStatement() instanceof IfStatement) { bracifyIfStatement((IfStatement) ifStatement.getThenStatement()); } Block block = createBracifiedCopy(ifStatement.getAST(), ifStatement.getThenStatement()); ifStatement.setThenStatement(block); } // check the else statement if it is a block Statement elseStatement = ifStatement.getElseStatement(); if (elseStatement != null && !(elseStatement instanceof Block)) { // in case the else statement is an further if statement // (else if) // do the recursion if (elseStatement instanceof IfStatement) { bracifyIfStatement((IfStatement) elseStatement); } else { // change the else statement to a block // Block block = ifStatement.getAST().newBlock(); // block.statements().add(ASTNode.copySubtree(block.getAST(), // elseStatement)); Block block = createBracifiedCopy(ifStatement.getAST(), ifStatement.getElseStatement()); ifStatement.setElseStatement(block); } } } public boolean visit(ForStatement node) { if (containsPosition(lineInfo, node.getStartPosition())) { Block block = createBracifiedCopy(node.getAST(), node.getBody()); node.setBody(block); } return true; } public boolean visit(DoStatement node) { if (containsPosition(lineInfo, node.getStartPosition())) { Block block = createBracifiedCopy(node.getAST(), node.getBody()); node.setBody(block); } return true; } public boolean visit(WhileStatement node) { if (containsPosition(lineInfo, node.getStartPosition())) { Block block = createBracifiedCopy(node.getAST(), node.getBody()); node.setBody(block); } return true; } private Block createBracifiedCopy(AST ast, Statement body) { Block block = ast.newBlock(); block.statements().add(ASTNode.copySubtree(block.getAST(), body)); return block; } }; }
From source file:net.sf.fast.ibatis.build.dao.DAOCustomBuilder.java
License:Apache License
/** * <p>// w ww. j a v a2 s. c om * create the code block with user specified return type. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); methodInvocation.setExpression(m1); methodInvocation.setName(ast.newSimpleName("queryForObject")); ast.newSimpleName("param"); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); CastExpression ce = ast.newCastExpression(); ce.setExpression(methodInvocation); ce.setType(ast.newSimpleType(ast.newSimpleName(fc.getReturnType()))); rs.setExpression(ce); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.dao.DAODeleteBuilder.java
License:Apache License
/** * <p>/*from w w w . j a va 2s . c o m*/ * create the delete code block. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); methodInvocation.setExpression(m1); methodInvocation.setName(ast.newSimpleName("delete")); ast.newSimpleName("param"); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(methodInvocation); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.dao.DAOInsertBuilder.java
License:Apache License
/** * <p>/*from w w w .j a v a2 s. c o m*/ * create the insert code block. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); methodInvocation.setExpression(m1); methodInvocation.setName(ast.newSimpleName("insert")); ast.newSimpleName("param"); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return block; }
From source file:net.sf.fast.ibatis.build.dao.DAOIntegerBuilder.java
License:Apache License
/** * <p>/*from www .j a v a 2 s .c om*/ * create the integer return code block. * mainly used to get record count from specific table. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); CastExpression castExpression = ast.newCastExpression(); castExpression.setType(ast.newSimpleType(ast.newSimpleName("Integer"))); castExpression.setExpression(m1); methodInvocation.setExpression(castExpression); methodInvocation.setName(ast.newSimpleName("queryForObject")); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(methodInvocation); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.dao.DAOListBuilder.java
License:Apache License
/** * <p>//from w w w. j av a 2s . c o m * create the List return code block. * mainly used to get records list from specific table. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); methodInvocation.setExpression(m1); methodInvocation.setName(ast.newSimpleName("queryForList")); ast.newSimpleName("param"); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(methodInvocation); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.dao.DAOUpdateBuilder.java
License:Apache License
/** * <p>//from ww w .jav a 2 s.co m * create the update code block. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); MethodInvocation m1 = ast.newMethodInvocation(); m1.setName(ast.newSimpleName("getSqlMapClientTemplate")); methodInvocation.setExpression(m1); methodInvocation.setName(ast.newSimpleName("update")); ast.newSimpleName("param"); StringLiteral literal = ast.newStringLiteral(); literal.setLiteralValue(Utils.stripFileExtension(fc.getXmlFileName()) + "." + fc.getMethodName()); methodInvocation.arguments().add(literal); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(methodInvocation); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.service.ServiceCustomBuilder.java
License:Apache License
/** * <p>/*from ww w. j a va2 s . com*/ * create the code block with user specified return type. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newName(Utils.lowFirstChar(fc.getModelName()) + "DAO")); methodInvocation.setName(ast.newSimpleName(fc.getMethodName())); methodInvocation.arguments().add(ast.newSimpleName("param")); ReturnStatement rs = ast.newReturnStatement(); rs.setExpression(methodInvocation); block.statements().add(rs); return block; }
From source file:net.sf.fast.ibatis.build.service.ServiceInsertBuilder.java
License:Apache License
/** * <p>//from ww w . j av a 2 s .co m * create the insert code block with dao invoked. * </p> * @param ast the ast tree. * fc the configuration. */ @SuppressWarnings("unchecked") public Block createBlock(AST ast, FastIbatisConfig fc) { Block block = ast.newBlock(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newName(Utils.lowFirstChar(fc.getModelName()) + "DAO")); methodInvocation.setName(ast.newSimpleName(fc.getMethodName())); methodInvocation.arguments().add(ast.newSimpleName("param")); ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return block; }