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


Java FieldAccess类代码示例

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


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

示例1: handle

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
	deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
	EqualsAndHashCode ann = annotation.getInstance();
	List<String> excludes = List.from(ann.exclude());
	List<String> includes = List.from(ann.of());
	JavacNode typeNode = annotationNode.up();
	
	checkForBogusFieldNames(typeNode, annotation);
	
	Boolean callSuper = ann.callSuper();
	if (!annotation.isExplicit("callSuper")) callSuper = null;
	if (!annotation.isExplicit("exclude")) excludes = null;
	if (!annotation.isExplicit("of")) includes = null;
	
	if (excludes != null && includes != null) {
		excludes = null;
		annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
	}
	
	FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
	
	generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:24,代码来源:HandleEqualsAndHashCode.java

示例2: handle

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.EQUALS_AND_HASH_CODE_FLAG_USAGE, "@EqualsAndHashCode");
	
	deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
	EqualsAndHashCode ann = annotation.getInstance();
	List<String> excludes = List.from(ann.exclude());
	List<String> includes = List.from(ann.of());
	JavacNode typeNode = annotationNode.up();
	List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@EqualsAndHashCode(onParam=", annotationNode);
	checkForBogusFieldNames(typeNode, annotation);
	
	Boolean callSuper = ann.callSuper();
	if (!annotation.isExplicit("callSuper")) callSuper = null;
	if (!annotation.isExplicit("exclude")) excludes = null;
	if (!annotation.isExplicit("of")) includes = null;
	
	if (excludes != null && includes != null) {
		excludes = null;
		annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
	}
	
	Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS);
	boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
	FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
	
	generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess, onParam);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:28,代码来源:HandleEqualsAndHashCode.java

示例3: generateEqualsAndHashCodeForType

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
public void generateEqualsAndHashCodeForType(JavacNode typeNode, JavacNode source) {
	if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
		//The annotation will make it happen, so we can skip it.
		return;
	}
	
	generateMethods(typeNode, source, null, null, null, false, FieldAccess.GETTER, List.<JCAnnotation>nil());
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:9,代码来源:HandleEqualsAndHashCode.java

示例4: createSimpleGetterBody

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
private List<JCStatement> createSimpleGetterBody(TreeMaker treeMaker, JavacNode field) {
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);

	JCStatement returnExpression = null;
	
	String varTypeString = fieldDecl.vartype.toString();
	boolean isMutable = false;
	boolean isTypeCastNeeded = false;
	if (Timestamp.class.getSimpleName().equals(varTypeString) || Timestamp.class.getName().equals(varTypeString)) {
		isMutable = true;
		isTypeCastNeeded = true;
	} else if (varTypeString.endsWith("[]")) {
		isMutable = true;
	}
	
	if (isMutable) {
		JCExpression nullCheck = treeMaker.Binary(CTC_EQUAL, fieldRef, treeMaker.Literal(CTC_BOT, null));
		JCExpression callClone = treeMaker.Apply(List.<JCExpression>nil(), treeMaker.Select(fieldRef, field.toName("clone")), List.<JCExpression>nil());					
		if (isTypeCastNeeded) {
			callClone = treeMaker.TypeCast(
					fieldDecl.vartype,
					callClone
			);
		}
		
		JCConditional conditional = treeMaker.Conditional(
				nullCheck, 
				treeMaker.Literal(CTC_BOT, null), 
				callClone
		);
		
		returnExpression = treeMaker.Return(conditional);
	} else {
		returnExpression = treeMaker.Return(fieldRef);
	}
	
	return List.<JCStatement>of(returnExpression);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:40,代码来源:HandleGetter.java

示例5: generateEqualsAndHashCodeForType

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
public void generateEqualsAndHashCodeForType(JavacNode typeNode, JavacNode source) {
	if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
		//The annotation will make it happen, so we can skip it.
		return;
	}
	
	generateMethods(typeNode, source, null, null, null, false, FieldAccess.GETTER);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:9,代码来源:HandleEqualsAndHashCode.java

示例6: createSimpleGetterBody

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
public List<JCStatement> createSimpleGetterBody(JavacTreeMaker treeMaker, JavacNode field) {
	return List.<JCStatement>of(treeMaker.Return(createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD)));
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:4,代码来源:HandleGetter.java

示例7: createSetter

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的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

示例8: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的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

示例9: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的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

