src/share/jaxws_classes/com/sun/xml/internal/ws/model/FieldSignature.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    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  */
    26 package com.sun.xml.internal.ws.model;
    28 import java.lang.reflect.*;
    30 /**
    31  * Creates vm signature string from Type
    32  *
    33  * TypeSignature: Z | C | B | S | I | F | J | D | FieldTypeSignature
    34  * FieldTypeSignature: ClassTypeSignature | [ TypeSignature | TypeVar
    35  * ClassTypeSignature: L Id ( / Id )* TypeArgs? ( . Id TypeArgs? )* ;
    36  * TypeArgs: < TypeArg+ >
    37  * TypeArg: * | ( + | - )? FieldTypeSignature
    38  * TypeVar: T Id ;
    39  *
    40  * @author Jitendra Kotamraju
    41  */
    42 final class FieldSignature {
    44     static String vms(Type t) {
    45         if (t instanceof Class && ((Class)t).isPrimitive()) {
    46             Class c = (Class)t;
    47             if (c == Integer.TYPE) {
    48                 return "I";
    49             } else if (c == Void.TYPE) {
    50                 return "V";
    51             } else if (c == Boolean.TYPE) {
    52                 return "Z";
    53             } else if (c == Byte.TYPE) {
    54                 return "B";
    55             } else if (c == Character.TYPE) {
    56                 return "C";
    57             } else if (c == Short.TYPE) {
    58                 return "S";
    59             } else if (c == Double.TYPE) {
    60                 return "D";
    61             } else if (c == Float.TYPE) {
    62                 return "F";
    63             } else if (c == Long.TYPE) {
    64                 return "J";
    65             }
    66         } else if (t instanceof Class && ((Class)t).isArray()) {
    67             return "["+vms(((Class)t).getComponentType());
    68         } else if (t instanceof Class || t instanceof ParameterizedType) {
    69             return "L"+fqcn(t)+";";
    70         } else if (t instanceof GenericArrayType) {
    71             return "["+vms(((GenericArrayType)t).getGenericComponentType());
    72         } else if (t instanceof TypeVariable) {
    73             // While creating wrapper bean fields, it doesn't create with TypeVariables
    74             // Otherwise, the type variable need to be declared in the wrapper bean class
    75             // return "T"+((TypeVariable)t).getName()+";";
    76             return "Ljava/lang/Object;";
    77         } else if (t instanceof WildcardType) {
    78             WildcardType w = (WildcardType)t;
    79             if (w.getLowerBounds().length > 0) {
    80                 return "-"+vms(w.getLowerBounds()[0]);
    81             } else if (w.getUpperBounds().length > 0) {
    82                 Type wt = w.getUpperBounds()[0];
    83                 if (wt.equals(Object.class)) {
    84                     return "*";
    85                 } else {
    86                     return "+"+vms(wt);
    87                 }
    88             }
    89         }
    90         throw new IllegalArgumentException("Illegal vms arg " + t);
    91     }
    93     private static String fqcn(Type t) {
    94         if (t instanceof Class) {
    95             Class c = (Class)t;
    96             if (c.getDeclaringClass() == null) {
    97                 return c.getName().replace('.', '/');
    98             } else {
    99                 return fqcn(c.getDeclaringClass())+"$"+c.getSimpleName();
   100             }
   101         } else if (t instanceof ParameterizedType) {
   102             ParameterizedType p = (ParameterizedType)t;
   103             if (p.getOwnerType() == null) {
   104                 return fqcn(p.getRawType())+args(p);
   105             } else {
   106                 assert p.getRawType() instanceof Class;
   107                 return fqcn(p.getOwnerType())+"."+
   108                         ((Class)p.getRawType()).getSimpleName()+args(p);
   109             }
   110         }
   111         throw new IllegalArgumentException("Illegal fqcn arg = "+t);
   112     }
   114     private static String args(ParameterizedType p) {
   115         StringBuilder sig = new StringBuilder("<");
   116         for(Type t : p.getActualTypeArguments()) {
   117             sig.append(vms(t));
   118         }
   119         return sig.append(">").toString();
   120     }
   122 }

mercurial