Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #416 from inferred/new.annotations.not.inherited
Browse files Browse the repository at this point in the history
Stop accidentally inheriting IgnoredByEquals/NotInToString
  • Loading branch information
alicederyn authored May 24, 2019
2 parents b6ab5cf + e1aafce commit adec063
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,10 @@ private void addPropertyData(
if (jacksonSupport.isPresent()) {
jacksonSupport.get().addJacksonAnnotations(propertyBuilder, method);
}
propertyBuilder.setInEqualsAndHashCode(method.getAnnotation(IgnoredByEquals.class) == null);
propertyBuilder.setInToString(method.getAnnotation(NotInToString.class) == null);
if (method.getEnclosingElement().equals(valueType)) {
propertyBuilder.setInEqualsAndHashCode(method.getAnnotation(IgnoredByEquals.class) == null);
propertyBuilder.setInToString(method.getAnnotation(NotInToString.class) == null);
}
if (propertyType.getKind().isPrimitive()) {
PrimitiveType unboxedType = types.getPrimitiveType(propertyType.getKind());
TypeMirror boxedType = types.erasure(types.boxedClass(unboxedType).asType());
Expand Down
56 changes: 54 additions & 2 deletions src/test/java/org/inferred/freebuilder/processor/AnalyserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void twoGetters_interface() throws CannotGenerateCodeException {
}

@Test
public void ignoredEqualsAndHashCode() throws CannotGenerateCodeException {
public void ignoredByEquals() throws CannotGenerateCodeException {
GeneratedBuilder builder = (GeneratedBuilder) analyser.analyse(model.newType(
"package com.example;",
"public class DataType {",
Expand All @@ -485,7 +485,33 @@ public void ignoredEqualsAndHashCode() throws CannotGenerateCodeException {
}

@Test
public void ignoredToString() throws CannotGenerateCodeException {
public void ignoredByEquals_notInherited() throws CannotGenerateCodeException {
model.newType(
"package com.example;",
"public interface HasName {",
" @" + IgnoredByEquals.class.getName() + " public abstract String getName();",
"}");
GeneratedBuilder builder = (GeneratedBuilder) analyser.analyse(model.newType(
"package com.example;",
"public class DataType implements HasName {",
" public static class Builder extends DataType_Builder {}",
"}"));

Property name = new Property.Builder()
.setAllCapsName("NAME")
.setCapitalizedName("Name")
.setFullyCheckedCast(true)
.setGetterName("getName")
.setName("name")
.setType(model.typeMirror(String.class))
.setUsingBeanConvention(true)
.setInEqualsAndHashCode(true)
.build();
assertThat(builder.getGeneratorsByProperty().keySet()).containsExactly(name);
}

@Test
public void notInToString() throws CannotGenerateCodeException {
GeneratedBuilder builder = (GeneratedBuilder) analyser.analyse(model.newType(
"package com.example;",
"public class DataType {",
Expand All @@ -506,6 +532,32 @@ public void ignoredToString() throws CannotGenerateCodeException {
assertThat(builder.getGeneratorsByProperty().keySet()).containsExactly(name);
}

@Test
public void notInToString_notInherited() throws CannotGenerateCodeException {
model.newType(
"package com.example;",
"public interface HasName {",
" @" + NotInToString.class.getName() + " public abstract String getName();",
"}");
GeneratedBuilder builder = (GeneratedBuilder) analyser.analyse(model.newType(
"package com.example;",
"public class DataType implements HasName {",
" public static class Builder extends DataType_Builder {}",
"}"));

Property name = new Property.Builder()
.setAllCapsName("NAME")
.setCapitalizedName("Name")
.setFullyCheckedCast(true)
.setGetterName("getName")
.setName("name")
.setType(model.typeMirror(String.class))
.setUsingBeanConvention(true)
.setInToString(true)
.build();
assertThat(builder.getGeneratorsByProperty().keySet()).containsExactly(name);
}

@Test
public void ignoredEqualsAndHashCodeAndToString() throws CannotGenerateCodeException {
GeneratedBuilder builder = (GeneratedBuilder) analyser.analyse(model.newType(
Expand Down

0 comments on commit adec063

Please sign in to comment.