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


Java JCStatement类代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCStatement的典型用法代码示例。如果您正苦于以下问题:Java JCStatement类的具体用法?Java JCStatement怎么用?Java JCStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JCStatement类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applySubstitutions

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private String applySubstitutions(final ExecutableElement element, final ImmutableSet<String> replacements) {
	if (Util.isAbstract(element)) {
		return "";
	}

	final StringWriter writer = new StringWriter();
	final SubstitutingPretty visitor = new SubstitutingPretty(writer,
			replacements,
			trees.getPath(element).getCompilationUnit(),
			Util.substitutePartialTypeNames(element));

	trees.getTree(element)
		.getBody()
		.getStatements()
		.stream()
		.map(JCStatement.class::cast)
		.forEach(tree -> {
			visitor.clearSubstitutions();
			visitor.printStat(tree);
			visitor.println();
		});

	return writer.toString();
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:25,代码来源:AstSubstitutionProcessor.java

示例2: visitForLoop

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
@Override
public void visitForLoop(final JCForLoop node) {
	print("for (");
	if (node.init.nonEmpty()) {
		if (node.init.head instanceof JCVariableDecl) {
			handleVarDef((JCVariableDecl)node.init.head, false);
			for (List<JCStatement> l = node.init.tail; l.nonEmpty(); l = l.tail) {
				final JCVariableDecl decl = (JCVariableDecl)l.head;
				print(", " + decl.name + " = ");
				printExpr(decl.init);
			}
		} else {
			printExprs(node.init);
		}
	}

	print("; ");
	if (node.cond != null) {
		printExpr(node.cond);
	}

	print("; ");
	printExprs(node.step);
	print(") ");
	printStat(node.body);
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:27,代码来源:AstSubstitutionProcessor.java

示例3: resolutionExceptionBlock

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.<JCStatement>of(
                make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:20,代码来源:Corraller.java

示例4: isConstructorCall

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
public static boolean isConstructorCall(final JCStatement statement) {
	if (!(statement instanceof JCExpressionStatement)) return false;
	JCExpression expr = ((JCExpressionStatement) statement).expr;
	if (!(expr instanceof JCMethodInvocation)) return false;
	JCExpression invocation = ((JCMethodInvocation) expr).meth;
	String name;
	if (invocation instanceof JCFieldAccess) {
		name = ((JCFieldAccess) invocation).name.toString();
	} else if (invocation instanceof JCIdent) {
		name = ((JCIdent) invocation).name.toString();
	} else {
		name = "";
	}
	
	return "super".equals(name) || "this".equals(name);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:JavacHandlerUtil.java

示例5: buildTryCatchBlock

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
public JCStatement buildTryCatchBlock(JavacNode node, List<JCStatement> contents, String exception, JCTree source) {
	JavacTreeMaker maker = node.getTreeMaker();
	
	Context context = node.getContext();
	JCBlock tryBlock = setGeneratedBy(maker.Block(0, contents), source, context);
	JCExpression varType = chainDots(node, exception.split("\\."));
	
	JCVariableDecl catchParam = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), node.toName("$ex"), varType, null);
	JCExpression lombokLombokSneakyThrowNameRef = chainDots(node, "lombok", "Lombok", "sneakyThrow");
	JCBlock catchBody = maker.Block(0, List.<JCStatement>of(maker.Throw(maker.Apply(
			List.<JCExpression>nil(), lombokLombokSneakyThrowNameRef,
			List.<JCExpression>of(maker.Ident(node.toName("$ex")))))));
	JCTry tryStatement = maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source, context)), null);
	if (JavacHandlerUtil.inNetbeansEditor(node)) {
		//set span (start and end position) of the try statement and the main block
		//this allows NetBeans to dive into the statement correctly:
		JCCompilationUnit top = (JCCompilationUnit) node.top().get();
		int startPos = contents.head.pos;
		int endPos = Javac.getEndPosition(contents.last().pos(), top);
		tryBlock.pos = startPos;
		tryStatement.pos = startPos;
		Javac.storeEnd(tryBlock, endPos, top);
		Javac.storeEnd(tryStatement, endPos, top);
	}
	return setGeneratedBy(tryStatement, source, context);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:HandleSneakyThrows.java

