Search in sources :

Example 1 with TypeName

use of lombok.core.configuration.TypeName in project lombok by rzwitserloot.

the class JavacHandlerUtil method findCopyableAnnotations.

/**
 * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
 */
public static List<JCAnnotation> findCopyableAnnotations(JavacNode node) {
    JCAnnotation anno = null;
    String annoName = null;
    for (JavacNode child : node.down()) {
        if (child.getKind() == Kind.ANNOTATION) {
            if (anno != null) {
                annoName = "";
                break;
            }
            JCAnnotation annotation = (JCAnnotation) child.get();
            annoName = annotation.annotationType.toString();
            anno = annotation;
        }
    }
    if (annoName == null)
        return List.nil();
    java.util.List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
    if (!annoName.isEmpty()) {
        for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, anno.annotationType))
            return List.of(anno);
        for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType))
            return List.of(anno);
    }
    ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
    for (JavacNode child : node.down()) {
        if (child.getKind() == Kind.ANNOTATION) {
            JCAnnotation annotation = (JCAnnotation) child.get();
            boolean match = false;
            for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, annotation.annotationType)) {
                result.append(annotation);
                match = true;
                break;
            }
            if (!match)
                for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) {
                    result.append(annotation);
                    break;
                }
        }
    }
    return result.toList();
}
Also used : TypeName(lombok.core.configuration.TypeName) JavacNode(lombok.javac.JavacNode) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 2 with TypeName

use of lombok.core.configuration.TypeName in project lombok by rzwitserloot.

the class EclipseHandlerUtil method findCopyableAnnotations.

/**
 * Searches the given field node for annotations and returns each one that is 'copyable' (either via configuration or from the base list).
 */
public static Annotation[] findCopyableAnnotations(EclipseNode node) {
    AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get();
    if (avd.annotations == null)
        return EMPTY_ANNOTATIONS_ARRAY;
    List<Annotation> result = new ArrayList<Annotation>();
    List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
    for (Annotation annotation : avd.annotations) {
        TypeReference typeRef = annotation.type;
        boolean match = false;
        if (typeRef != null && typeRef.getTypeName() != null) {
            for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, typeRef)) {
                result.add(annotation);
                match = true;
                break;
            }
            if (!match)
                for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) {
                    result.add(annotation);
                    break;
                }
        }
    }
    return result.toArray(EMPTY_ANNOTATIONS_ARRAY);
}
Also used : TypeName(lombok.core.configuration.TypeName) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) ArrayQualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference) ArrayTypeReference(org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference) SingleTypeReference(org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) ParameterizedSingleTypeReference(org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ParameterizedQualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference) AbstractVariableDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration) MarkerAnnotation(org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation) SingleMemberAnnotation(org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) NormalAnnotation(org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Aggregations

TypeName (lombok.core.configuration.TypeName)2 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)1 ListBuffer (com.sun.tools.javac.util.ListBuffer)1 ArrayList (java.util.ArrayList)1 JavacNode (lombok.javac.JavacNode)1 AbstractVariableDeclaration (org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration)1 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)1 ArrayQualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference)1 ArrayTypeReference (org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference)1 MarkerAnnotation (org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation)1 NormalAnnotation (org.eclipse.jdt.internal.compiler.ast.NormalAnnotation)1 ParameterizedQualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference)1 ParameterizedSingleTypeReference (org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference)1 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)1 SingleMemberAnnotation (org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation)1 SingleTypeReference (org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)1 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)1