use of lombok.Getter in project lombok by rzwitserloot.
the class JavacHandlerUtil method findGetter.
private static GetterMethod findGetter(JavacNode field) {
JCVariableDecl decl = (JCVariableDecl) field.get();
JavacNode typeNode = field.up();
for (String potentialGetterName : toAllGetterNames(field)) {
for (JavacNode potentialGetter : typeNode.down()) {
if (potentialGetter.getKind() != Kind.METHOD)
continue;
JCMethodDecl method = (JCMethodDecl) potentialGetter.get();
if (!method.name.toString().equalsIgnoreCase(potentialGetterName))
continue;
/**
* static getX() methods don't count.
*/
if ((method.mods.flags & Flags.STATIC) != 0)
continue;
/**
* Nor do getters with a non-empty parameter list.
*/
if (method.params != null && method.params.size() > 0)
continue;
return new GetterMethod(method.name, method.restype);
}
}
// Check if the field has a @Getter annotation.
boolean hasGetterAnnotation = false;
for (JavacNode child : field.down()) {
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Getter.class, child)) {
AnnotationValues<Getter> ann = createAnnotation(Getter.class, child);
// Definitely WONT have a getter.
if (ann.getInstance().value() == AccessLevel.NONE)
return null;
hasGetterAnnotation = true;
}
}
if (!hasGetterAnnotation && HandleGetter.fieldQualifiesForGetterGeneration(field)) {
// Check if the class has @Getter or @Data annotation.
JavacNode containingType = field.up();
if (containingType != null)
for (JavacNode child : containingType.down()) {
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Data.class, child))
hasGetterAnnotation = true;
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Getter.class, child)) {
AnnotationValues<Getter> ann = createAnnotation(Getter.class, child);
// Definitely WONT have a getter.
if (ann.getInstance().value() == AccessLevel.NONE)
return null;
hasGetterAnnotation = true;
}
}
}
if (hasGetterAnnotation) {
String getterName = toGetterName(field);
if (getterName == null)
return null;
return new GetterMethod(field.toName(getterName), decl.vartype);
}
return null;
}
use of lombok.Getter in project testcontainers-java by testcontainers.
the class DockerfileTrait method withDockerfileFromBuilder.
default SELF withDockerfileFromBuilder(Consumer<DockerfileBuilder> builderConsumer) {
DockerfileBuilder builder = new DockerfileBuilder();
builderConsumer.accept(builder);
// return Transferable because we want to build Dockerfile's content lazily
return ((SELF) this).withFileFromTransferable("Dockerfile", new Transferable() {
@Getter(lazy = true)
private final byte[] bytes = builder.build().getBytes();
@Override
public long getSize() {
return getBytes().length;
}
@Override
public String getDescription() {
return "Dockerfile: " + builder;
}
});
}
use of lombok.Getter 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;
}
}
use of lombok.Getter in project lombok by rzwitserloot.
the class HandleGetter method handle.
@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;
}
}
use of lombok.Getter in project lombok by rzwitserloot.
the class EclipseHandlerUtil method findGetter.
private static GetterMethod findGetter(EclipseNode field) {
FieldDeclaration fieldDeclaration = (FieldDeclaration) field.get();
boolean forceBool = FieldDeclaration_booleanLazyGetter.get(fieldDeclaration);
TypeReference fieldType = fieldDeclaration.type;
boolean isBoolean = forceBool || isBoolean(fieldType);
EclipseNode typeNode = field.up();
for (String potentialGetterName : toAllGetterNames(field, isBoolean)) {
for (EclipseNode potentialGetter : typeNode.down()) {
if (potentialGetter.getKind() != Kind.METHOD)
continue;
if (!(potentialGetter.get() instanceof MethodDeclaration))
continue;
MethodDeclaration method = (MethodDeclaration) potentialGetter.get();
if (!potentialGetterName.equalsIgnoreCase(new String(method.selector)))
continue;
/**
* static getX() methods don't count.
*/
if ((method.modifiers & ClassFileConstants.AccStatic) != 0)
continue;
/**
* Nor do getters with a non-empty parameter list.
*/
if (method.arguments != null && method.arguments.length > 0)
continue;
return new GetterMethod(method.selector, method.returnType);
}
}
// Check if the field has a @Getter annotation.
boolean hasGetterAnnotation = false;
for (EclipseNode child : field.down()) {
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Getter.class, child)) {
AnnotationValues<Getter> ann = createAnnotation(Getter.class, child);
// Definitely WONT have a getter.
if (ann.getInstance().value() == AccessLevel.NONE)
return null;
hasGetterAnnotation = true;
}
}
if (!hasGetterAnnotation && HandleGetter.fieldQualifiesForGetterGeneration(field)) {
// Check if the class has @Getter or @Data annotation.
EclipseNode containingType = field.up();
if (containingType != null)
for (EclipseNode child : containingType.down()) {
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Data.class, child))
hasGetterAnnotation = true;
if (child.getKind() == Kind.ANNOTATION && annotationTypeMatches(Getter.class, child)) {
AnnotationValues<Getter> ann = createAnnotation(Getter.class, child);
// Definitely WONT have a getter.
if (ann.getInstance().value() == AccessLevel.NONE)
return null;
hasGetterAnnotation = true;
}
}
}
if (hasGetterAnnotation) {
String getterName = toGetterName(field, isBoolean);
if (getterName == null)
return null;
return new GetterMethod(getterName.toCharArray(), fieldType);
}
return null;
}
Aggregations