示例6: generateCleanMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) {
	JavacTreeMaker maker = type.getTreeMaker();
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	
	for (BuilderFieldData bfd : builderFields) {
		if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
			bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, type, source, statements);
		}
	}
	
	statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, false))));
	JCBlock body = maker.Block(0, statements.toList());
	return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(maker, CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, 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;
	}

	 */
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:27,代码来源:HandleBuilder.java

示例7: generateBuilderMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
public JCMethodDecl generateBuilderMethod(boolean isStatic, String builderMethodName, String builderClassName, JavacNode type, List<JCTypeParameter> typeParams) {
	JavacTreeMaker maker = type.getTreeMaker();
	
	ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>();
	for (JCTypeParameter typeParam : typeParams) {
		typeArgs.append(maker.Ident(typeParam.name));
	}
	
	JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), List.<JCExpression>nil(), null);
	JCStatement statement = maker.Return(call);
	
	JCBlock body = maker.Block(0, List.<JCStatement>of(statement));
	int modifiers = Flags.PUBLIC;
	if (isStatic) modifiers |= Flags.STATIC;
	return maker.MethodDef(maker.Modifiers(modifiers), type.toName(builderMethodName), namePlusTypeParamsToTypeReference(maker, type.toName(builderClassName), typeParams), copyTypeParams(maker, typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:HandleBuilder.java

示例8: createCanEqual

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
	/* protected boolean canEqual(final java.lang.Object other) {
	 *     return other instanceof Outer.Inner.MyType;
	 * }
	 */
	JavacTreeMaker maker = typeNode.getTreeMaker();
	
	JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
	JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
	Name canEqualName = typeNode.toName("canEqual");
	JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
	Name otherName = typeNode.toName("other");
	long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
	List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));
	
	JCBlock body = maker.Block(0, List.<JCStatement>of(
			maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));
	
	return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:HandleEqualsAndHashCode.java

示例9: generateMethods

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
	if (useGuavaInstead(builderType)) {
		guavaMapSingularizer.generateMethods(data, builderType, source, fluent, chain);
		return;
	}
	
	JavacTreeMaker maker = builderType.getTreeMaker();
	
	JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
	generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
	
	returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
	generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
	
	returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
	generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacJavaUtilMapSingularizer.java

示例10: generateClearMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private void generateClearMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) {
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> thrown = List.nil();
	List<JCVariableDecl> params = List.nil();
	List<JCExpression> jceBlank = List.nil();
	
	JCExpression thisDotKeyField = chainDots(builderType, "this", data.getPluralName() + "$key");
	JCExpression thisDotKeyFieldDotClear = chainDots(builderType, "this", data.getPluralName() + "$key", "clear");
	JCExpression thisDotValueFieldDotClear = chainDots(builderType, "this", data.getPluralName() + "$value", "clear");
	JCStatement clearKeyCall = maker.Exec(maker.Apply(jceBlank, thisDotKeyFieldDotClear, jceBlank));
	JCStatement clearValueCall = maker.Exec(maker.Apply(jceBlank, thisDotValueFieldDotClear, jceBlank));
	JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotKeyField, maker.Literal(CTC_BOT, null));
	JCBlock clearCalls = maker.Block(0, List.of(clearKeyCall, clearValueCall));
	JCStatement ifSetCallClear = maker.If(cond, clearCalls, null);
	List<JCStatement> statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
	
	JCBlock body = maker.Block(0, statements);
	Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString()));
	JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null);
	injectMethod(builderType, method);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:23,代码来源:JavacJavaUtilMapSingularizer.java

