Skip to content

Commit

Permalink
[With] renaming lombok.experimental.Wither to lombok.experimental.With
Browse files Browse the repository at this point in the history
  • Loading branch information
rzwitserloot committed Aug 26, 2019
1 parent 7bf70ed commit c11edbf
Show file tree
Hide file tree
Showing 88 changed files with 912 additions and 807 deletions.
12 changes: 6 additions & 6 deletions src/core/lombok/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,14 @@ private ConfigurationKeys() {}
*/
public static final ConfigurationKey<Boolean> FIELD_NAME_CONSTANTS_UPPERCASE = new ConfigurationKey<Boolean>("lombok.fieldNameConstants.uppercase", "The default name of the constants inside the inner type generated by @FieldNameConstants follow the variable name precisely. If this config key is true, lombok will uppercase them as best it can. (default: false).") {};

// ----- Wither -----
// ----- With -----

/**
* lombok configuration: {@code lombok.wither.flagUsage} = {@code WARNING} | {@code ERROR}.
* lombok configuration: {@code lombok.with.flagUsage} = {@code WARNING} | {@code ERROR}.
*
* If set, <em>any</em> usage of {@code @Wither} results in a warning / error.
* If set, <em>any</em> usage of {@code @With} results in a warning / error.
*/
public static final ConfigurationKey<FlagUsageType> WITHER_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.wither.flagUsage", "Emit a warning or error if @Wither is used.") {};
public static final ConfigurationKey<FlagUsageType> WITH_FLAG_USAGE = new ConfigurationKey<FlagUsageType>("lombok.with.flagUsage", "Emit a warning or error if @With is used.") {};

// ----- SuperBuilder -----

Expand All @@ -625,9 +625,9 @@ private ConfigurationKeys() {}
/**
* lombok configuration: {@code lombok.copyableAnnotations} += &lt;TypeName: fully-qualified annotation class name&gt;.
*
* Copy these annotations to getters, setters, withers, builder-setters, etc.
* Copy these annotations to getters, setters, with methods, builder-setters, etc.
*/
public static final ConfigurationKey<List<TypeName>> COPYABLE_ANNOTATIONS = new ConfigurationKey<List<TypeName>>("lombok.copyableAnnotations", "Copy these annotations to getters, setters, withers, builder-setters, etc.") {};
public static final ConfigurationKey<List<TypeName>> COPYABLE_ANNOTATIONS = new ConfigurationKey<List<TypeName>>("lombok.copyableAnnotations", "Copy these annotations to getters, setters, with methods, builder-setters, etc.") {};

/**
* lombok configuration: {@code checkerframework} = {@code true} | {@code false} | &lt;String: MajorVer.MinorVer&gt; (Default: false).
Expand Down
94 changes: 94 additions & 0 deletions src/core/lombok/With.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2012-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package lombok;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import lombok.AccessLevel;

/**
* Put on any field to make lombok build a 'with' - a withX method which produces a clone of this object (except for 1 field which gets a new value).
* <p>
* Complete documentation is found at <a href="https://projectlombok.org/features/With">the project lombok features page for &#64;With</a>.
* <p>
* Example:
* <pre>
* private &#64;With final int foo;
* </pre>
*
* will generate:
*
* <pre>
* public SELF_TYPE withFoo(int foo) {
* return this.foo == foo ? this : new SELF_TYPE(otherField1, otherField2, foo);
* }
* </pre>
* <p>
* This annotation can also be applied to a class, in which case it'll be as if all non-static fields that don't already have
* a {@code With} annotation have the annotation.
*/
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
public @interface With {
/**
* If you want your with method to be non-public, you can specify an alternate access level here.
*
* @return The method will be generated with this access modifier.
*/
AccessLevel value() default AccessLevel.PUBLIC;

/**
* Any annotations listed here are put on the generated method.
* The syntax for this feature depends on JDK version (nothing we can do about that; it's to work around javac bugs).<br>
* up to JDK7:<br>
* {@code @With(onMethod=@__({@AnnotationsGoHere}))}<br>
* from JDK8:<br>
* {@code @With(onMethod_={@AnnotationsGohere})} // note the underscore after {@code onMethod}.
*
* @return List of annotations to apply to the generated method.
*/
AnyAnnotation[] onMethod() default {};

/**
* Any annotations listed here are put on the generated method's parameter.
* The syntax for this feature depends on JDK version (nothing we can do about that; it's to work around javac bugs).<br>
* up to JDK7:<br>
* {@code @With(onParam=@__({@AnnotationsGoHere}))}<br>
* from JDK8:<br>
* {@code @With(onParam_={@AnnotationsGohere})} // note the underscore after {@code onParam}.
*
* @return List of annotations to apply to the generated parameter in the method.
*/
AnyAnnotation[] onParam() default {};

/**
* Placeholder annotation to enable the placement of annotations on the generated code.
* @deprecated Don't use this annotation, ever - Read the documentation.
*/
@Deprecated
@Retention(RetentionPolicy.SOURCE)
@Target({})
@interface AnyAnnotation {}
}
3 changes: 2 additions & 1 deletion src/core/lombok/core/LombokInternalAliasing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2018 The Project Lombok Authors.
* Copyright (C) 2013-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -51,6 +51,7 @@ public static String processAliases(String in) {
m2.put("lombok.experimental.Builder", "lombok.Builder");
m2.put("lombok.experimental.var", "lombok.var");
m2.put("lombok.Delegate", "lombok.experimental.Delegate");
m2.put("lombok.experimental.Wither", "lombok.With");
ALIASES = Collections.unmodifiableMap(m2);
}
}
14 changes: 7 additions & 7 deletions src/core/lombok/core/handlers/HandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import lombok.Setter;
import lombok.ToString;
import lombok.Value;
import lombok.With;
import lombok.core.AST;
import lombok.core.AnnotationValues;
import lombok.core.JavaIdentifiers;
Expand All @@ -47,7 +48,6 @@
import lombok.core.configuration.FlagUsageType;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.Wither;

