private static String getPrefix(AnnotationNode anno) { return getMemberStringValue(anno, "prefix", ""); }
public static String getMemberStringValue(AnnotationNode node, String name) { return getMemberStringValue(node, name, null); }
private static String getBuilderClassName(ClassNode buildee, AnnotationNode anno) { return getMemberStringValue(anno, "builderClassName", buildee.getNameWithoutPackage() + "Initializer"); }
private static String getFullName(AnnotationNode anno, ClassNode buildee) { String builderClassName = getMemberStringValue(anno, "builderClassName", buildee.getNameWithoutPackage() + "Builder"); return buildee.getName() + "$" + builderClassName; }
@Deprecated public static List<String> getMemberList(AnnotationNode anno, String name) { List<String> list; Expression expr = anno.getMember(name); if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; list = getValueStringList(listExpression); } else { list = tokenize(getMemberStringValue(anno, name)); } return list; }
private static Visibility getVisForAnnotation(Class<? extends AnnotatedNode> clazz, AnnotationNode visAnno, String visId) { Map<String, Expression> visMembers = visAnno.getMembers(); if (visMembers == null) return Visibility.UNDEFINED; String id = getMemberStringValue(visAnno, "id", null); if ((id == null && visId != null) || (id != null && !id.equals(visId))) return Visibility.UNDEFINED; Visibility vis = null; if (clazz.equals(ConstructorNode.class)) { vis = getVisibility(visMembers.get("constructor")); } else if (clazz.equals(MethodNode.class)) { vis = getVisibility(visMembers.get("method")); } else if (clazz.equals(ClassNode.class)) { vis = getVisibility(visMembers.get("type")); } if (vis == null || vis == Visibility.UNDEFINED) { vis = getVisibility(visMembers.get("value")); } return vis; }
private void buildCommon(ClassNode buildee, AnnotationNode anno, List<FieldNode> fieldNodes, ClassNode builder) { String prefix = getMemberStringValue(anno, "prefix", ""); String buildMethodName = getMemberStringValue(anno, "buildMethodName", "create"); createBuilderConstructors(builder, buildee, fieldNodes); buildee.getModule().addClass(builder); String builderMethodName = getMemberStringValue(anno, "builderMethodName", "createInitializer"); buildee.addMethod(createBuilderMethod(buildMethodName, builder, fieldNodes.size(), builderMethodName)); for (int i = 0; i < fieldNodes.size(); i++) { builder.addMethod(createBuilderMethodForField(builder, fieldNodes, prefix, i)); } builder.addMethod(createBuildMethod(builder, buildMethodName, fieldNodes)); }
/** * Determine the correct modifiers by looking for a potential @VisibilityOptions annotation. * * @param anno The annotation being processed (if any) which may support a 'visibilityId' attribute * @param node The node being processed which may also be annotated with @VisibilityOptions * @param clazz The type of node being constructed * @param originalModifiers The modifier value to adjust or return if no applicable @VisibilityOptions is found * @return the updated modifiers */ public static int getVisibility(AnnotationNode anno, AnnotatedNode node, Class<? extends AnnotatedNode> clazz, int originalModifiers) { List<AnnotationNode> annotations = node.getAnnotations(VISIBILITY_OPTIONS_TYPE); if (annotations.isEmpty() || anno == null) return originalModifiers; String visId = getMemberStringValue(anno, "visibilityId", null); Visibility vis = null; if (visId == null) { vis = getVisForAnnotation(clazz, annotations.get(0), null); } else { for (AnnotationNode visAnno : annotations) { vis = getVisForAnnotation(clazz, visAnno, visId); if (vis != Visibility.UNDEFINED) break; } } if (vis == null || vis == Visibility.UNDEFINED) return originalModifiers; int result = originalModifiers & ~(ACC_PUBLIC | ACC_PROTECTED | ACC_PRIVATE); return result | vis.getModifier(); }
public static List<String> getMemberStringList(AnnotationNode anno, String name) { Expression expr = anno.getMember(name); if (expr == null) { return null; } if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; if (isUndefinedMarkerList(listExpression)) { return null; } return getValueStringList(listExpression); } return tokenize(getMemberStringValue(anno, name)); }
private static MethodNode createBuilderMethod(AnnotationNode anno, ClassNode builder) { String builderMethodName = getMemberStringValue(anno, "builderMethodName", "builder"); final BlockStatement body = new BlockStatement(); body.addStatement(returnS(ctorX(builder))); return new MethodNode(builderMethodName, PUBLIC_STATIC, builder, NO_PARAMS, NO_EXCEPTIONS, body); }
private static MethodNode createBuildMethod(AnnotationNode anno, ClassNode buildee, List<PropertyInfo> props) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); body.addStatement(returnS(initializeInstance(buildee, props, body))); return new MethodNode(buildMethodName, ACC_PUBLIC, newClass(buildee), NO_PARAMS, NO_EXCEPTIONS, body); }
for (AnnotationNode node : grabResolverAnnotations) { Map<String, Object> grabResolverMap = new HashMap<String, Object>(); String sval = getMemberStringValue(node, "value"); if (sval != null && sval.length() > 0) { for (String s : GRABRESOLVER_REQUIRED) { String mval = getMemberStringValue(node, s); if (mval != null && mval.isEmpty()) mval = null; if (mval != null) { } else { for (String s : GRABRESOLVER_REQUIRED) { String mval = getMemberStringValue(node, s); Expression member = node.getMember(s); if (member == null || (mval != null && mval.isEmpty())) { for (String s : GRAB_ALL) { Expression member = node.getMember(s); String mval = getMemberStringValue(node, s); if (mval != null && mval.isEmpty()) member = null; if (member == null && !GRAB_OPTIONAL.contains(s)) {
if (!getIncludeExclude(transform, anno, buildee, excludes, includes)) return; if (includes.size() == 1 && Undefined.isUndefined(includes.get(0))) includes = null; String prefix = getMemberStringValue(anno, "prefix", "set"); List<FieldNode> fields = getFields(transform, anno, buildee); if (includes != null) {
private static MethodNode createBuildMethodForMethod(AnnotationNode anno, ClassNode buildee, MethodNode mNode, Parameter[] params) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); ClassNode returnType; if (mNode instanceof ConstructorNode) { returnType = newClass(buildee); body.addStatement(returnS(ctorX(newClass(mNode.getDeclaringClass()), args(params)))); } else { body.addStatement(returnS(callX(newClass(mNode.getDeclaringClass()), mNode.getName(), args(params)))); returnType = newClass(mNode.getReturnType()); } return new MethodNode(buildMethodName, ACC_PUBLIC, returnType, NO_PARAMS, NO_EXCEPTIONS, body); }