src/share/jaxws_classes/com/sun/tools/internal/xjc/model/nav/NavigatorImpl.java

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

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

merge

     1 /*
     2  * Copyright (c) 1997, 2013, 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.tools.internal.xjc.model.nav;
    28 import java.lang.reflect.Type;
    29 import java.util.Collection;
    31 import com.sun.codemodel.internal.JClass;
    32 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
    33 import com.sun.xml.internal.bind.v2.runtime.Location;
    35 /**
    36  * {@link Navigator} implementation for XJC.
    37  *
    38  * Most of the Navigator methods are used for parsing the model, which doesn't happen
    39  * in XJC. So Most of the methods aren't really implemented. Implementations should
    40  * be filled in as needed.
    41  *
    42  * @author Kohsuke Kawaguchi
    43  */
    44 public final class NavigatorImpl implements Navigator<NType,NClass,Void,Void> {
    45     public static final NavigatorImpl theInstance = new NavigatorImpl();
    47     private NavigatorImpl() {
    48     }
    50     public NClass getSuperClass(NClass nClass) {
    51         throw new UnsupportedOperationException();
    52     }
    54     public NType getBaseClass(NType nt, NClass base) {
    55         if(nt instanceof EagerNType) {
    56             EagerNType ent = (EagerNType) nt;
    57             if (base instanceof EagerNClass) {
    58                 EagerNClass enc = (EagerNClass) base;
    59                 return create(Utils.REFLECTION_NAVIGATOR.getBaseClass(ent.t, enc.c));
    60             }
    61             // lazy class can never be a base type of an eager type
    62             return null;
    63         }
    64         if (nt instanceof NClassByJClass) {
    65             NClassByJClass nnt = (NClassByJClass) nt;
    66             if (base instanceof EagerNClass) {
    67                 EagerNClass enc = (EagerNClass) base;
    68                 return ref(nnt.clazz.getBaseClass(enc.c));
    69             }
    70         }
    72         throw new UnsupportedOperationException();
    73     }
    75     public String getClassName(NClass nClass) {
    76         throw new UnsupportedOperationException();
    77     }
    79     public String getTypeName(NType type) {
    80         return type.fullName();
    81     }
    83     public String getClassShortName(NClass nClass) {
    84         throw new UnsupportedOperationException();
    85     }
    87     public Collection<? extends Void> getDeclaredFields(NClass nClass) {
    88         throw new UnsupportedOperationException();
    89     }
    91     public Void getDeclaredField(NClass clazz, String fieldName) {
    92         throw new UnsupportedOperationException();
    93     }
    95     public Collection<? extends Void> getDeclaredMethods(NClass nClass) {
    96         throw new UnsupportedOperationException();
    97     }
    99     public NClass getDeclaringClassForField(Void aVoid) {
   100         throw new UnsupportedOperationException();
   101     }
   103     public NClass getDeclaringClassForMethod(Void aVoid) {
   104         throw new UnsupportedOperationException();
   105     }
   107     public NType getFieldType(Void aVoid) {
   108         throw new UnsupportedOperationException();
   109     }
   111     public String getFieldName(Void aVoid) {
   112         throw new UnsupportedOperationException();
   113     }
   115     public String getMethodName(Void aVoid) {
   116         throw new UnsupportedOperationException();
   117     }
   119     public NType getReturnType(Void aVoid) {
   120         throw new UnsupportedOperationException();
   121     }
   123     public NType[] getMethodParameters(Void aVoid) {
   124         throw new UnsupportedOperationException();
   125     }
   127     public boolean isStaticMethod(Void aVoid) {
   128         throw new UnsupportedOperationException();
   129     }
   131     public boolean isFinalMethod(Void aVoid) {
   132         throw new UnsupportedOperationException();
   133     }
   135     public boolean isSubClassOf(NType sub, NType sup) {
   136         throw new UnsupportedOperationException();
   137     }
   139     public NClass ref(Class c) {
   140         return create(c);
   141     }
   143     public NClass ref(JClass c) {
   144         if(c==null)     return null;
   145         return new NClassByJClass(c);
   146     }
   148     public NType use(NClass nc) {
   149         return nc;
   150     }
   152     public NClass asDecl(NType nt) {
   153         if(nt instanceof NClass)
   154             return (NClass)nt;
   155         else
   156             return null;
   157     }
   159     public NClass asDecl(Class c) {
   160         return ref(c);
   161     }
   163     public boolean isArray(NType nType) {
   164         throw new UnsupportedOperationException();
   165     }
   167     public boolean isArrayButNotByteArray(NType t) {
   168         throw new UnsupportedOperationException();
   169     }
   172     public NType getComponentType(NType nType) {
   173         throw new UnsupportedOperationException();
   174     }
   176     public NType getTypeArgument(NType nt, int i) {
   177         if (nt instanceof EagerNType) {
   178             EagerNType ent = (EagerNType) nt;
   179             return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i));
   180         }
   181         if (nt instanceof NClassByJClass) {
   182             NClassByJClass nnt = (NClassByJClass) nt;
   183             return ref(nnt.clazz.getTypeParameters().get(i));
   184         }
   186         throw new UnsupportedOperationException();
   187     }
   189     public boolean isParameterizedType(NType nt) {
   190         if (nt instanceof EagerNType) {
   191             EagerNType ent = (EagerNType) nt;
   192             return Utils.REFLECTION_NAVIGATOR.isParameterizedType(ent.t);
   193         }
   194         if (nt instanceof NClassByJClass) {
   195             NClassByJClass nnt = (NClassByJClass) nt;
   196             return nnt.clazz.isParameterized();
   197         }
   199         throw new UnsupportedOperationException();
   200     }
   202     public boolean isPrimitive(NType type) {
   203         throw new UnsupportedOperationException();
   204     }
   206     public NType getPrimitive(Class primitiveType) {
   207         return create(primitiveType);
   208     }
   210     @SuppressWarnings("FinalStaticMethod")
   211     public static final NType create(Type t) {
   212         if(t==null)     return null;
   213         if(t instanceof Class)
   214             return create((Class)t);
   216         return new EagerNType(t);
   217     }
   219     public static NClass create( Class c ) {
   220         if(c==null)     return null;
   221         return new EagerNClass(c);
   222     }
   224     /**
   225      * Creates a {@link NType} representation for a parameterized type
   226      * {@code RawType&lt;ParamType1,ParamType2,...> }.
   227      */
   228     public static NType createParameterizedType( NClass rawType, NType... args ) {
   229         return new NParameterizedType(rawType,args);
   230     }
   232     public static NType createParameterizedType( Class rawType, NType... args ) {
   233         return new NParameterizedType(create(rawType),args);
   234     }
   236     public Location getClassLocation(final NClass c) {
   237         // not really needed for XJC but doesn't hurt to have one
   238         return new Location() {
   239             @Override
   240             public String toString() {
   241                 return c.fullName();
   242             }
   243         };
   244     }
   246     public Location getFieldLocation(Void v) {
   247         throw new IllegalStateException();
   248     }
   250     public Location getMethodLocation(Void v) {
   251         throw new IllegalStateException();
   252     }
   254     public boolean hasDefaultConstructor(NClass nClass) {
   255         throw new UnsupportedOperationException();
   256     }
   258     public boolean isStaticField(Void aVoid) {
   259         throw new IllegalStateException();
   260     }
   262     public boolean isPublicMethod(Void aVoid) {
   263         throw new IllegalStateException();
   264     }
   266     public boolean isPublicField(Void aVoid) {
   267         throw new IllegalStateException();
   268     }
   270     public boolean isEnum(NClass c) {
   271         return isSubClassOf(c,create(Enum.class));
   272     }
   274     public <T> NType erasure(NType type) {
   275         if(type instanceof NParameterizedType) {
   276             NParameterizedType pt = (NParameterizedType) type;
   277             return pt.rawType;
   278         }
   279         return type;
   280     }
   282     public boolean isAbstract(NClass clazz) {
   283         return clazz.isAbstract();
   284     }
   286     /**
   287      * @deprecated
   288      *      no class generated by XJC is final.
   289      */
   290     public boolean isFinal(NClass clazz) {
   291         return false;
   292     }
   294     public Void[] getEnumConstants(NClass clazz) {
   295         throw new UnsupportedOperationException();
   296     }
   298     public NType getVoidType() {
   299         return ref(void.class);
   300     }
   302     public String getPackageName(NClass clazz) {
   303         // TODO: implement this method later
   304         throw new UnsupportedOperationException();
   305     }
   307     @Override
   308     public NClass loadObjectFactory(NClass referencePoint, String pkg) {
   309         throw new UnsupportedOperationException();
   310     }
   312     public boolean isBridgeMethod(Void method) {
   313         throw new UnsupportedOperationException();
   314     }
   316     public boolean isOverriding(Void method,NClass clazz) {
   317         throw new UnsupportedOperationException();
   318     }
   320     public boolean isInterface(NClass clazz) {
   321         throw new UnsupportedOperationException();
   322     }
   324     public boolean isTransient(Void f) {
   325         throw new UnsupportedOperationException();
   326     }
   328     public boolean isInnerClass(NClass clazz) {
   329         throw new UnsupportedOperationException();
   330     }
   332     @Override
   333     public boolean isSameType(NType t1, NType t2) {
   334          throw new UnsupportedOperationException();
   335     }
   336 }

mercurial