├── .checkstyle
├── .gitattributes
├── .github
└── workflows
│ ├── ci.yml
│ └── publish.yml
├── .gitignore
├── .test
└── .checkstyle
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── build.gradle
├── config
└── checkstyle
│ ├── checkstyle.xml
│ └── suppressions.xml
├── generated
└── main
│ └── java
│ └── org
│ └── inferred
│ └── freebuilder
│ └── processor
│ ├── BuildableType_Builder.java
│ ├── Datatype_Builder.java
│ ├── property
│ └── Property_Builder.java
│ └── source
│ └── TypeUsage_Builder.java
├── gradle.properties
├── gradle
├── java-compatibility.gradle
├── publication.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jar-footprint.txt
└── src
├── it
├── gwt
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── org
│ │ │ └── inferred
│ │ │ └── freebuilder
│ │ │ └── client
│ │ │ └── rpc
│ │ │ ├── MapGwtType.java
│ │ │ ├── NestedListGwtType.java
│ │ │ ├── OptionalGwtType.java
│ │ │ └── StringListGwtType.java
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── inferred
│ │ │ └── freebuilder
│ │ │ ├── GwtTests.java
│ │ │ ├── client
│ │ │ └── rpc
│ │ │ │ ├── MapTest.java
│ │ │ │ ├── MapTestService.java
│ │ │ │ ├── MapTestServiceAsync.java
│ │ │ │ ├── NestedListTest.java
│ │ │ │ ├── NestedListTestService.java
│ │ │ │ ├── NestedListTestServiceAsync.java
│ │ │ │ ├── OptionalTest.java
│ │ │ │ ├── OptionalTestService.java
│ │ │ │ ├── OptionalTestServiceAsync.java
│ │ │ │ ├── StringListTest.java
│ │ │ │ ├── StringListTestService.java
│ │ │ │ └── StringListTestServiceAsync.java
│ │ │ └── server
│ │ │ └── rpc
│ │ │ ├── MapTestServiceImpl.java
│ │ │ ├── NestedListTestServiceImpl.java
│ │ │ ├── OptionalTestServiceImpl.java
│ │ │ └── StringListTestServiceImpl.java
│ │ └── resources
│ │ └── org
│ │ └── inferred
│ │ └── freebuilder
│ │ └── TestServer.gwt.xml
├── lambda
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── org
│ │ │ └── inferred
│ │ │ └── freebuilder
│ │ │ ├── BiMapPropertyType.java
│ │ │ ├── DefaultedPropertiesType.java
│ │ │ ├── ListMultimapPropertyType.java
│ │ │ ├── ListPropertyType.java
│ │ │ ├── MapPropertyType.java
│ │ │ ├── MultisetPropertyType.java
│ │ │ ├── OptionalPropertiesType.java
│ │ │ ├── RequiredPropertiesType.java
│ │ │ ├── SetMultimapPropertyType.java
│ │ │ └── SetPropertyType.java
│ │ └── test
│ │ └── java
│ │ └── org
│ │ └── inferred
│ │ └── freebuilder
│ │ ├── BiMapPropertiesTest.java
│ │ ├── DefaultedPropertiesTest.java
│ │ ├── ListMultimapPropertiesTest.java
│ │ ├── ListPropertiesTest.java
│ │ ├── MapPropertiesTest.java
│ │ ├── MultisetPropertiesTest.java
│ │ ├── OptionalPropertiesTest.java
│ │ ├── RequiredPropertiesTest.java
│ │ ├── SetMultimapPropertiesTest.java
│ │ └── SetPropertiesTest.java
├── no-guava-j8
│ ├── invoker.properties
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── org
│ │ │ └── inferred
│ │ │ └── freebuilder
│ │ │ ├── OptionalProperties.java
│ │ │ └── OptionalProperty.java
│ │ └── test
│ │ └── java
│ │ └── org
│ │ └── inferred
│ │ └── freebuilder
│ │ ├── OptionalPropertiesTest.java
│ │ └── OptionalPropertyTest.java
├── no-guava
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── org
│ │ │ └── inferred
│ │ │ └── freebuilder
│ │ │ ├── ListProperty.java
│ │ │ ├── MapProperty.java
│ │ │ ├── PrimitiveProperty.java
│ │ │ └── SetProperty.java
│ │ └── test
│ │ └── java
│ │ └── org
│ │ └── inferred
│ │ └── freebuilder
│ │ ├── ListPropertyTest.java
│ │ ├── MapPropertyTest.java
│ │ ├── PrimitivePropertyTest.java
│ │ └── SetPropertyTest.java
└── vanilla
│ └── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── inferred
│ │ └── freebuilder
│ │ ├── DefaultedPropertiesType.java
│ │ ├── JacksonAnyGetterType.java
│ │ ├── MapGwtType.java
│ │ ├── NestedListGwtType.java
│ │ ├── NoFrillsDataInterface.java
│ │ ├── NoFrillsDataType.java
│ │ ├── OptionalGwtType.java
│ │ ├── RequiredPropertiesType.java
│ │ ├── StringListGwtType.java
│ │ └── WildcardListType.java
│ └── test
│ └── java
│ └── org
│ └── inferred
│ └── freebuilder
│ ├── DefaultsOptimizationTest.java
│ ├── JacksonAnyGetterTypeTest.java
│ ├── MapGwtTypeTest.java
│ ├── NestedListGwtTypeTest.java
│ ├── NoFrillsDataInterfaceTest.java
│ ├── NoFrillsDataTypeTest.java
│ ├── OptionalGwtTypeTest.java
│ ├── StringListGwtTypeTest.java
│ └── WildcardListTypeTest.java
├── main
└── java
│ └── org
│ └── inferred
│ └── freebuilder
│ ├── FreeBuilder.java
│ ├── IgnoredByEquals.java
│ ├── NotInToString.java
│ └── processor
│ ├── Analyser.java
│ ├── BuildableType.java
│ ├── BuilderFactory.java
│ ├── BuilderMethods.java
│ ├── Datatype.java
│ ├── Declarations.java
│ ├── GeneratedBuilder.java
│ ├── GeneratedStub.java
│ ├── GeneratedType.java
│ ├── GwtSupport.java
│ ├── JacksonSupport.java
│ ├── NameAndVisibility.java
│ ├── NamePicker.java
│ ├── Processor.java
│ ├── ToStringGenerator.java
│ ├── excerpt
│ ├── BuildableList.java
│ ├── CheckedBiMap.java
│ ├── CheckedList.java
│ ├── CheckedListMultimap.java
│ ├── CheckedMap.java
│ ├── CheckedMultiset.java
│ ├── CheckedNavigableSet.java
│ ├── CheckedSet.java
│ └── CheckedSetMultimap.java
│ ├── model
│ ├── MethodFinder.java
│ ├── MethodIntrospector.java
│ ├── ModelUtils.java
│ └── javac
│ │ └── JavacMethodIntrospector.java
│ ├── naming
│ ├── BeanConvention.java
│ ├── NamingConvention.java
│ ├── NamingConventions.java
│ └── PrefixlessConvention.java
│ ├── property
│ ├── BiMapProperty.java
│ ├── BuildableListProperty.java
│ ├── BuildableProperty.java
│ ├── DefaultProperty.java
│ ├── Factories.java
│ ├── ListMultimapProperty.java
│ ├── ListProperty.java
│ ├── MapProperty.java
│ ├── MergeAction.java
│ ├── MultisetProperty.java
│ ├── NullableProperty.java
│ ├── OptionalProperty.java
│ ├── PrimitiveOptionalProperty.java
│ ├── Property.java
│ ├── PropertyCodeGenerator.java
│ ├── SetMultimapProperty.java
│ ├── SetProperty.java
│ └── SortedSetProperty.java
│ └── source
│ ├── AnnotationSource.java
│ ├── CompilationUnitBuilder.java
│ ├── CompilerReflection.java
│ ├── ElementAppender.java
│ ├── Excerpt.java
│ ├── Excerpts.java
│ ├── FieldAccess.java
│ ├── FilerUtils.java
│ ├── FunctionalType.java
│ ├── IdKey.java
│ ├── ImportManager.java
│ ├── IsInvalidTypeVisitor.java
│ ├── LazyName.java
│ ├── ObjectsExcerpts.java
│ ├── PreconditionExcerpts.java
│ ├── QualifiedName.java
│ ├── QualifiedNameAppendable.java
│ ├── Quotes.java
│ ├── RoundEnvironments.java
│ ├── RuntimeReflection.java
│ ├── Scope.java
│ ├── ScopeHandler.java
│ ├── Shading.java
│ ├── SourceBuilder.java
│ ├── SourceParser.java
│ ├── TemplateApplier.java
│ ├── Type.java
│ ├── TypeClass.java
│ ├── TypeMirrorAppender.java
│ ├── TypeUsage.java
│ ├── ValueType.java
│ ├── Variable.java
│ └── feature
│ ├── EnvironmentFeatureSet.java
│ ├── Feature.java
│ ├── FeatureSet.java
│ ├── FeatureType.java
│ ├── GuavaLibrary.java
│ ├── JavaxPackage.java
│ ├── Jsr305.java
│ ├── SourceLevel.java
│ └── StaticFeatureSet.java
└── test
└── java
└── org
└── inferred
└── freebuilder
└── processor
├── AbstractBuilderTest.java
├── AnalyserTest.java
├── BuildableTypeTest.java
├── BuilderFactoryTest.java
├── FeatureSets.java
├── GeneratedTypeSubject.java
├── JacksonIntegrationTest.java
├── JacksonSupportTest.java
├── MultimapSubject.java
├── NamePickerTest.java
├── NamingConvention.java
├── ProcessorTest.java
├── ToStringGeneratorTest.java
├── model
├── ClassTypeImpl.java
├── GenericElement.java
├── GenericElementParameter.java
├── GenericElementTest.java
├── GenericMirror.java
├── GenericTypeElementImpl.java
├── ModelUtilsTest.java
├── NameImpl.java
├── NoTypes.java
├── NullTypeImpl.java
├── PackageElementImpl.java
├── PrimitiveTypeImpl.java
├── TypeParameterElementImpl.java
├── TypeVariableImpl.java
└── WildcardTypeImpl.java
├── property
├── ArrayPropertiesTest.java
├── BiMapMutateMethodTest.java
├── BiMapPropertyTest.java
├── BiMapSourceTest.java
├── BuildableListMutateMethodTest.java
├── BuildableListPropertyTest.java
├── BuildablePropertyTest.java
├── DefaultSourceTest.java
├── DefaultedMapperMethodTest.java
├── DefaultedPropertiesTest.java
├── DodgyIterable.java
├── ElementFactory.java
├── GenericTypeTest.java
├── GuavaOptionalSourceTest.java
├── JavaUtilOptionalSourceTest.java
├── ListMultimapMutateMethodTest.java
├── ListMultimapPropertyTest.java
├── ListMutateMethodTest.java
├── ListPropertyTest.java
├── ListSourceTest.java
├── MapMutateMethodTest.java
├── MapPropertyTest.java
├── MapSourceTest.java
├── MergeActionTest.java
├── MultisetMutateMethodTest.java
├── MultisetPropertyTest.java
├── NullableMapperMethodTest.java
├── NullablePropertyFactoryTest.java
├── NullablePropertyTest.java
├── NullableSourceTest.java
├── OptionalMapperMethodTest.java
├── OptionalPropertyTest.java
├── PrimitiveOptionalPropertyTest.java
├── PrimitiveOptionalSourceTest.java
├── RequiredMapperMethodTest.java
├── RequiredPropertiesTest.java
├── SetMultimapMutateMethodTest.java
├── SetMultimapPropertyTest.java
├── SetMutateMethodTest.java
├── SetPropertyTest.java
├── SetSourceTest.java
├── SetType.java
├── SortedSetMutateMethodTest.java
└── SortedSetPropertyTest.java
├── source
├── FilerUtilsTest.java
├── FunctionalTypeTest.java
├── LazyNameTest.java
├── MethodFinderTest.java
├── ObjectsExcerptsTest.java
├── Partial.java
├── PreconditionExcerptsTests.java
├── ScopeHandlerTests.java
├── ScopeTest.java
├── SourceBuilderTest.java
├── SourceParserTest.java
├── TypeClassTest.java
├── TypeMirrorAppenderTest.java
├── ValueTypeTest.java
├── feature
│ └── SourceLevelTest.java
└── testing
│ ├── BehaviorTester.java
│ ├── BehaviorTesterTest.java
│ ├── CompilationException.java
│ ├── CompilationUnit.java
│ ├── Diagnostics.java
│ ├── InMemoryFile.java
│ ├── InMemoryJavaFile.java
│ ├── MessagerRule.java
│ ├── Model.java
│ ├── ModelRule.java
│ ├── ModelRuleTest.java
│ ├── ModelTest.java
│ ├── MultipleDiagnosticSubjects.java
│ ├── ParameterizedBehaviorTestFactory.java
│ ├── ParameterizedBehaviorTestRunner.java
│ ├── SingleBehaviorTester.java
│ ├── Target.java
│ ├── TempJavaFileManager.java
│ ├── TestBuilder.java
│ ├── TestBuilderTest.java
│ └── TypeMirrors.java
└── testtype
├── AbstractNonComparable.java
├── NonComparable.java
└── OtherNonComparable.java
/.checkstyle:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.bat eol=crlf
2 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ "*" ]
8 |
9 | jobs:
10 | tests:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v2
14 | - name: Set up JDK 11
15 | uses: actions/setup-java@v2
16 | with:
17 | java-version: '11'
18 | distribution: 'temurin'
19 | - name: Set $JAVA_11_HOME
20 | run: echo "JAVA_11_HOME=$JAVA_HOME" >> $GITHUB_ENV
21 | - name: Set up JDK 8
22 | uses: actions/setup-java@v2
23 | with:
24 | java-version: '8'
25 | distribution: 'temurin'
26 | - name: Set $JAVA_8_HOME
27 | run: echo "JAVA_8_HOME=$JAVA_HOME" >> $GITHUB_ENV
28 | - name: Validate gradle wrapper
29 | uses: gradle/wrapper-validation-action@v1
30 | - name: Build
31 | uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
32 | with:
33 | arguments: build
34 |
35 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*'
7 |
8 | jobs:
9 | maven-central:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v2
13 | - name: Set up JDK 11
14 | uses: actions/setup-java@v2
15 | with:
16 | java-version: '11'
17 | distribution: 'temurin'
18 | - name: Set $JAVA_11_HOME
19 | run: echo "JAVA_11_HOME=$JAVA_HOME" >> $GITHUB_ENV
20 | - name: Set up JDK 8
21 | uses: actions/setup-java@v2
22 | with:
23 | java-version: '8'
24 | distribution: 'temurin'
25 | - name: Set $JAVA_8_HOME
26 | run: echo "JAVA_8_HOME=$JAVA_HOME" >> $GITHUB_ENV
27 | - name: Validate gradle wrapper
28 | uses: gradle/wrapper-validation-action@v1
29 | - name: Run checks
30 | uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
31 | with:
32 | arguments: check
33 | - name: Publish to Maven Central
34 | uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
35 | with:
36 | arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository
37 | env:
38 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SIGNING_KEY }}
39 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}
40 | ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
41 | ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dependency-reduced-pom.xml
2 |
3 | # Java class files
4 | *.class
5 |
6 | # generated files
7 | bin/
8 | gen/
9 |
10 | # Eclipse project files
11 | .classpath
12 | .project
13 | .settings
14 | .test
15 |
16 | # Intellij project files
17 | *.iml
18 | *.ipr
19 | *.iws
20 | .idea/
21 |
22 | # Gradle
23 | .gradletasknamecache
24 | .gradle/
25 | build/
26 | bin/
27 |
28 |
--------------------------------------------------------------------------------
/.test/.checkstyle:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Want to contribute? Great! First, read this page (including the small print at the end).
2 |
3 | ### Before you contribute
4 | Before we can use your code, you must sign the
5 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
6 | (CLA), which you can do online. The CLA is necessary mainly because you own the
7 | copyright to your changes, even after your contribution becomes part of our
8 | codebase, so we need your permission to use and distribute your code. We also
9 | need to be sure of various other things—for instance that you'll tell us if you
10 | know that your code infringes on other people's patents. You don't have to sign
11 | the CLA until after you've submitted your code for review and a member has
12 | approved it, but you must do it before we can put your code into our codebase.
13 | Before you start working on a larger contribution, you should get in touch with
14 | us first through the issue tracker with your idea so that we can help out and
15 | possibly guide you. Coordinating up front makes it much easier to avoid
16 | frustration later on.
17 |
18 | ### Building and testing
19 | FreeBuilder is built using [Gradle](http://gradle.org/). The following commands are especially useful:
20 |
21 | * `./gradlew eclipse` — Creates two Eclipse projects, `freebuilder` and `freebuilder-test`.
22 | * `./gradlew check` — Runs all unit and integration tests. These are automatically run against every PR, and will need to pass before any contribution will be accepted.
23 |
24 | ### Code reviews
25 | All submissions, including submissions by project members, require review. We
26 | use Github pull requests for this purpose.
27 |
28 | ### The small print
29 | Contributions made by corporations are covered by a different agreement than
30 | the one above, the Software Grant and Corporate Contributor License Agreement.
31 |
--------------------------------------------------------------------------------
/config/checkstyle/suppressions.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | autoService=com.google.auto.service:auto-service:1.0-rc2
2 | googleJavaFormat=com.google.googlejavaformat:google-java-format:1.2
3 | guava=com.google.guava:guava:16.0
4 | guavaTestlib=com.google.guava:guava-testlib:17.0
5 | gwtUser=com.google.gwt:gwt-user:2.8.0
6 | hamcrest=org.hamcrest:hamcrest-all:1.3
7 | jacksonVersion=2.9.3
8 | javassist=org.javassist:javassist:3.19.0-GA
9 | jsr305=com.google.code.findbugs:jsr305:3.0.0
10 | junit=junit:junit:4.12
11 | mockito=org.mockito:mockito-core:1.10.8
12 | reflections=org.reflections:reflections:0.9.11
13 | truth=com.google.truth:truth:0.24
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/inferred/FreeBuilder/6a0ba1b7007ab2a281c71eeec406efd7923dc39d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/jar-footprint.txt:
--------------------------------------------------------------------------------
1 | META-INF/
2 | META-INF/MANIFEST.MF
3 | META-INF/services/
4 | META-INF/services/javax.annotation.processing.Processor
5 | org/
6 | org/inferred/
7 | org/inferred/freebuilder/
8 | org/inferred/freebuilder/FreeBuilder.class
9 | org/inferred/freebuilder/IgnoredByEquals.class
10 | org/inferred/freebuilder/processor
11 | org/inferred/freebuilder/NotInToString.class
12 | org/inferred/freebuilder/shaded
13 |
--------------------------------------------------------------------------------
/src/it/gwt/src/main/java/org/inferred/freebuilder/client/rpc/MapGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import java.io.Serializable;
19 | import java.util.Map;
20 |
21 | import org.inferred.freebuilder.FreeBuilder;
22 |
23 | import com.google.common.annotations.GwtCompatible;
24 |
25 | /** Simple GWT-compatible FreeBuilder type with a map of strings to doubles. */
26 | @FreeBuilder
27 | @GwtCompatible(serializable = true)
28 | public interface MapGwtType extends Serializable {
29 | Map getDistances();
30 |
31 | /** Builder of {@link MapGwtType} instances. */
32 | class Builder extends MapGwtType_Builder { }
33 | }
34 |
--------------------------------------------------------------------------------
/src/it/gwt/src/main/java/org/inferred/freebuilder/client/rpc/NestedListGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import java.io.Serializable;
19 |
20 | import org.inferred.freebuilder.FreeBuilder;
21 |
22 | import com.google.common.annotations.GwtCompatible;
23 |
24 | /** Simple GWT-compatible FreeBuilder type with a nested buildable type containing a list. */
25 | @FreeBuilder
26 | @GwtCompatible(serializable = true)
27 | public interface NestedListGwtType extends Serializable {
28 | StringListGwtType getItem();
29 |
30 | /** Builder for {@link NestedListGwtType}. */
31 | class Builder extends NestedListGwtType_Builder { }
32 | }
33 |
--------------------------------------------------------------------------------
/src/it/gwt/src/main/java/org/inferred/freebuilder/client/rpc/OptionalGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import java.io.Serializable;
19 |
20 | import org.inferred.freebuilder.FreeBuilder;
21 |
22 | import com.google.common.annotations.GwtCompatible;
23 | import com.google.common.base.Optional;
24 |
25 | /** Simple GWT-compatible FreeBuilder type with a single optional String property. */
26 | @FreeBuilder
27 | @GwtCompatible(serializable = true)
28 | public interface OptionalGwtType extends Serializable {
29 | Optional getName();
30 |
31 | /** Builder for {@link OptionalGwtType}. */
32 | class Builder extends OptionalGwtType_Builder { }
33 | }
34 |
--------------------------------------------------------------------------------
/src/it/gwt/src/main/java/org/inferred/freebuilder/client/rpc/StringListGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import java.io.Serializable;
19 | import java.util.List;
20 |
21 | import org.inferred.freebuilder.FreeBuilder;
22 |
23 | import com.google.common.annotations.GwtCompatible;
24 |
25 | /** Simple GWT-compatible FreeBuilder type with a list of strings. */
26 | @FreeBuilder
27 | @GwtCompatible(serializable = true)
28 | public interface StringListGwtType extends Serializable {
29 | List getNames();
30 |
31 | /** Builder for {@link StringListGwtType}. */
32 | class Builder extends StringListGwtType_Builder { }
33 | }
34 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/GwtTests.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.google.gwt.junit.tools.GWTTestSuite;
4 |
5 | import org.inferred.freebuilder.client.rpc.MapTest;
6 | import org.inferred.freebuilder.client.rpc.NestedListTest;
7 | import org.inferred.freebuilder.client.rpc.OptionalTest;
8 | import org.inferred.freebuilder.client.rpc.StringListTest;
9 |
10 | public class GwtTests extends GWTTestSuite {
11 |
12 | public GwtTests() {
13 | addTest(new MapTest());
14 | addTest(new NestedListTest());
15 | addTest(new OptionalTest());
16 | addTest(new StringListTest());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/MapTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.core.client.GWT;
19 | import com.google.gwt.junit.client.GWTTestCase;
20 | import com.google.gwt.user.client.rpc.AsyncCallback;
21 | import com.google.gwt.user.client.rpc.ServiceDefTarget;
22 |
23 | public class MapTest extends GWTTestCase {
24 |
25 | private static final int RPC_TIMEOUT = 15000;
26 | private static final String MODULE_NAME = "org.inferred.freebuilder.TestServer";
27 | private static final MapGwtType VALUE = new MapGwtType.Builder()
28 | .putDistances("small", 1.0)
29 | .putDistances("medium", 10.3)
30 | .putDistances("large", 112.5)
31 | .build();
32 |
33 | private MapTestServiceAsync customFieldSerializerTestService;
34 |
35 | @Override
36 | public String getModuleName() {
37 | return MODULE_NAME;
38 | }
39 |
40 | @Override
41 | protected void gwtSetUp() throws Exception {
42 | super.gwtSetUp();
43 | delayTestFinish(RPC_TIMEOUT);
44 | }
45 |
46 | public void testSerialization() {
47 | MapTestServiceAsync service = getServiceAsync();
48 | service.echo(VALUE, new AsyncCallback() {
49 | @Override
50 | public void onFailure(Throwable caught) {
51 | throw new AssertionError(caught);
52 | }
53 |
54 | @Override
55 | public void onSuccess(MapGwtType result) {
56 | assertEquals(VALUE, result);
57 | finishTest();
58 | }
59 | });
60 | }
61 |
62 | private MapTestServiceAsync getServiceAsync() {
63 | if (customFieldSerializerTestService == null) {
64 | customFieldSerializerTestService =
65 | (MapTestServiceAsync) GWT.create(MapTestService.class);
66 | ((ServiceDefTarget) customFieldSerializerTestService)
67 | .setServiceEntryPoint(GWT.getModuleBaseURL() + "map");
68 | }
69 | return customFieldSerializerTestService;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/MapTestService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.RemoteService;
19 |
20 | public interface MapTestService extends RemoteService {
21 | MapGwtType echo(MapGwtType mapGwtType);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/MapTestServiceAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.AsyncCallback;
19 |
20 | public interface MapTestServiceAsync {
21 | void echo(MapGwtType mapGwtType, AsyncCallback callback);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/NestedListTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.core.client.GWT;
19 | import com.google.gwt.junit.client.GWTTestCase;
20 | import com.google.gwt.user.client.rpc.AsyncCallback;
21 | import com.google.gwt.user.client.rpc.ServiceDefTarget;
22 |
23 | public class NestedListTest extends GWTTestCase {
24 |
25 | private static final int RPC_TIMEOUT = 15000;
26 | private static final String MODULE_NAME = "org.inferred.freebuilder.TestServer";
27 | private static final NestedListGwtType VALUE = new NestedListGwtType.Builder()
28 | .setItem(new StringListGwtType.Builder()
29 | .addNames("john", "alice", "sam"))
30 | .build();
31 |
32 | private NestedListTestServiceAsync customFieldSerializerTestService;
33 |
34 | @Override
35 | public String getModuleName() {
36 | return MODULE_NAME;
37 | }
38 |
39 | @Override
40 | protected void gwtSetUp() throws Exception {
41 | super.gwtSetUp();
42 | delayTestFinish(RPC_TIMEOUT);
43 | }
44 |
45 | public void testSerialization() {
46 | NestedListTestServiceAsync service = getServiceAsync();
47 | service.echo(VALUE, new AsyncCallback() {
48 | @Override
49 | public void onFailure(Throwable caught) {
50 | throw new AssertionError(caught);
51 | }
52 |
53 | @Override
54 | public void onSuccess(NestedListGwtType result) {
55 | assertEquals(VALUE, result);
56 | finishTest();
57 | }
58 | });
59 | }
60 |
61 | private NestedListTestServiceAsync getServiceAsync() {
62 | if (customFieldSerializerTestService == null) {
63 | customFieldSerializerTestService =
64 | (NestedListTestServiceAsync) GWT.create(NestedListTestService.class);
65 | ((ServiceDefTarget) customFieldSerializerTestService)
66 | .setServiceEntryPoint(GWT.getModuleBaseURL() + "nested-list");
67 | }
68 | return customFieldSerializerTestService;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/NestedListTestService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.RemoteService;
19 |
20 | public interface NestedListTestService extends RemoteService {
21 | NestedListGwtType echo(NestedListGwtType nestedListGwtType);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/NestedListTestServiceAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.AsyncCallback;
19 |
20 | public interface NestedListTestServiceAsync {
21 | void echo(NestedListGwtType nestedListGwtType, AsyncCallback callback);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/OptionalTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.core.client.GWT;
19 | import com.google.gwt.junit.client.GWTTestCase;
20 | import com.google.gwt.user.client.rpc.AsyncCallback;
21 | import com.google.gwt.user.client.rpc.ServiceDefTarget;
22 |
23 | public class OptionalTest extends GWTTestCase {
24 |
25 | private static final int RPC_TIMEOUT = 15000;
26 | private static final String MODULE_NAME = "org.inferred.freebuilder.TestServer";
27 | private static final OptionalGwtType VALUE = new OptionalGwtType.Builder()
28 | .setName("Brian")
29 | .build();
30 |
31 | private OptionalTestServiceAsync customFieldSerializerTestService;
32 |
33 | @Override
34 | public String getModuleName() {
35 | return MODULE_NAME;
36 | }
37 |
38 | @Override
39 | protected void gwtSetUp() throws Exception {
40 | super.gwtSetUp();
41 | delayTestFinish(RPC_TIMEOUT);
42 | }
43 |
44 | public void testSerialization() {
45 | OptionalTestServiceAsync service = getServiceAsync();
46 | service.echo(VALUE, new AsyncCallback() {
47 | @Override
48 | public void onFailure(Throwable caught) {
49 | throw new AssertionError(caught);
50 | }
51 |
52 | @Override
53 | public void onSuccess(OptionalGwtType result) {
54 | assertEquals(VALUE, result);
55 | finishTest();
56 | }
57 | });
58 | }
59 |
60 | private OptionalTestServiceAsync getServiceAsync() {
61 | if (customFieldSerializerTestService == null) {
62 | customFieldSerializerTestService =
63 | (OptionalTestServiceAsync) GWT.create(OptionalTestService.class);
64 | ((ServiceDefTarget) customFieldSerializerTestService)
65 | .setServiceEntryPoint(GWT.getModuleBaseURL() + "optional");
66 | }
67 | return customFieldSerializerTestService;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/OptionalTestService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.RemoteService;
19 |
20 | public interface OptionalTestService extends RemoteService {
21 | OptionalGwtType echo(OptionalGwtType optionalGwtType);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/OptionalTestServiceAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.AsyncCallback;
19 |
20 | public interface OptionalTestServiceAsync {
21 | void echo(OptionalGwtType optionalGwtType, AsyncCallback callback);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/StringListTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.core.client.GWT;
19 | import com.google.gwt.junit.client.GWTTestCase;
20 | import com.google.gwt.user.client.rpc.AsyncCallback;
21 | import com.google.gwt.user.client.rpc.ServiceDefTarget;
22 |
23 | public class StringListTest extends GWTTestCase {
24 |
25 | private static final int RPC_TIMEOUT = 15000;
26 | private static final String MODULE_NAME = "org.inferred.freebuilder.TestServer";
27 | private static final StringListGwtType VALUE = new StringListGwtType.Builder()
28 | .addNames("john", "alice", "sam")
29 | .build();
30 |
31 | private StringListTestServiceAsync customFieldSerializerTestService;
32 |
33 | @Override
34 | public String getModuleName() {
35 | return MODULE_NAME;
36 | }
37 |
38 | @Override
39 | protected void gwtSetUp() throws Exception {
40 | super.gwtSetUp();
41 | delayTestFinish(RPC_TIMEOUT);
42 | }
43 |
44 | public void testSerialization() {
45 | StringListTestServiceAsync service = getServiceAsync();
46 | service.echo(VALUE, new AsyncCallback() {
47 | @Override
48 | public void onFailure(Throwable caught) {
49 | throw new AssertionError(caught);
50 | }
51 |
52 | @Override
53 | public void onSuccess(StringListGwtType result) {
54 | assertEquals(VALUE, result);
55 | finishTest();
56 | }
57 | });
58 | }
59 |
60 | private StringListTestServiceAsync getServiceAsync() {
61 | if (customFieldSerializerTestService == null) {
62 | customFieldSerializerTestService =
63 | (StringListTestServiceAsync) GWT.create(StringListTestService.class);
64 | ((ServiceDefTarget) customFieldSerializerTestService)
65 | .setServiceEntryPoint(GWT.getModuleBaseURL() + "string-list");
66 | }
67 | return customFieldSerializerTestService;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/StringListTestService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.RemoteService;
19 |
20 | public interface StringListTestService extends RemoteService {
21 | StringListGwtType echo(StringListGwtType stringListGwtType);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/client/rpc/StringListTestServiceAsync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.client.rpc;
17 |
18 | import com.google.gwt.user.client.rpc.AsyncCallback;
19 |
20 | public interface StringListTestServiceAsync {
21 | void echo(StringListGwtType stringListGwtType, AsyncCallback callback);
22 | }
23 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/server/rpc/MapTestServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.server.rpc;
17 |
18 | import org.inferred.freebuilder.client.rpc.MapGwtType;
19 | import org.inferred.freebuilder.client.rpc.MapTestService;
20 |
21 | import com.google.gwt.user.server.rpc.RemoteServiceServlet;
22 |
23 | public class MapTestServiceImpl extends RemoteServiceServlet implements MapTestService {
24 |
25 | @Override
26 | public MapGwtType echo(MapGwtType mapGwtType) {
27 | return mapGwtType;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/server/rpc/NestedListTestServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.server.rpc;
17 |
18 | import org.inferred.freebuilder.client.rpc.NestedListGwtType;
19 | import org.inferred.freebuilder.client.rpc.NestedListTestService;
20 |
21 | import com.google.gwt.user.server.rpc.RemoteServiceServlet;
22 |
23 | public class NestedListTestServiceImpl extends RemoteServiceServlet
24 | implements NestedListTestService {
25 |
26 | @Override
27 | public NestedListGwtType echo(NestedListGwtType mapGwtType) {
28 | return mapGwtType;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/server/rpc/OptionalTestServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.server.rpc;
17 |
18 | import org.inferred.freebuilder.client.rpc.OptionalGwtType;
19 | import org.inferred.freebuilder.client.rpc.OptionalTestService;
20 |
21 | import com.google.gwt.user.server.rpc.RemoteServiceServlet;
22 |
23 | public class OptionalTestServiceImpl extends RemoteServiceServlet implements OptionalTestService {
24 |
25 | @Override
26 | public OptionalGwtType echo(OptionalGwtType mapGwtType) {
27 | return mapGwtType;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/java/org/inferred/freebuilder/server/rpc/StringListTestServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations under
14 | * the License.
15 | */
16 | package org.inferred.freebuilder.server.rpc;
17 |
18 | import org.inferred.freebuilder.client.rpc.StringListGwtType;
19 | import org.inferred.freebuilder.client.rpc.StringListTestService;
20 |
21 | import com.google.gwt.user.server.rpc.RemoteServiceServlet;
22 |
23 | public class StringListTestServiceImpl extends RemoteServiceServlet
24 | implements StringListTestService {
25 |
26 | @Override
27 | public StringListGwtType echo(StringListGwtType mapGwtType) {
28 | return mapGwtType;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/gwt/src/test/resources/org/inferred/freebuilder/TestServer.gwt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/BiMapPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.google.common.collect.BiMap;
4 |
5 | @FreeBuilder
6 | public interface BiMapPropertyType {
7 |
8 | BiMap getNumbers();
9 |
10 | class Builder extends BiMapPropertyType_Builder {}
11 | }
12 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/DefaultedPropertiesType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | @FreeBuilder
4 | public interface DefaultedPropertiesType {
5 | String getFirstName();
6 | String getSurname();
7 |
8 | class Builder extends DefaultedPropertiesType_Builder {
9 | public Builder() {
10 | setFirstName("Joe");
11 | setSurname("Bloggs");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/ListMultimapPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.google.common.collect.ListMultimap;
4 |
5 | @FreeBuilder
6 | public interface ListMultimapPropertyType {
7 | ListMultimap getNumbers();
8 |
9 | class Builder extends ListMultimapPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/ListPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import java.util.List;
4 |
5 | @FreeBuilder
6 | public interface ListPropertyType {
7 | List getNames();
8 |
9 | class Builder extends ListPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/MapPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import java.util.Map;
4 |
5 | @FreeBuilder
6 | public interface MapPropertyType {
7 | Map getNumbers();
8 |
9 | class Builder extends MapPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/MultisetPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.google.common.collect.Multiset;
4 |
5 | @FreeBuilder
6 | public interface MultisetPropertyType {
7 | Multiset getNames();
8 |
9 | class Builder extends MultisetPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/OptionalPropertiesType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import com.google.common.annotations.GwtCompatible;
19 |
20 | import java.io.Serializable;
21 | import java.util.Optional;
22 |
23 | @FreeBuilder
24 | @GwtCompatible(serializable = true)
25 | public interface OptionalPropertiesType extends Serializable {
26 | Optional getFirstName();
27 | Optional getSurname();
28 |
29 | class Builder extends OptionalPropertiesType_Builder { }
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/RequiredPropertiesType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | @FreeBuilder
4 | public interface RequiredPropertiesType {
5 | String getFirstName();
6 | String getSurname();
7 |
8 | class Builder extends RequiredPropertiesType_Builder {}
9 | }
10 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/SetMultimapPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.google.common.collect.SetMultimap;
4 |
5 | @FreeBuilder
6 | public interface SetMultimapPropertyType {
7 | SetMultimap getNumbers();
8 |
9 | class Builder extends SetMultimapPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/main/java/org/inferred/freebuilder/SetPropertyType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import java.util.Set;
4 |
5 | @FreeBuilder
6 | public interface SetPropertyType {
7 | Set getNames();
8 |
9 | class Builder extends SetPropertyType_Builder {}
10 | }
11 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/BiMapPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableBiMap;
6 | import org.junit.Rule;
7 | import org.junit.Test;
8 | import org.junit.rules.ExpectedException;
9 |
10 | public class BiMapPropertiesTest {
11 |
12 | @Rule
13 | public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | BiMapPropertyType value = new BiMapPropertyType.Builder()
18 | .putNumbers(1, "one")
19 | .putNumbers(2, "two")
20 | .mutateNumbers(numbers -> numbers.replaceAll((i, s) -> s.toUpperCase() + " (" + i + ")"))
21 | .build();
22 | assertEquals(ImmutableBiMap.of(1, "ONE (1)", 2, "TWO (2)"), value.getNumbers());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/DefaultedPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.ExpectedException;
8 |
9 | import java.util.function.UnaryOperator;
10 |
11 | public class DefaultedPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMap() {
17 | DefaultedPropertiesType value = new DefaultedPropertiesType.Builder()
18 | .setFirstName("joe")
19 | .setSurname("bloggs")
20 | .mapFirstName(CAPITALIZE)
21 | .mapSurname(CAPITALIZE)
22 | .build();
23 | assertEquals("Joe", value.getFirstName());
24 | assertEquals("Bloggs", value.getSurname());
25 | }
26 |
27 | private static final UnaryOperator CAPITALIZE = s ->
28 | s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
29 | }
30 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/ListMultimapPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableListMultimap;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class ListMultimapPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | ListMultimapPropertyType value = new ListMultimapPropertyType.Builder()
18 | .putNumbers(1, "one")
19 | .putNumbers(1, "uno")
20 | .putNumbers(2, "two")
21 | .putNumbers(2, "dos")
22 | .mutateNumbers(numbers -> numbers.entries().forEach(entry -> entry.setValue(
23 | entry.getValue().toUpperCase() + " (" + entry.getKey() + ")")))
24 | .build();
25 | assertEquals(ImmutableListMultimap.of(1, "ONE (1)", 1, "UNO (1)", 2, "TWO (2)", 2, "DOS (2)"),
26 | value.getNumbers());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/ListPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableList;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class ListPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | ListPropertyType value = new ListPropertyType.Builder()
18 | .addNames("Alan", "Bob", "Chris", "Diana", "Emma", "Fred")
19 | .mutateNames(names -> names.subList(2, 4).clear())
20 | .build();
21 | assertEquals(ImmutableList.of("Alan", "Bob", "Emma", "Fred"), value.getNames());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/MapPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableMap;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class MapPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | MapPropertyType value = new MapPropertyType.Builder()
18 | .putNumbers(1, "one")
19 | .putNumbers(2, "two")
20 | .mutateNumbers(numbers -> numbers.replaceAll((i, s) -> s.toUpperCase() + " (" + i + ")"))
21 | .build();
22 | assertEquals(ImmutableMap.of(1, "ONE (1)", 2, "TWO (2)"), value.getNumbers());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/MultisetPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableMultiset;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class MultisetPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | MultisetPropertyType value = new MultisetPropertyType.Builder()
18 | .addNames("Alan", "Bob", "Chris", "Diana", "Emma", "Fred")
19 | .mutateNames(names -> names.removeIf(name -> name.matches("[CD].*")))
20 | .build();
21 | assertEquals(ImmutableMultiset.of("Alan", "Bob", "Emma", "Fred"), value.getNames());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/OptionalPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.ExpectedException;
8 |
9 | import java.util.Optional;
10 | import java.util.function.UnaryOperator;
11 |
12 | public class OptionalPropertiesTest {
13 |
14 | @Rule public final ExpectedException thrown = ExpectedException.none();
15 |
16 | @Test
17 | public void testMap() {
18 | OptionalPropertiesType value = new OptionalPropertiesType.Builder()
19 | .setFirstName("joe")
20 | .setSurname("bloggs")
21 | .mapFirstName(CAPITALIZE)
22 | .mapSurname(CAPITALIZE)
23 | .build();
24 | assertEquals(Optional.of("Joe"), value.getFirstName());
25 | assertEquals(Optional.of("Bloggs"), value.getSurname());
26 | }
27 |
28 | private static final UnaryOperator CAPITALIZE = s ->
29 | s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/RequiredPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import org.junit.Rule;
6 | import org.junit.Test;
7 | import org.junit.rules.ExpectedException;
8 |
9 | import java.util.function.UnaryOperator;
10 |
11 | public class RequiredPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMap() {
17 | RequiredPropertiesType value = new RequiredPropertiesType.Builder()
18 | .setFirstName("joe")
19 | .setSurname("bloggs")
20 | .mapFirstName(CAPITALIZE)
21 | .mapSurname(CAPITALIZE)
22 | .build();
23 | assertEquals("Joe", value.getFirstName());
24 | assertEquals("Bloggs", value.getSurname());
25 | }
26 |
27 | private static final UnaryOperator CAPITALIZE = s ->
28 | s.substring(0, 1).toUpperCase() + s.substring(1, s.length());
29 | }
30 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/SetMultimapPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableSetMultimap;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class SetMultimapPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | SetMultimapPropertyType value = new SetMultimapPropertyType.Builder()
18 | .putNumbers(1, "one")
19 | .putNumbers(1, "uno")
20 | .putNumbers(2, "two")
21 | .putNumbers(2, "dos")
22 | .mutateNumbers(numbers -> numbers.removeAll(2))
23 | .build();
24 | assertEquals(ImmutableSetMultimap.of(1, "one", 1, "uno"), value.getNumbers());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/lambda/src/test/java/org/inferred/freebuilder/SetPropertiesTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableSet;
6 |
7 | import org.junit.Rule;
8 | import org.junit.Test;
9 | import org.junit.rules.ExpectedException;
10 |
11 | public class SetPropertiesTest {
12 |
13 | @Rule public final ExpectedException thrown = ExpectedException.none();
14 |
15 | @Test
16 | public void testMutate() {
17 | SetPropertyType value = new SetPropertyType.Builder()
18 | .addNames("Alan", "Bob", "Chris", "Diana", "Emma", "Fred")
19 | .mutateNames(names -> names.removeIf(name -> name.matches("[CD].*")))
20 | .build();
21 | assertEquals(ImmutableSet.of("Alan", "Bob", "Emma", "Fred"), value.getNames());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/it/no-guava-j8/invoker.properties:
--------------------------------------------------------------------------------
1 | invoker.goals = clean test
2 |
--------------------------------------------------------------------------------
/src/it/no-guava-j8/src/main/java/org/inferred/freebuilder/OptionalProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package org.inferred.freebuilder;
15 |
16 | import java.io.Serializable;
17 | import java.util.Optional;
18 |
19 | @FreeBuilder
20 | public interface OptionalProperties extends Serializable {
21 | Optional getFirstName();
22 | Optional getMiddleName();
23 | Optional getSurname();
24 |
25 | class Builder extends OptionalProperties_Builder { }
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/no-guava-j8/src/main/java/org/inferred/freebuilder/OptionalProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 | package org.inferred.freebuilder;
15 |
16 | import java.io.Serializable;
17 | import java.util.Optional;
18 |
19 | @FreeBuilder
20 | public interface OptionalProperty extends Serializable {
21 | Optional getName();
22 |
23 | class Builder extends OptionalProperty_Builder { }
24 | }
25 |
--------------------------------------------------------------------------------
/src/it/no-guava-j8/src/test/java/org/inferred/freebuilder/OptionalPropertiesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.JUnit4;
23 |
24 | import java.util.Optional;
25 |
26 | @RunWith(JUnit4.class)
27 | public class OptionalPropertiesTest {
28 |
29 | private static final String NAME_1 = "name1";
30 | private static final String NAME_2 = "name2";
31 | private static final String NAME_3 = "name3";
32 |
33 | @Test
34 | public void testSetters() {
35 | OptionalProperties.Builder builder = new OptionalProperties.Builder();
36 | assertEquals(Optional.empty(), builder.build().getFirstName());
37 | assertEquals(Optional.empty(), builder.build().getMiddleName());
38 | assertEquals(Optional.empty(), builder.build().getSurname());
39 | assertEquals("OptionalProperties{}", builder.build().toString());
40 | builder.setFirstName(NAME_1);
41 | assertEquals(
42 | "OptionalProperties{firstName=name1}",
43 | builder.build().toString());
44 | builder.setMiddleName(NAME_2);
45 | assertEquals(
46 | "OptionalProperties{firstName=name1, middleName=name2}",
47 | builder.build().toString());
48 | builder.setSurname(NAME_3);
49 | assertEquals(Optional.of(NAME_1), builder.build().getFirstName());
50 | assertEquals(Optional.of(NAME_2), builder.build().getMiddleName());
51 | assertEquals(Optional.of(NAME_3), builder.build().getSurname());
52 | assertEquals(
53 | "OptionalProperties{firstName=name1, middleName=name2, surname=name3}",
54 | builder.build().toString());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/it/no-guava-j8/src/test/java/org/inferred/freebuilder/OptionalPropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.JUnit4;
23 |
24 | import java.util.Optional;
25 |
26 | /** FreeBuilder test using {@link ListProperty}. */
27 | @RunWith(JUnit4.class)
28 | public class OptionalPropertyTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testAllMethodInteractions() {
36 | OptionalProperty.Builder builder = new OptionalProperty.Builder();
37 | assertEquals(Optional.empty(), builder.build().getName());
38 | builder.setName(NAME_1);
39 | assertEquals(Optional.of(NAME_1), builder.build().getName());
40 | builder.mapName(n -> n.substring(0, 4) + "2");
41 | assertEquals(Optional.of(NAME_2), builder.build().getName());
42 | builder.clearName();
43 | assertEquals(Optional.empty(), builder.build().getName());
44 | builder.setName(NAME_3);
45 | assertEquals(Optional.of(NAME_3), builder.build().getName());
46 | builder.clear();
47 | assertEquals(Optional.empty(), builder.build().getName());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/main/java/org/inferred/freebuilder/ListProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import java.io.Serializable;
19 | import java.util.List;
20 |
21 | @FreeBuilder
22 | public interface ListProperty extends Serializable {
23 | List getNames();
24 |
25 | class Builder extends ListProperty_Builder { }
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/main/java/org/inferred/freebuilder/MapProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import java.io.Serializable;
19 | import java.util.Map;
20 |
21 | @FreeBuilder
22 | public interface MapProperty extends Serializable {
23 | Map getDistances();
24 |
25 | class Builder extends MapProperty_Builder { }
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/main/java/org/inferred/freebuilder/PrimitiveProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | @FreeBuilder
19 | public interface PrimitiveProperty {
20 | int getProperty();
21 |
22 | class Builder extends PrimitiveProperty_Builder {}
23 | }
24 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/main/java/org/inferred/freebuilder/SetProperty.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import java.io.Serializable;
19 | import java.util.Set;
20 |
21 | @FreeBuilder
22 | public interface SetProperty extends Serializable {
23 | Set getNames();
24 |
25 | class Builder extends SetProperty_Builder { }
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/test/java/org/inferred/freebuilder/ListPropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static java.util.Arrays.asList;
19 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.junit.runners.JUnit4;
25 |
26 | /** FreeBuilder test using {@link ListProperty}. */
27 | @RunWith(JUnit4.class)
28 | public class ListPropertyTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testAllMethodInteractions() {
36 | ListProperty.Builder builder = new ListProperty.Builder();
37 | builder.addNames(NAME_1);
38 | assertEquals(asList(NAME_1), builder.build().getNames());
39 | builder.addNames(NAME_2, NAME_3);
40 | assertEquals(asList(NAME_1, NAME_2, NAME_3), builder.build().getNames());
41 | builder.clearNames();
42 | assertEquals(asList(), builder.build().getNames());
43 | builder.addAllNames(asList(NAME_2, NAME_1));
44 | assertEquals(asList(NAME_2, NAME_1), builder.build().getNames());
45 | builder.clear();
46 | assertEquals(asList(), builder.build().getNames());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/test/java/org/inferred/freebuilder/PrimitivePropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.JUnit4;
23 |
24 | /**
25 | * Integration test for {@link org.inferred.freebuilder.FreeBuilder
26 | * FreeBuilder}, using the {@link PrimitiveProperty}.
27 | */
28 | @RunWith(JUnit4.class)
29 | public class PrimitivePropertyTest {
30 |
31 | @Test
32 | public void test() {
33 | PrimitiveProperty b = new PrimitiveProperty.Builder()
34 | .setProperty(11)
35 | .build();
36 | assertEquals(11, b.getProperty());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/it/no-guava/src/test/java/org/inferred/freebuilder/SetPropertyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import org.junit.Test;
21 | import org.junit.runner.RunWith;
22 | import org.junit.runners.JUnit4;
23 |
24 | import java.util.HashSet;
25 | import java.util.Set;
26 |
27 | /** FreeBuilder test using {@link ListProperty}. */
28 | @RunWith(JUnit4.class)
29 | public class SetPropertyTest {
30 |
31 | private static final String NAME_1 = "name1";
32 | private static final String NAME_2 = "name2";
33 | private static final String NAME_3 = "name3";
34 |
35 | @Test
36 | public void testAllMethodInteractions() {
37 | SetProperty.Builder builder = new SetProperty.Builder();
38 | builder.addNames(NAME_1);
39 | assertEquals(newHashSet(NAME_1), builder.build().getNames());
40 | builder.addNames(NAME_1);
41 | assertEquals(newHashSet(NAME_1), builder.build().getNames());
42 | builder.addNames(NAME_2, NAME_3);
43 | assertEquals(newHashSet(NAME_1, NAME_2, NAME_3), builder.build().getNames());
44 | builder.clearNames();
45 | assertEquals(newHashSet(), builder.build().getNames());
46 | builder.addAllNames(newHashSet(NAME_2, NAME_1));
47 | assertEquals(newHashSet(NAME_2, NAME_1), builder.build().getNames());
48 | builder.clear();
49 | assertEquals(newHashSet(), builder.build().getNames());
50 | }
51 |
52 | @SafeVarargs
53 | private static Set newHashSet(E... items) {
54 | Set list = new HashSet<>();
55 | for (E item : items) {
56 | list.add(item);
57 | }
58 | return list;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/DefaultedPropertiesType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | @FreeBuilder
4 | public interface DefaultedPropertiesType {
5 | String getFirstName();
6 | String getSurname();
7 |
8 | class Builder extends DefaultedPropertiesType_Builder {
9 | public Builder() {
10 | setFirstName("Joe");
11 | setSurname("Bloggs");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/JacksonAnyGetterType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.fasterxml.jackson.annotation.JsonAnyGetter;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import com.fasterxml.jackson.databind.JsonNode;
6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
7 |
8 | import java.util.Map;
9 |
10 | @FreeBuilder
11 | @JsonDeserialize(builder = JacksonAnyGetterType.Builder.class)
12 | public interface JacksonAnyGetterType {
13 | @JsonProperty("simple_property")
14 | String getSimpleProperty();
15 | @JsonAnyGetter
16 | Map getUnknownProperties();
17 |
18 | class Builder extends JacksonAnyGetterType_Builder {}
19 | }
20 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/MapGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import com.google.common.annotations.GwtCompatible;
19 |
20 | import java.io.Serializable;
21 | import java.util.Map;
22 |
23 | /** Simple GWT-compatible FreeBuilder type with a map of strings to doubles. */
24 | @FreeBuilder
25 | @GwtCompatible(serializable = true)
26 | public interface MapGwtType extends Serializable {
27 | Map getDistances();
28 |
29 | /** Builder for {@link StringListGwtType}. */
30 | class Builder extends MapGwtType_Builder { }
31 | }
32 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/NestedListGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import com.google.common.annotations.GwtCompatible;
19 |
20 | import java.io.Serializable;
21 |
22 | /** Simple GWT-compatible FreeBuilder type with a nested buildable type containing a list. */
23 | @FreeBuilder
24 | @GwtCompatible(serializable = true)
25 | public interface NestedListGwtType extends Serializable {
26 | StringListGwtType getItem();
27 |
28 | /** Builder for {@link NestedListGwtType}. */
29 | class Builder extends NestedListGwtType_Builder { }
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/NoFrillsDataInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | /** A trivial {@link FreeBuilder @FreeBuilder} interface with no customization. */
19 | @FreeBuilder
20 | public interface NoFrillsDataInterface {
21 | int getPropertyA();
22 | boolean isPropertyB();
23 |
24 | /** Builder for {@link NoFrillsDataInterface}. */
25 | class Builder extends NoFrillsDataInterface_Builder {}
26 | }
27 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/NoFrillsDataType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | /** A trivial {@link FreeBuilder @FreeBuilder} type with no customization. */
19 | @FreeBuilder
20 | public abstract class NoFrillsDataType {
21 | public abstract int getPropertyA();
22 | public abstract boolean isPropertyB();
23 |
24 | /** Builder for {@link NoFrillsDataType}. */
25 | public static class Builder extends NoFrillsDataType_Builder {}
26 | public static Builder builder() {
27 | return new Builder();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/OptionalGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import com.google.common.annotations.GwtCompatible;
19 | import com.google.common.base.Optional;
20 |
21 | import java.io.Serializable;
22 |
23 | /** Simple GWT-compatible FreeBuilder type with a single optional String property. */
24 | @FreeBuilder
25 | @GwtCompatible(serializable = true)
26 | public interface OptionalGwtType extends Serializable {
27 | Optional getName();
28 |
29 | /** Builder for {@link OptionalGwtType}. */
30 | class Builder extends OptionalGwtType_Builder { }
31 | }
32 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/RequiredPropertiesType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | @FreeBuilder
4 | public interface RequiredPropertiesType {
5 | String getFirstName();
6 | String getSurname();
7 |
8 | class Builder extends RequiredPropertiesType_Builder {}
9 | }
10 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/StringListGwtType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import com.google.common.annotations.GwtCompatible;
19 |
20 | import java.io.Serializable;
21 | import java.util.List;
22 |
23 | /** Simple GWT-compatible FreeBuilder type with a list of strings. */
24 | @FreeBuilder
25 | @GwtCompatible(serializable = true)
26 | public interface StringListGwtType extends Serializable {
27 | List getNames();
28 |
29 | /** Builder for {@link StringListGwtType}. */
30 | class Builder extends StringListGwtType_Builder { }
31 | }
32 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/main/java/org/inferred/freebuilder/WildcardListType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import java.util.List;
19 |
20 | @FreeBuilder
21 | public interface WildcardListType {
22 | List extends Number> numbers();
23 |
24 | class Builder extends WildcardListType_Builder { }
25 | }
26 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/DefaultsOptimizationTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import com.google.common.collect.ImmutableSet;
6 |
7 | import org.junit.Test;
8 |
9 | import java.lang.reflect.Field;
10 | import java.lang.reflect.Modifier;
11 | import java.util.HashSet;
12 | import java.util.Set;
13 |
14 | public class DefaultsOptimizationTest {
15 |
16 | @Test
17 | public void testNoDefaultsNoOptimisation() {
18 | assertEquals(
19 | ImmutableSet.of("firstName", "surname", "_unsetProperties"),
20 | fieldsOn(RequiredPropertiesType.Builder.class.getSuperclass()));
21 | }
22 |
23 | @Test
24 | public void testDefaultsOptimisation() {
25 | assertEquals(
26 | ImmutableSet.of("firstName", "surname"),
27 | fieldsOn(DefaultedPropertiesType.Builder.class.getSuperclass()));
28 | }
29 |
30 | private static Set fieldsOn(Class> cls) {
31 | Set generatedFields = new HashSet<>();
32 | for (Field field : cls.getDeclaredFields()) {
33 | if (!Modifier.isStatic(field.getModifiers())) {
34 | generatedFields.add(field.getName());
35 | }
36 | }
37 | return generatedFields;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/JacksonAnyGetterTypeTest.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import com.fasterxml.jackson.databind.node.IntNode;
6 | import com.fasterxml.jackson.databind.node.TextNode;
7 | import org.junit.Test;
8 |
9 | import java.io.IOException;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertNotNull;
13 | import static org.junit.Assert.assertTrue;
14 |
15 | public class JacksonAnyGetterTypeTest {
16 |
17 | private final ObjectMapper objectMapper = new ObjectMapper();
18 |
19 | @Test
20 | public void testDeserializeJsonWithAnyGetter() throws IOException {
21 | JacksonAnyGetterType parsed = objectMapper.readValue(
22 | "{\"simple_property\": \"simpleValue\", \"other_property\": 3}",
23 | JacksonAnyGetterType.class);
24 |
25 | assertEquals("simpleValue", parsed.getSimpleProperty());
26 | assertNotNull(parsed.getUnknownProperties());
27 | assertEquals(1, parsed.getUnknownProperties().size());
28 | assertEquals(new IntNode(3), parsed.getUnknownProperties().get("other_property"));
29 | }
30 |
31 | @Test
32 | public void testSerializeJsonWithAnyGetter() throws JsonProcessingException {
33 | JacksonAnyGetterType getterType = new JacksonAnyGetterType.Builder()
34 | .setSimpleProperty("checkValue")
35 | .putUnknownProperties("propertyOne", new TextNode("abc"))
36 | .putUnknownProperties("propertyTwo", new IntNode(2)).build();
37 |
38 | String json = objectMapper.writeValueAsString(getterType);
39 | assertTrue("should contain simple_property",
40 | json.contains("\"simple_property\":\"checkValue\""));
41 | assertTrue("should contain propertyOne", json.contains("\"propertyOne\":\"abc\""));
42 | assertTrue("should contain propertyTwo", json.contains("\"propertyTwo\":2"));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/MapGwtTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import com.google.common.collect.ImmutableMap;
21 |
22 | import java.util.Map;
23 |
24 | import org.junit.Test;
25 | import org.junit.runner.RunWith;
26 | import org.junit.runners.JUnit4;
27 |
28 | /** FreeBuilder test using {@link MapGwtType}. */
29 | @RunWith(JUnit4.class)
30 | public class MapGwtTypeTest {
31 |
32 | private static final String NAME_1 = "name1";
33 | private static final String NAME_2 = "name2";
34 | private static final String NAME_3 = "name3";
35 | private static final double DISTANCE_1 = 8.7;
36 | private static final double DISTANCE_2 = 13.1;
37 | private static final double DISTANCE_3 = 27.0;
38 |
39 | @Test
40 | public void testAllMethodInteractions() {
41 | MapGwtType.Builder builder = new MapGwtType.Builder();
42 | Map distancesView = builder.getDistances();
43 | assertEquals(ImmutableMap.of(), distancesView);
44 | assertEquals(ImmutableMap.of(), builder.build().getDistances());
45 | builder.putDistances(NAME_1, DISTANCE_1);
46 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1), distancesView);
47 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1), builder.build().getDistances());
48 | builder.putAllDistances(ImmutableMap.of(NAME_2, DISTANCE_2, NAME_3, DISTANCE_3));
49 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1, NAME_2, DISTANCE_2, NAME_3, DISTANCE_3),
50 | distancesView);
51 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1, NAME_2, DISTANCE_2, NAME_3, DISTANCE_3),
52 | builder.build().getDistances());
53 | builder.removeDistances(NAME_2);
54 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1, NAME_3, DISTANCE_3), distancesView);
55 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1, NAME_3, DISTANCE_3),
56 | builder.build().getDistances());
57 | builder.clearDistances();
58 | assertEquals(ImmutableMap.of(), distancesView);
59 | assertEquals(ImmutableMap.of(), builder.build().getDistances());
60 | builder.putDistances(NAME_1, DISTANCE_1);
61 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1), distancesView);
62 | assertEquals(ImmutableMap.of(NAME_1, DISTANCE_1), builder.build().getDistances());
63 | builder.clear();
64 | assertEquals(ImmutableMap.of(), distancesView);
65 | assertEquals(ImmutableMap.of(), builder.build().getDistances());
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/NestedListGwtTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static java.util.Arrays.asList;
19 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.junit.runners.JUnit4;
25 |
26 | /** FreeBuilder test using {@link NestedListGwtType}. */
27 | @RunWith(JUnit4.class)
28 | public class NestedListGwtTypeTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testAllMethodInteractions() {
36 | NestedListGwtType.Builder builder = new NestedListGwtType.Builder();
37 | // getItemBuilder()
38 | builder.getItemBuilder().addNames(NAME_1);
39 | assertEquals(asList(NAME_1), builder.build().getItem().getNames());
40 | // setItem(Value)
41 | builder.setItem(new StringListGwtType.Builder()
42 | .addNames(NAME_2, NAME_3)
43 | .build());
44 | assertEquals(asList(NAME_2, NAME_3), builder.build().getItem().getNames());
45 | // setItem(Builder)
46 | builder.setItem(new StringListGwtType.Builder()
47 | .addNames(NAME_1, NAME_3));
48 | assertEquals(asList(NAME_1, NAME_3), builder.build().getItem().getNames());
49 | // Top-level clear()
50 | builder.clear();
51 | assertEquals(asList(), builder.build().getItem().getNames());
52 | // mergeFrom(Value)
53 | builder.mergeFrom(new NestedListGwtType.Builder()
54 | .setItem(new StringListGwtType.Builder()
55 | .addNames(NAME_2))
56 | .build());
57 | assertEquals(asList(NAME_2), builder.build().getItem().getNames());
58 | // mergeFrom(Builder)
59 | builder.mergeFrom(new NestedListGwtType.Builder()
60 | .setItem(new StringListGwtType.Builder()
61 | .addNames(NAME_3)));
62 | assertEquals(asList(NAME_2, NAME_3), builder.build().getItem().getNames());
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/NoFrillsDataInterfaceTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 | import static org.junit.Assert.assertTrue;
20 |
21 | import org.junit.Test;
22 | import org.junit.runner.RunWith;
23 | import org.junit.runners.JUnit4;
24 |
25 | /**
26 | * Integration test for {@link org.inferred.freebuilder.FreeBuilder
27 | * FreeBuilder}, using the {@link NoFrillsDataInterface}.
28 | */
29 | @RunWith(JUnit4.class)
30 | public class NoFrillsDataInterfaceTest {
31 |
32 | @Test
33 | public void test() {
34 | NoFrillsDataInterface b = new NoFrillsDataInterface.Builder()
35 | .setPropertyA(11)
36 | .setPropertyB(true)
37 | .build();
38 | assertEquals(11, b.getPropertyA());
39 | assertTrue(b.isPropertyB());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/NoFrillsDataTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 | import static org.junit.Assert.assertTrue;
20 |
21 | import org.junit.Test;
22 | import org.junit.runner.RunWith;
23 | import org.junit.runners.JUnit4;
24 |
25 | /**
26 | * Integration test for {@link org.inferred.freebuilder.FreeBuilder
27 | * FreeBuilder}, using the {@link NoFrillsDataType}.
28 | */
29 | @RunWith(JUnit4.class)
30 | public class NoFrillsDataTypeTest {
31 |
32 | @Test
33 | public void test() {
34 | NoFrillsDataType value = NoFrillsDataType.builder()
35 | .setPropertyA(11)
36 | .setPropertyB(true)
37 | .build();
38 | assertEquals(11, value.getPropertyA());
39 | assertTrue(value.isPropertyB());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/OptionalGwtTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import com.google.common.base.Optional;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.junit.runners.JUnit4;
25 |
26 | /** FreeBuilder test using {@link OptionalGwtType}. */
27 | @RunWith(JUnit4.class)
28 | public class OptionalGwtTypeTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testAllMethodInteractions() {
36 | OptionalGwtType.Builder builder = new OptionalGwtType.Builder();
37 | builder.setName(NAME_1);
38 | assertEquals(Optional.of(NAME_1), builder.getName());
39 | assertEquals(Optional.of(NAME_1), builder.build().getName());
40 | builder.clearName();
41 | assertEquals(Optional.absent(), builder.getName());
42 | assertEquals(Optional.absent(), builder.build().getName());
43 | builder.setNullableName(NAME_3);
44 | assertEquals(Optional.of(NAME_3), builder.getName());
45 | assertEquals(Optional.of(NAME_3), builder.build().getName());
46 | builder.setName(Optional.absent());
47 | assertEquals(Optional.absent(), builder.getName());
48 | assertEquals(Optional.absent(), builder.build().getName());
49 | builder.setNullableName(null);
50 | assertEquals(Optional.absent(), builder.getName());
51 | assertEquals(Optional.absent(), builder.build().getName());
52 | builder.setName(Optional.of(NAME_2));
53 | assertEquals(Optional.of(NAME_2), builder.getName());
54 | assertEquals(Optional.of(NAME_2), builder.build().getName());
55 | builder.clear();
56 | assertEquals(Optional.absent(), builder.getName());
57 | assertEquals(Optional.absent(), builder.build().getName());
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/StringListGwtTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static java.util.Arrays.asList;
19 |
20 | import static org.junit.Assert.assertEquals;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.junit.runners.JUnit4;
25 |
26 | /** FreeBuilder test using {@link StringListGwtType}. */
27 | @RunWith(JUnit4.class)
28 | public class StringListGwtTypeTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testAllMethodInteractions() {
36 | StringListGwtType.Builder builder = new StringListGwtType.Builder();
37 | builder.addNames(NAME_1);
38 | assertEquals(asList(NAME_1), builder.build().getNames());
39 | builder.addNames(NAME_2, NAME_3);
40 | assertEquals(asList(NAME_1, NAME_2, NAME_3), builder.build().getNames());
41 | builder.clearNames();
42 | assertEquals(asList(), builder.build().getNames());
43 | builder.addAllNames(asList(NAME_2, NAME_1));
44 | assertEquals(asList(NAME_2, NAME_1), builder.build().getNames());
45 | builder.clear();
46 | assertEquals(asList(), builder.build().getNames());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/it/vanilla/src/test/java/org/inferred/freebuilder/WildcardListTypeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import static org.junit.Assert.assertEquals;
19 |
20 | import java.util.Arrays;
21 |
22 | import org.junit.Test;
23 | import org.junit.runner.RunWith;
24 | import org.junit.runners.JUnit4;
25 |
26 | /** FreeBuilder test using {@link WildcardListType}. */
27 | @RunWith(JUnit4.class)
28 | public class WildcardListTypeTest {
29 |
30 | private static final String NAME_1 = "name1";
31 | private static final String NAME_2 = "name2";
32 | private static final String NAME_3 = "name3";
33 |
34 | @Test
35 | public void testBuild() {
36 | WildcardListType value = new WildcardListType.Builder()
37 | .addNumbers(1)
38 | .addNumbers(2.8)
39 | .build();
40 | assertEquals(Arrays.asList(1, 2.8), value.numbers());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/FreeBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Annotates a type that has an auto-generated builder.
25 | *
26 | *
Quick start
27 | *
28 | *
Create your value type (e.g. {@code Person}) as an interface or abstract class, containing
29 | * an abstract accessor method for each desired field. This accessor must be non-void,
30 | * parameterless, and start with 'get' or 'is'. Add the {@code @FreeBuilder} annotation to your
31 | * class, and it will automatically generate an implementing class and a package-visible builder API
32 | * ({@code Person_Builder}), which you must subclass. For instance:
33 | *
34 | *
@FreeBuilder
35 | * public interface Person {
36 | * /** Returns the person's full (English) name. */
37 | * String getName();
38 | * /** Returns the person's age in years, rounded down. */
39 | * int getAge();
40 | * /** Builder of {@link Person} instances. */
41 | * class Builder extends Person_Builder { }
42 | * }
43 | *
44 | *
You can now use the {@code Builder} class:
45 | *
46 | *
Person person = new Person.Builder()
47 | * .setName("Phil")
48 | * .setAge(31)
49 | * .build();
50 | * System.out.println(person); // Person{name=Phil, age=31}
To maintain the contract of {@link Object#hashCode()}), the value of these properties will
16 | * also be ignored in the generated implementation of that method.
17 | *
18 | *
Warning: Dropping properties from equality checks makes it very easy to accidentally
19 | * write broken unit tests (and hard to write good ones). If you find yourself wanting to use
20 | * this annotation, consider first whether you actually want a different collection type
21 | * (typicaly a {@link Map} rather than a {@link Set}, for instance), or whether you can use an
22 | * explicit field-ignoring {@link Comparator} in the parts of the code that need it.
23 | */
24 | @Target(ElementType.METHOD)
25 | @Retention(RetentionPolicy.SOURCE)
26 | public @interface IgnoredByEquals {
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/NotInToString.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * {@link FreeBuilder} will not include properties annotated {@code @NotInToString} in the output of
10 | * its generated {@link Object#toString()} implementation.
11 | */
12 | @Target(ElementType.METHOD)
13 | @Retention(RetentionPolicy.SOURCE)
14 | public @interface NotInToString {
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/Declarations.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor;
2 |
3 | import org.inferred.freebuilder.processor.BuilderFactory.TypeInference;
4 | import org.inferred.freebuilder.processor.source.Scope;
5 | import org.inferred.freebuilder.processor.source.Scope.Level;
6 | import org.inferred.freebuilder.processor.source.SourceBuilder;
7 | import org.inferred.freebuilder.processor.source.Variable;
8 |
9 | import java.util.Optional;
10 |
11 | public class Declarations {
12 |
13 | private static final String UPCAST_COMMENT =
14 | "// Upcast to access private fields; otherwise, oddly, we get an access violation.";
15 |
16 | private enum Declaration implements Scope.Key {
17 | UPCAST, FRESH_BUILDER;
18 |
19 | @Override
20 | public Level level() {
21 | return Level.METHOD;
22 | }
23 | }
24 |
25 | /**
26 | * Upcasts a Builder instance to the generated superclass, to allow access to private fields.
27 | *
28 | *
Reuses an existing upcast instance if one was already declared in this scope.
29 | *
30 | * @param code the {@link SourceBuilder} to add the declaration to
31 | * @param datatype metadata about the user type the builder is being generated for
32 | * @param builder the Builder instance to upcast
33 | * @returns a variable holding the upcasted instance
34 | */
35 | public static Variable upcastToGeneratedBuilder(
36 | SourceBuilder code, Datatype datatype, String builder) {
37 | return code.scope().computeIfAbsent(Declaration.UPCAST, () -> {
38 | Variable base = new Variable("base");
39 | code.addLine(UPCAST_COMMENT)
40 | .addLine("%s %s = %s;", datatype.getGeneratedBuilder(), base, builder);
41 | return base;
42 | });
43 | }
44 |
45 | /**
46 | * Declares a fresh Builder to copy default property values from.
47 | *
48 | *
Reuses an existing fresh Builder instance if one was already declared in this scope.
49 | *
50 | * @returns a variable holding a fresh Builder, if a no-args factory method is available to
51 | * create one with
52 | */
53 | public static Optional freshBuilder(SourceBuilder code, Datatype datatype) {
54 | if (!datatype.getBuilderFactory().isPresent()) {
55 | return Optional.empty();
56 | }
57 | return Optional.of(code.scope().computeIfAbsent(Declaration.FRESH_BUILDER, () -> {
58 | Variable defaults = new Variable("defaults");
59 | code.addLine("%s %s = %s;",
60 | datatype.getGeneratedBuilder(),
61 | defaults,
62 | datatype.getBuilderFactory().get()
63 | .newBuilder(datatype.getBuilder(), TypeInference.INFERRED_TYPES));
64 | return defaults;
65 | }));
66 | }
67 |
68 | private Declarations() {}
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/GeneratedStub.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor;
2 |
3 | import org.inferred.freebuilder.processor.source.Excerpts;
4 | import org.inferred.freebuilder.processor.source.QualifiedName;
5 | import org.inferred.freebuilder.processor.source.SourceBuilder;
6 | import org.inferred.freebuilder.processor.source.TypeClass;
7 |
8 | class GeneratedStub extends GeneratedType {
9 |
10 | private final QualifiedName datatype;
11 | private final TypeClass stub;
12 |
13 | GeneratedStub(QualifiedName datatype, TypeClass stub) {
14 | this.datatype = datatype;
15 | this.stub = stub;
16 | }
17 |
18 | @Override
19 | public void addTo(SourceBuilder code) {
20 | code.addLine("// Autogenerated code. Do not modify.")
21 | .addLine("package %s;", stub.getQualifiedName().getPackage())
22 | .addLine("")
23 | .addLine("/**")
24 | .addLine(" * Placeholder. Create {@code %s.Builder} and subclass this type.", datatype)
25 | .addLine(" */")
26 | .add(Excerpts.generated(Processor.class))
27 | .addLine("abstract class %s {}", stub.declaration());
28 | }
29 |
30 | @Override
31 | protected void addFields(FieldReceiver fields) {
32 | fields.add("datatype", datatype);
33 | fields.add("stub", stub);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/GeneratedType.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor;
2 |
3 | import org.inferred.freebuilder.processor.source.Excerpt;
4 | import org.inferred.freebuilder.processor.source.ValueType;
5 |
6 | abstract class GeneratedType extends ValueType implements Excerpt {
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/NameAndVisibility.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor;
2 |
3 | import org.inferred.freebuilder.processor.Datatype.Visibility;
4 |
5 | import java.util.Objects;
6 |
7 | public class NameAndVisibility {
8 |
9 | public static NameAndVisibility of(String name, Visibility visibility) {
10 | return new NameAndVisibility(name, visibility);
11 | }
12 |
13 | private final String name;
14 | private final Visibility visibility;
15 |
16 | private NameAndVisibility(String name, Visibility visibility) {
17 | this.name = name;
18 | this.visibility = visibility;
19 | }
20 |
21 | public String name() {
22 | return name;
23 | }
24 |
25 | public Visibility visibility() {
26 | return visibility;
27 | }
28 |
29 | @Override
30 | public int hashCode() {
31 | return Objects.hash(name, visibility);
32 | }
33 |
34 | @Override
35 | public boolean equals(Object obj) {
36 | if (this == obj) {
37 | return true;
38 | }
39 | if (!(obj instanceof NameAndVisibility)) {
40 | return false;
41 | }
42 | NameAndVisibility other = (NameAndVisibility) obj;
43 | return Objects.equals(name, other.name) && visibility == other.visibility;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "NameAndVisibility{name=" + name + ", visibility=" + visibility + "}";
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/excerpt/CheckedSet.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor.excerpt;
2 |
3 | import org.inferred.freebuilder.processor.source.Excerpt;
4 | import org.inferred.freebuilder.processor.source.LazyName;
5 | import org.inferred.freebuilder.processor.source.SourceBuilder;
6 | import org.inferred.freebuilder.processor.source.ValueType;
7 |
8 | import java.util.AbstractSet;
9 | import java.util.Iterator;
10 | import java.util.Set;
11 | import java.util.function.Consumer;
12 |
13 | /**
14 | * Excerpts defining a set implementation that delegates to a provided add method to perform
15 | * element validation and insertion into a backing set.
16 | */
17 | public class CheckedSet extends ValueType implements Excerpt {
18 |
19 | public static final LazyName TYPE = LazyName.of("CheckedSet", new CheckedSet());
20 |
21 | private CheckedSet() {}
22 |
23 | @Override
24 | public void addTo(SourceBuilder code) {
25 | code.addLine("")
26 | .addLine("/**")
27 | .addLine(" * A set implementation that delegates to a provided add method")
28 | .addLine(" * to perform element validation and insertion into a backing set.")
29 | .addLine(" */")
30 | .addLine("private static class %s extends %s {", TYPE, AbstractSet.class)
31 | .addLine("")
32 | .addLine(" private final %s set;", Set.class)
33 | .addLine(" private final %s add;", Consumer.class)
34 | .addLine("")
35 | .addLine(" %s(%s set, %s add) {", TYPE, Set.class, Consumer.class)
36 | .addLine(" this.set = set;")
37 | .addLine(" this.add = add;")
38 | .addLine(" }")
39 | .addLine("")
40 | .addLine("")
41 | .addLine(" @Override public %s iterator() {", Iterator.class)
42 | .addLine(" return set.iterator();")
43 | .addLine(" }")
44 | .addLine("")
45 | .addLine(" @Override public int size() {")
46 | .addLine(" return set.size();")
47 | .addLine(" }")
48 | .addLine("")
49 | .addLine(" @Override public boolean contains(Object e) {")
50 | .addLine(" return set.contains(e);")
51 | .addLine(" }")
52 | .addLine("")
53 | .addLine(" @Override public boolean add(E e) {")
54 | .addLine(" if (!set.contains(e)) {")
55 | .addLine(" add.accept(e);")
56 | .addLine(" return true;")
57 | .addLine(" } else {")
58 | .addLine(" return false;")
59 | .addLine(" }")
60 | .addLine(" }")
61 | .addLine("")
62 | .addLine(" @Override public boolean remove(Object e) {")
63 | .addLine(" return set.remove(e);")
64 | .addLine(" }")
65 | .addLine("}");
66 | }
67 |
68 | @Override
69 | protected void addFields(FieldReceiver fields) {}
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/naming/NamingConvention.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.processor.naming;
17 |
18 | import org.inferred.freebuilder.processor.property.Property;
19 |
20 | import java.util.Optional;
21 |
22 | import javax.lang.model.element.ExecutableElement;
23 | import javax.lang.model.element.TypeElement;
24 |
25 | public interface NamingConvention {
26 | /**
27 | * Verifies {@code method} is an abstract getter following this naming convention. Any
28 | * deviations will be logged as an error.
29 | */
30 | Optional getPropertyNames(TypeElement valueType, ExecutableElement method);
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/property/Factories.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor.property;
2 |
3 | import com.google.common.collect.ImmutableList;
4 |
5 | import java.util.List;
6 |
7 | public class Factories {
8 |
9 | /**
10 | * Factories of {@link PropertyCodeGenerator} instances. Note: order is important; the default
11 | * factory should always be last.
12 | */
13 | public static final List PROPERTY_FACTORIES = ImmutableList.of(
14 | new NullableProperty.Factory(), // Must be first, as no other factory supports nulls
15 | new BuildableListProperty.Factory(), // Must be before ListProperty
16 | new ListProperty.Factory(),
17 | new SetProperty.Factory(),
18 | new SortedSetProperty.Factory(),
19 | new MapProperty.Factory(),
20 | new BiMapProperty.Factory(),
21 | new MultisetProperty.Factory(),
22 | new ListMultimapProperty.Factory(),
23 | new SetMultimapProperty.Factory(),
24 | new PrimitiveOptionalProperty.Factory(),
25 | new OptionalProperty.Factory(),
26 | new BuildableProperty.Factory(),
27 | new DefaultProperty.Factory()); // Must be last, as it will always return a CodeGenerator
28 |
29 | private Factories() { }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/property/MergeAction.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor.property;
2 |
3 | import static com.google.common.collect.Iterables.getLast;
4 |
5 | import com.google.common.collect.ImmutableList;
6 | import com.google.common.collect.SetMultimap;
7 | import com.google.common.collect.TreeMultimap;
8 |
9 | import org.inferred.freebuilder.processor.source.SourceBuilder;
10 | import org.inferred.freebuilder.processor.source.ValueType;
11 |
12 | import java.util.List;
13 | import java.util.Set;
14 |
15 | /**
16 | * Readable action fragments for documenting mergeFrom behaviors.
17 | */
18 | public class MergeAction extends ValueType {
19 |
20 | public static MergeAction appendingToCollections() {
21 | return new MergeAction("appending to", "collections", false);
22 | }
23 |
24 | public static MergeAction skippingDefaults() {
25 | return new MergeAction("skipping", "defaults", false);
26 | }
27 |
28 | public static MergeAction skippingEmptyOptionals() {
29 | return new MergeAction("skipping", "empty optionals", false);
30 | }
31 |
32 | public static MergeAction skippingUnsetProperties() {
33 | return new MergeAction("skipping", "unset properties", true);
34 | }
35 |
36 | /**
37 | * Emits a sentence fragment combining all the merge actions.
38 | */
39 | public static void addActionsTo(
40 | SourceBuilder code,
41 | Set mergeActions,
42 | boolean forBuilder) {
43 | SetMultimap nounsByVerb = TreeMultimap.create();
44 | mergeActions.forEach(mergeAction -> {
45 | if (forBuilder || !mergeAction.builderOnly) {
46 | nounsByVerb.put(mergeAction.verb, mergeAction.noun);
47 | }
48 | });
49 | List verbs = ImmutableList.copyOf(nounsByVerb.keySet());
50 | String lastVerb = getLast(verbs, null);
51 | for (String verb : nounsByVerb.keySet()) {
52 | code.add(", %s%s", (verbs.size() > 1 && verb.equals(lastVerb)) ? "and " : "", verb);
53 | List nouns = ImmutableList.copyOf(nounsByVerb.get(verb));
54 | for (int i = 0; i < nouns.size(); ++i) {
55 | String separator = (i == 0) ? "" : (i == nouns.size() - 1) ? " and" : ",";
56 | code.add("%s %s", separator, nouns.get(i));
57 | }
58 | }
59 | }
60 |
61 | private final String verb;
62 | private final String noun;
63 | private final boolean builderOnly;
64 |
65 | private MergeAction(String verb, String noun, boolean builderOnly) {
66 | this.verb = verb;
67 | this.noun = noun;
68 | this.builderOnly = builderOnly;
69 | }
70 |
71 | @Override
72 | protected void addFields(FieldReceiver fields) {
73 | fields.add("verb", verb);
74 | fields.add("noun", noun);
75 | fields.add("builderOnly", builderOnly);
76 | }
77 |
78 | @Override
79 | public String toString() {
80 | return verb + " " + noun + (builderOnly ? " on builders" : "");
81 | }
82 | }
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/ElementAppender.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor.source;
2 |
3 | import javax.lang.model.element.Element;
4 | import javax.lang.model.element.PackageElement;
5 | import javax.lang.model.element.TypeElement;
6 | import javax.lang.model.util.SimpleElementVisitor8;
7 |
8 | class ElementAppender extends SimpleElementVisitor8 {
9 | private static final ElementAppender INSTANCE = new ElementAppender();
10 |
11 | public static void appendShortened(Element arg, QualifiedNameAppendable source) {
12 | INSTANCE.visit(arg, source);
13 | }
14 |
15 | private ElementAppender() { }
16 |
17 | @Override
18 | public Void visitPackage(PackageElement pkg, QualifiedNameAppendable a) {
19 | a.append(pkg.getQualifiedName());
20 | return null;
21 | }
22 |
23 | @Override
24 | public Void visitType(TypeElement type, QualifiedNameAppendable a) {
25 | a.append(QualifiedName.of(type));
26 | return null;
27 | }
28 |
29 | @Override
30 | protected Void defaultAction(Element e, QualifiedNameAppendable a) {
31 | a.append(e.toString());
32 | return null;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/Excerpt.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.processor.source;
17 |
18 | /**
19 | * An object representing a source code excerpt, e.g. a type.
20 | */
21 | @FunctionalInterface
22 | public interface Excerpt {
23 | void addTo(SourceBuilder source);
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/Excerpts.java:
--------------------------------------------------------------------------------
1 | package org.inferred.freebuilder.processor.source;
2 |
3 | import org.inferred.freebuilder.processor.source.feature.JavaxPackage;
4 |
5 | public class Excerpts {
6 |
7 | public static final Excerpt EMPTY = code -> { };
8 |
9 | public static Excerpt add(String fmt, Object... args) {
10 | return code -> code.add(fmt, args);
11 | }
12 |
13 | /**
14 | * Returns an excerpt of the {@link javax.annotation.Generated} annotation, if available,
15 | * with value set to the full name of the {@code generator} class as recommended.
16 | */
17 | public static Excerpt generated(Class> generator) {
18 | return code -> {
19 | code.feature(JavaxPackage.JAVAX).generated().ifPresent(generated -> {
20 | code.addLine("@%s(\"%s\")", generated, generator.getName());
21 | });
22 | };
23 | }
24 |
25 | public static Excerpt join(String separator, Iterable> excerpts) {
26 | return code -> appendJoined(code, separator, excerpts);
27 | }
28 |
29 | private static void appendJoined(SourceBuilder source, String separator, Iterable> excerpts) {
30 | String itemPrefix = "";
31 | for (Object object : excerpts) {
32 | source.add("%s%s", itemPrefix, object);
33 | itemPrefix = separator;
34 | }
35 | }
36 |
37 | private Excerpts() {}
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/FieldAccess.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.processor.source;
17 |
18 | public class FieldAccess extends ValueType implements Excerpt {
19 |
20 | private final String fieldName;
21 |
22 | public FieldAccess(String fieldName) {
23 | this.fieldName = fieldName;
24 | }
25 |
26 | @Override
27 | public void addTo(SourceBuilder source) {
28 | IdKey key = new IdKey(fieldName);
29 | if (source.scope().canStore(key)) {
30 | // In method scope; we may need to qualify the field reference
31 | Object idOwner = source.scope().putIfAbsent(key, this);
32 | if (idOwner != null && !idOwner.equals(this)) {
33 | source.add("this.");
34 | }
35 | }
36 | source.add(fieldName);
37 | }
38 |
39 | public Excerpt on(Object obj) {
40 | return code -> code.add("%s.%s", obj, fieldName);
41 | }
42 |
43 | @Override
44 | protected void addFields(FieldReceiver fields) {
45 | fields.add("fieldName", fieldName);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/FilerUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.processor.source;
17 |
18 | import java.io.IOException;
19 | import java.io.Writer;
20 |
21 | import javax.annotation.processing.Filer;
22 | import javax.lang.model.element.Element;
23 |
24 | /** Static utility methods for working with {@link Filer}. */
25 | public class FilerUtils {
26 |
27 | /**
28 | * Writes {@code unit} to the correct file.
29 | *
30 | *
This is complicated by an EJC bug that returns the wrong object from
31 | * {@link Writer#append(CharSequence)}.
32 | */
33 | public static void writeCompilationUnit(
34 | Filer filer,
35 | SourceBuilder unit,
36 | Element originatingElement) throws IOException {
37 | String typename = unit.typename().toString();
38 | String finalSource = unit.toString();
39 | try (Writer writer = filer.createSourceFile(typename, originatingElement).openWriter()) {
40 | writer.append(finalSource);
41 | }
42 | }
43 |
44 | private FilerUtils() {}
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/inferred/freebuilder/processor/source/IdKey.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.inferred.freebuilder.processor.source;
17 |
18 | import org.inferred.freebuilder.processor.source.Scope.Level;
19 |
20 | /**
21 | * Maps Java identifiers to their usage (e.g. a parameter, a variable) in the current method scope.
22 | */
23 | class IdKey extends ValueType implements Scope.Key