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