use of lombok.AccessLevel in project lombok by rzwitserloot.
the class HandleSetter method handle.
public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.SETTER_FLAG_USAGE, "@Setter");
EclipseNode node = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
if (level == AccessLevel.NONE || node == null)
return;
List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod", annotationNode);
List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam", annotationNode);
switch(node.getKind()) {
case FIELD:
createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
break;
case TYPE:
if (!onMethod.isEmpty()) {
annotationNode.addError("'onMethod' is not supported for @Setter on a type.");
}
if (!onParam.isEmpty()) {
annotationNode.addError("'onParam' is not supported for @Setter on a type.");
}
generateSetterForType(node, annotationNode, level, false);
break;
}
}
use of lombok.AccessLevel in project lombok by rzwitserloot.
the class HandleFieldDefaults method visitType.
@Override
public void visitType(EclipseNode typeNode, TypeDeclaration type) {
AnnotationValues<FieldDefaults> fieldDefaults = null;
EclipseNode source = typeNode;
boolean levelIsExplicit = false;
boolean makeFinalIsExplicit = false;
FieldDefaults fd = null;
for (EclipseNode jn : typeNode.down()) {
if (jn.getKind() != Kind.ANNOTATION)
continue;
Annotation ann = (Annotation) jn.get();
TypeReference typeTree = ann.type;
if (typeTree == null)
continue;
if (typeTree instanceof SingleTypeReference) {
char[] t = ((SingleTypeReference) typeTree).token;
if (!Arrays.equals(t, FIELD_DEFAULTS))
continue;
} else if (typeTree instanceof QualifiedTypeReference) {
char[][] t = ((QualifiedTypeReference) typeTree).tokens;
if (!Eclipse.nameEquals(t, "lombok.experimental.FieldDefaults"))
continue;
} else {
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;
}
break;
}
if (fd == null && (type.modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 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);
}
use of lombok.AccessLevel in project lombok by rzwitserloot.
the class HandleWither method handle.
@Override
public void handle(AnnotationValues<Wither> annotation, Annotation ast, EclipseNode annotationNode) {
handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
EclipseNode node = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
if (level == AccessLevel.NONE || node == null)
return;
List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod", annotationNode);
List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam", annotationNode);
switch(node.getKind()) {
case FIELD:
createWitherForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
break;
case TYPE:
if (!onMethod.isEmpty()) {
annotationNode.addError("'onMethod' is not supported for @Wither on a type.");
}
if (!onParam.isEmpty()) {
annotationNode.addError("'onParam' is not supported for @Wither on a type.");
}
generateWitherForType(node, annotationNode, level, false);
break;
}
}
use of lombok.AccessLevel in project lombok by rzwitserloot.
the class HandleWither method handle.
@Override
public void handle(AnnotationValues<Wither> annotation, JCAnnotation ast, JavacNode annotationNode) {
handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
deleteAnnotationIfNeccessary(annotationNode, Wither.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode node = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
if (level == AccessLevel.NONE || node == null)
return;
List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod", annotationNode);
List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam", annotationNode);
switch(node.getKind()) {
case FIELD:
createWitherForFields(level, fields, annotationNode, true, onMethod, onParam);
break;
case TYPE:
if (!onMethod.isEmpty())
annotationNode.addError("'onMethod' is not supported for @Wither on a type.");
if (!onParam.isEmpty())
annotationNode.addError("'onParam' is not supported for @Wither on a type.");
generateWitherForType(node, annotationNode, level, false);
break;
}
}
use of lombok.AccessLevel in project lombok by rzwitserloot.
the class HandleGetter method handle.
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;
}
}
Aggregations