src/share/jaxws_classes/com/sun/tools/internal/jxc/model/nav/ApNavigator.java

Wed, 12 Jun 2013 14:47:09 +0100

author
mkos
date
Wed, 12 Jun 2013 14:47:09 +0100
changeset 384
8f2986ff0235
parent 368
0989ad8c0860
child 450
b0c2840e2513
permissions
-rw-r--r--

8013021: Rebase 8005432 & 8003542 against the latest jdk8/jaxws
8003542: Improve processing of MTOM attachments
8005432: Update access to JAX-WS
Reviewed-by: mullan

ohair@286 1 /*
jjg@363 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.tools.internal.jxc.model.nav;
ohair@286 27
ohair@286 28 import com.sun.source.tree.CompilationUnitTree;
ohair@286 29 import com.sun.source.util.TreePath;
ohair@286 30 import com.sun.source.util.Trees;
ohair@286 31 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
ohair@286 32 import com.sun.xml.internal.bind.v2.runtime.Location;
ohair@286 33
ohair@286 34 import javax.annotation.processing.ProcessingEnvironment;
jjg@363 35 import javax.lang.model.element.AnnotationMirror;
ohair@286 36 import javax.lang.model.element.Element;
ohair@286 37 import javax.lang.model.element.ElementKind;
ohair@286 38 import javax.lang.model.element.ExecutableElement;
ohair@286 39 import javax.lang.model.element.Modifier;
ohair@286 40 import javax.lang.model.element.TypeElement;
ohair@286 41 import javax.lang.model.element.TypeParameterElement;
ohair@286 42 import javax.lang.model.element.VariableElement;
ohair@286 43 import javax.lang.model.type.ArrayType;
ohair@286 44 import javax.lang.model.type.DeclaredType;
ohair@286 45 import javax.lang.model.type.PrimitiveType;
ohair@286 46 import javax.lang.model.type.TypeKind;
ohair@286 47 import javax.lang.model.type.TypeMirror;
ohair@286 48 import javax.lang.model.type.TypeVariable;
ohair@286 49 import javax.lang.model.type.TypeVisitor;
ohair@286 50 import javax.lang.model.type.WildcardType;
ohair@286 51 import javax.lang.model.util.ElementFilter;
ohair@286 52 import javax.lang.model.util.Elements;
ohair@286 53 import javax.lang.model.util.SimpleTypeVisitor6;
ohair@286 54 import javax.lang.model.util.Types;
alanb@368 55 import java.lang.annotation.Annotation;
ohair@286 56 import java.util.Collection;
ohair@286 57 import java.util.HashMap;
ohair@286 58 import java.util.HashSet;
ohair@286 59 import java.util.List;
ohair@286 60 import java.util.Map;
ohair@286 61
ohair@286 62 /**
ohair@286 63 * {@link Navigator} implementation for annotation processing.
ohair@286 64 * TODO: check the spec on how generics are supposed to be handled
ohair@286 65 *
ohair@286 66 * @author Kohsuke Kawaguchi (kk@kohsuke.org)
ohair@286 67 */
ohair@286 68 public class ApNavigator implements Navigator<TypeMirror, TypeElement, VariableElement, ExecutableElement> {
ohair@286 69
ohair@286 70 private final ProcessingEnvironment env;
ohair@286 71
ohair@286 72 private final PrimitiveType primitiveByte;
ohair@286 73
ohair@286 74 public ApNavigator(ProcessingEnvironment env) {
ohair@286 75 this.env = env;
ohair@286 76 this.primitiveByte = env.getTypeUtils().getPrimitiveType(TypeKind.BYTE);
ohair@286 77 }
ohair@286 78
ohair@286 79 public TypeElement getSuperClass(TypeElement typeElement) {
ohair@286 80 if (typeElement.getKind().equals(ElementKind.CLASS)) {
ohair@286 81 TypeMirror sup = typeElement.getSuperclass();
ohair@286 82 if (!sup.getKind().equals(TypeKind.NONE))
ohair@286 83 return (TypeElement) ((DeclaredType) sup).asElement();
ohair@286 84 else
ohair@286 85 return null;
ohair@286 86 }
ohair@286 87 return env.getElementUtils().getTypeElement(Object.class.getName());
ohair@286 88 }
ohair@286 89
ohair@286 90 public TypeMirror getBaseClass(TypeMirror type, TypeElement sup) {
ohair@286 91 return baseClassFinder.visit(type, sup);
ohair@286 92 }
ohair@286 93
ohair@286 94 public String getClassName(TypeElement t) {
ohair@286 95 return t.getQualifiedName().toString();
ohair@286 96 }
ohair@286 97
ohair@286 98 public String getTypeName(TypeMirror typeMirror) {
ohair@286 99 return typeMirror.toString();
ohair@286 100 }
ohair@286 101
ohair@286 102 public String getClassShortName(TypeElement t) {
ohair@286 103 return t.getSimpleName().toString();
ohair@286 104 }
ohair@286 105
ohair@286 106 public Collection<VariableElement> getDeclaredFields(TypeElement typeElement) {
ohair@286 107 return ElementFilter.fieldsIn(typeElement.getEnclosedElements());
ohair@286 108 }
ohair@286 109
ohair@286 110 public VariableElement getDeclaredField(TypeElement clazz, String fieldName) {
ohair@286 111 for (VariableElement fd : ElementFilter.fieldsIn(clazz.getEnclosedElements())) {
ohair@286 112 if (fd.getSimpleName().toString().equals(fieldName))
ohair@286 113 return fd;
ohair@286 114 }
ohair@286 115 return null;
ohair@286 116 }
ohair@286 117
ohair@286 118 public Collection<ExecutableElement> getDeclaredMethods(TypeElement typeElement) {
ohair@286 119 return ElementFilter.methodsIn(typeElement.getEnclosedElements());
ohair@286 120 }
ohair@286 121
ohair@286 122 public TypeElement getDeclaringClassForField(VariableElement f) {
ohair@286 123 return (TypeElement) f.getEnclosingElement();
ohair@286 124 }
ohair@286 125
ohair@286 126 public TypeElement getDeclaringClassForMethod(ExecutableElement m) {
ohair@286 127 return (TypeElement) m.getEnclosingElement();
ohair@286 128 }
ohair@286 129
ohair@286 130 public TypeMirror getFieldType(VariableElement f) {
ohair@286 131 return f.asType();
ohair@286 132 }
ohair@286 133
ohair@286 134 public String getFieldName(VariableElement f) {
ohair@286 135 return f.getSimpleName().toString();
ohair@286 136 }
ohair@286 137
ohair@286 138 public String getMethodName(ExecutableElement m) {
ohair@286 139 return m.getSimpleName().toString();
ohair@286 140 }
ohair@286 141
ohair@286 142 public TypeMirror getReturnType(ExecutableElement m) {
ohair@286 143 return m.getReturnType();
ohair@286 144 }
ohair@286 145
ohair@286 146 public TypeMirror[] getMethodParameters(ExecutableElement m) {
ohair@286 147 Collection<? extends VariableElement> ps = m.getParameters();
ohair@286 148 TypeMirror[] r = new TypeMirror[ps.size()];
ohair@286 149 int i=0;
ohair@286 150 for (VariableElement p : ps)
ohair@286 151 r[i++] = p.asType();
ohair@286 152 return r;
ohair@286 153 }
ohair@286 154
ohair@286 155 public boolean isStaticMethod(ExecutableElement m) {
ohair@286 156 return hasModifier(m, Modifier.STATIC);
ohair@286 157 }
ohair@286 158
ohair@286 159 public boolean isFinalMethod(ExecutableElement m) {
ohair@286 160 return hasModifier(m, Modifier.FINAL);
ohair@286 161 }
ohair@286 162
ohair@286 163 private boolean hasModifier(Element d, Modifier mod) {
ohair@286 164 return d.getModifiers().contains(mod);
ohair@286 165 }
ohair@286 166
ohair@286 167 public boolean isSubClassOf(TypeMirror sub, TypeMirror sup) {
ohair@286 168 if(sup==DUMMY)
ohair@286 169 // see ref(). if the sub type is known to Annotation Processing,
ohair@286 170 // its base class must be known. Thus if the sup is DUMMY,
ohair@286 171 // it cannot possibly be the super type.
ohair@286 172 return false;
ohair@286 173 return env.getTypeUtils().isSubtype(sub,sup);
ohair@286 174 }
ohair@286 175
ohair@286 176 private String getSourceClassName(Class clazz) {
ohair@286 177 Class<?> d = clazz.getDeclaringClass();
ohair@286 178 if(d==null)
ohair@286 179 return clazz.getName();
ohair@286 180 else {
ohair@286 181 String shortName = clazz.getName().substring(d.getName().length()+1/*for $*/);
ohair@286 182 return getSourceClassName(d)+'.'+shortName;
ohair@286 183 }
ohair@286 184 }
ohair@286 185
ohair@286 186 public TypeMirror ref(Class c) {
ohair@286 187 if(c.isArray())
ohair@286 188 return env.getTypeUtils().getArrayType( ref(c.getComponentType()) );
ohair@286 189 if(c.isPrimitive())
ohair@286 190 return getPrimitive(c);
ohair@286 191 TypeElement t = env.getElementUtils().getTypeElement(getSourceClassName(c));
ohair@286 192 // Annotation Processing only operates on a set of classes used in the compilation,
ohair@286 193 // and it won't recognize additional classes (even if they are visible from javac)
ohair@286 194 // and return null.
ohair@286 195 //
ohair@286 196 // this is causing a problem where we check if a type is collection.
ohair@286 197 // so until the problem is fixed in Annotation Processing, work around the issue
ohair@286 198 // by returning a dummy token
ohair@286 199 // TODO: check if this is still valid
ohair@286 200 if(t==null)
ohair@286 201 return DUMMY;
ohair@286 202 return env.getTypeUtils().getDeclaredType(t);
ohair@286 203 }
ohair@286 204
ohair@286 205 public TypeMirror use(TypeElement t) {
ohair@286 206 assert t != null;
ohair@286 207 return env.getTypeUtils().getDeclaredType(t);
ohair@286 208 }
ohair@286 209
ohair@286 210 public TypeElement asDecl(TypeMirror m) {
ohair@286 211 m = env.getTypeUtils().erasure(m);
ohair@286 212 if (m.getKind().equals(TypeKind.DECLARED)) {
ohair@286 213 DeclaredType d = (DeclaredType) m;
ohair@286 214 return (TypeElement) d.asElement();
ohair@286 215 } else
ohair@286 216 return null;
ohair@286 217 }
ohair@286 218
ohair@286 219 public TypeElement asDecl(Class c) {
ohair@286 220 return env.getElementUtils().getTypeElement(getSourceClassName(c));
ohair@286 221 }
ohair@286 222
ohair@286 223 public TypeMirror erasure(TypeMirror t) {
ohair@286 224 Types tu = env.getTypeUtils();
ohair@286 225 t = tu.erasure(t);
ohair@286 226 if (t.getKind().equals(TypeKind.DECLARED)) {
ohair@286 227 DeclaredType dt = (DeclaredType)t;
ohair@286 228 if (!dt.getTypeArguments().isEmpty())
ohair@286 229 return tu.getDeclaredType((TypeElement) dt.asElement());
ohair@286 230 }
ohair@286 231 return t;
ohair@286 232 }
ohair@286 233
ohair@286 234 public boolean isAbstract(TypeElement clazz) {
ohair@286 235 return hasModifier(clazz,Modifier.ABSTRACT);
ohair@286 236 }
ohair@286 237
ohair@286 238 public boolean isFinal(TypeElement clazz) {
ohair@286 239 return hasModifier(clazz,Modifier.FINAL);
ohair@286 240 }
ohair@286 241
ohair@286 242 public VariableElement[] getEnumConstants(TypeElement clazz) {
ohair@286 243 List<? extends Element> elements = env.getElementUtils().getAllMembers(clazz);
ohair@286 244 Collection<VariableElement> constants = new HashSet<VariableElement>();
ohair@286 245 for (Element element : elements) {
ohair@286 246 if (element.getKind().equals(ElementKind.ENUM_CONSTANT)) {
ohair@286 247 constants.add((VariableElement) element);
ohair@286 248 }
ohair@286 249 }
ohair@286 250 return constants.toArray(new VariableElement[constants.size()]);
ohair@286 251 }
ohair@286 252
ohair@286 253 public TypeMirror getVoidType() {
ohair@286 254 return env.getTypeUtils().getNoType(TypeKind.VOID);
ohair@286 255 }
ohair@286 256
ohair@286 257 public String getPackageName(TypeElement clazz) {
ohair@286 258 return env.getElementUtils().getPackageOf(clazz).getQualifiedName().toString();
ohair@286 259 }
ohair@286 260
ohair@286 261 public TypeElement findClass(String className, TypeElement referencePoint) {
ohair@286 262 return env.getElementUtils().getTypeElement(className);
ohair@286 263 }
ohair@286 264
ohair@286 265 public boolean isBridgeMethod(ExecutableElement method) {
ohair@286 266 return method.getModifiers().contains(Modifier.VOLATILE);
ohair@286 267 }
ohair@286 268
ohair@286 269 public boolean isOverriding(ExecutableElement method, TypeElement base) {
ohair@286 270 Elements elements = env.getElementUtils();
ohair@286 271
ohair@286 272 while (true) {
ohair@286 273 for (ExecutableElement m : ElementFilter.methodsIn(elements.getAllMembers(base))) {
ohair@286 274 if (elements.overrides(method, m, base))
ohair@286 275 return true;
ohair@286 276 }
ohair@286 277
ohair@286 278 if (base.getSuperclass().getKind().equals(TypeKind.NONE))
ohair@286 279 return false;
ohair@286 280 base = (TypeElement) env.getTypeUtils().asElement(base.getSuperclass());
ohair@286 281 }
ohair@286 282 }
ohair@286 283
ohair@286 284 public boolean isInterface(TypeElement clazz) {
ohair@286 285 return clazz.getKind().isInterface();
ohair@286 286 }
ohair@286 287
ohair@286 288 public boolean isTransient(VariableElement f) {
ohair@286 289 return f.getModifiers().contains(Modifier.TRANSIENT);
ohair@286 290 }
ohair@286 291
ohair@286 292 public boolean isInnerClass(TypeElement clazz) {
ohair@286 293 return clazz.getEnclosingElement() != null && !clazz.getModifiers().contains(Modifier.STATIC);
ohair@286 294 }
ohair@286 295
ohair@286 296 @Override
ohair@286 297 public boolean isSameType(TypeMirror t1, TypeMirror t2) {
ohair@286 298 return env.getTypeUtils().isSameType(t1, t2);
ohair@286 299 }
ohair@286 300
ohair@286 301 public boolean isArray(TypeMirror type) {
ohair@286 302 return type != null && type.getKind().equals(TypeKind.ARRAY);
ohair@286 303 }
ohair@286 304
ohair@286 305 public boolean isArrayButNotByteArray(TypeMirror t) {
ohair@286 306 if(!isArray(t))
ohair@286 307 return false;
ohair@286 308
ohair@286 309 ArrayType at = (ArrayType) t;
ohair@286 310 TypeMirror ct = at.getComponentType();
ohair@286 311
ohair@286 312 return !ct.equals(primitiveByte);
ohair@286 313 }
ohair@286 314
ohair@286 315 public TypeMirror getComponentType(TypeMirror t) {
ohair@286 316 if (isArray(t)) {
ohair@286 317 ArrayType at = (ArrayType) t;
ohair@286 318 return at.getComponentType();
ohair@286 319 }
ohair@286 320
ohair@286 321 throw new IllegalArgumentException();
ohair@286 322 }
ohair@286 323
ohair@286 324 public TypeMirror getTypeArgument(TypeMirror typeMirror, int i) {
ohair@286 325 if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED)) {
ohair@286 326 DeclaredType declaredType = (DeclaredType) typeMirror;
ohair@286 327 TypeMirror[] args = declaredType.getTypeArguments().toArray(new TypeMirror[declaredType.getTypeArguments().size()]);
ohair@286 328 return args[i];
ohair@286 329 } else throw new IllegalArgumentException();
ohair@286 330 }
ohair@286 331
ohair@286 332 public boolean isParameterizedType(TypeMirror typeMirror) {
ohair@286 333 if (typeMirror != null && typeMirror.getKind().equals(TypeKind.DECLARED)) {
ohair@286 334 DeclaredType d = (DeclaredType) typeMirror;
ohair@286 335 return !d.getTypeArguments().isEmpty();
ohair@286 336 }
ohair@286 337 return false;
ohair@286 338 }
ohair@286 339
ohair@286 340 public boolean isPrimitive(TypeMirror t) {
ohair@286 341 return t.getKind().isPrimitive();
ohair@286 342 }
ohair@286 343
ohair@286 344 private static final Map<Class, TypeKind> primitives = new HashMap<Class, TypeKind>();
ohair@286 345
ohair@286 346 static {
ohair@286 347 primitives.put(Integer.TYPE, TypeKind.INT);
ohair@286 348 primitives.put(Byte.TYPE, TypeKind.BYTE);
ohair@286 349 primitives.put(Float.TYPE, TypeKind.FLOAT);
ohair@286 350 primitives.put(Boolean.TYPE, TypeKind.BOOLEAN);
ohair@286 351 primitives.put(Short.TYPE, TypeKind.SHORT);
ohair@286 352 primitives.put(Long.TYPE, TypeKind.LONG);
ohair@286 353 primitives.put(Double.TYPE, TypeKind.DOUBLE);
ohair@286 354 primitives.put(Character.TYPE, TypeKind.CHAR);
ohair@286 355 }
ohair@286 356
ohair@286 357 public TypeMirror getPrimitive(Class primitiveType) {
ohair@286 358 assert primitiveType.isPrimitive();
ohair@286 359 if(primitiveType==void.class)
ohair@286 360 return getVoidType();
ohair@286 361 return env.getTypeUtils().getPrimitiveType(primitives.get(primitiveType));
ohair@286 362 }
ohair@286 363
ohair@286 364 /**
ohair@286 365 * see {@link #ref(Class)}.
ohair@286 366 */
ohair@286 367 private static final TypeMirror DUMMY = new TypeMirror() {
ohair@286 368 @Override
ohair@286 369 public <R, P> R accept(TypeVisitor<R, P> v, P p) {
ohair@286 370 throw new IllegalStateException();
ohair@286 371 }
ohair@286 372
ohair@286 373 @Override
ohair@286 374 public TypeKind getKind() {
ohair@286 375 throw new IllegalStateException();
ohair@286 376 }
jjg@363 377
alanb@368 378 // @Override
jjg@363 379 public List<? extends AnnotationMirror> getAnnotationMirrors() {
jjg@363 380 throw new IllegalStateException();
jjg@363 381 }
jjg@363 382
alanb@368 383 // @Override
jjg@363 384 public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
jjg@363 385 throw new IllegalStateException();
jjg@363 386 }
jjg@363 387
alanb@368 388 // @Override
jjg@363 389 public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
jjg@363 390 throw new IllegalStateException();
jjg@363 391 }
ohair@286 392 };
ohair@286 393
ohair@286 394 public Location getClassLocation(TypeElement typeElement) {
ohair@286 395 Trees trees = Trees.instance(env);
ohair@286 396 return getLocation(typeElement.getQualifiedName().toString(), trees.getPath(typeElement));
ohair@286 397 }
ohair@286 398
ohair@286 399 public Location getFieldLocation(VariableElement variableElement) {
ohair@286 400 return getLocation(variableElement);
ohair@286 401 }
ohair@286 402
ohair@286 403 public Location getMethodLocation(ExecutableElement executableElement) {
ohair@286 404 return getLocation(executableElement);
ohair@286 405 }
ohair@286 406
ohair@286 407 public boolean hasDefaultConstructor(TypeElement t) {
ohair@286 408 if (t == null || !t.getKind().equals(ElementKind.CLASS))
ohair@286 409 return false;
ohair@286 410
ohair@286 411 for (ExecutableElement init : ElementFilter.constructorsIn(env.getElementUtils().getAllMembers(t))) {
ohair@286 412 if (init.getParameters().isEmpty())
ohair@286 413 return true;
ohair@286 414 }
ohair@286 415 return false;
ohair@286 416 }
ohair@286 417
ohair@286 418 public boolean isStaticField(VariableElement f) {
ohair@286 419 return hasModifier(f,Modifier.STATIC);
ohair@286 420 }
ohair@286 421
ohair@286 422 public boolean isPublicMethod(ExecutableElement m) {
ohair@286 423 return hasModifier(m,Modifier.PUBLIC);
ohair@286 424 }
ohair@286 425
ohair@286 426 public boolean isPublicField(VariableElement f) {
ohair@286 427 return hasModifier(f,Modifier.PUBLIC);
ohair@286 428 }
ohair@286 429
ohair@286 430 public boolean isEnum(TypeElement t) {
ohair@286 431 return t != null && t.getKind().equals(ElementKind.ENUM);
ohair@286 432 }
ohair@286 433
ohair@286 434 private Location getLocation(Element element) {
ohair@286 435 Trees trees = Trees.instance(env);
ohair@286 436 return getLocation(
ohair@286 437 ((TypeElement) element.getEnclosingElement()).getQualifiedName() + "." + element.getSimpleName(),
ohair@286 438 trees.getPath(element)
ohair@286 439 );
ohair@286 440 }
ohair@286 441
ohair@286 442 private Location getLocation(final String name, final TreePath treePath) {
ohair@286 443 return new Location() {
ohair@286 444 public String toString() {
ohair@286 445 if (treePath == null)
ohair@286 446 return name + " (Unknown Source)";
ohair@286 447 // just like stack trace, we just print the file name and
ohair@286 448 // not the whole path. The idea is that the package name should
ohair@286 449 // provide enough clue on which directory it lives.
ohair@286 450 CompilationUnitTree compilationUnit = treePath.getCompilationUnit();
ohair@286 451 Trees trees = Trees.instance(env);
ohair@286 452 long startPosition = trees.getSourcePositions().getStartPosition(compilationUnit, treePath.getLeaf());
ohair@286 453 return name + "(" +
ohair@286 454 compilationUnit.getSourceFile().getName() + ":" + compilationUnit.getLineMap().getLineNumber(startPosition) +
ohair@286 455 ")";
ohair@286 456 }
ohair@286 457 };
ohair@286 458 }
ohair@286 459
ohair@286 460 /**
ohair@286 461 * Implements {@link #getBaseClass}.
ohair@286 462 */
ohair@286 463 private final SimpleTypeVisitor6<TypeMirror, TypeElement> baseClassFinder = new SimpleTypeVisitor6<TypeMirror, TypeElement>() {
ohair@286 464 @Override
ohair@286 465 public TypeMirror visitDeclared(DeclaredType t, TypeElement sup) {
ohair@286 466 if (t.asElement().equals(sup))
ohair@286 467 return t;
ohair@286 468
ohair@286 469 for (TypeMirror i : env.getTypeUtils().directSupertypes(t)) {
ohair@286 470 TypeMirror r = visitDeclared((DeclaredType) i, sup);
ohair@286 471 if (r != null)
ohair@286 472 return r;
ohair@286 473 }
ohair@286 474
ohair@286 475 // otherwise recursively apply super class and base types
ohair@286 476 TypeMirror superclass = ((TypeElement) t.asElement()).getSuperclass();
ohair@286 477 if (!superclass.getKind().equals(TypeKind.NONE)) {
ohair@286 478 TypeMirror r = visitDeclared((DeclaredType) superclass, sup);
ohair@286 479 if (r != null)
ohair@286 480 return r;
ohair@286 481 }
ohair@286 482 return null;
ohair@286 483 }
ohair@286 484
ohair@286 485 @Override
ohair@286 486 public TypeMirror visitTypeVariable(TypeVariable t, TypeElement typeElement) {
ohair@286 487 // we are checking if T (declared as T extends A&B&C) is assignable to sup.
ohair@286 488 // so apply bounds recursively.
ohair@286 489 for (TypeMirror typeMirror : ((TypeParameterElement) t.asElement()).getBounds()) {
ohair@286 490 TypeMirror m = visit(typeMirror, typeElement);
ohair@286 491 if (m != null)
ohair@286 492 return m;
ohair@286 493 }
ohair@286 494 return null;
ohair@286 495 }
ohair@286 496
ohair@286 497 @Override
ohair@286 498 public TypeMirror visitArray(ArrayType t, TypeElement typeElement) {
ohair@286 499 // we are checking if t=T[] is assignable to sup.
ohair@286 500 // the only case this is allowed is sup=Object,
ohair@286 501 // and Object isn't parameterized.
ohair@286 502 return null;
ohair@286 503 }
ohair@286 504
ohair@286 505 @Override
ohair@286 506 public TypeMirror visitWildcard(WildcardType t, TypeElement typeElement) {
ohair@286 507 // we are checking if T (= ? extends A&B&C) is assignable to sup.
ohair@286 508 // so apply bounds recursively.
ohair@286 509 return visit(t.getExtendsBound(), typeElement);
ohair@286 510 }
ohair@286 511
ohair@286 512 @Override
ohair@286 513 protected TypeMirror defaultAction(TypeMirror e, TypeElement typeElement) {
ohair@286 514 return e;
ohair@286 515 }
ohair@286 516 };
ohair@286 517 }

mercurial