示例10: createWither

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
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);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:68,代码来源:HandleWither.java

示例11: createField

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
private static JCVariableDecl createField(Object anno, JavacNode fieldNode) {
	TreeMaker maker = fieldNode.getTreeMaker();
	JCVariableDecl field = (JCVariableDecl) fieldNode.get();
	
	String relatedFieldName = null;
	boolean isOneToOne = false;
	boolean isUnique = false;

	Name baseTypeName = ((JCClassDecl) fieldNode.up().get()).name;
	JCIdent baseType = maker.Ident(baseTypeName);		
	JCExpression referenceType = getFieldType(fieldNode, FieldAccess.ALWAYS_FIELD);
	
	if (anno instanceof OneToOne) {
		isOneToOne = true;
		relatedFieldName = ((OneToOne) anno).field();
	} else {
		relatedFieldName = ((OneToMany) anno).field();
		isUnique = ((OneToMany) anno).unique();

		if (referenceType instanceof JCTypeApply) {
			referenceType = ((JCTypeApply) referenceType).arguments.get(0);
		}
	}
	
	JCClassDecl anonClass = maker.AnonymousClassDef(
			maker.Modifiers(0),
			List.<JCTree>of(
					createGetReferencedKeyMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType),
					createSetReferencedObjectMethod(fieldNode, maker, field, baseType, isUnique),
					createSetRelatedIdMethod(fieldNode, maker, relatedFieldName, isOneToOne, baseType, referenceType)
			)
	);
	
	JCVariableDecl var = maker.VarDef(
			maker.Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL),
			fieldNode.toName(toUpperCase(field.name.toString())),
			maker.TypeApply(
					(isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
					List.<JCExpression>of(baseType, referenceType)
			),
			maker.NewClass(
					null,
					List.<JCExpression>nil(),
					maker.TypeApply(
							(isOneToOne ? chainDots(fieldNode, OneToOneRelation.class) : chainDots(fieldNode, OneToManyRelation.class)),
							List.<JCExpression>of(baseType, referenceType)
					),
					List.<JCExpression>nil(),
					anonClass
			)
	);
	
	return var;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:55,代码来源:HandleRelations.java

示例12: createSetReferencedObjectMethod

import lombok.javac.handlers.JavacHandlerUtil.FieldAccess; //导入依赖的package包/类
private static JCMethodDecl createSetReferencedObjectMethod(JavacNode fieldNode, TreeMaker maker, JCVariableDecl field, JCIdent baseType, boolean isUnique) {
	JCExpression refVariableType = getFieldType(fieldNode, FieldAccess.ALWAYS_FIELD);
	if (isUnique) {
		refVariableType = maker.TypeApply(
				chainDots(fieldNode, java.util.List.class),
				List.<JCExpression>of(refVariableType)
		);
	}
	
	JCStatement statement = null;
	if (isUnique) {
		statement = maker.Exec(
				maker.Assign(
						maker.Select(
								maker.Ident(fieldNode.toName("item")),
								field.name
						),
						maker.Apply(
								List.<JCExpression>nil(),
								maker.Select(
										maker.Ident(fieldNode.toName("this")),
										fieldNode.toName("firstOrDefault")
								),
								List.<JCExpression>of(
										maker.Ident(fieldNode.toName("ref"))
								)
						)
				)
		);
	} else {
		statement = maker.Exec(
				maker.Assign(
						maker.Select(
							maker.Ident(fieldNode.toName("item")),
							field.name
						),
						maker.Ident(fieldNode.toName("ref"))
				)
		);
	}
	return maker.MethodDef(
			maker.Modifiers(Flags.PUBLIC, List.of(maker.Annotation(chainDots(fieldNode, Override.class), List.<JCExpression>nil()))),
			fieldNode.toName("setReferencedObject"),
			maker.Type(new JCNoType(getCtcInt(TypeTags.class, "VOID"))),
			List.<JCTypeParameter>nil(),
			List.<JCVariableDecl>of(
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("item"),
							baseType,
							null
					),
					maker.VarDef(
							maker.Modifiers(Flags.FINAL),
							fieldNode.toName("ref"),
							refVariableType,
							null
					)
			),
			List.<JCExpression>nil(),
			maker.Block(
					0,
					List.<JCStatement>of(
							statement
					)
			),
			null
	);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:70,代码来源:HandleRelations.java


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