< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.model;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectInputStream;
  30 import java.lang.annotation.*;
  31 import java.lang.reflect.Array;
  32 import java.lang.reflect.Method;
  33 import java.util.LinkedHashMap;
  34 import java.util.Map;

  35 import sun.reflect.annotation.*;
  36 
  37 import javax.lang.model.type.MirroredTypeException;
  38 import javax.lang.model.type.MirroredTypesException;
  39 import javax.lang.model.type.TypeMirror;
  40 
  41 import com.sun.tools.javac.code.*;
  42 import com.sun.tools.javac.code.Symbol.*;
  43 import com.sun.tools.javac.code.Type.ArrayType;
  44 import com.sun.tools.javac.util.*;
  45 
  46 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
  47 import static com.sun.tools.javac.code.Kinds.Kind.*;
  48 
  49 /**
  50  * A generator of dynamic proxy implementations of
  51  * java.lang.annotation.Annotation.
  52  *
  53  * <p> The "dynamic proxy return form" of an annotation element value is
  54  * the form used by sun.reflect.annotation.AnnotationInvocationHandler.


 275     }
 276 
 277 
 278     /**
 279      * ExceptionProxy for MirroredTypeException.
 280      * The toString, hashCode, and equals methods forward to the underlying
 281      * type.
 282      */
 283     private static final class MirroredTypeExceptionProxy extends ExceptionProxy {
 284         static final long serialVersionUID = 269;
 285 
 286         private transient TypeMirror type;
 287         private final String typeString;
 288 
 289         MirroredTypeExceptionProxy(TypeMirror t) {
 290             type = t;
 291             typeString = t.toString();
 292         }
 293 
 294         public String toString() {
 295             return typeString;
 296         }
 297 
 298         public int hashCode() {
 299             return (type != null ? type : typeString).hashCode();
 300         }
 301 
 302         public boolean equals(Object obj) {
 303             return type != null &&
 304                    obj instanceof MirroredTypeExceptionProxy &&
 305                    type.equals(((MirroredTypeExceptionProxy) obj).type);
 306         }
 307 
 308         protected RuntimeException generateException() {
 309             return new MirroredTypeException(type);
 310         }
 311 
 312         // Explicitly set all transient fields.
 313         private void readObject(ObjectInputStream s)
 314             throws IOException, ClassNotFoundException {
 315             s.defaultReadObject();


 318     }
 319 
 320 
 321     /**
 322      * ExceptionProxy for MirroredTypesException.
 323      * The toString, hashCode, and equals methods foward to the underlying
 324      * types.
 325      */
 326     private static final class MirroredTypesExceptionProxy extends ExceptionProxy {
 327         static final long serialVersionUID = 269;
 328 
 329         private transient List<TypeMirror> types;
 330         private final String typeStrings;
 331 
 332         MirroredTypesExceptionProxy(List<TypeMirror> ts) {
 333             types = ts;
 334             typeStrings = ts.toString();
 335         }
 336 
 337         public String toString() {
 338             return typeStrings;


 339         }
 340 
 341         public int hashCode() {
 342             return (types != null ? types : typeStrings).hashCode();
 343         }
 344 
 345         public boolean equals(Object obj) {
 346             return types != null &&
 347                    obj instanceof MirroredTypesExceptionProxy &&
 348                    types.equals(
 349                       ((MirroredTypesExceptionProxy) obj).types);
 350         }
 351 
 352         protected RuntimeException generateException() {
 353             return new MirroredTypesException(types);
 354         }
 355 
 356         // Explicitly set all transient fields.
 357         private void readObject(ObjectInputStream s)
 358             throws IOException, ClassNotFoundException {


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.model;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectInputStream;
  30 import java.lang.annotation.*;
  31 import java.lang.reflect.Array;
  32 import java.lang.reflect.Method;
  33 import java.util.LinkedHashMap;
  34 import java.util.Map;
  35 import java.util.stream.Collectors;
  36 import sun.reflect.annotation.*;
  37 
  38 import javax.lang.model.type.MirroredTypeException;
  39 import javax.lang.model.type.MirroredTypesException;
  40 import javax.lang.model.type.TypeMirror;
  41 
  42 import com.sun.tools.javac.code.*;
  43 import com.sun.tools.javac.code.Symbol.*;
  44 import com.sun.tools.javac.code.Type.ArrayType;
  45 import com.sun.tools.javac.util.*;
  46 
  47 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
  48 import static com.sun.tools.javac.code.Kinds.Kind.*;
  49 
  50 /**
  51  * A generator of dynamic proxy implementations of
  52  * java.lang.annotation.Annotation.
  53  *
  54  * <p> The "dynamic proxy return form" of an annotation element value is
  55  * the form used by sun.reflect.annotation.AnnotationInvocationHandler.


 276     }
 277 
 278 
 279     /**
 280      * ExceptionProxy for MirroredTypeException.
 281      * The toString, hashCode, and equals methods forward to the underlying
 282      * type.
 283      */
 284     private static final class MirroredTypeExceptionProxy extends ExceptionProxy {
 285         static final long serialVersionUID = 269;
 286 
 287         private transient TypeMirror type;
 288         private final String typeString;
 289 
 290         MirroredTypeExceptionProxy(TypeMirror t) {
 291             type = t;
 292             typeString = t.toString();
 293         }
 294 
 295         public String toString() {
 296             return typeString + ".class";
 297         }
 298 
 299         public int hashCode() {
 300             return (type != null ? type : typeString).hashCode();
 301         }
 302 
 303         public boolean equals(Object obj) {
 304             return type != null &&
 305                    obj instanceof MirroredTypeExceptionProxy &&
 306                    type.equals(((MirroredTypeExceptionProxy) obj).type);
 307         }
 308 
 309         protected RuntimeException generateException() {
 310             return new MirroredTypeException(type);
 311         }
 312 
 313         // Explicitly set all transient fields.
 314         private void readObject(ObjectInputStream s)
 315             throws IOException, ClassNotFoundException {
 316             s.defaultReadObject();


 319     }
 320 
 321 
 322     /**
 323      * ExceptionProxy for MirroredTypesException.
 324      * The toString, hashCode, and equals methods foward to the underlying
 325      * types.
 326      */
 327     private static final class MirroredTypesExceptionProxy extends ExceptionProxy {
 328         static final long serialVersionUID = 269;
 329 
 330         private transient List<TypeMirror> types;
 331         private final String typeStrings;
 332 
 333         MirroredTypesExceptionProxy(List<TypeMirror> ts) {
 334             types = ts;
 335             typeStrings = ts.toString();
 336         }
 337 
 338         public String toString() {
 339             return types.stream()
 340                 .map(t -> t.toString() + ".class")
 341                 .collect(Collectors.joining(", ", "{", "}"));
 342         }
 343 
 344         public int hashCode() {
 345             return (types != null ? types : typeStrings).hashCode();
 346         }
 347 
 348         public boolean equals(Object obj) {
 349             return types != null &&
 350                    obj instanceof MirroredTypesExceptionProxy &&
 351                    types.equals(
 352                       ((MirroredTypesExceptionProxy) obj).types);
 353         }
 354 
 355         protected RuntimeException generateException() {
 356             return new MirroredTypesException(types);
 357         }
 358 
 359         // Explicitly set all transient fields.
 360         private void readObject(ObjectInputStream s)
 361             throws IOException, ClassNotFoundException {
< prev index next >