Java Code Examples for lombok.core.AnnotationValues#isExplicit()

The following examples show how to use lombok.core.AnnotationValues#isExplicit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.REQUIRED_ARGS_CONSTRUCTOR_FLAG_USAGE, "@RequiredArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
	RequiredArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(
			typeNode, level, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO,
			suppressConstructorProperties, onConstructor, annotationNode);
}
 
Example 2
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<AllArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return;
	AllArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(
			typeNode, level, findAllFields(typeNode), staticName, SkipIfConstructorExists.NO,
			suppressConstructorProperties, onConstructor, annotationNode);
}
 
Example 3
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 6 votes vote down vote up
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);
}
 
Example 4
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.REQUIRED_ARGS_CONSTRUCTOR_FLAG_USAGE, "@RequiredArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	deleteAnnotationIfNeccessary(annotationNode, RequiredArgsConstructor.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
	List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor=", annotationNode);
	RequiredArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	
	new HandleConstructor().generateConstructor(typeNode, level, onConstructor, findRequiredFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, annotationNode);
}
 
Example 5
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
@Override public void handle(AnnotationValues<AllArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	deleteAnnotationIfNeccessary(annotationNode, AllArgsConstructor.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return;
	List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor=", annotationNode);
	AllArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	Boolean suppressConstructorProperties = null;
	if (annotation.isExplicit("suppressConstructorProperties")) {
		@SuppressWarnings("deprecation")
		boolean suppress = ann.suppressConstructorProperties();
		suppressConstructorProperties = suppress;
	}
	new HandleConstructor().generateConstructor(typeNode, level, onConstructor, findAllFields(typeNode), staticName, SkipIfConstructorExists.NO, suppressConstructorProperties, annotationNode);
}
 
Example 6
Source File: HandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static boolean shouldReturnThis0(AnnotationValues<Accessors> accessors, AST<?, ?, ?> ast) {
	boolean chainForced = accessors.isExplicit("chain");
	boolean fluentForced = accessors.isExplicit("fluent");
	Accessors instance = accessors.getInstance();
	
	boolean chain = instance.chain();
	boolean fluent = instance.fluent();
	
	if (chainForced) return chain;
	
	if (!chainForced) {
		Boolean chainConfig = ast.readConfiguration(ConfigurationKeys.ACCESSORS_CHAIN);
		if (chainConfig != null) return chainConfig;
	}
	
	if (!fluentForced) {
		Boolean fluentConfig = ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT);
		if (fluentConfig != null) fluent = fluentConfig;
	}
	
	return chain || fluent;
}
 
Example 7
Source File: HandleToString.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void handle(AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString");
	
	ToString ann = annotation.getInstance();
	List<String> excludes = Arrays.asList(ann.exclude());
	List<String> includes = Arrays.asList(ann.of());
	EclipseNode typeNode = annotationNode.up();
	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.");
	}
	
	checkForBogusFieldNames(typeNode, annotation);
	
	Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_DO_NOT_USE_GETTERS);
	boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
	FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
	
	Boolean fieldNamesConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES);
	boolean includeFieldNames = annotation.isExplicit("includeFieldNames") || fieldNamesConfiguration == null ? ann.includeFieldNames() : fieldNamesConfiguration;

	generateToString(typeNode, annotationNode, excludes, includes, includeFieldNames, callSuper, true, fieldAccess);
}
 
Example 8
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<EqualsAndHashCode> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.EQUALS_AND_HASH_CODE_FLAG_USAGE, "@EqualsAndHashCode");
	
	EqualsAndHashCode ann = annotation.getInstance();
	List<String> excludes = Arrays.asList(ann.exclude());
	List<String> includes = Arrays.asList(ann.of());
	EclipseNode typeNode = annotationNode.up();
	
	List<Annotation> 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);
}
 
Example 9
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 5 votes vote down vote up
@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);
}
 
Example 10
Source File: HandleToString.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<ToString> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString");
	
	deleteAnnotationIfNeccessary(annotationNode, ToString.class);
	
	ToString 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.");
	}
	
	Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_DO_NOT_USE_GETTERS);
	boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
	FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
	
	Boolean fieldNamesConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES);
	boolean includeFieldNames = annotation.isExplicit("includeFieldNames") || fieldNamesConfiguration == null ? ann.includeFieldNames() : fieldNamesConfiguration;
	
	generateToString(typeNode, annotationNode, excludes, includes, includeFieldNames, callSuper, true, fieldAccess);
}
 
Example 11
Source File: HandleEqualsAndHashCode.java    From EasyMPermission with MIT License 5 votes vote down vote up
@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);
}
 
Example 12
Source File: HandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static String toAccessorName(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean,
		String booleanPrefix, String normalPrefix, boolean adhereToFluent) {
	
	fieldName = fieldName.toString();
	if (fieldName.length() == 0) return null;
	
	if (Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.GETTER_CONSEQUENT_BOOLEAN))) isBoolean = false;
	boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix");
	boolean explicitFluent = accessors != null && accessors.isExplicit("fluent");
	
	Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null;
	
	List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
	boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
	
	fieldName = removePrefix(fieldName, prefix);
	if (fieldName == null) return null;
	
	String fName = fieldName.toString();
	if (adhereToFluent && fluent) return fName;
	
	if (isBoolean && fName.startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
		// The field is for example named 'isRunning'.
		return booleanPrefix + fName.substring(2);
	}
	
	return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName);
}
 
Example 13
Source File: HandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static List<String> toAllAccessorNames(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean,
		String booleanPrefix, String normalPrefix, boolean adhereToFluent) {
	
	if (Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.GETTER_CONSEQUENT_BOOLEAN))) isBoolean = false;
	if (!isBoolean) {
		String accessorName = toAccessorName(ast, accessors, fieldName, false, booleanPrefix, normalPrefix, adhereToFluent);
		return (accessorName == null) ? Collections.<String>emptyList() : Collections.singletonList(accessorName);
	}
	
	boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix");
	boolean explicitFluent = accessors != null && accessors.isExplicit("fluent");
	
	Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null;
	
	List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
	boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
	
	fieldName = removePrefix(fieldName, prefix);
	if (fieldName == null) return Collections.emptyList();
	
	List<String> baseNames = toBaseNames(fieldName, isBoolean, fluent);
	
	Set<String> names = new HashSet<String>();
	for (String baseName : baseNames) {
		if (adhereToFluent && fluent) {
			names.add(baseName);
		} else {
			names.add(buildAccessorName(normalPrefix, baseName));
			if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName));
		}
	}
	
	return new ArrayList<String>(names);
	
}