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

The following examples show how to use lombok.core.AnnotationValues#getInstance() . 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: HandleTable.java    From sqlitemagic with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(AnnotationValues<Table> annotation, JCTree.JCAnnotation ast, JavacNode annotationNode) {
  if (environment.isProcessingFailed()) {
    return;
  }
  Table tableInstance = annotation.getInstance();

  deleteAnnotationIfNeccessary(annotationNode, Table.class);
  deleteImportFromCompilationUnit(annotationNode, Table.class.getCanonicalName());

  JavacNode tableNode = annotationNode.up();
  final JavacTreeMaker maker = tableNode.getTreeMaker();

  final String tableName = getTableName(tableInstance, tableNode);
  final TableElement tableElement = environment.getTableElementByTableName(tableName);
  generateMagicMethods(maker, tableNode);
  generateMissingIdIfNeeded(maker, tableNode, tableElement);
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
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 8
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);
	
}
 
Example 9
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 10
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 11
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 12
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 13
Source File: HandleGetter.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<Getter> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_FLAG_USAGE, "@Getter");
	
	Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
	deleteAnnotationIfNeccessary(annotationNode, Getter.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode node = annotationNode.up();
	Getter annotationInstance = annotation.getInstance();
	AccessLevel level = annotationInstance.value();
	boolean lazy = annotationInstance.lazy();
	if (lazy) handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_LAZY_FLAG_USAGE, "@Getter(lazy=true)");
	
	if (level == AccessLevel.NONE) {
		if (lazy) annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE.");
		return;
	}
	
	if (node == null) return;
	
	List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createGetterForFields(level, fields, annotationNode, true, lazy, onMethod);
		break;
	case TYPE:
		if (!onMethod.isEmpty()) {
			annotationNode.addError("'onMethod' is not supported for @Getter on a type.");
		}
		if (lazy) annotationNode.addError("'lazy' is not supported for @Getter on a type.");
		generateGetterForType(node, annotationNode, level, false);
		break;
	}
}
 
Example 14
Source File: HandleConstructor.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.NO_ARGS_CONSTRUCTOR_FLAG_USAGE, "@NoArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	deleteAnnotationIfNeccessary(annotationNode, NoArgsConstructor.class);
	deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
	JavacNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
	List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
	NoArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	if (level == AccessLevel.NONE) return;
	String staticName = ann.staticName();
	List<JavacNode> fields = List.nil();
	new HandleConstructor().generateConstructor(typeNode, level, onConstructor, fields, staticName, SkipIfConstructorExists.NO, null, annotationNode);
}
 
Example 15
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 16
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 17
Source File: HandleGetter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void handle(AnnotationValues<Getter> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_FLAG_USAGE, "@Getter");
	
	EclipseNode node = annotationNode.up();
	Getter annotationInstance = annotation.getInstance();
	AccessLevel level = annotationInstance.value();
	boolean lazy = annotationInstance.lazy();
	if (lazy) handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_LAZY_FLAG_USAGE, "@Getter(lazy=true)");
	
	if (level == AccessLevel.NONE) {
		if (lazy) annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE.");
		return;
	}
	
	if (node == null) return;
	
	List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod=", annotationNode);
	
	switch (node.getKind()) {
	case FIELD:
		createGetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, lazy, onMethod);
		break;
	case TYPE:
		if (!onMethod.isEmpty()) {
			annotationNode.addError("'onMethod' is not supported for @Getter on a type.");
		}
		if (lazy) annotationNode.addError("'lazy' is not supported for @Getter on a type.");
		generateGetterForType(node, annotationNode, level, false);
		break;
	}
}
 
Example 18
Source File: HandleConstructor.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
	handleFlagUsage(annotationNode, ConfigurationKeys.NO_ARGS_CONSTRUCTOR_FLAG_USAGE, "@NoArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
	
	EclipseNode typeNode = annotationNode.up();
	if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
	NoArgsConstructor ann = annotation.getInstance();
	AccessLevel level = ann.access();
	String staticName = ann.staticName();
	if (level == AccessLevel.NONE) return;
	List<EclipseNode> fields = new ArrayList<EclipseNode>();
	
	List<Annotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor=", annotationNode);
	
	new HandleConstructor().generateConstructor(typeNode, level, fields, staticName, SkipIfConstructorExists.NO, null, onConstructor, annotationNode);
}