Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch for "AutoValue should respect @Nullable annotations on types #283" #293

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ script:
jdk:
- oraclejdk7
- openjdk7
- oraclejdk8

branches:
except:
Expand Down
6 changes: 6 additions & 0 deletions value/src/it/functional-java8/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
invoker.goals = clean verify

invoker.profiles.1 =
invoker.profiles.2 = eclipse

invoker.java.version=1.8+
92 changes: 92 additions & 0 deletions value/src/it/functional-java8/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013 Google, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- TODO(gak): see if we can manage these dependencies any better -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.auto.value.it.functional</groupId>
<artifactId>functional-java8</artifactId>
<version>HEAD-SNAPSHOT</version>
<name>Auto-Value Functional Integration Test (Java 8)</name>
<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>@auto.version@</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>18.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>eclipse</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Acom.google.auto.value.EclipseHackTest=1</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.google.auto.value.AutoValue;

import java.util.Map;

/**
* @author emcmanus@google.com (Éamonn McManus)
*/
public class PackagelessNestedValueType {
@AutoValue
public abstract static class Nested {
abstract Map<Integer, String> numberNames();

public static Nested create(Map<Integer, String> numberNames) {
return new AutoValue_PackagelessNestedValueType_Nested(numberNames);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.google.auto.value.AutoValue;

import java.util.Map;

import com.google.auto.value.annotation.Nullable;

/**
* Simple package-less value type for tests.
*
* @see PackagelessValueTypeTest
* @author emcmanus@google.com (Éamonn McManus)
*/
@AutoValue
public abstract class PackagelessValueType {
// The getters here are formatted as an illustration of what getters typically look in real
// classes. In particular they have doc comments.

/**
* @return A string that is a nullable string.
*/
@Nullable public abstract String string();

/**
* @return An integer that is an integer.
*/
public abstract int integer();

/**
* @return A non-null map where the keys are strings and the values are longs.
*/
public abstract Map<String, Long> map();

public static PackagelessValueType create(
@Nullable String string, int integer, Map<String, Long> map) {
// The subclass AutoValue_PackagelessValueType is created by the annotation processor that is
// triggered by the presence of the @AutoValue annotation. It has a constructor for each
// of the abstract getter methods here, in order. The constructor stashes the values here
// in private final fields, and each method is implemented to return the value of the
// corresponding field.
return new AutoValue_PackagelessValueType(string, integer, map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.google.auto.value;

import java.util.Map;

/**
* @author emcmanus@google.com (Éamonn McManus)
*/
public class NestedValueType {
@AutoValue
public abstract static class Nested {
abstract Map<Integer, String> numberNames();

public static Nested create(Map<Integer, String> numberNames) {
return new AutoValue_NestedValueType_Nested(numberNames);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.auto.value;

import java.util.Map;

import com.google.auto.value.annotation.Nullable;

/**
* Simple value type for tests.
*
* @see SimpleValueTypeTest
* @author emcmanus@google.com (Éamonn McManus)
*/
@AutoValue
public abstract class SimpleValueType {
// The getters here are formatted as an illustration of what getters typically look in real
// classes. In particular they have doc comments.

/**
* @return A string that is a nullable string.
*/
@Nullable public abstract String string();

/**
* @return An integer that is an integer.
*/
public abstract int integer();

/**
* @return A non-null map where the keys are strings and the values are longs.
*/
public abstract Map<String, Long> map();

public static SimpleValueType create(
@Nullable String string, int integer, Map<String, Long> map) {
// The subclass AutoValue_SimpleValueType is created by the annotation processor that is
// triggered by the presence of the @AutoValue annotation. It has a constructor for each
// of the abstract getter methods here, in order. The constructor stashes the values here
// in private final fields, and each method is implemented to return the value of the
// corresponding field.
return new AutoValue_SimpleValueType(string, integer, map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.google.auto.value.annotation;
/**
* NOTE: Testing with org.eclipse.jdt.annotation.Nullable (v2) doesn't work because it has
* RetentionPolicy.CLASS, but RUNTIME is needed for
* com.google.auto.value.AutoValueTest.testNullablePropertyConstructorParameterIsNullable()
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE })
public @interface Nullable {
// empty body
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.google.common.collect.ImmutableMap;
import com.google.common.testing.NullPointerTester;

import junit.framework.TestCase;

import java.util.Map;

import org.junit.Ignore;

/**
* @author emcmanus@google.com (Éamonn McManus)
*/
public class PackagelessValueTypeTest extends TestCase {
public void testPackagelessValueType() {
final String happy = "happy";
final int testInt = 23;
final Map<String, Long> testMap = ImmutableMap.of("happy", 23L);
PackagelessValueType simple = PackagelessValueType.create(happy, testInt, testMap);
assertSame(happy, simple.string());
assertEquals(testInt, simple.integer());
assertSame(testMap, simple.map());
assertEquals("PackagelessValueType{string=happy, integer=23, map={happy=23}}",
simple.toString());
int expectedHashCode = 1;
expectedHashCode = (expectedHashCode * 1000003) ^ happy.hashCode();
expectedHashCode = (expectedHashCode * 1000003) ^ ((Object) testInt).hashCode();
expectedHashCode = (expectedHashCode * 1000003) ^ testMap.hashCode();
assertEquals(expectedHashCode, simple.hashCode());
}

public void testNestedValueType() {
ImmutableMap<Integer, String> numberNames = ImmutableMap.of(1, "un", 2, "deux");
PackagelessNestedValueType.Nested nested =
PackagelessNestedValueType.Nested.create(numberNames);
assertEquals(numberNames, nested.numberNames());
}

@Ignore("NullPointerTester doesn't support type annotations yet")
public void ignoredTestNull() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(PackagelessValueType.class);
}
}
Loading