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


Java FieldDefaults类代码示例

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


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

示例1: handle

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
public void handle(AnnotationValues<FieldDefaults> annotation, Annotation ast, EclipseNode annotationNode) {
	handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.FIELD_DEFAULTS_FLAG_USAGE, "@FieldDefaults");
	
	EclipseNode node = annotationNode.up();
	FieldDefaults instance = annotation.getInstance();
	AccessLevel level = instance.level();
	boolean makeFinal = instance.makeFinal();
	
	if (level == AccessLevel.NONE && !makeFinal) {
		annotationNode.addError("This does nothing; provide either level or makeFinal or both.");
		return;
	}
	
	if (level == AccessLevel.PACKAGE) {
		annotationNode.addError("Setting 'level' to PACKAGE does nothing. To force fields as package private, use the @PackagePrivate annotation on the field.");
	}
	
	if (!makeFinal && annotation.isExplicit("makeFinal")) {
		annotationNode.addError("Setting 'makeFinal' to false does nothing. To force fields to be non-final, use the @NonFinal annotation on the field.");
	}
	
	if (node == null) return;
	
	generateFieldDefaultsForType(node, annotationNode, level, makeFinal, false);
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:26,代码来源:HandleFieldDefaults.java

示例2: handle

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
@Override public void handle(AnnotationValues<FieldDefaults> annotation, JCAnnotation ast, JavacNode annotationNode) {
	deleteAnnotationIfNeccessary(annotationNode, FieldDefaults.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode node = annotationNode.up();
	FieldDefaults instance = annotation.getInstance();
	AccessLevel level = instance.level();
	boolean makeFinal = instance.makeFinal();
	
	if (level == AccessLevel.NONE && !makeFinal) {
		annotationNode.addError("This does nothing; provide either level or makeFinal or both.");
		return;
	}
	
	if (node == null) return;
	
	generateFieldDefaultsForType(node, annotationNode, level, makeFinal, false);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:18,代码来源:HandleFieldDefaults.java

示例3: handle

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
@Override public void handle(AnnotationValues<FieldDefaults> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.FIELD_DEFAULTS_FLAG_USAGE, "@FieldDefaults");
	
	deleteAnnotationIfNeccessary(annotationNode, FieldDefaults.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode node = annotationNode.up();
	FieldDefaults instance = annotation.getInstance();
	AccessLevel level = instance.level();
	boolean makeFinal = instance.makeFinal();
	
	if (level == AccessLevel.NONE && !makeFinal) {
		annotationNode.addError("This does nothing; provide either level or makeFinal or both.");
		return;
	}
	
	if (level == AccessLevel.PACKAGE) {
		annotationNode.addError("Setting 'level' to PACKAGE does nothing. To force fields as package private, use the @PackagePrivate annotation on the field.");
	}
	
	if (!makeFinal && annotation.isExplicit("makeFinal")) {
		annotationNode.addError("Setting 'makeFinal' to false does nothing. To force fields to be non-final, use the @NonFinal annotation on the field.");
	}
	
	if (node == null) return;
	
	generateFieldDefaultsForType(node, annotationNode, level, makeFinal, false);
}
 
开发者ID:mobmead,项目名称:EasyMPermission,代码行数:28,代码来源:HandleFieldDefaults.java

示例4: generateFieldDefaultsForType

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
public boolean generateFieldDefaultsForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) {
	if (checkForTypeLevelFieldDefaults) {
		if (hasAnnotation(FieldDefaults.class, typeNode)) {
			//The annotation will make it happen, so we can skip it.
			return true;
		}
	}
	
	TypeDeclaration typeDecl = null;
	if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
	int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
	boolean notAClass = (modifiers &
			(ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0;
	
	if (typeDecl == null || notAClass) {
		pos.addError("@FieldDefaults is only supported on a class or an enum.");
		return false;
	}
	
	for (EclipseNode field : typeNode.down()) {
		if (field.getKind() != Kind.FIELD) continue;
		FieldDeclaration fieldDecl = (FieldDeclaration) field.get();
		if (!filterField(fieldDecl, false)) continue;
		
		Class<?> t = field.get().getClass();
		if (t == FieldDeclaration.class) {
			// There are various other things that extend FieldDeclaration that really
			// aren't field declarations. Typing 'ma' in an otherwise blank class is a
			// CompletionOnFieldType object (extends FieldDeclaration). If we mess with the
			// modifiers of such a thing, you take away template suggestions such as
			// 'main method'. See issue 411.
			setFieldDefaultsForField(field, pos.get(), level, makeFinal);
		}
	}
	return true;
}
 
开发者ID:redundent,项目名称:lombok,代码行数:37,代码来源:HandleFieldDefaults.java

示例5: handle

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
public void handle(AnnotationValues<FieldDefaults> annotation, Annotation ast, EclipseNode annotationNode) {
	EclipseNode node = annotationNode.up();
	FieldDefaults instance = annotation.getInstance();
	AccessLevel level = instance.level();
	boolean makeFinal = instance.makeFinal();
	
	if (level == AccessLevel.NONE && !makeFinal) {
		annotationNode.addError("This does nothing; provide either level or makeFinal or both.");
		return;
	}
	
	if (node == null) return;
	
	generateFieldDefaultsForType(node, annotationNode, level, makeFinal, false);
}
 
开发者ID:redundent,项目名称:lombok,代码行数:16,代码来源:HandleFieldDefaults.java

示例6: visitType

import lombok.experimental.FieldDefaults; //导入依赖的package包/类
@Override public void visitType(JavacNode typeNode, JCClassDecl type) {
	AnnotationValues<FieldDefaults> fieldDefaults = null;
	JavacNode source = typeNode;
	
	boolean levelIsExplicit = false;
	boolean makeFinalIsExplicit = false;
	FieldDefaults fd = null;
	for (JavacNode jn : typeNode.down()) {
		if (jn.getKind() != Kind.ANNOTATION) continue;
		JCAnnotation ann = (JCAnnotation) jn.get();
		JCTree typeTree = ann.annotationType;
		if (typeTree == null) continue;
		String typeTreeToString = typeTree.toString();
		if (!typeTreeToString.equals("FieldDefaults") && !typeTreeToString.equals("lombok.experimental.FieldDefaults")) continue;
		if (!typeMatches(FieldDefaults.class, jn, typeTree)) continue;
		
		source = jn;
		fieldDefaults = createAnnotation(FieldDefaults.class, jn);
		levelIsExplicit = fieldDefaults.isExplicit("level");
		makeFinalIsExplicit = fieldDefaults.isExplicit("makeFinal");
		
		handleExperimentalFlagUsage(jn, ConfigurationKeys.FIELD_DEFAULTS_FLAG_USAGE, "@FieldDefaults");
		
		fd = fieldDefaults.getInstance();
		if (!levelIsExplicit && !makeFinalIsExplicit) {
			jn.addError("This does nothing; provide either level or makeFinal or both.");
		}
		
		if (levelIsExplicit && fd.level() == AccessLevel.NONE) {
			jn.addError("AccessLevel.NONE doesn't mean anything here. Pick another value.");
			levelIsExplicit = false;
		}
		
		deleteAnnotationIfNeccessary(jn, FieldDefaults.class);
		deleteImportFromCompilationUnit(jn, "lombok.AccessLevel");
		break;
	}
	
	if (fd == null && (type.mods.flags & (Flags.INTERFACE | Flags.ANNOTATION)) != 0) return;
	
	boolean defaultToPrivate = levelIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_PRIVATE_EVERYWHERE));
	boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
	
	if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null) return;
	AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
	boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
	
	generateFieldDefaultsForType(typeNode, source, fdAccessLevel, fdToFinal, false);
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:50,代码来源:HandleFieldDefaults.java


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