|
| 1 | +/* |
| 2 | + * Copyright 2019 Google LLC |
| 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 com.google.auto.value; |
| 17 | + |
| 18 | +import static com.google.common.truth.Truth.assertThat; |
| 19 | + |
| 20 | +import com.google.common.collect.ImmutableList; |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.runner.RunWith; |
| 23 | +import org.junit.runners.JUnit4; |
| 24 | + |
| 25 | +/** |
| 26 | + * Like {@link AutoValueTest}, but with code that doesn't build with at least some versions of |
| 27 | + * Eclipse, and should therefore not be included in {@link CompileWithEclipseTest}. (The latter is |
| 28 | + * not currently present in the open-source build.) |
| 29 | + */ |
| 30 | +@RunWith(JUnit4.class) |
| 31 | +public class AutoValueNotEclipseTest { |
| 32 | + interface ImmutableListOf<T> { |
| 33 | + ImmutableList<T> list(); |
| 34 | + } |
| 35 | + |
| 36 | + // This provoked the following with the Eclipse compiler: |
| 37 | + // java.lang.NullPointerException |
| 38 | + // at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.readableName(ParameterizedTypeBinding.java:1021) |
| 39 | + // at org.eclipse.jdt.internal.compiler.apt.model.DeclaredTypeImpl.toString(DeclaredTypeImpl.java:118) |
| 40 | + // at java.lang.String.valueOf(String.java:2996) |
| 41 | + // at java.lang.StringBuilder.append(StringBuilder.java:131) |
| 42 | + // at org.eclipse.jdt.internal.compiler.apt.model.TypesImpl.asMemberOf(TypesImpl.java:130) |
| 43 | + // at com.google.auto.value.processor.EclipseHack.methodReturnType(EclipseHack.java:124) |
| 44 | + // at com.google.auto.value.processor.TypeVariables.lambda$rewriteReturnTypes$1(TypeVariables.java:106) |
| 45 | + @AutoValue |
| 46 | + abstract static class PropertyBuilderInheritsType implements ImmutableListOf<String> { |
| 47 | + static Builder builder() { |
| 48 | + return new AutoValue_AutoValueNotEclipseTest_PropertyBuilderInheritsType.Builder(); |
| 49 | + } |
| 50 | + |
| 51 | + @AutoValue.Builder |
| 52 | + abstract static class Builder { |
| 53 | + abstract ImmutableList.Builder<String> listBuilder(); |
| 54 | + abstract PropertyBuilderInheritsType build(); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void propertyBuilderInheritsType() { |
| 60 | + PropertyBuilderInheritsType.Builder builder = PropertyBuilderInheritsType.builder(); |
| 61 | + builder.listBuilder().add("foo", "bar"); |
| 62 | + PropertyBuilderInheritsType x = builder.build(); |
| 63 | + assertThat(x.list()).containsExactly("foo", "bar").inOrder(); |
| 64 | + } |
| 65 | +} |
0 commit comments