本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCReturn类的典型用法代码示例。如果您正苦于以下问题:Java JCReturn类的具体用法?Java JCReturn怎么用?Java JCReturn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCReturn类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCReturn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inlineBody
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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);
}
示例2: diffReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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];
}
示例3: checkLambdaCompatible
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
/** 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);
}
示例4: getReturnType
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
/** Get the type associated with given return expression. */
Type getReturnType(JCReturn ret) {
if (ret.expr == null) {
return syms.voidType;
} else {
return ret.expr.type;
}
}
示例5: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
@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();
}
示例6: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
@Override public void visitReturn(JCReturn tree) {
aPrint("return");
if (tree.expr != null) {
print(" ");
print(tree.expr);
}
println(";", tree);
}
示例7: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public void visitReturn(JCReturn that) {
try {
print("JCReturn:");
} catch (Exception e) {
}
super.visitReturn(that);
}
示例8: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public void visitReturn(JCReturn tree) {
try {
print("return");
if (tree.expr != null) {
print(" ");
printExpr(tree.expr);
}
print(";");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例9: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public void visitReturn(JCReturn tree) {
try {
print("return");
if (tree.expr != null) {
print(" ");
printExpr(tree.expr);
}
print(";");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例10: visitReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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;
}
示例11: Return
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public JCReturn Return(JCExpression expr) {
return invoke(Return, expr);
}
示例12: createSetter
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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;
}
示例13: createWither
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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;
}
示例14: AJCReturn
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public AJCReturn(JCReturn ltree) {
super(ltree.expr);
}
示例15: createWither
import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
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;
}