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


Java JCVariableDecl类代码示例

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


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

示例1: handleVarDef

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
private void handleVarDef(final JCVariableDecl node, final boolean endStatement) {
	final TreePath path = trees.getPath(compilationUnit, node);
	final TypeMirror typeMirror = trees.getElement(path).asType();

	printExpr(node.mods);
	print(substitutionInventory.applyTypeSubstitution(typeMirror));
	print(" ");
	print(node.name); // variable name
	if (node.init != null) {
		print(" = ");
		printExpr(node.init);
	}
	if (endStatement) {
		print(";");
	}
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:17,代码来源:AstSubstitutionProcessor.java

示例2: createField

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) {
	JavacTreeMaker maker = typeNode.getTreeMaker();
	
	// private static final <loggerType> log = <factoryMethod>(<parameter>);
	JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName());
	JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName());

	JCExpression loggerName;
	if (loggerTopic == null || loggerTopic.trim().length() == 0) {
		loggerName = framework.createFactoryParameter(typeNode, loggingType);
	} else {
		loggerName = maker.Literal(loggerTopic);
	}

	JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName));

	JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
			maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)),
			typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext());
	
	injectFieldAndMarkGenerated(typeNode, fieldDecl);
	return true;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:24,代码来源:HandleLog.java

