Search in sources :

Example 1 with Accessors

use of lombok.experimental.Accessors in project lombok by rzwitserloot.

the class HandlerUtil method toAllAccessorNames.

private static List<String> toAllAccessorNames(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean, String booleanPrefix, String normalPrefix, boolean adhereToFluent) {
    if (Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.GETTER_CONSEQUENT_BOOLEAN)))
        isBoolean = false;
    if (!isBoolean) {
        String accessorName = toAccessorName(ast, accessors, fieldName, false, booleanPrefix, normalPrefix, adhereToFluent);
        return (accessorName == null) ? Collections.<String>emptyList() : Collections.singletonList(accessorName);
    }
    boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix");
    boolean explicitFluent = accessors != null && accessors.isExplicit("fluent");
    Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null;
    List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
    boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
    fieldName = removePrefix(fieldName, prefix);
    if (fieldName == null)
        return Collections.emptyList();
    List<String> baseNames = toBaseNames(fieldName, isBoolean, fluent);
    Set<String> names = new HashSet<String>();
    for (String baseName : baseNames) {
        if (adhereToFluent && fluent) {
            names.add(baseName);
        } else {
            names.add(buildAccessorName(normalPrefix, baseName));
            if (!normalPrefix.equals(booleanPrefix))
                names.add(buildAccessorName(booleanPrefix, baseName));
        }
    }
    return new ArrayList<String>(names);
}
Also used : ArrayList(java.util.ArrayList) ToString(lombok.ToString) Accessors(lombok.experimental.Accessors) HashSet(java.util.HashSet)

Example 2 with Accessors

use of lombok.experimental.Accessors in project lombok by rzwitserloot.

the class HandlerUtil method toAccessorName.

private static String toAccessorName(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean, String booleanPrefix, String normalPrefix, boolean adhereToFluent) {
    fieldName = fieldName.toString();
    if (fieldName.length() == 0)
        return null;
    if (Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.GETTER_CONSEQUENT_BOOLEAN)))
        isBoolean = false;
    boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix");
    boolean explicitFluent = accessors != null && accessors.isExplicit("fluent");
    Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null;
    List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
    boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
    fieldName = removePrefix(fieldName, prefix);
    if (fieldName == null)
        return null;
    String fName = fieldName.toString();
    if (adhereToFluent && fluent)
        return fName;
    if (isBoolean && fName.startsWith("is") && fieldName.length() > 2 && !Character.isLowerCase(fieldName.charAt(2))) {
        // The field is for example named 'isRunning'.
        return booleanPrefix + fName.substring(2);
    }
    return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName);
}
Also used : ToString(lombok.ToString) Accessors(lombok.experimental.Accessors)

Example 3 with Accessors

use of lombok.experimental.Accessors in project lombok by rzwitserloot.

the class HandlerUtil method shouldReturnThis0.

public static boolean shouldReturnThis0(AnnotationValues<Accessors> accessors, AST<?, ?, ?> ast) {
    boolean chainForced = accessors.isExplicit("chain");
    boolean fluentForced = accessors.isExplicit("fluent");
    Accessors instance = accessors.getInstance();
    boolean chain = instance.chain();
    boolean fluent = instance.fluent();
    if (chainForced)
        return chain;
    if (!chainForced) {
        Boolean chainConfig = ast.readConfiguration(ConfigurationKeys.ACCESSORS_CHAIN);
        if (chainConfig != null)
            return chainConfig;
    }
    if (!fluentForced) {
        Boolean fluentConfig = ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT);
        if (fluentConfig != null)
            fluent = fluentConfig;
    }
    return chain || fluent;
}
Also used : Accessors(lombok.experimental.Accessors)

Aggregations

Accessors (lombok.experimental.Accessors)3 ToString (lombok.ToString)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1