Search in sources :

Example 1 with AccessLevel

use of lombok.AccessLevel in project lombok by rzwitserloot.

the class HandleSetter method handle.

public void handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
    handleFlagUsage(annotationNode, ConfigurationKeys.SETTER_FLAG_USAGE, "@Setter");
    EclipseNode node = annotationNode.up();
    AccessLevel level = annotation.getInstance().value();
    if (level == AccessLevel.NONE || node == null)
        return;
    List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod", annotationNode);
    List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam", annotationNode);
    switch(node.getKind()) {
        case FIELD:
            createSetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
            break;
        case TYPE:
            if (!onMethod.isEmpty()) {
                annotationNode.addError("'onMethod' is not supported for @Setter on a type.");
            }
            if (!onParam.isEmpty()) {
                annotationNode.addError("'onParam' is not supported for @Setter on a type.");
            }
            generateSetterForType(node, annotationNode, level, false);
            break;
    }
}
Also used : EclipseNode(lombok.eclipse.EclipseNode) AccessLevel(lombok.AccessLevel) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Example 2 with AccessLevel

use of lombok.AccessLevel in project lombok by rzwitserloot.

the class HandleFieldDefaults method visitType.

@Override
public void visitType(EclipseNode typeNode, TypeDeclaration type) {
    AnnotationValues<FieldDefaults> fieldDefaults = null;
    EclipseNode source = typeNode;
    boolean levelIsExplicit = false;
    boolean makeFinalIsExplicit = false;
    FieldDefaults fd = null;
    for (EclipseNode jn : typeNode.down()) {
        if (jn.getKind() != Kind.ANNOTATION)
            continue;
        Annotation ann = (Annotation) jn.get();
        TypeReference typeTree = ann.type;
        if (typeTree == null)
            continue;
        if (typeTree instanceof SingleTypeReference) {
            char[] t = ((SingleTypeReference) typeTree).token;
            if (!Arrays.equals(t, FIELD_DEFAULTS))
                continue;
        } else if (typeTree instanceof QualifiedTypeReference) {
            char[][] t = ((QualifiedTypeReference) typeTree).tokens;
            if (!Eclipse.nameEquals(t, "lombok.experimental.FieldDefaults"))
                continue;
        } else {
            continue;
        }
        if (!typeMatches(FieldDefaults.class, jn, typeTree))
            continue;
        source = jn;
        fieldDefaults = createAnnotation(FieldDefaults.class, jn);
        levelIsExplicit = fieldDefaults.isExplicit("level");
        makeFinalIsExplicit = fieldDefaults.isExplicit("makeFinal");
        handleExperimentalFlagUsage(jn, ConfigurationKeys.FIELD_DEFAULTS_FLAG_USAGE, "@FieldDefaults");
        fd = fieldDefaults.getInstance();
        if (!levelIsExplicit && !makeFinalIsExplicit) {
            jn.addError("This does nothing; provide either level or makeFinal or both.");
        }
        if (levelIsExplicit && fd.level() == AccessLevel.NONE) {
            jn.addError("AccessLevel.NONE doesn't mean anything here. Pick another value.");
            levelIsExplicit = false;
        }
        break;
    }
    if (fd == null && (type.modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0)
        return;
    boolean defaultToPrivate = levelIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_PRIVATE_EVERYWHERE));
    boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
    if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null)
        return;
    AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
    boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
    generateFieldDefaultsForType(typeNode, source, fdAccessLevel, fdToFinal, false);
}
Also used : SingleTypeReference(org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) EclipseNode(lombok.eclipse.EclipseNode) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) SingleTypeReference(org.eclipse.jdt.internal.compiler.ast.SingleTypeReference) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) AccessLevel(lombok.AccessLevel) FieldDefaults(lombok.experimental.FieldDefaults)

Example 3 with AccessLevel

use of lombok.AccessLevel in project lombok by rzwitserloot.

the class HandleWither method handle.