/**
* Container for static utility methods useful for some of the standard lombok handlers, regardless of
Expand Down Expand Up @@ -406,7 +406,7 @@ public static boolean shouldReturnThis0(AnnotationValues<Accessors> accessors, A
@SuppressWarnings({"all", "unchecked", "deprecation"})
public static final List<String> INVALID_ON_BUILDERS = Collections.unmodifiableList(
Arrays.<String>asList(
Getter.class.getName(), Setter.class.getName(), Wither.class.getName(),
Getter.class.getName(), Setter.class.getName(), With.class.getName(), "lombok.experimental.Wither",
ToString.class.getName(), EqualsAndHashCode.class.getName(),
RequiredArgsConstructor.class.getName(), AllArgsConstructor.class.getName(), NoArgsConstructor.class.getName(),
Data.class.getName(), Value.class.getName(), "lombok.experimental.Value", FieldDefaults.class.getName()));
Expand Down Expand Up @@ -502,7 +502,7 @@ public static String toSetterName(AST<?, ?, ?> ast, AnnotationValues<Accessors>
}

/**
* Generates a wither name from a given field name.
* Generates a with name from a given field name.
*
* Strategy:
* <ul>
Expand All @@ -518,9 +518,9 @@ public static String toSetterName(AST<?, ?, ?> ast, AnnotationValues<Accessors>
* @param accessors Accessors configuration.
* @param fieldName the name of the field.
* @param isBoolean if the field is of type 'boolean'. For fields of type {@code java.lang.Boolean}, you should provide {@code false}.
* @return The wither name for this field, or {@code null} if this field does not fit expected patterns and therefore cannot be turned into a getter name.
* @return The with name for this field, or {@code null} if this field does not fit expected patterns and therefore cannot be turned into a getter name.
*/
public static String toWitherName(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
public static String toWithName(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
return toAccessorName(ast, accessors, fieldName, isBoolean, "with", "with", false);
}

Expand Down Expand Up @@ -582,7 +582,7 @@ public static List<String> toAllSetterNames(AST<?, ?, ?> ast, AnnotationValues<A
}

/**
* Returns all names of methods that would represent the wither for a field with the provided name.
* Returns all names of methods that would represent the with for a field with the provided name.
*
* For example if {@code isBoolean} is true, then a field named {@code isRunning} would produce:<br />
* {@code [withRunning, withIsRunning]}
Expand All @@ -591,7 +591,7 @@ public static List<String> toAllSetterNames(AST<?, ?, ?> ast, AnnotationValues<A
* @param fieldName the name of the field.
* @param isBoolean if the field is of type 'boolean'. For fields of type 'java.lang.Boolean', you should provide {@code false}.
*/
public static List<String> toAllWitherNames(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
public static List<String> toAllWithNames(AST<?, ?, ?> ast, AnnotationValues<Accessors> accessors, CharSequence fieldName, boolean isBoolean) {
return toAllAccessorNames(ast, accessors, fieldName, isBoolean, "with", "with", false);
}

Expand Down
16 changes: 8 additions & 8 deletions src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1417,20 +1417,20 @@ public static String toSetterName(EclipseNode field, boolean isBoolean) {
}

/**
* Translates the given field into all possible wither names.
* Convenient wrapper around {@link TransformationsUtil#toAllWitherNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
* Translates the given field into all possible with names.
* Convenient wrapper around {@link TransformationsUtil#toAllWithNames(lombok.core.AnnotationValues, CharSequence, boolean)}.
*/
public static java.util.List<String> toAllWitherNames(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toAllWitherNames(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
public static java.util.List<String> toAllWithNames(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toAllWithNames(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
* @return the likely wither name for the stated field. (e.g. private boolean foo; to withFoo).
* @return the likely with name for the stated field. (e.g. private boolean foo; to withFoo).
*
* Convenient wrapper around {@link TransformationsUtil#toWitherName(lombok.core.AnnotationValues, CharSequence, boolean)}.
* Convenient wrapper around {@link TransformationsUtil#toWithName(lombok.core.AnnotationValues, CharSequence, boolean)}.
*/
public static String toWitherName(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toWitherName(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
public static String toWithName(EclipseNode field, boolean isBoolean) {
return HandlerUtil.toWithName(field.getAst(), getAccessorsForField(field), field.getName(), isBoolean);
}

/**
Expand Down

0 comments on commit c11edbf

Please sign in to comment.