Skip to content

Commit

Permalink
Removed the dependency on lombok version 1.16.20, which was used for …
Browse files Browse the repository at this point in the history
…the experimental versions of the @builder and @value annotations. (#551)

* Removed the dependency on lombok version 1.16.20, which was used for the experimental versions of the @builder and @value annotations.

@builder was promoted in lombok from experimental to the main package in v1.16.0 on January 26th, 2015, nearly 4 years ago.
@value was promoted in lombok from experimental to the main package in v0.12.0 on July 16th, 2013, over 5 years ago.

The experimental versions of @builder and @value have been replaced with the main package versions, or otherwise removed where appropriate.

The chain and fluent options to @builder are now the default, so the BuilderChainAndFluent test was removed.
The ValueExperimental test no longer seems relevant so it was also removed.
Other tests were updated as necessary.

* Removed or updated @SuppressWarnings annotations.  Removed isFluentBuilder() and isChainBuilder() from the BuilderHandler class.

* Removed duplicate Value class annotation.

* Added non-varargs constructors to avoid using @SuppressWarnings annotations, to match AbstractClassProcessor.
  • Loading branch information
RohanTalip authored and mplushnikov committed Dec 10, 2018
1 parent 8244262 commit 543e9cb
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 211 deletions.
11 changes: 0 additions & 11 deletions build.gradle
Expand Up @@ -110,12 +110,10 @@ jacocoTestReport {
// Configurations
configurations {
lombok
lombok_dep
}

dependencies {
lombok group: 'org.projectlombok', name: 'lombok', version: '1.18.2', classifier: 'sources', ext: 'jar'
lombok_dep group: 'org.projectlombok', name: 'lombok', version: '1.16.20', classifier: 'sources', ext: 'jar'

testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.+'
Expand Down Expand Up @@ -149,15 +147,6 @@ copy {
into("generated/src")
}

copy {
includeEmptyDirs = false
from({ zipTree(configurations.lombok_dep.singleFile) }) {
include 'lombok/experimental/Value.java'
include 'lombok/experimental/Builder.java'
}
into("generated/src")
}

copy {
includeEmptyDirs = false
from({ zipTree(configurations.lombok.singleFile) }) {
Expand Down
Expand Up @@ -36,7 +36,6 @@ JavaFileManager getServiceManager(GlobalSearchScope scope) {

@Nullable
@Override
@SuppressWarnings("deprecation")
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
final int lastDot = qualifiedName.lastIndexOf('.');
if (lastDot < 0) {
Expand All @@ -51,12 +50,12 @@ public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchSc

final PsiClass parentClass = getPsiClassAndPreventRecursionCalls(parentName, scope);
if (null != parentClass) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(parentClass, Builder.class, lombok.experimental.Builder.class)) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(parentClass, Builder.class)) {
return parentClass.findInnerClassByName(shortName, false);
} else {
final Collection<PsiMethod> psiMethods = PsiClassUtil.collectClassMethodsIntern(parentClass);
for (PsiMethod psiMethod : psiMethods) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiMethod, Builder.class, lombok.experimental.Builder.class)) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiMethod, Builder.class)) {
return parentClass.findInnerClassByName(shortName, false);
}
}
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void prepareRenaming(@NotNull PsiElement element, @NotNull String newFiel
}
}

final PsiAnnotation builderAnnotation = PsiAnnotationSearchUtil.findAnnotation(containingClass, Builder.class, lombok.experimental.Builder.class);
final PsiAnnotation builderAnnotation = PsiAnnotationSearchUtil.findAnnotation(containingClass, Builder.class);
if (null != builderAnnotation) {
final PsiAnnotation singularAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiField, Singular.class);
final BuilderElementHandler handler = SingularHandlerFactory.getHandlerFor(psiField, singularAnnotation);
Expand Down
Expand Up @@ -109,7 +109,7 @@ private boolean shouldGenerateRequiredArgsConstructor(@NotNull PsiClass psiClass
boolean result = false;
// create required constructor only if there are no other constructor annotations
if (PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, NoArgsConstructor.class, RequiredArgsConstructor.class, AllArgsConstructor.class,
Builder.class, lombok.experimental.Builder.class)) {
Builder.class)) {
final Collection<PsiMethod> definedConstructors = PsiClassUtil.collectClassConstructorIntern(psiClass);
filterToleratedElements(definedConstructors);

Expand Down
Expand Up @@ -152,15 +152,14 @@ protected Collection<PsiMethod> createEqualAndHashCode(@NotNull PsiClass psiClas
return result;
}

@SuppressWarnings("deprecation")
private boolean shouldGenerateCanEqual(@NotNull PsiClass psiClass) {
final boolean isNotDirectDescendantOfObject = PsiClassUtil.hasSuperClass(psiClass);
if (isNotDirectDescendantOfObject) {
return true;
}

final boolean isFinal = psiClass.hasModifierProperty(PsiModifier.FINAL) ||
(PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class, lombok.experimental.Value.class) && PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, NonFinal.class));
(PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class) && PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, NonFinal.class));
return !isFinal;
}

