Search in sources :

Example 1 with FieldAccess

use of lombok.core.handlers.HandlerUtil.FieldAccess in project lombok by rzwitserloot.

the class HandleToString method handle.

public void handle(AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) {
    handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString");
    ToString ann = annotation.getInstance();
    boolean onlyExplicitlyIncluded = annotationNode.getAst().getBooleanAnnotationValue(annotation, "onlyExplicitlyIncluded", ConfigurationKeys.TO_STRING_ONLY_EXPLICITLY_INCLUDED);
    List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(annotationNode.up(), onlyExplicitlyIncluded, annotation, annotationNode);
    if (members == null)
        return;
    Boolean callSuper = ann.callSuper();
    if (!annotation.isExplicit("callSuper"))
        callSuper = null;
    Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_DO_NOT_USE_GETTERS);
    boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
    FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
    Boolean fieldNamesConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES);
    boolean includeFieldNames = annotation.isExplicit("includeFieldNames") || fieldNamesConfiguration == null ? ann.includeFieldNames() : fieldNamesConfiguration;
    generateToString(annotationNode.up(), annotationNode, members, includeFieldNames, callSuper, true, fieldAccess);
}
Also used : Included(lombok.core.handlers.InclusionExclusionUtils.Included) ToString(lombok.ToString) FieldAccess(lombok.core.handlers.HandlerUtil.FieldAccess)

Example 2 with FieldAccess

use of lombok.core.handlers.HandlerUtil.FieldAccess in project lombok by rzwitserloot.

the class HandleEqualsAndHashCode method generateEqualsAndHashCodeForType.

public void generateEqualsAndHashCodeForType(JavacNode typeNode, JavacNode source) {
    if (hasAnnotation(EqualsAndHashCode.class, typeNode)) {
        // The annotation will make it happen, so we can skip it.
        return;
    }
    Boolean doNotUseGettersConfiguration = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS);
    FieldAccess access = doNotUseGettersConfiguration == null || !doNotUseGettersConfiguration ? FieldAccess.GETTER : FieldAccess.PREFER_FIELD;
    java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members = InclusionExclusionUtils.handleEqualsAndHashCodeMarking(typeNode, null, null);
    generateMethods(typeNode, source, members, null, false, false, access, List.<JCAnnotation>nil());
}
Also used : Included(lombok.core.handlers.InclusionExclusionUtils.Included) EqualsAndHashCode(lombok.EqualsAndHashCode) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) FieldAccess(lombok.core.handlers.HandlerUtil.FieldAccess)

Example 3 with FieldAccess

use of lombok.core.handlers.HandlerUtil.FieldAccess in project lombok by rzwitserloot.

the class HandleEqualsAndHashCode method handle.

@Override
public void handle(AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) {
    handleFlagUsage(annotationNode, ConfigurationKeys.EQUALS_AND_HASH_CODE_FLAG_USAGE, "@EqualsAndHashCode");
    deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class);
    deleteImportFromCompilationUnit(annotationNode, CacheStrategy.class.getName());
    EqualsAndHashCode ann = annotation.getInstance();
    java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members = InclusionExclusionUtils.handleEqualsAndHashCodeMarking(annotationNode.up(), annotation, annotationNode);
    JavacNode typeNode = annotationNode.up();
    List<JCAnnotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@EqualsAndHashCode(onParam", annotationNode);
    Boolean callSuper = ann.callSuper();
    if (!annotation.isExplicit("callSuper"))
        callSuper = null;
    Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS);
    boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration;
    FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER;
    boolean cacheHashCode = ann.cacheStrategy() == CacheStrategy.LAZY;
    generateMethods(typeNode, annotationNode, members, callSuper, true, cacheHashCode, fieldAccess, onParam);
}
Also used : JavacNode(lombok.javac.JavacNode) EqualsAndHashCode(lombok.EqualsAndHashCode) Included(lombok.core.handlers.InclusionExclusionUtils.Included) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) FieldAccess(lombok.core.handlers.HandlerUtil.FieldAccess) CacheStrategy(lombok.EqualsAndHashCode.CacheStrategy) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 4 with FieldAccess

use of lombok.core.handlers.HandlerUtil.FieldAccess in project lombok by rzwitserloot.

the class HandleToString method generateToStringForType.

public void generateToStringForType(EclipseNode typeNode, EclipseNode errorNode) {
    if (hasAnnotation(ToString.class, typeNode)) {
        // The annotation will make it happen, so we can skip it.
        return;
    }
    AnnotationValues<ToString> anno = AnnotationValues.of(ToString.class);
    boolean includeFieldNames = typeNode.getAst().getBooleanAnnotationValue(anno, "includeFieldNames", ConfigurationKeys.TO_STRING_INCLUDE_FIELD_NAMES);
    boolean onlyExplicitlyIncluded = typeNode.getAst().getBooleanAnnotationValue(anno, "onlyExplicitlyIncluded", ConfigurationKeys.TO_STRING_ONLY_EXPLICITLY_INCLUDED);
    Boolean doNotUseGettersConfiguration = typeNode.getAst().readConfiguration(ConfigurationKeys.TO_STRING_DO_NOT_USE_GETTERS);
    FieldAccess access = doNotUseGettersConfiguration == null || !doNotUseGettersConfiguration ? FieldAccess.GETTER : FieldAccess.PREFER_FIELD;
    List<Included<EclipseNode, ToString.Include>> members = InclusionExclusionUtils.handleToStringMarking(typeNode, onlyExplicitlyIncluded, null, null);
    generateToString(typeNode, errorNode, members, includeFieldNames, null, false, access);
}
Also used : Included(lombok.core.handlers.InclusionExclusionUtils.Included) ToString(lombok.ToString) FieldAccess(lombok.core.handlers.HandlerUtil.FieldAccess)

Aggregations

FieldAccess (lombok.core.handlers.HandlerUtil.FieldAccess)4 Included (lombok.core.handlers.InclusionExclusionUtils.Included)4 JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)2 EqualsAndHashCode (lombok.EqualsAndHashCode)2 ToString (lombok.ToString)2 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)1 CacheStrategy (lombok.EqualsAndHashCode.CacheStrategy)1 JavacNode (lombok.javac.JavacNode)1