Java Code Examples for com.sun.source.tree.LambdaExpressionTree.BodyKind#EXPRESSION
The following examples show how to use
com.sun.source.tree.LambdaExpressionTree.BodyKind#EXPRESSION .
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: Lambda.java From netbeans with Apache License 2.0 | 6 votes |
@Hint(displayName="#DN_expression2Return", description="#DESC_expression2Return", category="suggestions", hintKind=Hint.Kind.ACTION, minSourceVersion = "8") @Messages({ "DN_expression2Return=Convert Lambda Body to Use a Block", "DESC_expression2Return=Converts lambda bodies to use blocks rather than expressions", "ERR_expression2Return=", "FIX_expression2Return=Use block as the lambda's body" }) @TriggerPattern("($args$) -> $lambdaExpression") public static ErrorDescription expression2Return(HintContext ctx) { if (((LambdaExpressionTree) ctx.getPath().getLeaf()).getBodyKind() != BodyKind.EXPRESSION) { return null; } TypeMirror lambdaExpressionType = ctx.getInfo().getTrees().getTypeMirror(ctx.getVariables().get("$lambdaExpression")); String target = lambdaExpressionType == null || lambdaExpressionType.getKind() != TypeKind.VOID ? "($args$) -> { return $lambdaExpression; }" : "($args$) -> { $lambdaExpression; }"; return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), Bundle.ERR_expression2Return(), JavaFixUtilities.rewriteFix(ctx, Bundle.FIX_expression2Return(), ctx.getPath(), target)); }
Example 2
Source File: ArgumentAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Check lambda against given target result */ private void checkLambdaCompatible(Type descriptor, ResultInfo resultInfo) { CheckContext checkContext = resultInfo.checkContext; ResultInfo bodyResultInfo = attr.lambdaBodyResult(speculativeTree, descriptor, resultInfo); for (JCReturn ret : returnExpressions()) { Type t = getReturnType(ret); if (speculativeTree.getBodyKind() == BodyKind.EXPRESSION || !t.hasTag(VOID)) { checkSpeculative(ret.expr, t, bodyResultInfo); } } attr.checkLambdaCompatible(speculativeTree, descriptor, checkContext); }
Example 3
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 4
Source File: Flow.java From openjdk-jdk9 with GNU General Public License v2.0 | 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 5
Source File: ArgumentAttr.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** Check lambda against given target result */ private void checkLambdaCompatible(Type descriptor, ResultInfo resultInfo) { CheckContext checkContext = resultInfo.checkContext; ResultInfo bodyResultInfo = attr.lambdaBodyResult(speculativeTree, descriptor, resultInfo); for (JCReturn ret : returnExpressions()) { Type t = getReturnType(ret); if (speculativeTree.getBodyKind() == BodyKind.EXPRESSION || !t.hasTag(VOID)) { checkSpeculative(ret.expr, t, bodyResultInfo); } } attr.checkLambdaCompatible(speculativeTree, descriptor, checkContext); }
Example 6
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 7
Source File: JCTree.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 8
Source File: JCTree.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 9
Source File: JCTree.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 10
Source File: DeferredAttr.java From hottub with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }
Example 11
Source File: JCTree.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 12
Source File: DeferredAttr.java From openjdk-jdk9 with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }
Example 13
Source File: DeferredAttr.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }
Example 14
Source File: JCTree.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 15
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 16
Source File: DeferredAttr.java From openjdk-jdk8u with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }
Example 17
Source File: JCTree.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 18
Source File: DeferredAttr.java From jdk8u60 with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }
Example 19
Source File: JCTree.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public BodyKind getBodyKind() { return body.hasTag(BLOCK) ? BodyKind.STATEMENT : BodyKind.EXPRESSION; }
Example 20
Source File: DeferredAttr.java From TencentKona-8 with GNU General Public License v2.0 | 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("incompatible.arg.types.in.lambda")); } 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("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", 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("unexpected.ret.val")); } } else { boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible && !canLambdaBodyCompleteNormally(tree); if (!isValueCompatible && !isVoidCompatible) { log.error(tree.body.pos(), "lambda.body.neither.value.nor.void.compatible"); } if (!isValueCompatible) { resultInfo.checkContext.report(tree.pos(), diags.fragment("incompatible.ret.type.in.lambda", diags.fragment("missing.ret.val", currentReturnType))); } } } } }