Expand Down
Expand Up @@ -37,10 +37,9 @@ public class ValueProcessor extends AbstractClassProcessor {
private final AllArgsConstructorProcessor allArgsConstructorProcessor;
private final NoArgsConstructorProcessor noArgsConstructorProcessor;

@SuppressWarnings({"deprecation", "unchecked"})
public ValueProcessor(GetterProcessor getterProcessor, EqualsAndHashCodeProcessor equalsAndHashCodeProcessor,
ToStringProcessor toStringProcessor, AllArgsConstructorProcessor allArgsConstructorProcessor, NoArgsConstructorProcessor noArgsConstructorProcessor) {
super(PsiMethod.class, Value.class, lombok.experimental.Value.class);
super(PsiMethod.class, Value.class);

this.getterProcessor = getterProcessor;
this.equalsAndHashCodeProcessor = equalsAndHashCodeProcessor;
Expand Down Expand Up @@ -68,7 +67,7 @@ private boolean validateAnnotationOnRightType(@NotNull PsiClass psiClass, @NotNu
return result;
}

@SuppressWarnings("deprecation")
@SuppressWarnings({"unchecked"})
protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {

if (PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, Getter.class)) {
Expand All @@ -82,7 +81,7 @@ protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnot
}
// create required constructor only if there are no other constructor annotations
if (PsiAnnotationSearchUtil.isNotAnnotatedWith(psiClass, NoArgsConstructor.class, RequiredArgsConstructor.class, AllArgsConstructor.class,
lombok.experimental.Builder.class, lombok.Builder.class)) {
lombok.Builder.class)) {
final Collection<PsiMethod> definedConstructors = PsiClassUtil.collectClassConstructorIntern(psiClass);
filterToleratedElements(definedConstructors);
// and only if there are no any other constructors!
Expand Down
Expand Up @@ -26,6 +26,12 @@ public abstract class AbstractBuilderPreDefinedInnerClassProcessor extends Abstr

protected final BuilderHandler builderHandler;

AbstractBuilderPreDefinedInnerClassProcessor(@NotNull BuilderHandler builderHandler, @NotNull Class<? extends PsiElement> supportedClass,
@NotNull Class<? extends Annotation> supportedAnnotationClass) {
super(supportedClass, supportedAnnotationClass);
this.builderHandler = builderHandler;
}

AbstractBuilderPreDefinedInnerClassProcessor(@NotNull BuilderHandler builderHandler, @NotNull Class<? extends PsiElement> supportedClass,
@NotNull Class<? extends Annotation> supportedAnnotationClass,
@NotNull Class<? extends Annotation>... equivalentAnnotationClasses) {
Expand Down
Expand Up @@ -24,9 +24,8 @@ public class BuilderClassProcessor extends AbstractClassProcessor {

private final BuilderHandler builderHandler;

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderClassProcessor(@NotNull BuilderHandler builderHandler) {
super(PsiClass.class, Builder.class, lombok.experimental.Builder.class);
super(PsiClass.class, Builder.class);
this.builderHandler = builderHandler;
}

Expand Down
Expand Up @@ -23,9 +23,8 @@
*/
public class BuilderPreDefinedInnerClassFieldProcessor extends AbstractBuilderPreDefinedInnerClassProcessor {

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderPreDefinedInnerClassFieldProcessor(@NotNull BuilderHandler builderHandler) {
super(builderHandler, PsiField.class, Builder.class, lombok.experimental.Builder.class);
super(builderHandler, PsiField.class, Builder.class);
}

@Override
Expand Down
Expand Up @@ -23,9 +23,8 @@
*/
public class BuilderPreDefinedInnerClassMethodProcessor extends AbstractBuilderPreDefinedInnerClassProcessor {

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderPreDefinedInnerClassMethodProcessor(@NotNull BuilderHandler builderHandler) {
super(builderHandler, PsiMethod.class, Builder.class, lombok.experimental.Builder.class);
super(builderHandler, PsiMethod.class, Builder.class);
}

protected void generatePsiElements(@NotNull PsiClass psiParentClass, @Nullable PsiMethod psiParentMethod, @NotNull PsiClass psiBuilderClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
Expand Down
Expand Up @@ -38,9 +38,8 @@ public class BuilderProcessor extends AbstractClassProcessor {
private final BuilderHandler builderHandler;
private final AllArgsConstructorProcessor allArgsConstructorProcessor;

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderProcessor(@NotNull AllArgsConstructorProcessor allArgsConstructorProcessor, @NotNull BuilderHandler builderHandler) {
super(PsiMethod.class, Builder.class, lombok.experimental.Builder.class);
super(PsiMethod.class, Builder.class);
this.builderHandler = builderHandler;
this.allArgsConstructorProcessor = allArgsConstructorProcessor;
}
Expand Down
Expand Up @@ -159,10 +159,9 @@ private PsiMethod findExistedMethod(final Collection<PsiMethod> definedMethods,
}

@NotNull
@SuppressWarnings("deprecation")
protected Collection<PsiField> getAllNotInitializedAndNotStaticFields(@NotNull PsiClass psiClass) {
Collection<PsiField> allNotInitializedNotStaticFields = new ArrayList<PsiField>();
final boolean classAnnotatedWithValue = PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class, lombok.experimental.Value.class);
final boolean classAnnotatedWithValue = PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class);
for (PsiField psiField : psiClass.getFields()) {
// skip fields named $
boolean addField = !psiField.getName().startsWith(LombokUtils.LOMBOK_INTERN_FIELD_MARKER);
Expand Down Expand Up @@ -191,10 +190,9 @@ public Collection<PsiField> getAllFields(@NotNull PsiClass psiClass) {
}

@NotNull
@SuppressWarnings("deprecation")
public Collection<PsiField> getRequiredFields(@NotNull PsiClass psiClass) {
Collection<PsiField> result = new ArrayList<PsiField>();
final boolean classAnnotatedWithValue = PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class, lombok.experimental.Value.class);
final boolean classAnnotatedWithValue = PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Value.class);

for (PsiField psiField : getAllNotInitializedAndNotStaticFields(psiClass)) {
final PsiModifierList modifierList = psiField.getModifierList();
Expand Down
Expand Up @@ -118,10 +118,9 @@ private boolean validIsWitherUnique(@NotNull PsiField psiField, @NotNull final P
return true;
}

@SuppressWarnings("deprecation")
@SuppressWarnings({"unchecked"})
public boolean validConstructor(@NotNull PsiClass psiClass, @NotNull ProblemBuilder builder) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, AllArgsConstructor.class, Value.class, lombok.experimental.Value.class,
Builder.class, lombok.experimental.Builder.class)) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, AllArgsConstructor.class, Value.class, Builder.class)) {
return true;
}

Expand Down
Expand Up @@ -53,7 +53,7 @@ public class BuilderHandler {
private static final Collection<String> INVALID_ON_BUILDERS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
Getter.class.getSimpleName(), Setter.class.getSimpleName(), Wither.class.getSimpleName(), ToString.class.getSimpleName(), EqualsAndHashCode.class.getSimpleName(),
RequiredArgsConstructor.class.getSimpleName(), AllArgsConstructor.class.getSimpleName(), NoArgsConstructor.class.getSimpleName(),
Data.class.getSimpleName(), Value.class.getSimpleName(), lombok.experimental.Value.class.getSimpleName(), FieldDefaults.class.getSimpleName())));
Data.class.getSimpleName(), Value.class.getSimpleName(), FieldDefaults.class.getSimpleName())));

