Java Code Examples for com.sun.tools.javac.tree.JCTree.JCLambda#getBodyKind()
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCLambda#getBodyKind() .
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: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitLambda(JCLambda tree) { if (inLambda || tree.getBodyKind() == BodyKind.EXPRESSION) { return; } inLambda = true; try { super.visitLambda(tree); } finally { inLambda = false; } }
Example 2
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitLambda(JCLambda tree) { final Bits prevUninits = new Bits(uninits); final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; int nextadrPrev = nextadr; ListBuffer<AssignPendingExit> prevPending = pendingExits; try { returnadr = nextadr; pendingExits = new ListBuffer<>(); for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); inits.incl(def.sym.adr); uninits.excl(def.sym.adr); } if (tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { scanExpr(tree.body); } else { scan(tree.body); } } finally { returnadr = returnadrPrev; uninits.assign(prevUninits); inits.assign(prevInits); pendingExits = prevPending; nextadr = nextadrPrev; } }
Example 3
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Performs speculative attribution of a lambda body and returns the speculative lambda tree, * in the absence of a target-type. Since {@link Attr#visitLambda(JCLambda)} cannot type-check * lambda bodies w/o a suitable target-type, this routine 'unrolls' the lambda by turning it * into a regular block, speculatively type-checks the block and then puts back the pieces. */ JCLambda attribSpeculativeLambda(JCLambda that, Env<AttrContext> env, ResultInfo resultInfo) { ListBuffer<JCStatement> stats = new ListBuffer<>(); stats.addAll(that.params); if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { stats.add(make.Return((JCExpression)that.body)); } else { stats.add((JCBlock)that.body); } JCBlock lambdaBlock = make.Block(0, stats.toList()); Env<AttrContext> localEnv = attr.lambdaEnv(that, env); try { localEnv.info.returnResult = resultInfo; JCBlock speculativeTree = (JCBlock)attribSpeculative(lambdaBlock, localEnv, resultInfo); List<JCVariableDecl> args = StreamSupport.stream(speculativeTree.getStatements()) .filter(s -> s.hasTag(Tag.VARDEF)) .map(t -> (JCVariableDecl)t) .collect(List.collector()); JCTree lambdaBody = speculativeTree.getStatements().last(); if (lambdaBody.hasTag(Tag.RETURN)) { lambdaBody = ((JCReturn)lambdaBody).expr; } JCLambda speculativeLambda = make.Lambda(args, lambdaBody); attr.preFlow(speculativeLambda); flow.analyzeLambda(env, speculativeLambda, make, false); return speculativeLambda; } finally { localEnv.info.scope.leave(); } }
Example 4
Source File: AssertCheckAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
boolean isSimpleStringArg(JCExpression e) { switch (e.getTag()) { case LAMBDA: JCLambda lambda = (JCLambda)e; return (lambda.getBodyKind() == BodyKind.EXPRESSION) && isSimpleStringArg((JCExpression)lambda.body); default: Symbol argSym = TreeInfo.symbolFor(e); return (e.type.constValue() != null || (argSym != null && argSym.kind == Kinds.Kind.VAR)); } }
Example 5
Source File: TreePruner.java From bazel with Apache License 2.0 | 5 votes |
@Override public void visitLambda(JCLambda tree) { if (tree.getBodyKind() == BodyKind.STATEMENT) { JCExpression ident = make.at(tree).QualIdent(symtab.assertionErrorType.tsym); JCThrow throwTree = make.Throw(make.NewClass(null, List.nil(), ident, List.nil(), null)); tree.body = make.Block(0, List.of(throwTree)); } }
Example 6
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void visitLambda(JCLambda tree) { Check.CheckContext checkContext = resultInfo.checkContext; Type pt = resultInfo.pt; if (!inferenceContext.inferencevars.contains(pt)) { //must be a functional descriptor Type descriptorType = null; try { descriptorType = types.findDescriptorType(pt); } catch (Types.FunctionDescriptorLookupError ex) { checkContext.report(null, ex.getDiagnostic()); } if (descriptorType.getParameterTypes().length() != tree.params.length()) { checkContext.report(tree, diags.fragment(Fragments.IncompatibleArgTypesInLambda)); } Type currentReturnType = descriptorType.getReturnType(); boolean returnTypeIsVoid = currentReturnType.hasTag(VOID); if (tree.getBodyKind() == BodyKind.EXPRESSION) { boolean isExpressionCompatible = !returnTypeIsVoid || TreeInfo.isExpressionStatement((JCExpression)tree.getBody()); if (!isExpressionCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment(Fragments.IncompatibleRetTypeInLambda(Fragments.MissingRetVal(currentReturnType)))); } } else { LambdaBodyStructChecker lambdaBodyChecker = new LambdaBodyStructChecker(); tree.body.accept(lambdaBodyChecker); boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible; if (returnTypeIsVoid) { if (!isVoidCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment(Fragments.UnexpectedRetVal)); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), Errors.LambdaBodyNeitherValueNorVoidCompatible); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment(Fragments.IncompatibleRetTypeInLambda(Fragments.MissingRetVal(currentReturnType)))); } } } } }
Example 7
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private JCBlock makeLambdaBody(JCLambda tree, JCMethodDecl lambdaMethodDecl) { return tree.getBodyKind() == JCLambda.BodyKind.EXPRESSION ? makeLambdaExpressionBody((JCExpression)tree.body, lambdaMethodDecl) : makeLambdaStatementBody((JCBlock)tree.body, lambdaMethodDecl, tree.canCompleteNormally); }