/** * Returns true if the specified class node is annotated with the {@link Trait} interface. * @param cNode a class node * @return true if the specified class node is annotated with the {@link Trait} interface. */ public static boolean isAnnotatedWithTrait(final ClassNode cNode) { List<AnnotationNode> traitAnn = cNode.getAnnotations(Traits.TRAIT_CLASSNODE); return traitAnn != null && !traitAnn.isEmpty(); }
private static boolean notTransform(ClassNode annotationClassNode) { return annotationClassNode.getAnnotations(ASTTRANSFORMCLASS_TYPE).isEmpty(); }
static boolean makeImmutable(ClassNode cNode) { List<AnnotationNode> annotations = cNode.getAnnotations(ImmutablePropertyUtils.IMMUTABLE_OPTIONS_TYPE); AnnotationNode annoImmutable = annotations.isEmpty() ? null : annotations.get(0); return annoImmutable != null; }
@Override public List<AnnotationNode> getAnnotations() { List<AnnotationNode> nodes = new LinkedList<AnnotationNode>(); for (ClassNode delegate : delegates) { List<AnnotationNode> annotations = delegate.getAnnotations(); if (annotations != null) nodes.addAll(annotations); } return nodes; }
@Override public List<AnnotationNode> getAnnotations(final ClassNode type) { List<AnnotationNode> nodes = new LinkedList<AnnotationNode>(); for (ClassNode delegate : delegates) { List<AnnotationNode> annotations = delegate.getAnnotations(type); if (annotations != null) nodes.addAll(annotations); } return nodes; }
@Override public List<AnnotationNode> getAnnotations() { lazyInitSupers(); return super.getAnnotations(); }
@Override public List<AnnotationNode> getAnnotations(ClassNode type) { lazyInitSupers(); return super.getAnnotations(type); }
private static boolean isCloneableType(ClassNode fieldType) { return isOrImplements(fieldType, CLONEABLE_TYPE) || !fieldType.getAnnotations(MY_TYPE).isEmpty(); }
public List<AnnotationNode> getAnnotations(ClassNode type) { if (redirect!=null) return redirect.getAnnotations(type); lazyClassInit(); return super.getAnnotations(type); }
public List<AnnotationNode> getAnnotations() { if (redirect!=null) return redirect.getAnnotations(); lazyClassInit(); return super.getAnnotations(); }
private static List<AnnotationNode> getTargetListFromAnnotations(ClassNode alias) { List<AnnotationNode> annotations = alias.getAnnotations(); if (annotations.size() < 2) { return Collections.emptyList(); } List<AnnotationNode> ret = new ArrayList<AnnotationNode>(annotations.size()); for (AnnotationNode an : annotations) { ClassNode type = an.getClassNode(); if (type.getName().equals(AnnotationCollector.class.getName()) || "java.lang.annotation".equals(type.getPackageName())) continue; AnnotationNode toAdd = new AnnotationNode(type); copyMembers(an, toAdd); ret.add(toAdd); } return ret; }
private static ClassNode getSerializeClass(ClassNode alias) { List<AnnotationNode> annotations = alias.getAnnotations(ClassHelper.make(AnnotationCollector.class)); if (!annotations.isEmpty()) { AnnotationNode annotationNode = annotations.get(0); Expression member = annotationNode.getMember("serializeClass"); if (member instanceof ClassExpression) { ClassExpression ce = (ClassExpression) member; if (!ce.getType().getName().equals(AnnotationCollector.class.getName())) { alias = ce.getType(); } } } return alias; }
private static boolean hasImmutableAnnotation(ClassNode type) { List<AnnotationNode> annotations = type.getAnnotations(); for (AnnotationNode next : annotations) { String name = next.getClassNode().getName(); if (matchingMarkerName(name)) return true; } return false; }
private void lazyInit() { if (lazyInitDone) return; synchronized (initLock) { if (!lazyInitDone) { for (AnnotationNode annotation : getClassNode().getAnnotations()) { VMPluginFactory.getPlugin().configureAnnotationNodeFromDefinition(annotation, this); } lazyInitDone = true; } } }
public static List<String> getKnownImmutableClasses(AbstractASTTransformation xform, ClassNode cNode) { List<AnnotationNode> annotations = cNode.getAnnotations(ImmutablePropertyUtils.IMMUTABLE_OPTIONS_TYPE); AnnotationNode anno = annotations.isEmpty() ? null : annotations.get(0); final List<String> immutableClasses = new ArrayList<String>(); if (anno == null) return immutableClasses; final Expression expression = anno.getMember(MEMBER_KNOWN_IMMUTABLE_CLASSES); if (expression == null) return immutableClasses; if (!(expression instanceof ListExpression)) { xform.addError("Use the Groovy list notation [el1, el2] to specify known immutable classes via \"" + MEMBER_KNOWN_IMMUTABLE_CLASSES + "\"", anno); return immutableClasses; } final ListExpression listExpression = (ListExpression) expression; for (Expression listItemExpression : listExpression.getExpressions()) { if (listItemExpression instanceof ClassExpression) { immutableClasses.add(listItemExpression.getType().getName()); } } return immutableClasses; } }
/** * Copies annotation from the trait to the helper, excluding the trait annotation itself * @param cNode the trait class node * @param helper the helper class node */ private static void copyClassAnnotations(final ClassNode cNode, final ClassNode helper) { List<AnnotationNode> annotations = cNode.getAnnotations(); for (AnnotationNode annotation : annotations) { if (!annotation.getClassNode().equals(Traits.TRAIT_CLASSNODE)) { helper.addAnnotation(annotation); } } }
public static List<String> getKnownImmutables(AbstractASTTransformation xform, ClassNode cNode) { List<AnnotationNode> annotations = cNode.getAnnotations(ImmutablePropertyUtils.IMMUTABLE_OPTIONS_TYPE); AnnotationNode anno = annotations.isEmpty() ? null : annotations.get(0); final List<String> immutables = new ArrayList<String>(); if (anno == null) return immutables; final Expression expression = anno.getMember(MEMBER_KNOWN_IMMUTABLES); if (expression == null) return immutables; if (!(expression instanceof ListExpression)) { xform.addError("Use the Groovy list notation [el1, el2] to specify known immutable property names via \"" + MEMBER_KNOWN_IMMUTABLES + "\"", anno); return immutables; } final ListExpression listExpression = (ListExpression) expression; for (Expression listItemExpression : listExpression.getExpressions()) { if (listItemExpression instanceof ConstantExpression) { immutables.add((String) ((ConstantExpression) listItemExpression).getValue()); } } if (!xform.checkPropertyList(cNode, immutables, "knownImmutables", anno, "immutable class", false)) return immutables; return immutables; }
public void configureAnnotation(AnnotationNode node) { ClassNode type = node.getClassNode(); VMPlugin plugin = VMPluginFactory.getPlugin(); List<AnnotationNode> annotations = type.getAnnotations(); for (AnnotationNode an : annotations) { plugin.configureAnnotationNodeFromDefinition(an, node); } plugin.configureAnnotationNodeFromDefinition(node, node); }
public static PropertyHandler createPropertyHandler(AbstractASTTransformation xform, GroovyClassLoader loader, ClassNode cNode) { List<AnnotationNode> annotations = cNode.getAnnotations(PROPERTY_OPTIONS_TYPE); AnnotationNode anno = annotations.isEmpty() ? null : annotations.get(0); if (anno == null) return new groovy.transform.options.DefaultPropertyHandler();
private void processClass(ClassNode cNode, AnnotationNode node) { if (cNode.isInterface()) { addError("Error processing interface '" + cNode.getName() + "'. " + MY_TYPE_NAME + " only allowed for classes.", cNode); return; } boolean copyConstructorAnnotations = memberHasValue(node, "constructorAnnotations", true); boolean copyParameterAnnotations = memberHasValue(node, "parameterAnnotations", true); ClassNode sNode = cNode.getSuperClass(); List<AnnotationNode> superAnnotations = sNode.getAnnotations(MY_TYPE); if (superAnnotations.size() == 1) { // We need @InheritConstructors from parent classes processed first // so force that order here. The transformation is benign on an already // processed node so processing twice in any order won't matter bar // a very small time penalty. processClass(sNode, node); } for (ConstructorNode cn : sNode.getDeclaredConstructors()) { addConstructorUnlessAlreadyExisting(cNode, cn, copyConstructorAnnotations, copyParameterAnnotations); } }