private final ToStringProcessor toStringProcessor;
private final NoArgsConstructorProcessor noArgsConstructorProcessor;
Expand Down Expand Up @@ -315,8 +315,7 @@ private Stream<BuilderInfo> createBuilderInfos(@NotNull PsiAnnotation psiAnnotat
result = PsiClassUtil.collectClassFieldsIntern(psiClass).stream().map(BuilderInfo::fromPsiField)
.filter(BuilderInfo::useForBuilder);
}
return result.map(info -> info.withFluent(isFluentBuilder(psiAnnotation)))
.map(info -> info.withChain(isChainBuilder(psiAnnotation)));
return result;
}

public List<BuilderInfo> createBuilderInfos(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass psiClass,
Expand Down Expand Up @@ -522,16 +521,4 @@ private void addTypeParameters(PsiClass builderClass, PsiMethod psiMethod, Lombo
methodBuilder.withTypeParameter(psiTypeParameter);
}
}

// These exist just to support the 'old' lombok.experimental.Builder, which had these properties. lombok.Builder no longer has them.
private static final String ANNOTATION_FLUENT = "fluent";
private static final String ANNOTATION_CHAIN = "chain";

private boolean isFluentBuilder(@NotNull PsiAnnotation psiAnnotation) {
return PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, ANNOTATION_FLUENT, true);
}

