当前位置: 首页>>代码示例>>Java>>正文


Java JCReturn类代码示例

本文整理汇总了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);
}
 
开发者ID:google,项目名称:error-prone,代码行数:23,代码来源:ULambda.java

示例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];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:CasualDiff.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ArgumentAttr.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ArgumentAttr.java

示例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();
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:14,代码来源:AstSubstitutionProcessor.java

示例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);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:9,代码来源:PrettyPrinter.java

示例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);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:8,代码来源:PrintAstVisitor.java

示例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);
	}
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:13,代码来源:PrettyCommentsPrinter.java

示例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);
    }
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:13,代码来源:Pretty.java

示例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;
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:29,代码来源:Attr.java

示例11: Return

import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public JCReturn Return(JCExpression expr) {
	return invoke(Return, expr);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:JavacTreeMaker.java

示例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;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:59,代码来源:HandleSetter.java

示例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;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:75,代码来源:HandleWither.java

示例14: AJCReturn

import com.sun.tools.javac.tree.JCTree.JCReturn; //导入依赖的package包/类
public AJCReturn(JCReturn ltree) {
    super(ltree.expr);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:4,代码来源:AJCReturn.java

示例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;
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:69,代码来源:HandleWither.java


注:本文中的com.sun.tools.javac.tree.JCTree.JCReturn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。