tree = ci.getTreeUtilities().parseStatement( "{\n" + expression + ";\n}", // NOI18N sourcePtr
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param method figures out the scope for attribution. * @param bodyText text which will be used for method body creation. * @return a new tree for <tt>bodyText</tt>. */ public BlockTree createMethodBody(MethodTree method, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), method)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
/** * Creates a new BlockTree for provided <tt>bodyText</tt>. * * @param lambda figures out the scope for attribution. * @param bodyText text which will be used for lambda body creation. * @return a new tree for <tt>bodyText</tt>. * @since 2.19 */ public BlockTree createLambdaBody(LambdaExpressionTree lambda, String bodyText) { SourcePositions[] positions = new SourcePositions[1]; final TreeUtilities treeUtils = copy.getTreeUtilities(); StatementTree body = treeUtils.parseStatement(bodyText, positions); assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!"; Scope scope = copy.getTrees().getScope(TreePath.getPath(copy.getCompilationUnit(), lambda)); treeUtils.attributeTree(body, scope); mapComments((BlockTree) body, bodyText, copy, handler, positions[0]); new TreePosCleaner().scan(body, null); return (BlockTree) body; }
StatementTree body = bodyText != null ? copy.getTreeUtilities().parseStatement(bodyText, positions) : null; if (body != null) { assert Tree.Kind.BLOCK == body.getKind() : "Not a statement block!";
String blockText = controller.getText().substring(blockPos, upToOffset ? offset : (int) sourcePositions.getEndPosition(root, tree)); final SourcePositions[] sp = new SourcePositions[1]; final StatementTree block = (((BlockTree) tree).isStatic() ? tu.parseStaticBlock(blockText, sp) : tu.parseStatement(blockText, sp)); if (block == null) { return null; : controller.getText().substring(blockPos, (int) sourcePositions.getEndPosition(root, blockPath.getLeaf())); final SourcePositions[] sp = new SourcePositions[1]; final StatementTree block = (((BlockTree) blockPath.getLeaf()).isStatic() ? tu.parseStaticBlock(blockText, sp) : tu.parseStatement(blockText, sp)); if (block == null) { return null; final Tree body = bodyText.charAt(0) == '{' ? tu.parseStatement(bodyText, sp) : tu.parseExpression(bodyText, sp); final Tree fake = body instanceof ExpressionTree ? new ExpressionStatementTree() { @Override