Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarneim committed Apr 24, 2018
2 parents cd67b8a + 72d67a4 commit 939a528
Show file tree
Hide file tree
Showing 59 changed files with 372 additions and 223 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/karneim/pojobuilder/model/PropertyM.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public String getPropertyName() {
return propertyName;
}

public boolean isField() {
return isAccessibleViaFieldAccess();
}

public String getWithMethodName() {
return withMethodName;
}
Expand Down Expand Up @@ -260,4 +264,5 @@ public String toString() {
+ readableViaGetterMethod + ", writableViaFactoryMethodParameter=" + writableViaFactoryMethodParameter
+ ", fieldAccess=" + fieldAccess + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,15 @@ private void emitWithMethodUsingBuilderInterface(TypeM builderType, TypeM selfTy
String withMethodName = prop.getWithMethodName();
String pojoTypeStr = writer.compressType(pojoType.getName());
String parameterTypeStr = prop.getParameterizedBuilderInterfaceType(interfaceType, optional).getGenericType();
String propertyLink = prop.isAccessibleViaFieldAccess()
? String.format("{@link %s#%s}", pojoTypeStr, prop.getPropertyName())
: prop.getPropertyName();

writer.emitEmptyLine();
writer.emitJavadoc("Sets the default builder for the {@link %s#%s} property.\n\n"//
writer.emitJavadoc("Sets the default builder for the %s property.\n\n"//
+ "@param builder the default builder\n"//
+ "@return this builder"//
, pojoTypeStr, prop.getPropertyName());
, propertyLink);
writer.beginMethod(selfType.getGenericType(), withMethodName, EnumSet.of(PUBLIC), parameterTypeStr, "builder");
writer.emitStatement("this.%s = builder", prop.getBuilderFieldName());
if (optional == null) {
Expand Down Expand Up @@ -438,11 +441,15 @@ private void emitWithMethod(TypeM builderType, TypeM selfType, TypeM pojoType, P
} else {
parameterTypeStr = propertyType.getGenericType();
}
String propertyLink = prop.isAccessibleViaFieldAccess()
? String.format("{@link %s#%s}", pojoTypeStr, prop.getPropertyName())
: prop.getPropertyName();

writer.emitEmptyLine();
writer.emitJavadoc("Sets the default value for the {@link %s#%s} property.\n\n"//
writer.emitJavadoc("Sets the default value for the %s property.\n\n"//
+ "@param value the default value\n"//
+ "@return this builder"//
, pojoTypeStr, prop.getPropertyName());
, propertyLink);
writer.beginMethod(selfType.getGenericType(), withMethodName, EnumSet.of(PUBLIC), parameterTypeStr, "value");
if (optional == null) {
writer.emitStatement("this.%s = value", valueFieldName);
Expand All @@ -468,12 +475,14 @@ private void emitWithOptionalMethod(TypeM builderType, TypeM selfType, TypeM poj
String pojoTypeStr = writer.compressType(pojoType.getName());
String optionalParameterTypeStr = prop.getOptionalPropertyType(optional).getGenericType();
optionalParameterTypeStr = writer.compressType(optionalParameterTypeStr);

String propertyLink = prop.isAccessibleViaFieldAccess()
? String.format("{@link %s#%s}", pojoTypeStr, prop.getPropertyName())
: prop.getPropertyName();
writer.emitEmptyLine();
writer.emitJavadoc("Optionally sets the default value for the {@link %s#%s} property.\n\n"//
writer.emitJavadoc("Optionally sets the default value for the %s property.\n\n"//
+ "@param optionalValue the optional default value\n"//
+ "@return this builder"//
, pojoTypeStr, prop.getPropertyName());
, propertyLink);
writer.beginMethod(selfType.getGenericType(), withMethodName, EnumSet.of(PUBLIC), optionalParameterTypeStr,
"optionalValue");
String condition;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.karneim.pojobuilder.processor.with.publicfields;

import net.karneim.pojobuilder.processor.AnnotationProcessor;
import net.karneim.pojobuilder.processor.with.ProcessorTestSupport;
import org.junit.Test;

import static net.karneim.pojobuilder.PbAssertions.assertThat;
import static net.karneim.pojobuilder.testenv.JavaProject.Compilation;

/**
* @feature The {@link AnnotationProcessor} generates builder classes.
*/
public class AnnotationProcessor_PublicFields_Test extends ProcessorTestSupport {

/**
* @throws Exception
*/
@Test
public void testPublicFields() {
// Given:
sourceFor(Pojo.class);
// When:
prj.compile();
// Then:
assertThat(prj)
.generatedSameSourceAs(PojoBuilder.class)
.compiled(PojoBuilder.class)
.reported(Compilation.Success);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AnotherPojoBuilder() {
}

/**
* Sets the default value for the {@link Pojo#file} property.
* Sets the default value for the file property.
*
* @param value the default value
* @return this builder
Expand All @@ -38,7 +38,7 @@ public AnotherPojoBuilder withFile(File value) {
}

/**
* Sets the default builder for the {@link Pojo#file} property.
* Sets the default builder for the file property.
*
* @param builder the default builder
* @return this builder
Expand All @@ -50,7 +50,7 @@ public AnotherPojoBuilder withFile(Builder<? extends File> builder) {
}

/**
* Sets the default value for the {@link Pojo#age} property.
* Sets the default value for the age property.
*
* @param value the default value
* @return this builder
Expand All @@ -62,7 +62,7 @@ public AnotherPojoBuilder withAge(int value) {
}

/**
* Sets the default builder for the {@link Pojo#age} property.
* Sets the default builder for the age property.
*
* @param builder the default builder
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public GenericPojoBuilder<P> withName(Builder<? extends String> builder) {
}

/**
* Sets the default value for the {@link GenericPojo#content} property.
* Sets the default value for the content property.
*
* @param value the default value
* @return this builder
Expand All @@ -58,7 +58,7 @@ public GenericPojoBuilder<P> withContent(P value) {
}

/**
* Sets the default builder for the {@link GenericPojo#content} property.
* Sets the default builder for the content property.
*
* @param builder the default builder
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Pojo2Builder() {
}

/**
* Sets the default value for the {@link Pojo2#file} property.
* Sets the default value for the file property.
*
* @param value the default value
* @return this builder
Expand All @@ -47,7 +47,7 @@ public Pojo2Builder withName(String value) {
}

/**
* Sets the default value for the {@link Pojo2#age} property.
* Sets the default value for the age property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Pojo3Builder() {
}

/**
* Sets the default value for the {@link Pojo3#file} property.
* Sets the default value for the file property.
*
* @param value the default value
* @return this builder
Expand All @@ -38,7 +38,7 @@ public Pojo3Builder withFile(File value) {
}

/**
* Sets the default builder for the {@link Pojo3#file} property.
* Sets the default builder for the file property.
*
* @param builder the default builder
* @return this builder
Expand Down Expand Up @@ -74,7 +74,7 @@ public Pojo3Builder withName(Supplier<? extends String> builder) {
}

/**
* Sets the default value for the {@link Pojo3#age} property.
* Sets the default value for the age property.
*
* @param value the default value
* @return this builder
Expand All @@ -86,7 +86,7 @@ public Pojo3Builder withAge(int value) {
}

/**
* Sets the default builder for the {@link Pojo3#age} property.
* Sets the default builder for the age property.
*
* @param builder the default builder
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PojoBuilder() {
}

/**
* Sets the default value for the {@link Pojo#file} property.
* Sets the default value for the file property.
*
* @param value the default value
* @return this builder
Expand All @@ -38,7 +38,7 @@ public PojoBuilder withFile(File value) {
}

/**
* Sets the default builder for the {@link Pojo#file} property.
* Sets the default builder for the file property.
*
* @param builder the default builder
* @return this builder
Expand Down Expand Up @@ -74,7 +74,7 @@ public PojoBuilder withName(Builder<? extends String> builder) {
}

/**
* Sets the default value for the {@link Pojo#age} property.
* Sets the default value for the age property.
*
* @param value the default value
* @return this builder
Expand All @@ -86,7 +86,7 @@ public PojoBuilder withAge(int value) {
}

/**
* Sets the default builder for the {@link Pojo#age} property.
* Sets the default builder for the age property.
*
* @param builder the default builder
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Pojo5Builder() {
}

/**
* Sets the default value for the {@link Pojo5#name} property.
* Sets the default value for the name property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Pojo2Builder() {
}

/**
* Sets the default value for the {@link Pojo2#firstname} property.
* Sets the default value for the firstname property.
*
* @param value the default value
* @return this builder
Expand All @@ -32,7 +32,7 @@ public Pojo2Builder withFirstname(String value) {
}

/**
* Sets the default value for the {@link Pojo2#surname} property.
* Sets the default value for the surname property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AddressBuilder() {
}

/**
* Sets the default value for the {@link Address#street} property.
* Sets the default value for the street property.
*
* @param value the default value
* @return this builder
Expand All @@ -34,7 +34,7 @@ public AddressBuilder withStreet(String value) {
}

/**
* Sets the default value for the {@link Address#city} property.
* Sets the default value for the city property.
*
* @param value the default value
* @return this builder
Expand All @@ -46,7 +46,7 @@ public AddressBuilder withCity(String value) {
}

/**
* Sets the default value for the {@link Address#postCode} property.
* Sets the default value for the postCode property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Pojo2Builder() {
}

/**
* Sets the default value for the {@link Pojo2#firstname} property.
* Sets the default value for the firstname property.
*
* @param value the default value
* @return this builder
Expand All @@ -32,7 +32,7 @@ public Pojo2Builder withFirstname(String value) {
}

/**
* Sets the default value for the {@link Pojo2#surname} property.
* Sets the default value for the surname property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PojoBuilder() {
}

/**
* Sets the default value for the {@link Pojo#firstname} property.
* Sets the default value for the firstname property.
*
* @param value the default value
* @return this builder
Expand All @@ -34,7 +34,7 @@ public PojoBuilder withFirstname(String value) {
}

/**
* Sets the default value for the {@link Pojo#surname} property.
* Sets the default value for the surname property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Pojo1Builder withCity(String value) {
}

/**
* Sets the default value for the {@link Pojo1#postCode} property.
* Sets the default value for the postCode property.
*
* @param value the default value
* @return this builder
Expand All @@ -60,7 +60,7 @@ public Pojo1Builder withPostCode(String value) {
}

/**
* Sets the default value for the {@link Pojo1#url} property.
* Sets the default value for the url property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ContainerBuilder() {
}

/**
* Sets the default value for the {@link Container#content} property.
* Sets the default value for the content property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public FileContainerBuilder() {
}

/**
* Sets the default value for the {@link Container#content} property.
* Sets the default value for the content property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public GenericListContainerBuilder() {
}

/**
* Sets the default value for the {@link Container#content} property.
* Sets the default value for the content property.
*
* @param value the default value
* @return this builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PairBuilder() {
}

/**
* Sets the default value for the {@link Pair#left} property.
* Sets the default value for the left property.
*
* @param value the default value
* @return this builder
Expand All @@ -32,7 +32,7 @@ public PairBuilder<L, R> withLeft(L value) {
}

/**
* Sets the default value for the {@link Pair#right} property.
* Sets the default value for the right property.
*
* @param value the default value
* @return this builder
Expand Down
Loading

0 comments on commit 939a528

Please sign in to comment.