@Override
public void handle(AnnotationValues<Wither> annotation, Annotation ast, EclipseNode annotationNode) {
    handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
    EclipseNode node = annotationNode.up();
    AccessLevel level = annotation.getInstance().value();
    if (level == AccessLevel.NONE || node == null)
        return;
    List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod", annotationNode);
    List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam", annotationNode);
    switch(node.getKind()) {
        case FIELD:
            createWitherForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod, onParam);
            break;
        case TYPE:
            if (!onMethod.isEmpty()) {
                annotationNode.addError("'onMethod' is not supported for @Wither on a type.");
            }
            if (!onParam.isEmpty()) {
                annotationNode.addError("'onParam' is not supported for @Wither on a type.");
            }
            generateWitherForType(node, annotationNode, level, false);
            break;
    }
}
Also used : EclipseNode(lombok.eclipse.EclipseNode) AccessLevel(lombok.AccessLevel) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Example 4 with AccessLevel

use of lombok.AccessLevel in project lombok by rzwitserloot.

the class HandleWither method handle.

@Override
public void handle(AnnotationValues<Wither> annotation, JCAnnotation ast, JavacNode annotationNode) {
    handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHER_FLAG_USAGE, "@Wither");
    Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields();
    deleteAnnotationIfNeccessary(annotationNode, Wither.class);
    deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
    JavacNode node = annotationNode.up();
    AccessLevel level = annotation.getInstance().value();
    if (level == AccessLevel.NONE || node == null)
        return;
    List<JCAnnotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Wither(onMethod", annotationNode);
    List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Wither(onParam", annotationNode);
    switch(node.getKind()) {
        case FIELD:
            createWitherForFields(level, fields, annotationNode, true, onMethod, onParam);
            break;
        case TYPE:
            if (!onMethod.isEmpty())
                annotationNode.addError("'onMethod' is not supported for @Wither on a type.");
            if (!onParam.isEmpty())
                annotationNode.addError("'onParam' is not supported for @Wither on a type.");
            generateWitherForType(node, annotationNode, level, false);
            break;
    }
}
Also used : JavacNode(lombok.javac.JavacNode) AccessLevel(lombok.AccessLevel) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 5 with AccessLevel

use of lombok.AccessLevel in project lombok by rzwitserloot.

the class HandleGetter method handle.

public void handle(AnnotationValues<Getter> annotation, Annotation ast, EclipseNode annotationNode) {
    handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_FLAG_USAGE, "@Getter");
    EclipseNode node = annotationNode.up();
    Getter annotationInstance = annotation.getInstance();
    AccessLevel level = annotationInstance.value();
    boolean lazy = annotationInstance.lazy();
    if (lazy)
        handleFlagUsage(annotationNode, ConfigurationKeys.GETTER_LAZY_FLAG_USAGE, "@Getter(lazy=true)");
    if (level == AccessLevel.NONE) {
        if (lazy)
            annotationNode.addWarning("'lazy' does not work with AccessLevel.NONE.");
        return;
    }
    if (node == null)
        return;
    List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Getter(onMethod", annotationNode);
    switch(node.getKind()) {
        case FIELD:
            createGetterForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, annotationNode.get(), true, lazy, onMethod);
            break;
        case TYPE:
            if (!onMethod.isEmpty()) {
                annotationNode.addError("'onMethod' is not supported for @Getter on a type.");
            }
            if (lazy)
                annotationNode.addError("'lazy' is not supported for @Getter on a type.");
            generateGetterForType(node, annotationNode, level, false);
            break;
    }
}
Also used : Getter(lombok.Getter) EclipseNode(lombok.eclipse.EclipseNode) AccessLevel(lombok.AccessLevel) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Aggregations

AccessLevel (lombok.AccessLevel)8 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)4 EclipseNode (lombok.eclipse.EclipseNode)4 JavacNode (lombok.javac.JavacNode)4 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)4 Getter (lombok.Getter)2 FieldDefaults (lombok.experimental.FieldDefaults)2 JCTree (com.sun.tools.javac.tree.JCTree)1 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)1 SingleTypeReference (org.eclipse.jdt.internal.compiler.ast.SingleTypeReference)1 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)1