external/guava/guava/src/com/google/common/reflect/Types.java:317: error: TypeVariableImpl is not abstract and does not override abstract method getAnnotatedBounds() in TypeVariable private static final class TypeVariableImpl<D extends GenericDeclaration>



index 0f05f78..be358c7 100644



--- a external/guava/guava/src/com/google/common/reflect/Types.java



+++ b external/guava/guava/src/com/google/common/reflect/Types.java



@@ -19,30 +19,36 @@
1919 import static com.google.common.base.Preconditions.checkArgument;

2020 import static com.google.common.base.Preconditions.checkNotNull;

2121 import static com.google.common.collect.Iterables.transform;

2222 

2323 import com.google.common.annotations.VisibleForTesting;

2424 import com.google.common.base.Function;

2525 import com.google.common.base.Joiner;

2626 import com.google.common.base.Objects;

2727 import com.google.common.base.Predicates;

2828 import com.google.common.collect.ImmutableList;


29+import com.google.common.collect.ImmutableMap;

2930 import com.google.common.collect.Iterables;

3031 

3132 import java.io.Serializable;

3233 import java.lang.reflect.Array;

3334 import java.lang.reflect.GenericArrayType;

3435 import java.lang.reflect.GenericDeclaration;


36+import java.lang.reflect.InvocationHandler;


37+import java.lang.reflect.InvocationTargetException;


38+import java.lang.reflect.Method;

3539 import java.lang.reflect.ParameterizedType;


40+import java.lang.reflect.Proxy;

3641 import java.lang.reflect.Type;

3742 import java.lang.reflect.TypeVariable;

3843 import java.lang.reflect.WildcardType;


44+import java.security.AccessControlException;

3945 import java.util.Arrays;

4046 import java.util.Collection;

4147 import java.util.concurrent.atomic.AtomicReference;

4248 

4349 import javax.annotation.Nullable;

4450 

4551 /**

4652  * Utilities for working with {@link Type}.

4753  *

4854  * @author Ben Yu



@@ -139,21 +145,21 @@

139145  throw new AssertionError();

140146  }

141147  }

142148 

143149  /**

144150  * Returns a new {@link TypeVariable} that belongs to {@code declaration} with

145151  * {@code name} and {@code bounds}.

146152  */

147153  static <D extends GenericDeclaration> TypeVariable<D> newArtificialTypeVariable(

148154  D declaration, String name, Type... bounds) {

149
- return new TypeVariableImpl<D>(


155+ return newTypeVariableImpl(

150156  declaration,

151157  name,

152158  (bounds.length == 0)

153159  ? new Type[] { Object.class }

154160  : bounds);

155161  }

156162 

157163  /** Returns a new {@link WildcardType} with {@code upperBound}. */

158164  @VisibleForTesting static WildcardType subtypeOf(Type upperBound) {

159165  return new WildcardTypeImpl(new Type[0], new Type[] { upperBound });



@@ -307,59 +313,135 @@

307313  ParameterizedType that = (ParameterizedType) other;

308314  return getRawType().equals(that.getRawType())

309315  && Objects.equal(getOwnerType(), that.getOwnerType())

310316  && Arrays.equals(

311317  getActualTypeArguments(), that.getActualTypeArguments());

312318  }

313319 

314320  private static final long serialVersionUID = 0;

315321  }

316322 

317
- private static final class TypeVariableImpl<D extends GenericDeclaration>

