Java Code Examples for com.sun.tools.javac.tree.JCTree#JCStatement
The following examples show how to use
com.sun.tools.javac.tree.JCTree#JCStatement .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VanillaPartialReparser.java From netbeans with Apache License 2.0 | 6 votes |
public JCTree.JCBlock reparseMethodBody(Context ctx, CompilationUnitTree topLevel, MethodTree methodToReparse, String newBodyText, final Map<JCTree, Object> docComments) throws IllegalArgumentException, IllegalAccessException { int startPos = ((JCTree.JCBlock)methodToReparse.getBody()).pos; char[] body = new char[startPos + newBodyText.length() + 1]; Arrays.fill(body, 0, startPos, ' '); for (int i = 0; i < newBodyText.length(); i++) { body[startPos + i] = newBodyText.charAt(i); } body[startPos + newBodyText.length()] = '\u0000'; CharBuffer buf = CharBuffer.wrap(body, 0, body.length - 1); com.sun.tools.javac.parser.JavacParser parser = newParser(ctx, buf, ((JCTree.JCBlock)methodToReparse.getBody()).pos, ((JCTree.JCCompilationUnit)topLevel).endPositions); final JCTree.JCStatement statement = parser.parseStatement(); if (statement.getKind() == Tree.Kind.BLOCK) { if (docComments != null) { docComments.putAll((Map<JCTree, Object>) lazyDocCommentsTable.get(parserDocComments.get(parser))); } return (JCTree.JCBlock) statement; } return null; }
Example 2
Source File: CompleteWord.java From javaide with GNU General Public License v3.0 | 6 votes |
private void collectFromMethod(Editor editor, String incomplete, List<SuggestItem> result, JCTree.JCMethodDecl method) { //add field from start position of method to the cursor List<JCTree.JCStatement> statements = method.getBody().getStatements(); for (JCTree.JCStatement statement : statements) { if (statement instanceof JCTree.JCVariableDecl) { JCTree.JCVariableDecl field = (JCTree.JCVariableDecl) statement; addVariable(field, editor, incomplete, result); } } //add params List<JCTree.JCVariableDecl> parameters = method.getParameters(); for (JCTree.JCVariableDecl parameter : parameters) { addVariable(parameter, editor, incomplete, result); } }
Example 3
Source File: BootstrapInserter.java From manifold with Apache License 2.0 | 6 votes |
@Override public void visitClassDef( JCTree.JCClassDecl tree ) { super.visitClassDef( tree ); if( tree.sym != null && !tree.sym.isInner() ) { if( okToInsertBootstrap( tree ) ) { JCTree.JCStatement newNode = buildBootstrapStaticBlock(); ArrayList<JCTree> newDefs = new ArrayList<>( tree.defs ); newDefs.add( 0, newNode ); tree.defs = List.from( newDefs ); } } result = tree; }
Example 4
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
private static void analyzeSwitch(SourceContext context, JCTree.JCSwitch jcSwitch) throws IOException { JCTree.JCExpression expression = jcSwitch.getExpression(); analyzeParsedTree(context, expression); List<JCTree.JCCase> cases = jcSwitch.getCases(); if (nonNull(cases)) { for (JCTree.JCCase jcCase : cases) { JCTree.JCExpression expression1 = jcCase.getExpression(); analyzeParsedTree(context, expression1); List<JCTree.JCStatement> statements = jcCase.getStatements(); analyzeSimpleStatements(context, statements); } } }
Example 5
Source File: GenerateGetMethodProcessor.java From java-master with Apache License 2.0 | 5 votes |
private JCTree.JCMethodDecl createGetterMethodDecl(JCTree.JCVariableDecl jcVariableDecl) { ListBuffer<JCTree.JCStatement> statements = new ListBuffer<>(); statements.append(treeMaker.Return(treeMaker.Select(treeMaker.Ident(names.fromString("this")), jcVariableDecl.getName()))); JCTree.JCBlock body = treeMaker.Block(0, statements.toList()); return treeMaker.MethodDef(treeMaker.Modifiers(Flags.PUBLIC), getNewMethodName(jcVariableDecl.getName()), jcVariableDecl.vartype, List.nil(), List.nil(), List.nil(), body, null); }
Example 6
Source File: BootstrapInserter.java From manifold with Apache License 2.0 | 5 votes |
private JCTree.JCStatement buildBootstrapStaticBlock() { TreeMaker make = _javacJacker.getTreeMaker(); JavacElements javacElems = _javacJacker.getJavacElements(); JCTree.JCMethodInvocation bootstrapInitCall = make.Apply( List.nil(), memberAccess( make, javacElems, IBootstrap.class.getName() + ".dasBoot" ), List.nil() ); return make.Block( Modifier.STATIC, List.of( make.Exec( bootstrapInitCall ) ) ); }
Example 7
Source File: JavaParserVisitor.java From rewrite with Apache License 2.0 | 5 votes |
@Override public J visitIf(IfTree node, Formatting fmt) { skip("if"); J.Parentheses<Expression> ifPart = convert(node.getCondition()); Statement then = convert(node.getThenStatement()); J.If.Else elsePart = null; if (node.getElseStatement() instanceof JCTree.JCStatement) { var elsePrefix = sourceBefore("else"); elsePart = new J.If.Else(randomId(), convert(node.getElseStatement(), statementDelim), format(elsePrefix)); } return new J.If(randomId(), ifPart, then, elsePart, fmt); }
Example 8
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private static void analyzeSimpleStatements( SourceContext context, @Nullable List<JCTree.JCStatement> statements) throws IOException { if (nonNull(statements)) { for (JCTree.JCStatement statement : statements) { analyzeParsedTree(context, statement); } } }
Example 9
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private static void analyzeForLoop(SourceContext context, JCTree.JCForLoop forLoop) throws IOException { List<JCTree.JCStatement> initializer = forLoop.getInitializer(); JCTree.JCExpression condition = forLoop.getCondition(); List<JCTree.JCExpressionStatement> updates = forLoop.getUpdate(); JCTree.JCStatement statement = forLoop.getStatement(); analyzeSimpleStatements(context, initializer); analyzeParsedTree(context, condition); analyzeExpressionStatements(context, updates); analyzeParsedTree(context, statement); }
Example 10
Source File: TreeAnalyzer.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private static void analyzeEnhancedForLoop( SourceContext context, JCTree.JCEnhancedForLoop forLoop) throws IOException { JCTree.JCExpression expression = forLoop.getExpression(); analyzeParsedTree(context, expression); JCTree.JCVariableDecl variable = forLoop.getVariable(); analyzeParsedTree(context, variable); JCTree.JCStatement statement = forLoop.getStatement(); analyzeParsedTree(context, statement); }
Example 11
Source File: SingletonJavacHandler.java From tutorials with MIT License | 5 votes |
private JCTree.JCBlock addReturnBlock(JavacTreeMaker singletonClassTreeMaker, JavacNode holderInnerClass) { JCTree.JCClassDecl holderInnerClassDecl = (JCTree.JCClassDecl) holderInnerClass.get(); JavacTreeMaker holderInnerClassTreeMaker = holderInnerClass.getTreeMaker(); JCTree.JCIdent holderInnerClassType = holderInnerClassTreeMaker.Ident(holderInnerClassDecl.name); JCTree.JCFieldAccess instanceVarAccess = holderInnerClassTreeMaker.Select(holderInnerClassType, holderInnerClass.toName("INSTANCE")); JCTree.JCReturn returnValue = singletonClassTreeMaker.Return(instanceVarAccess); ListBuffer<JCTree.JCStatement> statements = new ListBuffer<>(); statements.append(returnValue); return singletonClassTreeMaker.Block(0L, statements.toList()); }
Example 12
Source File: HandleTable.java From sqlitemagic with Apache License 2.0 | 4 votes |
private static JCTree.JCBlock defaultMagicMethodBody(JavacTreeMaker maker, JavacNode tableElement) { JCTree.JCExpression exType = genTypeRef(tableElement, RuntimeException.class.getCanonicalName()); JCTree.JCExpression exception = maker.NewClass(null, List.<JCTree.JCExpression>nil(), exType, List.<JCTree.JCExpression>of(maker.Literal(ERROR_PROCESSOR_DID_NOT_RUN)), null); final JCTree.JCStatement statement = maker.Throw(exception); return maker.Block(0, List.of(statement)); }