ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.tools.internal.xjc.model.nav; ohair@286: ohair@286: import java.lang.reflect.Type; ohair@286: import java.util.Collection; ohair@286: ohair@286: import com.sun.codemodel.internal.JClass; ohair@286: import com.sun.xml.internal.bind.v2.model.nav.Navigator; ohair@286: import com.sun.xml.internal.bind.v2.runtime.Location; ohair@286: ohair@286: /** ohair@286: * {@link Navigator} implementation for XJC. ohair@286: * ohair@286: * Most of the Navigator methods are used for parsing the model, which doesn't happen ohair@286: * in XJC. So Most of the methods aren't really implemented. Implementations should ohair@286: * be filled in as needed. ohair@286: * ohair@286: * @author Kohsuke Kawaguchi ohair@286: */ ohair@286: public final class NavigatorImpl implements Navigator { ohair@286: public static final NavigatorImpl theInstance = new NavigatorImpl(); ohair@286: ohair@286: private NavigatorImpl() { ohair@286: } ohair@286: ohair@286: public NClass getSuperClass(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getBaseClass(NType nt, NClass base) { ohair@286: if(nt instanceof EagerNType) { ohair@286: EagerNType ent = (EagerNType) nt; ohair@286: if (base instanceof EagerNClass) { ohair@286: EagerNClass enc = (EagerNClass) base; mkos@450: return create(Utils.REFLECTION_NAVIGATOR.getBaseClass(ent.t, enc.c)); ohair@286: } ohair@286: // lazy class can never be a base type of an eager type ohair@286: return null; ohair@286: } ohair@286: if (nt instanceof NClassByJClass) { ohair@286: NClassByJClass nnt = (NClassByJClass) nt; ohair@286: if (base instanceof EagerNClass) { ohair@286: EagerNClass enc = (EagerNClass) base; ohair@286: return ref(nnt.clazz.getBaseClass(enc.c)); ohair@286: } ohair@286: } ohair@286: ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public String getClassName(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public String getTypeName(NType type) { ohair@286: return type.fullName(); ohair@286: } ohair@286: ohair@286: public String getClassShortName(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public Collection getDeclaredFields(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public Void getDeclaredField(NClass clazz, String fieldName) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public Collection getDeclaredMethods(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NClass getDeclaringClassForField(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NClass getDeclaringClassForMethod(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getFieldType(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public String getFieldName(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public String getMethodName(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getReturnType(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType[] getMethodParameters(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isStaticMethod(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isFinalMethod(Void aVoid) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isSubClassOf(NType sub, NType sup) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NClass ref(Class c) { ohair@286: return create(c); ohair@286: } ohair@286: ohair@286: public NClass ref(JClass c) { ohair@286: if(c==null) return null; ohair@286: return new NClassByJClass(c); ohair@286: } ohair@286: ohair@286: public NType use(NClass nc) { ohair@286: return nc; ohair@286: } ohair@286: ohair@286: public NClass asDecl(NType nt) { ohair@286: if(nt instanceof NClass) ohair@286: return (NClass)nt; ohair@286: else ohair@286: return null; ohair@286: } ohair@286: ohair@286: public NClass asDecl(Class c) { ohair@286: return ref(c); ohair@286: } ohair@286: ohair@286: public boolean isArray(NType nType) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isArrayButNotByteArray(NType t) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: ohair@286: public NType getComponentType(NType nType) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getTypeArgument(NType nt, int i) { ohair@286: if (nt instanceof EagerNType) { ohair@286: EagerNType ent = (EagerNType) nt; mkos@450: return create(Utils.REFLECTION_NAVIGATOR.getTypeArgument(ent.t,i)); ohair@286: } ohair@286: if (nt instanceof NClassByJClass) { ohair@286: NClassByJClass nnt = (NClassByJClass) nt; ohair@286: return ref(nnt.clazz.getTypeParameters().get(i)); ohair@286: } ohair@286: ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isParameterizedType(NType nt) { ohair@286: if (nt instanceof EagerNType) { ohair@286: EagerNType ent = (EagerNType) nt; mkos@450: return Utils.REFLECTION_NAVIGATOR.isParameterizedType(ent.t); ohair@286: } ohair@286: if (nt instanceof NClassByJClass) { ohair@286: NClassByJClass nnt = (NClassByJClass) nt; ohair@286: return nnt.clazz.isParameterized(); ohair@286: } ohair@286: ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isPrimitive(NType type) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getPrimitive(Class primitiveType) { ohair@286: return create(primitiveType); ohair@286: } ohair@286: alanb@368: @SuppressWarnings("FinalStaticMethod") ohair@286: public static final NType create(Type t) { ohair@286: if(t==null) return null; ohair@286: if(t instanceof Class) ohair@286: return create((Class)t); ohair@286: ohair@286: return new EagerNType(t); ohair@286: } ohair@286: ohair@286: public static NClass create( Class c ) { ohair@286: if(c==null) return null; ohair@286: return new EagerNClass(c); ohair@286: } ohair@286: ohair@286: /** ohair@286: * Creates a {@link NType} representation for a parameterized type ohair@286: * {@code RawType<ParamType1,ParamType2,...> }. ohair@286: */ ohair@286: public static NType createParameterizedType( NClass rawType, NType... args ) { ohair@286: return new NParameterizedType(rawType,args); ohair@286: } ohair@286: ohair@286: public static NType createParameterizedType( Class rawType, NType... args ) { ohair@286: return new NParameterizedType(create(rawType),args); ohair@286: } ohair@286: ohair@286: public Location getClassLocation(final NClass c) { ohair@286: // not really needed for XJC but doesn't hurt to have one ohair@286: return new Location() { alanb@368: @Override ohair@286: public String toString() { ohair@286: return c.fullName(); ohair@286: } ohair@286: }; ohair@286: } ohair@286: alanb@368: public Location getFieldLocation(Void v) { ohair@286: throw new IllegalStateException(); ohair@286: } ohair@286: alanb@368: public Location getMethodLocation(Void v) { ohair@286: throw new IllegalStateException(); ohair@286: } ohair@286: ohair@286: public boolean hasDefaultConstructor(NClass nClass) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isStaticField(Void aVoid) { ohair@286: throw new IllegalStateException(); ohair@286: } ohair@286: ohair@286: public boolean isPublicMethod(Void aVoid) { ohair@286: throw new IllegalStateException(); ohair@286: } ohair@286: ohair@286: public boolean isPublicField(Void aVoid) { ohair@286: throw new IllegalStateException(); ohair@286: } ohair@286: ohair@286: public boolean isEnum(NClass c) { ohair@286: return isSubClassOf(c,create(Enum.class)); ohair@286: } ohair@286: ohair@286: public NType erasure(NType type) { ohair@286: if(type instanceof NParameterizedType) { ohair@286: NParameterizedType pt = (NParameterizedType) type; ohair@286: return pt.rawType; ohair@286: } ohair@286: return type; ohair@286: } ohair@286: ohair@286: public boolean isAbstract(NClass clazz) { ohair@286: return clazz.isAbstract(); ohair@286: } ohair@286: ohair@286: /** ohair@286: * @deprecated ohair@286: * no class generated by XJC is final. ohair@286: */ ohair@286: public boolean isFinal(NClass clazz) { ohair@286: return false; ohair@286: } ohair@286: ohair@286: public Void[] getEnumConstants(NClass clazz) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public NType getVoidType() { ohair@286: return ref(void.class); ohair@286: } ohair@286: ohair@286: public String getPackageName(NClass clazz) { ohair@286: // TODO: implement this method later ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: mkos@450: @Override mkos@450: public NClass loadObjectFactory(NClass referencePoint, String pkg) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isBridgeMethod(Void method) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isOverriding(Void method,NClass clazz) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isInterface(NClass clazz) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isTransient(Void f) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: public boolean isInnerClass(NClass clazz) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: ohair@286: @Override ohair@286: public boolean isSameType(NType t1, NType t2) { ohair@286: throw new UnsupportedOperationException(); ohair@286: } ohair@286: }