示例11: generateMethods

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
	if (useGuavaInstead(builderType)) {
		guavaListSetSingularizer.generateMethods(data, builderType, source, fluent, chain);
		return;
	}
	
	JavacTreeMaker maker = builderType.getTreeMaker();
	Name thisName = builderType.toName("this");
	
	JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
	generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
	
	returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
	generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
	
	returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
	returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
	generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:JavacJavaUtilListSetSingularizer.java

示例12: generateClearMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private void generateClearMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source) {
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> thrown = List.nil();
	List<JCVariableDecl> params = List.nil();
	List<JCExpression> jceBlank = List.nil();
	
	JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName());
	JCExpression thisDotFieldDotClear = maker.Select(maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), builderType.toName("clear"));
	JCStatement clearCall = maker.Exec(maker.Apply(jceBlank, thisDotFieldDotClear, jceBlank));
	JCExpression cond = maker.Binary(CTC_NOT_EQUAL, thisDotField, maker.Literal(CTC_BOT, null));
	JCStatement ifSetCallClear = maker.If(cond, clearCall, null);
	List<JCStatement> statements = returnStatement != null ? List.of(ifSetCallClear, returnStatement) : List.of(ifSetCallClear);
	
	JCBlock body = maker.Block(0, statements);
	Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString()));
	JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, params, thrown, body, null);
	injectMethod(builderType, method);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:20,代码来源:JavacJavaUtilListSetSingularizer.java

示例13: generateSingularMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
void generateSingularMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> thrown = List.nil();
	
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
	JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "add");
	JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getSingularName())));
	statements.append(maker.Exec(invokeAdd));
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name name = data.getSingularName();
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("add", name.toString()));
	JCExpression paramType = cloneParamType(0, maker, data.getTypeArgs(), builderType, source);
	JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getSingularName(), paramType, null);
	JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
	injectMethod(builderType, method);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacJavaUtilListSetSingularizer.java

示例14: generatePluralMethod

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
void generatePluralMethod(JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent) {
	List<JCTypeParameter> typeParams = List.nil();
	List<JCExpression> thrown = List.nil();
	
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC);
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	statements.append(createConstructBuilderVarIfNeeded(maker, data, builderType, false, source));
	JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), "addAll");
	JCExpression invokeAdd = maker.Apply(List.<JCExpression>nil(), thisDotFieldDotAdd, List.<JCExpression>of(maker.Ident(data.getPluralName())));
	statements.append(maker.Exec(invokeAdd));
	if (returnStatement != null) statements.append(returnStatement);
	JCBlock body = maker.Block(0, statements.toList());
	Name name = data.getPluralName();
	long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
	if (!fluent) name = builderType.toName(HandlerUtil.buildAccessorName("addAll", name.toString()));
	JCExpression paramType = chainDots(builderType, "java", "util", "Collection");
	paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs(), source);
	JCVariableDecl param = maker.VarDef(maker.Modifiers(paramFlags), data.getPluralName(), paramType, null);
	JCMethodDecl method = maker.MethodDef(mods, name, returnType, typeParams, List.of(param), thrown, body, null);
	injectMethod(builderType, method);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:JavacJavaUtilListSetSingularizer.java

示例15: createListCopy

import com.sun.tools.javac.tree.JCTree.JCStatement; //导入依赖的package包/类
private List<JCStatement> createListCopy(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
	List<JCExpression> jceBlank = List.nil();
	Name thisName = builderType.toName("this");
	
	JCExpression argToUnmodifiable; {
		 // new java.util.ArrayList<Generics>(this.pluralName);
		List<JCExpression> constructorArgs = List.nil();
		JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName());
		constructorArgs = List.<JCExpression>of(thisDotPluralName);
		JCExpression targetTypeExpr = chainDots(builderType, "java", "util", "ArrayList");
		targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs(), source);
		argToUnmodifiable = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null);
	}
	
	JCStatement unmodifiableStat; {
		// pluralname = Collections.unmodifiableInterfaceType(-newlist-);
		JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiableList"), List.of(argToUnmodifiable));
		unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
	}
	
	return List.of(unmodifiableStat);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:23,代码来源:JavacJavaUtilListSingularizer.java


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