use of com.sun.tools.javac.tree.JCTree.JCModifiers in project lombok by rzwitserloot.
the class HandleBuilder method generateBuilderFields.
public void generateBuilderFields(BuilderJob job) {
int len = job.builderFields.size();
java.util.List<JavacNode> existing = new ArrayList<JavacNode>();
for (JavacNode child : job.builderType.down()) {
if (child.getKind() == Kind.FIELD)
existing.add(child);
}
java.util.List<JCVariableDecl> generated = new ArrayList<JCVariableDecl>();
for (int i = len - 1; i >= 0; i--) {
BuilderFieldData bfd = job.builderFields.get(i);
if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
java.util.List<JavacNode> generateSingularFields = bfd.singularData.getSingularizer().generateFields(bfd.singularData, job.builderType, job.sourceNode);
for (JavacNode field : generateSingularFields) {
generated.add((JCVariableDecl) field.get());
}
bfd.createdFields.addAll(generateSingularFields);
} else {
JavacNode field = null, setFlag = null;
for (JavacNode exists : existing) {
Name n = ((JCVariableDecl) exists.get()).name;
if (n.equals(bfd.builderFieldName))
field = exists;
if (n.equals(bfd.nameOfSetFlag))
setFlag = exists;
}
JavacTreeMaker maker = job.getTreeMaker();
if (field == null) {
JCModifiers mods = maker.Modifiers(Flags.PRIVATE);
JCVariableDecl newField = maker.VarDef(mods, bfd.builderFieldName, cloneType(maker, bfd.type, job.sourceNode), null);
field = injectFieldAndMarkGenerated(job.builderType, newField);
generated.add(newField);
}
if (setFlag == null && bfd.nameOfSetFlag != null) {
JCModifiers mods = maker.Modifiers(Flags.PRIVATE);
JCVariableDecl newField = maker.VarDef(mods, bfd.nameOfSetFlag, maker.TypeIdent(CTC_BOOLEAN), null);
injectFieldAndMarkGenerated(job.builderType, newField);
generated.add(newField);
}
bfd.createdFields.add(field);
}
}
for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, job.sourceNode);
}
use of com.sun.tools.javac.tree.JCTree.JCModifiers in project lombok by rzwitserloot.
the class HandleBuilder method makeBuilderClass.
public JavacNode makeBuilderClass(BuilderJob job) {
// boolean isStatic, JavacNode source, JavacNode tdParent, String builderClassName, List<JCTypeParameter> typeParams, JCAnnotation ast, AccessLevel access) {
// isStatic, annotationNode, tdParent, builderClassName, typeParams, ast, accessForOuters
JavacTreeMaker maker = job.getTreeMaker();
int modifiers = toJavacModifier(job.accessOuters);
if (job.isStatic)
modifiers |= Flags.STATIC;
JCModifiers mods = maker.Modifiers(modifiers);
JCClassDecl builder = maker.ClassDef(mods, job.getBuilderClassName(), job.copyTypeParams(), null, List.<JCExpression>nil(), List.<JCTree>nil());
recursiveSetGeneratedBy(builder, job.sourceNode);
return injectType(job.parentType, builder);
}
use of com.sun.tools.javac.tree.JCTree.JCModifiers in project lombok by rzwitserloot.
the class JavacNode method isStatic.
@Override
public boolean isStatic() {
if (node instanceof JCClassDecl) {
JCClassDecl t = (JCClassDecl) node;
long f = t.mods.flags;
if (((Flags.INTERFACE | Flags.ENUM) & f) != 0)
return true;
JavacNode directUp = directUp();
if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT)
return true;
if (!(directUp.get() instanceof JCClassDecl))
return false;
JCClassDecl p = (JCClassDecl) directUp.get();
f = p.mods.flags;
if (((Flags.INTERFACE | Flags.ENUM) & f) != 0)
return true;
}
if (node instanceof JCVariableDecl) {
JavacNode directUp = directUp();
if (directUp != null && directUp.get() instanceof JCClassDecl) {
JCClassDecl p = (JCClassDecl) directUp.get();
long f = p.mods.flags;
if ((Flags.INTERFACE & f) != 0)
return true;
}
}
JCModifiers mods = getModifiers();
if (mods == null)
return false;
return (mods.flags & Flags.STATIC) != 0;
}
use of com.sun.tools.javac.tree.JCTree.JCModifiers in project lombok by rzwitserloot.
the class HandleSuperBuilder method generateAbstractBuildMethod.
private JCMethodDecl generateAbstractBuildMethod(SuperBuilderJob job, boolean override, String classGenericName) {
JavacTreeMaker maker = job.getTreeMaker();
List<JCAnnotation> annotations = List.nil();
if (override) {
JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(job.builderType, "Override"), List.<JCExpression>nil());
annotations = List.of(overrideAnnotation);
}
if (job.checkerFramework.generateSideEffectFree())
annotations = annotations.prepend(maker.Annotation(genTypeRef(job.builderType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
JCModifiers modifiers = maker.Modifiers(Flags.PUBLIC | Flags.ABSTRACT, annotations);
Name name = job.toName(job.buildMethodName);
JCExpression returnType = maker.Ident(job.toName(classGenericName));
JCVariableDecl recv = HandleBuilder.generateReceiver(job);
JCMethodDecl methodDef;
if (recv != null && maker.hasMethodDefWithRecvParam()) {
methodDef = maker.MethodDefWithRecvParam(modifiers, name, returnType, List.<JCTypeParameter>nil(), recv, List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
} else {
methodDef = maker.MethodDef(modifiers, name, returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
}
return methodDef;
}
use of com.sun.tools.javac.tree.JCTree.JCModifiers in project lombok by rzwitserloot.
the class HandleSuperBuilder method generateBuilderImplClass.
/**
* Creates and returns the concrete builder implementation class and injects it into the annotated class.
*/
private JavacNode generateBuilderImplClass(SuperBuilderJob job) {
JavacTreeMaker maker = job.getTreeMaker();
JCModifiers mods = maker.Modifiers(Flags.STATIC | Flags.PRIVATE | Flags.FINAL);
// Extend the abstract builder.
JCExpression extending = namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderAbstractClassName), false, List.<JCTypeParameter>nil());
// Add builder-specific type params required for inheritable builders.
// 1. The return type for the build() method (named "C" in the abstract builder), which is the annotated class.
JCExpression annotatedClass = namePlusTypeParamsToTypeReference(maker, job.parentType, job.typeParams);
// 2. The return type for all setter methods (named "B" in the abstract builder), which is this builder class.
JCExpression builderImplClassExpression = namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderImplClassName), false, job.typeParams);
ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode);
typeParamsForBuilder.append(annotatedClass);
typeParamsForBuilder.append(builderImplClassExpression);
extending = maker.TypeApply(extending, typeParamsForBuilder.toList());
JCClassDecl builder = maker.ClassDef(mods, job.toName(job.builderImplClassName), copyTypeParams(job.parentType, job.typeParams), extending, List.<JCExpression>nil(), List.<JCTree>nil());
recursiveSetGeneratedBy(builder, job.sourceNode);
return injectType(job.parentType, builder);
}
Aggregations