JCTree inlineBody(Inliner inliner) throws CouldNotResolveImportException { if (getBody() instanceof UPlaceholderExpression) { UPlaceholderExpression body = (UPlaceholderExpression) getBody(); Optional<List<JCStatement>> blockBinding = inliner.getOptionalBinding(body.placeholder().blockKey()); if (blockBinding.isPresent()) { // this lambda is of the form args -> blockPlaceholder(); List<JCStatement> blockInlined = UPlaceholderExpression.copier(body.arguments(), inliner) .copy(blockBinding.get(), inliner); if (blockInlined.size() == 1) { if (blockInlined.get(0) instanceof JCReturn) { return ((JCReturn) blockInlined.get(0)).getExpression(); } else if (blockInlined.get(0) instanceof JCExpressionStatement) { return ((JCExpressionStatement) blockInlined.get(0)).getExpression(); } } return inliner.maker().Block(0, blockInlined); } } return getBody().inline(inliner); }
protected int diffReturn(JCReturn oldT, JCReturn newT, int[] bounds) { int localPointer = bounds[0]; if (oldT.expr != newT.expr) { if (oldT.expr == null) { tokenSequence.move(endPos(oldT)); tokenSequence.movePrevious(); copyTo(localPointer, localPointer = tokenSequence.offset()); if (tokenSequence.token().id() == JavaTokenId.SEMICOLON) { tokenSequence.movePrevious(); } if (tokenSequence.token().id() != JavaTokenId.WHITESPACE) { printer.print(" "); } printer.print(newT.expr); } else if (newT.expr == null) { copyTo(localPointer, localPointer = getOldPos(oldT) + "return".length()); localPointer = endPos(oldT.expr); } else { int[] exprBounds = getBounds(oldT.expr); copyTo(bounds[0], exprBounds[0]); localPointer = diffTree(oldT.expr, newT.expr, exprBounds); } } copyTo(localPointer, bounds[1]); return bounds[1]; }
/** 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); }
/** Get the type associated with given return expression. */ Type getReturnType(JCReturn ret) { if (ret.expr == null) { return syms.voidType; } else { return ret.expr.type; } }
@Override public void visitReturn(final JCReturn node) { if (replacements.isEmpty()) { super.visitReturn(node); return; } // For return, the only meaningful substitution occurs when there is // only a single field, so we assume that here. substitutionStack.push(replacements.stream().collect(joining(","))); super.visitReturn(node); substitutionStack.pop(); }
@Override public void visitReturn(JCReturn tree) { aPrint("return"); if (tree.expr != null) { print(" "); print(tree.expr); } println(";", tree); }
public void visitReturn(JCReturn that) { try { print("JCReturn:"); } catch (Exception e) { } super.visitReturn(that); }
public void visitReturn(JCReturn tree) { try { print("return"); if (tree.expr != null) { print(" "); printExpr(tree.expr); } print(";"); } catch (IOException e) { throw new UncheckedIOException(e); } }
public void visitReturn(JCReturn tree) { // Check that there is an enclosing method which is // nested within than the enclosing class. if (env.enclMethod == null || env.enclMethod.sym.owner != env.enclClass.sym) { log.error(tree.pos(), "ret.outside.meth"); } else { // Attribute return expression, if it exists, and check that // it conforms to result type of enclosing method. Symbol m = env.enclMethod.sym; if (m.type.getReturnType().tag == VOID) { if (tree.expr != null) log.error(tree.expr.pos(), "cant.ret.val.from.meth.decl.void"); } else if (tree.expr == null) { log.error(tree.pos(), "missing.ret.val"); } else { // de.so.ma // check for JCSqlQuery SqlQueryNodeTransformer transformer = SqlQueryNodeTransformer.getInstance(); tree.expr = transformer.transformPotentialSqlQuery( tree.expr, env, m.type.getReturnType(), this, enter, memberEnter); attribExpr(tree.expr, env, m.type.getReturnType()); } } result = null; }
public JCReturn Return(JCExpression expr) { return invoke(Return, expr); }
public static JCMethodDecl createSetter(long access, JavacNode field, JavacTreeMaker treeMaker, String setterName, boolean shouldReturnThis, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) { if (setterName == null) return null; JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD); JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(fieldDecl.name)); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN); List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN); Name methodName = field.toName(setterName); List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); if (nonNulls.isEmpty()) { statements.append(treeMaker.Exec(assign)); } else { JCStatement nullCheck = generateNullCheck(treeMaker, field, source); if (nullCheck != null) statements.append(nullCheck); statements.append(treeMaker.Exec(assign)); } JCExpression methodType = null; if (shouldReturnThis) { methodType = cloneSelfType(field); } if (methodType == null) { //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6. methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID)); shouldReturnThis = false; } if (shouldReturnThis) { JCReturn returnStatement = treeMaker.Return(treeMaker.Ident(field.toName("this"))); statements.append(returnStatement); } JCBlock methodBody = treeMaker.Block(0, statements.toList()); List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.of(param); List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); } JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); copyJavadoc(field, decl, CopyJavadoc.SETTER); return decl; }
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam, boolean makeAbstract) { String witherName = toWitherName(field); if (witherName == null) return null; JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN); List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN); Name methodName = field.toName(witherName); JCExpression returnType = cloneSelfType(field); JCBlock methodBody = null; long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); if (!makeAbstract) { ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); JCExpression selfType = cloneSelfType(field); if (selfType == null) return null; ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); for (JavacNode child : field.up().down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl childDecl = (JCVariableDecl) child.get(); // Skip fields that start with $ if (childDecl.name.toString().startsWith("$")) continue; long fieldFlags = childDecl.mods.flags; // Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; // Skip initialized final fields. if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue; if (child.get() == field.get()) { args.append(maker.Ident(fieldDecl.name)); } else { args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD)); } } JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null); JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name)); JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass); JCReturn returnStatement = maker.Return(conditional); if (nonNulls.isEmpty()) { statements.append(returnStatement); } else { JCStatement nullCheck = generateNullCheck(maker, field, source); if (nullCheck != null) statements.append(nullCheck); statements.append(returnStatement); } methodBody = maker.Block(0, statements.toList()); } List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.of(param); List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); } if (makeAbstract) access = access | Flags.ABSTRACT; JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); copyJavadoc(field, decl, CopyJavadoc.WITHER); return decl; }
public AJCReturn(JCReturn ltree) { super(ltree.expr); }
public AJCReturn(JCReturn ltree, String lcomment) { this(ltree); setComment(lcomment); }
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) { String witherName = toWitherName(field); if (witherName == null) return null; JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN); List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN); Name methodName = field.toName(witherName); List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); JCExpression selfType = cloneSelfType(field); if (selfType == null) return null; ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); for (JavacNode child : field.up().down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl childDecl = (JCVariableDecl) child.get(); // Skip fields that start with $ if (childDecl.name.toString().startsWith("$")) continue; long fieldFlags = childDecl.mods.flags; // Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; // Skip initialized final fields. if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue; if (child.get() == field.get()) { args.append(maker.Ident(fieldDecl.name)); } else { args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD)); } } JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null); JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name)); JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass); JCReturn returnStatement = maker.Return(conditional); if (nonNulls.isEmpty()) { statements.append(returnStatement); } else { JCStatement nullCheck = generateNullCheck(maker, field, source); if (nullCheck != null) statements.append(nullCheck); statements.append(returnStatement); } JCExpression returnType = cloneSelfType(field); JCBlock methodBody = maker.Block(0, statements.toList()); List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.of(param); List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); } JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); copyJavadoc(field, decl, CopyJavadoc.WITHER); return decl; }
@Override public JCReturn inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().Return(getExpression().inline(inliner)); }
@Override public void visitReturn(JCReturn tree) { printNode(tree); child("expr", tree.expr); indent--; }
@Override public void visitReturn(JCReturn node) { set(node, new Return().rawValue(toTree(node.getExpression()))); }
@Override public Choice<State<JCReturn>> visitReturn(ReturnTree node, State<?> state) { return chooseSubtrees(state, s -> unifyExpression(node.getExpression(), s), maker()::Return); }
private JCMethodDecl createWither(long access, JavacNode field, TreeMaker treeMaker, JCTree source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) { String witherName = toWitherName(field); if (witherName == null) return null; JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); ListBuffer<JCStatement> statements = ListBuffer.lb(); List<JCAnnotation> nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN); List<JCAnnotation> nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN); Name methodName = field.toName(witherName); List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(Flags.FINAL, annsOnParam), fieldDecl.name, fieldDecl.vartype, null); JCExpression selfType = cloneSelfType(field); if (selfType == null) return null; TreeMaker maker = field.getTreeMaker(); ListBuffer<JCExpression> args = ListBuffer.lb(); for (JavacNode child : field.up().down()) { if (child.getKind() != Kind.FIELD) continue; JCVariableDecl childDecl = (JCVariableDecl) child.get(); // Skip fields that start with $ if (childDecl.name.toString().startsWith("$")) continue; long fieldFlags = childDecl.mods.flags; // Skip static fields. if ((fieldFlags & Flags.STATIC) != 0) continue; // Skip initialized final fields. if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue; if (child.get() == field.get()) { args.append(maker.Ident(fieldDecl.name)); } else { args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD)); } } JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null); JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name)); JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass); JCReturn returnStatement = maker.Return(conditional); if (nonNulls.isEmpty()) { statements.append(returnStatement); } else { JCStatement nullCheck = generateNullCheck(treeMaker, field); if (nullCheck != null) statements.append(nullCheck); statements.append(returnStatement); } JCExpression returnType = cloneSelfType(field); JCBlock methodBody = treeMaker.Block(0, statements.toList()); List<JCTypeParameter> methodGenericParams = List.nil(); List<JCVariableDecl> parameters = List.of(param); List<JCExpression> throwsClauses = List.nil(); JCExpression annotationMethodDefaultValue = null; List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod); if (isFieldDeprecated(field)) { annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(chainDots(field, "java", "lang", "Deprecated"), List.<JCExpression>nil())); } return recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, returnType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); }