diff options
-rw-r--r-- | build.gradle | 6 | ||||
-rw-r--r-- | src/test/examples/autovalue/SimpleAutoValue.java | 54 |
2 files changed, 60 insertions, 0 deletions
diff --git a/build.gradle b/build.gradle index 35da63e27..ef09f766e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ apply plugin: 'idea' apply plugin: 'com.google.protobuf' apply plugin: 'com.cookpad.android.licensetools' apply plugin: 'net.ltgt.errorprone-base' +apply plugin: "net.ltgt.apt" def errorProneConfiguration = [ '-XepDisableAllChecks', @@ -51,6 +52,7 @@ buildscript { // classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1' classpath files("third_party/shadow/shadow-2.0.1.jar") classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13" + classpath "net.ltgt.gradle:gradle-apt-plugin:0.12" } } @@ -169,12 +171,16 @@ dependencies { jctfTestsCompile sourceSets.jctfCommon.output examplesAndroidOCompile group: 'org.ow2.asm', name: 'asm', version: '6.0' examplesAndroidPCompile group: 'org.ow2.asm', name: 'asm', version: '6.0' + // Import Guava for @Nullable annotation + examplesCompile 'com.google.guava:guava:23.0' examplesCompile 'com.google.protobuf:protobuf-lite:3.0.0' + examplesCompileOnly "com.google.auto.value:auto-value:1.5" examplesRuntime 'com.google.protobuf:protobuf-lite:3.0.0' supportLibs 'com.android.support:support-v4:25.4.0' supportLibs 'junit:junit:4.12' supportLibs 'com.android.support.test.espresso:espresso-core:3.0.0' debugTestResourcesKotlinCompileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3' + apt 'com.google.auto.value:auto-value:1.5' } licenseTools { diff --git a/src/test/examples/autovalue/SimpleAutoValue.java b/src/test/examples/autovalue/SimpleAutoValue.java new file mode 100644 index 000000000..2c0b2c659 --- /dev/null +++ b/src/test/examples/autovalue/SimpleAutoValue.java @@ -0,0 +1,54 @@ +// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. +package autovalue; + +import com.google.auto.value.AutoValue; +import javax.annotation.Nullable; + +public class SimpleAutoValue { + + @AutoValue + static abstract class Pair { + + Pair() { + // Intentionally left empty. + } + + abstract int getOne(); + + @Nullable + abstract String getOther(); + + abstract String getRequiredOther(); + + static Builder builder() { + return new AutoValue_SimpleAutoValue_Pair.Builder(); + } + + @AutoValue.Builder + abstract static class Builder { + + abstract Builder setOne(int value); + + abstract Builder setOther(String value); + + abstract Builder setRequiredOther(String value); + + abstract Pair build(); + } + } + + public static void main(String... args) { + Pair.Builder builder = Pair.builder(); + builder.setOne(42); + builder.setRequiredOther("123"); + System.out.println(builder.build()); + builder = Pair.builder(); + try { + builder.build(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +} |