示例3: visitVarDef

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
@Override
public void visitVarDef(JCVariableDecl tree) {
    boolean isJavacPack = tree.sym.outermostClass().fullname.toString()
            .contains(packageToCheck);
    if (isJavacPack &&
        (tree.sym.flags() & SYNTHETIC) == 0 &&
        tree.sym.owner.kind == TYP) {
        if (!ignoreField(tree.sym.owner.flatName().toString(),
                tree.getName().toString())) {
            boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0;
            boolean nonFinalStaticEnumField =
                    (tree.sym.flags() & (ENUM | FINAL)) == 0;
            boolean nonFinalStaticField =
                    (tree.sym.flags() & STATIC) != 0 &&
                    (tree.sym.flags() & FINAL) == 0;
            if (enumClass ? nonFinalStaticEnumField : nonFinalStaticField) {
                messages.error(tree, "crules.err.var.must.be.final", tree);
            }
        }
    }
    super.visitVarDef(tree);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:MutableFieldsAnalyzer.java

示例4: applySubstitutions

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
String applySubstitutions(final VariableElement element) {

		final JCVariableDecl tree = (JCVariableDecl)trees.getTree(element);
		if (tree.init != null) {
			final StringWriter writer = new StringWriter();
			final SubstitutingPretty visitor = new SubstitutingPretty(
					writer,
					ImmutableSet.of(),
					trees.getPath(element).getCompilationUnit(),
					false);
			visitor.printExpr(tree.init);
			return writer.toString();
		}

		return "";
	}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:17,代码来源:AstSubstitutionProcessor.java

示例5: visitVarDef

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
@Override
public void visitVarDef(final JCVariableDecl node) {
	// Note: The behavior here is to break out list definitions such as:
	//
	// int x = 0, y = 1;
	//
	// to separate statements:
	//
	// int x = 0;
	// int y = 1;
	//
	// Places where this can't be done,
	// e.g. for loops, will call handleVarDef directly so that this
	// visitor method does not get invoked.
	handleVarDef(node, true);
}
 
开发者ID:FermioCloud,项目名称:java-code-templates,代码行数:17,代码来源:AstSubstitutionProcessor.java

示例6: visitForLoop

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的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

示例7: buildTree

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected JavacNode buildTree(JCTree node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((JCCompilationUnit) node);
	case TYPE:
		return buildType((JCClassDecl) node);
	case FIELD:
		return buildField((JCVariableDecl) node);
	case INITIALIZER:
		return buildInitializer((JCBlock) node);
	case METHOD:
		return buildMethod((JCMethodDecl) node);
	case ARGUMENT:
		return buildLocalVar((JCVariableDecl) node, kind);
	case LOCAL:
		return buildLocalVar((JCVariableDecl) node, kind);
	case STATEMENT:
		return buildStatementOrExpression(node);
	case ANNOTATION:
		return buildAnnotation((JCAnnotation) node, false);
	default:
		throw new AssertionError("Did not expect: " + kind);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:JavacAST.java

示例8: buildType

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
private JavacNode buildType(JCClassDecl type) {
	if (setAndGetAsHandled(type)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	
	for (JCAnnotation annotation : type.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, false));
	for (JCTree def : type.defs) {
		/* A def can be:
		 *   JCClassDecl for inner types
		 *   JCMethodDecl for constructors and methods
		 *   JCVariableDecl for fields
		 *   JCBlock for (static) initializers
		 */
		if (def instanceof JCMethodDecl) addIfNotNull(childNodes, buildMethod((JCMethodDecl)def));
		else if (def instanceof JCClassDecl) addIfNotNull(childNodes, buildType((JCClassDecl)def));
		else if (def instanceof JCVariableDecl) addIfNotNull(childNodes, buildField((JCVariableDecl)def));
		else if (def instanceof JCBlock) addIfNotNull(childNodes, buildInitializer((JCBlock)def));
	}
	
	return putInMap(new JavacNode(this, type, childNodes, Kind.TYPE));
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacAST.java

示例9: findFields

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
public static List<JavacNode> findFields(JavacNode typeNode, boolean nullMarked) {
	ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>();
	for (JavacNode child : typeNode.down()) {
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		long fieldFlags = fieldDecl.mods.flags;
		//Skip static fields.
		if ((fieldFlags & Flags.STATIC) != 0) continue;
		boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
		boolean isNonNull = nullMarked && !findAnnotations(child, NON_NULL_PATTERN).isEmpty();
		if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child);
	}
	return fields.toList();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:HandleConstructor.java

示例10: findAllFields

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
public static List<JavacNode> findAllFields(JavacNode typeNode) {
	ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>();
	for (JavacNode child : typeNode.down()) {
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		long fieldFlags = fieldDecl.mods.flags;
		//Skip static fields.
		if ((fieldFlags & Flags.STATIC) != 0) continue;
		//Skip initialized final fields
		boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
		if (!isFinal || fieldDecl.init == null) fields.append(child);
	}
	return fields.toList();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:17,代码来源:HandleConstructor.java

示例11: setFieldDefaultsForField

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
public void setFieldDefaultsForField(JavacNode fieldNode, AccessLevel level, boolean makeFinal) {
	JCVariableDecl field = (JCVariableDecl) fieldNode.get();
	if (level != null && level != AccessLevel.NONE) {
		if ((field.mods.flags & (Flags.PUBLIC | Flags.PRIVATE | Flags.PROTECTED)) == 0) {
			if (!hasAnnotationAndDeleteIfNeccessary(PackagePrivate.class, fieldNode)) {
				field.mods.flags |= toJavacModifier(level);
			}
		}
	}
	
	if (makeFinal && (field.mods.flags & Flags.FINAL) == 0) {
		if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, fieldNode)) {
			if ((field.mods.flags & Flags.STATIC) == 0 || field.init != null) {
				field.mods.flags |= Flags.FINAL;
			}
		}
	}
	
	fieldNode.rebuild();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:HandleFieldDefaults.java

示例12: fieldExists

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
/**
 * Checks if there is a field with the provided name.
 * 
 * @param fieldName the field name to check for.
 * @param node Any node that represents the Type (JCClassDecl) to look in, or any child node thereof.
 */
public static MemberExistsResult fieldExists(String fieldName, JavacNode node) {
	node = upToTypeNode(node);
	
	if (node != null && node.get() instanceof JCClassDecl) {
		for (JCTree def : ((JCClassDecl)node.get()).defs) {
			if (def instanceof JCVariableDecl) {
				if (((JCVariableDecl)def).name.contentEquals(fieldName)) {
					return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
				}
			}
		}
	}
	
	return MemberExistsResult.NOT_EXISTS;
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:22,代码来源:JavacHandlerUtil.java

示例13: createListOfNonExistentFields

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的package包/类
/**
 * Given a list of field names and a node referring to a type, finds each name in the list that does not match a field within the type.
 */
public static List<Integer> createListOfNonExistentFields(List<String> list, JavacNode type, boolean excludeStandard, boolean excludeTransient) {
	boolean[] matched = new boolean[list.size()];
	
	for (JavacNode child : type.down()) {
		if (list.isEmpty()) break;
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl field = (JCVariableDecl)child.get();
		if (excludeStandard) {
			if ((field.mods.flags & Flags.STATIC) != 0) continue;
			if (field.name.toString().startsWith("$")) continue;
		}
		if (excludeTransient && (field.mods.flags & Flags.TRANSIENT) != 0) continue;
		
		int idx = list.indexOf(child.getName());
		if (idx > -1) matched[idx] = true;
	}
	
	ListBuffer<Integer> problematic = new ListBuffer<Integer>();
	for (int i = 0 ; i < list.size() ; i++) {
		if (!matched[i]) problematic.append(i);
	}
	
	return problematic.toList();
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:28,代码来源:JavacHandlerUtil.java

示例14: generateCleanMethod

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的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

示例15: generateBuilderMethod

import com.sun.tools.javac.tree.JCTree.JCVariableDecl; //导入依赖的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


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