com.sun.tools.javac.tree.JCTree.JCLambda Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCLambda.
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: TypeAnnotations.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #2
Source File: TypeAnnotations.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #3
Source File: TypeAnnotations.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #4
Source File: TypeAnnotationPosition.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private TypeAnnotationPosition(final TargetType ttype, final int pos, final int parameter_index, final JCLambda onLambda, final int type_index, final int bound_index, final List<TypePathEntry> location) { Assert.checkNonNull(location); this.type = ttype; this.pos = pos; this.parameter_index = parameter_index; this.onLambda = onLambda; this.type_index = type_index; this.bound_index = bound_index; this.location = location; }
Example #5
Source File: TypeAnnotations.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #6
Source File: TypeAnnotations.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #7
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 6 votes |
private Expression convertLambda(JCLambda expression) { MethodDescriptor functionalMethodDescriptor = environment.getJsFunctionMethodDescriptor(expression.type); return processEnclosedBy( functionalMethodDescriptor, () -> FunctionExpression.newBuilder() .setTypeDescriptor(getTargetType(expression)) .setParameters( expression.getParameters().stream() .map(variable -> createVariable((JCVariableDecl) variable, true)) .collect(toImmutableList())) .setStatements( convertLambdaBody( expression.getBody(), functionalMethodDescriptor.getReturnTypeDescriptor()) .getStatements()) .setSourcePosition(getSourcePosition(expression)) .build()); }
Example #8
Source File: TypeAnnotations.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private int methodParamIndex(List<JCTree> path, JCTree param) { List<JCTree> curr = path; while (curr.head.getTag() != Tag.METHODDEF && curr.head.getTag() != Tag.LAMBDA) { curr = curr.tail; } if (curr.head.getTag() == Tag.METHODDEF) { JCMethodDecl method = (JCMethodDecl)curr.head; return method.params.indexOf(param); } else if (curr.head.getTag() == Tag.LAMBDA) { JCLambda lambda = (JCLambda)curr.head; return lambda.params.indexOf(param); } else { Assert.error("methodParamIndex expected to find method or lambda for param: " + param); return -1; } }
Example #9
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
JCLambda lambda() { int prevPos = make.pos; try { make.at(tree); //body generation - this can be either a method call or a //new instance creation expression, depending on the member reference kind VarSymbol rcvr = addParametersReturnReceiver(); JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE) ? expressionInvoke(rcvr) : expressionNew(); JCLambda slam = make.Lambda(params.toList(), expr); slam.targets = tree.targets; slam.type = tree.type; slam.pos = tree.pos; return slam; } finally { make.at(prevPos); } }
Example #10
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void apportionTypeAnnotations(JCLambda tree, Supplier<List<Attribute.TypeCompound>> source, Consumer<List<Attribute.TypeCompound>> owner, Consumer<List<Attribute.TypeCompound>> lambda) { ListBuffer<Attribute.TypeCompound> ownerTypeAnnos = new ListBuffer<>(); ListBuffer<Attribute.TypeCompound> lambdaTypeAnnos = new ListBuffer<>(); for (Attribute.TypeCompound tc : source.get()) { if (tc.position.onLambda == tree) { lambdaTypeAnnos.append(tc); } else { ownerTypeAnnos.append(tc); } } if (lambdaTypeAnnos.nonEmpty()) { owner.accept(ownerTypeAnnos.toList()); lambda.accept(lambdaTypeAnnos.toList()); } }
Example #11
Source File: ImmutableTreeTranslator.java From netbeans with Apache License 2.0 | 6 votes |
protected final LambdaExpressionTree rewriteChildren(LambdaExpressionTree tree) { Tree body = translate(tree.getBody()); List<? extends VariableTree> parameters = translate(tree.getParameters()); if (body != tree.getBody() || parameters != tree.getParameters()) { LambdaExpressionTree n = make.LambdaExpression(parameters, body); // issue #239256, NETBEANS-345 // Subsequent to the construction of tree, the vartype of the head // param might have been filled in, so we need to copy tree's paramKind. ((JCLambda)n).paramKind = ((JCLambda)tree).paramKind; model.setType(n, model.getType(tree)); copyCommentTo(tree,n); copyPosTo(tree,n); tree = n; } return tree; }
Example #12
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void visitLambda(JCLambda tree) { if ((tree.type != null && tree.type.isErroneous()) || inLambda) { return; } List<Type> prevCaught = caught; List<Type> prevThrown = thrown; ListBuffer<FlowPendingExit> prevPending = pendingExits; inLambda = true; try { pendingExits = new ListBuffer<>(); caught = List.of(syms.throwableType); thrown = List.nil(); scan(tree.body); inferredThrownTypes = thrown; } finally { pendingExits = prevPending; caught = prevCaught; thrown = prevThrown; inLambda = false; } }
Example #13
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void visitLambda(JCLambda tree) { if (tree.type != null && tree.type.isErroneous()) { return; } ListBuffer<PendingExit> prevPending = pendingExits; boolean prevAlive = alive; try { pendingExits = new ListBuffer<>(); alive = true; scanStat(tree.body); tree.canCompleteNormally = alive; } finally { pendingExits = prevPending; alive = prevAlive; } }
Example #14
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public List<Type> analyzeLambdaThrownTypes(final Env<AttrContext> env, JCLambda that, TreeMaker make) { //we need to disable diagnostics temporarily; the problem is that if //a lambda expression contains e.g. an unreachable statement, an error //message will be reported and will cause compilation to skip the flow analyis //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { new LambdaAssignAnalyzer(env).analyzeTree(env, that); LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); flowAnalyzer.analyzeTree(env, that, make); return flowAnalyzer.inferredThrownTypes; } finally { log.popDiagnosticHandler(diagHandler); } }
Example #15
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void analyzeLambda(Env<AttrContext> env, JCLambda that, TreeMaker make, boolean speculative) { Log.DiagnosticHandler diagHandler = null; //we need to disable diagnostics temporarily; the problem is that if //a lambda expression contains e.g. an unreachable statement, an error //message will be reported and will cause compilation to skip the flow analyis //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis //related errors, which will allow for more errors to be detected if (!speculative) { diagHandler = new Log.DiscardDiagnosticHandler(log); } try { new LambdaAliveAnalyzer().analyzeTree(env, that, make); } finally { if (!speculative) { log.popDiagnosticHandler(diagHandler); } } }
Example #16
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private LambdaTranslationContext analyzeLambda(JCLambda tree, String statKey) { List<Frame> prevStack = frameStack; try { LambdaTranslationContext context = new LambdaTranslationContext(tree); frameStack = frameStack.prepend(new Frame(tree)); for (JCVariableDecl param : tree.params) { context.addSymbol(param.sym, PARAM); frameStack.head.addLocal(param.sym); } contextMap.put(tree, context); super.visitLambda(tree); context.complete(); if (dumpLambdaToMethodStats) { log.note(tree, statKey, context.needsAltMetafactory(), context.translatedSym); } return context; } finally { frameStack = prevStack; } }
Example #17
Source File: TypeAnnotations.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. TypeAnnotationPosition pos = new TypeAnnotationPosition(); pos.type = TargetType.METHOD_FORMAL_PARAMETER; pos.parameter_index = i; pos.pos = param.vartype.pos; pos.onLambda = tree; separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } ++i; } push(tree); scan(tree.body); scan(tree.params); pop(); } finally { currentLambda = prevLambda; } }
Example #18
Source File: TypeAnnotationPosition.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a {@code TypeAnnotationPosition} for a method return. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodReturn(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_RETURN, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
Example #19
Source File: Analyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public JCTree visitLambdaExpression(LambdaExpressionTree node, Void _unused) { JCLambda oldLambda = (JCLambda)node; JCLambda newLambda = (JCLambda)super.visitLambdaExpression(node, _unused); if (oldLambda.paramKind == ParameterKind.IMPLICIT) { //reset implicit lambda parameters (whose type might have been set during attr) newLambda.paramKind = ParameterKind.IMPLICIT; newLambda.params.forEach(p -> p.vartype = null); } return newLambda; }
Example #20
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
LambdaTranslationContext(JCLambda tree) { super(tree); Frame frame = frameStack.head; switch (frame.tree.getTag()) { case VARDEF: assignedTo = self = ((JCVariableDecl) frame.tree).sym; break; case ASSIGN: self = null; assignedTo = TreeInfo.symbol(((JCAssign) frame.tree).getVariable()); break; default: assignedTo = self = null; break; } // This symbol will be filled-in in complete this.translatedSym = makePrivateSyntheticMethod(0, null, null, owner.enclClass()); translatedSymbols = new EnumMap<>(LambdaSymbolKind.class); translatedSymbols.put(PARAM, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(LOCAL_VAR, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(CAPTURED_OUTER_THIS, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>()); freeVarProcessedLocalClasses = new HashSet<>(); }
Example #21
Source File: TypeAnnotations.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void visitLambda(JCLambda tree) { JCLambda prevLambda = currentLambda; try { currentLambda = tree; int i = 0; for (JCVariableDecl param : tree.params) { if (!param.mods.annotations.isEmpty()) { // Nothing to do for separateAnnotationsKinds if // there are no annotations of either kind. TypeAnnotationPosition pos = new TypeAnnotationPosition(); pos.type = TargetType.METHOD_FORMAL_PARAMETER; pos.parameter_index = i; pos.pos = param.vartype.pos; pos.onLambda = tree; separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos); } ++i; } push(tree); scan(tree.body); scan(tree.params); pop(); } finally { currentLambda = prevLambda; } }
Example #22
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
boolean canLambdaBodyCompleteNormally(JCLambda tree) { List<JCVariableDecl> oldParams = tree.params; LocalCacheContext localCacheContext = argumentAttr.withLocalCacheContext(); try { tree.params = StreamSupport.stream(tree.params) .map(vd -> make.VarDef(vd.mods, vd.name, make.Erroneous(), null)) .collect(List.collector()); return attribSpeculativeLambda(tree, env, attr.unknownExprInfo).canCompleteNormally; } finally { localCacheContext.leave(); tree.params = oldParams; } }
Example #23
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 #24
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitLambda(JCLambda tree) { JCTree prevTree = currentTree; try { currentTree = tree; super.visitLambda(tree); } finally { currentTree = prevTree; } }
Example #25
Source File: TypeAnnotationPosition.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a {@code TypeAnnotationPosition} for a type parameter. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition typeParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int pos) { return new TypeAnnotationPosition(TargetType.CLASS_TYPE_PARAMETER, pos, parameter_index, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
Example #26
Source File: TypeAnnotationPosition.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a {@code TypeAnnotationPosition} for an exception parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition exceptionParameter(final List<TypePathEntry> location, final JCLambda onLambda, final int pos) { return new TypeAnnotationPosition(TargetType.EXCEPTION_PARAMETER, pos, Integer.MIN_VALUE, onLambda, Integer.MIN_VALUE, Integer.MIN_VALUE, location); }
Example #27
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) { return; } inLambda = true; try { super.visitLambda(tree); } finally { inLambda = false; } }
Example #28
Source File: Analyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override JCLambda map (JCNewClass oldTree, JCNewClass newTree){ JCMethodDecl md = (JCMethodDecl)decls(newTree.def).head; List<JCVariableDecl> params = md.params; JCBlock body = md.body; return make.Lambda(params, body); }
Example #29
Source File: TypeAnnotationPosition.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Create a {@code TypeAnnotationPosition} for a method type * parameter bound. * * @param location The type path. * @param onLambda The lambda for this variable. * @param parameter_index The index of the type parameter. * @param bound_index The index of the type parameter bound. * @param pos The position from the associated tree node. */ public static TypeAnnotationPosition methodTypeParameterBound(final List<TypePathEntry> location, final JCLambda onLambda, final int parameter_index, final int bound_index, final int pos) { return new TypeAnnotationPosition(TargetType.METHOD_TYPE_PARAMETER_BOUND, pos, parameter_index, onLambda, Integer.MIN_VALUE, bound_index, location); }
Example #30
Source File: ArgumentAttr.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void visitLambda(JCLambda that) { if (that.paramKind == ParameterKind.EXPLICIT) { //if lambda is explicit, we can save info in the corresponding argument type processArg(that, () -> { JCLambda speculativeLambda = deferredAttr.attribSpeculativeLambda(that, env, attr.methodAttrInfo); return new ExplicitLambdaType(that, env, speculativeLambda); }); } else { //otherwise just use a deferred type setResult(that, deferredAttr.new DeferredType(that, env)); } }