318
- implements TypeVariable<D> {


323+ private static <D extends GenericDeclaration> TypeVariable<D> newTypeVariableImpl(


324+ D genericDeclaration, String name, Type[] bounds) {


325+ TypeVariableImpl<D> typeVariableImpl =


326+ new TypeVariableImpl<D>(genericDeclaration, name, bounds);


327+ @SuppressWarnings("unchecked")


328+ TypeVariable<D> typeVariable = Reflection.newProxy(


329+ TypeVariable.class, new TypeVariableInvocationHandler(typeVariableImpl));


330+ return typeVariable;


331+ }


332+


333+ /**


334+ * Invocation handler to work around a compatibility problem between Java 7 and Java 8.


335+ *


336+ * <p>Java 8 introduced a new method {@code getAnnotatedBounds()} in the {@link TypeVariable}


337+ * interface, whose return type {@code AnnotatedType[]} is also new in Java 8. That means that we


338+ * cannot implement that interface in source code in a way that will compile on both Java 7 and


339+ * Java 8. If we include the {@code getAnnotatedBounds()} method then its return type means


340+ * it won't compile on Java 7, while if we don't include the method then the compiler will


341+ * complain that an abstract method is unimplemented. So instead we use a dynamic proxy to


342+ * get an implementation. If the method being called on the {@code TypeVariable} instance has


343+ * the same name as one of the public methods of {@link TypeVariableImpl}, the proxy calls


344+ * the same method on its instance of {@code TypeVariableImpl}. Otherwise it throws {@link


345+ * UnsupportedOperationException}; this should only apply to {@code getAnnotatedBounds()}. This


346+ * does mean that users on Java 8 who obtain an instance of {@code TypeVariable} from {@link


347+ * TypeResolver#resolveType} will not be able to call {@code getAnnotatedBounds()} on it, but that


348+ * should hopefully be rare.


349+ *


350+ * <p>This workaround should be removed at a distant future time when we no longer support Java


351+ * versions earlier than 8.


352+ */


353+ private static final class TypeVariableInvocationHandler implements InvocationHandler {


354+ private static final ImmutableMap<String, Method> typeVariableMethods;


355+ static {


356+ ImmutableMap.Builder<String, Method> builder = ImmutableMap.builder();


357+ for (Method method : TypeVariableImpl.class.getMethods()) {


358+ if (method.getDeclaringClass().equals(TypeVariableImpl.class)) {


359+ try {


360+ method.setAccessible(true);


361+ } catch (AccessControlException e) {


362+ // OK: the method is accessible to us anyway. The setAccessible call is only for


363+ // unusual execution environments where that might not be true.


364+ }


365+ builder.put(method.getName(), method);


366+ }


367+ }


368+ typeVariableMethods = builder.build();


369+ }


370+


371+ private final TypeVariableImpl<?> typeVariableImpl;


372+


373+ TypeVariableInvocationHandler(TypeVariableImpl<?> typeVariableImpl) {


374+ this.typeVariableImpl = typeVariableImpl;


375+ }


376+


377+ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {


378+ String methodName = method.getName();


379+ Method typeVariableMethod = typeVariableMethods.get(methodName);


380+ if (typeVariableMethod == null) {


381+ throw new UnsupportedOperationException(methodName);


382+ } else {


383+ try {


384+ return typeVariableMethod.invoke(typeVariableImpl, args);


385+ } catch (InvocationTargetException e) {


386+ throw e.getCause();


387+ }


388+ }


389+ }


390+ }


391+


392+ private static final class TypeVariableImpl<D extends GenericDeclaration> {

319393 

320394  private final D genericDeclaration;

321395  private final String name;

322396  private final ImmutableList<Type> bounds;

323397 

324398  TypeVariableImpl(D genericDeclaration, String name, Type[] bounds) {

325399  disallowPrimitiveType(bounds, "bound for type variable");

326400  this.genericDeclaration = checkNotNull(genericDeclaration);

327401  this.name = checkNotNull(name);

328402  this.bounds = ImmutableList.copyOf(bounds);

329403  }

330404 

331
- @Override public Type[] getBounds() {


405+ public Type[] getBounds() {

332406  return toArray(bounds);

333407  }

334408 

335
- @Override public D getGenericDeclaration() {


409+ public D getGenericDeclaration() {

336410  return genericDeclaration;

337411  }

338412 

339
- @Override public String getName() {


413+ public String getName() {


414+ return name;


415+ }


416+


417+ public String getTypeName() {

340418  return name;

341419  }

342420 

343421  @Override public String toString() {

344422  return name;

345423  }

346424 

347425  @Override public int hashCode() {

348426  return genericDeclaration.hashCode() ^ name.hashCode();

349427  }

350428 

351429  @Override public boolean equals(Object obj) {

352430  if (NativeTypeVariableEquals.NATIVE_TYPE_VARIABLE_ONLY) {

353431  // equal only to our TypeVariable implementation with identical bounds

354
- if (obj instanceof TypeVariableImpl) {

355
- TypeVariableImpl<?> that = (TypeVariableImpl<?>) obj;


432+ if (obj != null


433+ && Proxy.isProxyClass(obj.getClass())


434+ && Proxy.getInvocationHandler(obj) instanceof TypeVariableInvocationHandler) {


435+ TypeVariableInvocationHandler typeVariableInvocationHandler =


436+ (TypeVariableInvocationHandler) Proxy.getInvocationHandler(obj);


437+ TypeVariableImpl<?> that = typeVariableInvocationHandler.typeVariableImpl;

356438  return name.equals(that.getName())

357439  && genericDeclaration.equals(that.getGenericDeclaration())

358440  && bounds.equals(that.bounds);

359441  }

360442  return false;

361443  } else {

362444  // equal to any TypeVariable implementation regardless of bounds

363445  if (obj instanceof TypeVariable) {

364446  TypeVariable<?> that = (TypeVariable<?>) obj;

365447  return name.equals(that.getName())


+ Recent posts