private boolean isChainBuilder(@NotNull PsiAnnotation psiAnnotation) {
return PsiAnnotationUtil.getBooleanAnnotationValue(psiAnnotation, ANNOTATION_CHAIN, true);
}
}
Expand Up @@ -220,7 +220,7 @@ private String buildAttributeNameString(boolean doNotUseGetters, @NotNull PsiFie
final String getterName = LombokUtils.getGetterName(classField);

final boolean hasGetter;
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Data.class, Value.class, lombok.experimental.Value.class, Getter.class)) {
if (PsiAnnotationSearchUtil.isAnnotatedWith(psiClass, Data.class, Value.class, Getter.class)) {
final PsiAnnotation getterLombokAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiClass, Getter.class);
hasGetter = null == getterLombokAnnotation || null != LombokProcessorUtil.getMethodModifier(getterLombokAnnotation);
} else {
Expand Down
Expand Up @@ -27,6 +27,10 @@
*/
public abstract class AbstractMethodProcessor extends AbstractProcessor implements MethodProcessor {

AbstractMethodProcessor(@NotNull Class<? extends PsiElement> supportedClass, @NotNull Class<? extends Annotation> supportedAnnotationClass) {
super(supportedClass, supportedAnnotationClass);
}

AbstractMethodProcessor(@NotNull Class<? extends PsiElement> supportedClass, @NotNull Class<? extends Annotation> supportedAnnotationClass, Class<? extends Annotation>... equivalentAnnotationClasses) {
super(supportedClass, supportedAnnotationClass, equivalentAnnotationClasses);
}
Expand Down
Expand Up @@ -24,9 +24,8 @@ public class BuilderClassMethodProcessor extends AbstractMethodProcessor {

private final BuilderHandler builderHandler;

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderClassMethodProcessor(@NotNull BuilderHandler builderHandler) {
super(PsiClass.class, Builder.class, lombok.experimental.Builder.class);
super(PsiClass.class, Builder.class);
this.builderHandler = builderHandler;
}

Expand Down
Expand Up @@ -24,9 +24,8 @@ public class BuilderMethodProcessor extends AbstractMethodProcessor {

private final BuilderHandler builderHandler;

@SuppressWarnings({"deprecation", "unchecked"})
public BuilderMethodProcessor(@NotNull BuilderHandler builderHandler) {
super(PsiMethod.class, Builder.class, lombok.experimental.Builder.class);
super(PsiMethod.class, Builder.class);
this.builderHandler = builderHandler;
}

Expand Down
Expand Up @@ -30,7 +30,7 @@ public boolean isSupported(@NotNull PsiModifierList modifierList) {

PsiClass searchableClass = PsiTreeUtil.getParentOfType(modifierList, PsiClass.class, true);

return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, lombok.Value.class, lombok.experimental.Value.class);
return null != searchableClass && PsiAnnotationSearchUtil.isAnnotatedWith(searchableClass, lombok.Value.class);
}

@Override
Expand Down
Expand Up @@ -37,10 +37,6 @@ public void setUp() throws Exception {
doTest(true);
}

public void testBuilder$BuilderChainAndFluent() {
doTest(true);
}

public void testBuilder$BuilderWithAccessors() {
doTest(true);
}
Expand Down
Expand Up @@ -22,11 +22,7 @@ protected boolean shouldCompareCodeBlocks() {
doTest(true);
}

public void testValue$ValueExperimental() {
doTest(true);
}

public void testValue$ValueExperimentalStarImport() {
public void testValue$ValueStarImport() {
doTest(true);
}

Expand Down
50 changes: 0 additions & 50 deletions testData/after/builder/BuilderChainAndFluent.java

This file was deleted.

6 changes: 4 additions & 2 deletions testData/after/builder/BuilderExampleCustomized.java
Expand Up @@ -19,12 +19,14 @@ public static class HelloWorldBuilder {
HelloWorldBuilder() {
}

public void setName(String name) {
public HelloWorldBuilder name(String name) {
this.name = name;
return this;
}

public void setAge(int age) {
public HelloWorldBuilder age(int age) {
this.age = age;
return this;
}

public BuilderExampleCustomized execute() {
Expand Down

0 comments on commit 543e9cb

Please sign in to comment.