Search in sources :

Example 6 with MarkerAnnotation

use of org.eclipse.jdt.core.dom.MarkerAnnotation in project lombok by rzwitserloot.

the class PatchValEclipse method createValAnnotation.

public static MarkerAnnotation createValAnnotation(AST ast, Annotation original, int start, int end) {
    MarkerAnnotation out = null;
    try {
        out = Reflection.markerAnnotationConstructor.newInstance(ast);
    } catch (InstantiationException e) {
        throw Lombok.sneakyThrow(e);
    } catch (IllegalAccessException e) {
        throw Lombok.sneakyThrow(e);
    } catch (InvocationTargetException e) {
        throw Lombok.sneakyThrow(e);
    }
    if (out != null) {
        SimpleName valName = ast.newSimpleName("val");
        valName.setSourceRange(start, end - start + 1);
        if (original.type instanceof SingleTypeReference) {
            out.setTypeName(valName);
            setIndex(valName, 1);
        } else {
            SimpleName lombokName = ast.newSimpleName("lombok");
            lombokName.setSourceRange(start, end - start + 1);
            setIndex(lombokName, 1);
            setIndex(valName, 2);
            QualifiedName fullName = ast.newQualifiedName(lombokName, valName);
            setIndex(fullName, 1);
            fullName.setSourceRange(start, end - start + 1);
            out.setTypeName(fullName);
        }
        out.setSourceRange(start, end - start + 1);
    }
    return out;
}
Also used : MarkerAnnotation(org.eclipse.jdt.core.dom.MarkerAnnotation) SingleTypeReference(org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

MarkerAnnotation (org.eclipse.jdt.core.dom.MarkerAnnotation)6 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 Name (org.eclipse.jdt.core.dom.Name)3 SimpleName (org.eclipse.jdt.core.dom.SimpleName)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nullable (javax.annotation.Nullable)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1