Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.internal.xjc.model.nav; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.lang.reflect.Type; |
aoqi@0 | 29 | import java.util.Collection; |
aoqi@0 | 30 | |
aoqi@0 | 31 | import com.sun.codemodel.internal.JClass; |
aoqi@0 | 32 | import com.sun.xml.internal.bind.v2.model.nav.Navigator; |
aoqi@0 | 33 | import com.sun.xml.internal.bind.v2.runtime.Location; |
aoqi@0 | 34 | |
aoqi@0 | 35 | /** |
aoqi@0 | 36 | * {@link Navigator} implementation for XJC. |
aoqi@0 | 37 | * |
aoqi@0 | 38 | * Most of the Navigator methods are used for parsing the model, which doesn't happen |
aoqi@0 | 39 | * in XJC. So Most of the methods aren't really implemented. Implementations should |
aoqi@0 | 40 | * be filled in as needed. |
aoqi@0 | 41 | * |
aoqi@0 | 42 | * @author Kohsuke Kawaguchi |
aoqi@0 | 43 | */ |
aoqi@0 | 44 | public final class NavigatorImpl implements Navigator<NType,NClass,Void,Void> { |
aoqi@0 | 45 | public static final NavigatorImpl theInstance = new NavigatorImpl(); |
aoqi@0 | 46 | |
aoqi@0 | 47 | private NavigatorImpl() { |
aoqi@0 | 48 | } |
aoqi@0 | 49 | |
aoqi@0 | 50 | public NClass getSuperClass(NClass nClass) { |
aoqi@0 | 51 | throw new UnsupportedOperationException(); |
aoqi@0 | 52 | } |
aoqi@0 | 53 | |
aoqi@0 | 54 | public NType getBaseClass(NType nt, NClass base) { |
aoqi@0 | 55 | if(nt instanceof EagerNType) { |
aoqi@0 | 56 | EagerNType ent = (EagerNType) nt; |
aoqi@0 | 57 | if (base instanceof EagerNClass) { |
aoqi@0 | 58 | EagerNClass enc = (EagerNClass) base; |
aoqi@0 | 59 | return create(Utils.REFLECTION_NAVIGATOR.getBaseClass(ent.t, enc.c)); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | // lazy class can never be a base type of an eager type |
aoqi@0 | 62 | return null; |
aoqi@0 | 63 | } |
aoqi@0 | 64 | if (nt instanceof NClassByJClass) { |
aoqi@0 | 65 | NClassByJClass nnt = (NClassByJClass) nt; |
aoqi@0 | 66 | if (base instanceof EagerNClass) { |
aoqi@0 | 67 | EagerNClass enc = (EagerNClass) base; |
aoqi@0 | 68 | return ref(nnt.clazz.getBaseClass(enc.c)); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | } |
aoqi@0 | 71 | |
aoqi@0 | 72 | throw new UnsupportedOperationException(); |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | public String getClassName(NClass nClass) { |
aoqi@0 | 76 | throw new UnsupportedOperationException(); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | public String getTypeName(NType type) { |
aoqi@0 | 80 | return type.fullName(); |
aoqi@0 | 81 | } |
aoqi@0 | 82 | |
aoqi@0 | 83 | public String getClassShortName(NClass nClass) { |
aoqi@0 | 84 | throw new UnsupportedOperationException(); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | public Collection<? extends Void> getDeclaredFields(NClass nClass) { |
aoqi@0 | 88 | throw new UnsupportedOperationException(); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | public Void getDeclaredField(NClass clazz, String fieldName) { |
aoqi@0 | 92 | throw new UnsupportedOperationException(); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | public Collection<? extends Void> getDeclaredMethods(NClass nClass) { |
aoqi@0 | 96 | throw new UnsupportedOperationException(); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | public NClass getDeclaringClassForField(Void aVoid) { |
aoqi@0 | 100 | throw new UnsupportedOperationException(); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | public NClass getDeclaringClassForMethod(Void aVoid) { |
aoqi@0 | 104 | throw new UnsupportedOperationException(); |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | public NType getFieldType(Void aVoid) { |
aoqi@0 | 108 | throw new UnsupportedOperationException(); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | public String getFieldName(Void aVoid) { |
aoqi@0 | 112 | throw new UnsupportedOperationException(); |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | public String getMethodName(Void aVoid) { |
aoqi@0 | 116 | throw new UnsupportedOperationException(); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | public NType getReturnType(Void aVoid) { |
aoqi@0 | 120 | throw new UnsupportedOperationException(); |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | public NType[] getMethodParameters(Void aVoid) { |
aoqi@0 | 124 | throw new UnsupportedOperationException(); |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | public boolean isStaticMethod(Void aVoid) { |
aoqi@0 | 128 | throw new UnsupportedOperationException(); |
aoqi@0 | 129 | } |
aoqi@0 | 130 | |
aoqi@0 | 131 | public boolean isFinalMethod(Void aVoid) { |
aoqi@0 | 132 | throw new UnsupportedOperationException(); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
aoqi@0 | 135 | public boolean isSubClassOf(NType sub, NType sup) { |
aoqi@0 | 136 | throw new UnsupportedOperationException(); |
aoqi@0 | 137 | } |
aoqi@0 | 138 | |
aoqi@0 | 139 | public NClass ref(Class c) { |
aoqi@0 | 140 | return create(c); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | |
aoqi@0 | 143 | public NClass ref(JClass c) { |
aoqi@0 | 144 | if(c==null) return null; |
aoqi@0 | 145 | return new NClassByJClass(c); |
aoqi@0 | 146 | } |
aoqi@0 | 147 | |
aoqi@0 | 148 | public NType use(NClass nc) { |
aoqi@0 | 149 | return nc; |
aoqi@0 | 150 | } |
aoqi@0 | 151 | |
aoqi@0 | 152 | public NClass asDecl(NType nt) { |
aoqi@0 | 153 | if(nt instanceof NClass) |
aoqi@0 | 154 | return (NClass)nt; |
aoqi@0 | 155 | else |
aoqi@0 | 156 | return null; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | public NClass asDecl(Class c) { |
aoqi@0 | 160 | return ref(c); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | |
aoqi@0 | 163 | public boolean isArray(NType nType) { |
aoqi@0 | 164 | throw new UnsupportedOperationException(); |
aoqi@0 | 165 | } |
aoqi@0 | 166 | |
aoqi@0 | 167 | public boolean isArrayButNotByteArray(NType t) { |
aoqi@0 | 168 | throw new UnsupportedOperationException(); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | |
aoqi@0 | 171 | |
aoqi@0 | 172 | public NType getComponentType(NType nType) { |
aoqi@0 | 173 | throw new UnsupportedOperationException(); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | |
aoqi@0 | 176 | public NType getTypeArgument(NType nt, int i) { |
aoqi@0 | 177 | if (nt instanceof EagerNType) { |
aoqi@0 | 178 | EagerNType ent = (EagerNType) nt; |
aoqi@0 | 179 | return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i)); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | if (nt instanceof NClassByJClass) { |
aoqi@0 | 182 | NClassByJClass nnt = (NClassByJClass) nt; |
aoqi@0 | 183 | return ref(nnt.clazz.getTypeParameters().get(i)); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | |
aoqi@0 | 186 | throw new UnsupportedOperationException(); |
aoqi@0 | 187 | } |
aoqi@0 | 188 | |
aoqi@0 | 189 | public boolean isParameterizedType(NType nt) { |
aoqi@0 | 190 | if (nt instanceof EagerNType) { |
aoqi@0 | 191 | EagerNType ent = (EagerNType) nt; |
aoqi@0 | 192 | return Utils.REFLECTION_NAVIGATOR.isParameterizedType(ent.t); |
aoqi@0 | 193 | } |
aoqi@0 | 194 | if (nt instanceof NClassByJClass) { |
aoqi@0 | 195 | NClassByJClass nnt = (NClassByJClass) nt; |
aoqi@0 | 196 | return nnt.clazz.isParameterized(); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | throw new UnsupportedOperationException(); |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | public boolean isPrimitive(NType type) { |
aoqi@0 | 203 | throw new UnsupportedOperationException(); |
aoqi@0 | 204 | } |
aoqi@0 | 205 | |
aoqi@0 | 206 | public NType getPrimitive(Class primitiveType) { |
aoqi@0 | 207 | return create(primitiveType); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | |
aoqi@0 | 210 | @SuppressWarnings("FinalStaticMethod") |
aoqi@0 | 211 | public static final NType create(Type t) { |
aoqi@0 | 212 | if(t==null) return null; |
aoqi@0 | 213 | if(t instanceof Class) |
aoqi@0 | 214 | return create((Class)t); |
aoqi@0 | 215 | |
aoqi@0 | 216 | return new EagerNType(t); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | public static NClass create( Class c ) { |
aoqi@0 | 220 | if(c==null) return null; |
aoqi@0 | 221 | return new EagerNClass(c); |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | /** |
aoqi@0 | 225 | * Creates a {@link NType} representation for a parameterized type |
aoqi@0 | 226 | * {@code RawType<ParamType1,ParamType2,...> }. |
aoqi@0 | 227 | */ |
aoqi@0 | 228 | public static NType createParameterizedType( NClass rawType, NType... args ) { |
aoqi@0 | 229 | return new NParameterizedType(rawType,args); |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | public static NType createParameterizedType( Class rawType, NType... args ) { |
aoqi@0 | 233 | return new NParameterizedType(create(rawType),args); |
aoqi@0 | 234 | } |
aoqi@0 | 235 | |
aoqi@0 | 236 | public Location getClassLocation(final NClass c) { |
aoqi@0 | 237 | // not really needed for XJC but doesn't hurt to have one |
aoqi@0 | 238 | return new Location() { |
aoqi@0 | 239 | @Override |
aoqi@0 | 240 | public String toString() { |
aoqi@0 | 241 | return c.fullName(); |
aoqi@0 | 242 | } |
aoqi@0 | 243 | }; |
aoqi@0 | 244 | } |
aoqi@0 | 245 | |
aoqi@0 | 246 | public Location getFieldLocation(Void v) { |
aoqi@0 | 247 | throw new IllegalStateException(); |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | public Location getMethodLocation(Void v) { |
aoqi@0 | 251 | throw new IllegalStateException(); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | public boolean hasDefaultConstructor(NClass nClass) { |
aoqi@0 | 255 | throw new UnsupportedOperationException(); |
aoqi@0 | 256 | } |
aoqi@0 | 257 | |
aoqi@0 | 258 | public boolean isStaticField(Void aVoid) { |
aoqi@0 | 259 | throw new IllegalStateException(); |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | public boolean isPublicMethod(Void aVoid) { |
aoqi@0 | 263 | throw new IllegalStateException(); |
aoqi@0 | 264 | } |
aoqi@0 | 265 | |
aoqi@0 | 266 | public boolean isPublicField(Void aVoid) { |
aoqi@0 | 267 | throw new IllegalStateException(); |
aoqi@0 | 268 | } |
aoqi@0 | 269 | |
aoqi@0 | 270 | public boolean isEnum(NClass c) { |
aoqi@0 | 271 | return isSubClassOf(c,create(Enum.class)); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | |
aoqi@0 | 274 | public <T> NType erasure(NType type) { |
aoqi@0 | 275 | if(type instanceof NParameterizedType) { |
aoqi@0 | 276 | NParameterizedType pt = (NParameterizedType) type; |
aoqi@0 | 277 | return pt.rawType; |
aoqi@0 | 278 | } |
aoqi@0 | 279 | return type; |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | public boolean isAbstract(NClass clazz) { |
aoqi@0 | 283 | return clazz.isAbstract(); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | /** |
aoqi@0 | 287 | * @deprecated |
aoqi@0 | 288 | * no class generated by XJC is final. |
aoqi@0 | 289 | */ |
aoqi@0 | 290 | public boolean isFinal(NClass clazz) { |
aoqi@0 | 291 | return false; |
aoqi@0 | 292 | } |
aoqi@0 | 293 | |
aoqi@0 | 294 | public Void[] getEnumConstants(NClass clazz) { |
aoqi@0 | 295 | throw new UnsupportedOperationException(); |
aoqi@0 | 296 | } |
aoqi@0 | 297 | |
aoqi@0 | 298 | public NType getVoidType() { |
aoqi@0 | 299 | return ref(void.class); |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | public String getPackageName(NClass clazz) { |
aoqi@0 | 303 | // TODO: implement this method later |
aoqi@0 | 304 | throw new UnsupportedOperationException(); |
aoqi@0 | 305 | } |
aoqi@0 | 306 | |
aoqi@0 | 307 | @Override |
aoqi@0 | 308 | public NClass loadObjectFactory(NClass referencePoint, String pkg) { |
aoqi@0 | 309 | throw new UnsupportedOperationException(); |
aoqi@0 | 310 | } |
aoqi@0 | 311 | |
aoqi@0 | 312 | public boolean isBridgeMethod(Void method) { |
aoqi@0 | 313 | throw new UnsupportedOperationException(); |
aoqi@0 | 314 | } |
aoqi@0 | 315 | |
aoqi@0 | 316 | public boolean isOverriding(Void method,NClass clazz) { |
aoqi@0 | 317 | throw new UnsupportedOperationException(); |
aoqi@0 | 318 | } |
aoqi@0 | 319 | |
aoqi@0 | 320 | public boolean isInterface(NClass clazz) { |
aoqi@0 | 321 | throw new UnsupportedOperationException(); |
aoqi@0 | 322 | } |
aoqi@0 | 323 | |
aoqi@0 | 324 | public boolean isTransient(Void f) { |
aoqi@0 | 325 | throw new UnsupportedOperationException(); |
aoqi@0 | 326 | } |
aoqi@0 | 327 | |
aoqi@0 | 328 | public boolean isInnerClass(NClass clazz) { |
aoqi@0 | 329 | throw new UnsupportedOperationException(); |
aoqi@0 | 330 | } |
aoqi@0 | 331 | |
aoqi@0 | 332 | @Override |
aoqi@0 | 333 | public boolean isSameType(NType t1, NType t2) { |
aoqi@0 | 334 | throw new UnsupportedOperationException(); |
aoqi@0 | 335 | } |
aoqi@0 | 336 | } |