src/share/classes/com/sun/tools/javadoc/TypeVariableImpl.java

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 1992
23f0f3c9c44a
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

duke@1 1 /*
jjg@1521 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javadoc;
duke@1 27
duke@1 28 import com.sun.javadoc.*;
duke@1 29
jjg@1521 30 import com.sun.tools.javac.code.Attribute;
jjg@1521 31 import com.sun.tools.javac.code.Attribute.TypeCompound;
duke@1 32 import com.sun.tools.javac.code.Kinds;
duke@1 33 import com.sun.tools.javac.code.Symbol;
duke@1 34 import com.sun.tools.javac.code.Symbol.ClassSymbol;
duke@1 35 import com.sun.tools.javac.code.Symbol.MethodSymbol;
duke@1 36 import com.sun.tools.javac.code.Type;
duke@1 37 import com.sun.tools.javac.code.Type.TypeVar;
duke@1 38 import com.sun.tools.javac.util.List;
duke@1 39 import com.sun.tools.javac.util.Name;
jjg@113 40 import com.sun.tools.javac.util.Names;
duke@1 41
duke@1 42 /**
duke@1 43 * Implementation of <code>TypeVariable</code>, which
duke@1 44 * represents a type variable.
duke@1 45 *
jjg@1359 46 * <p><b>This is NOT part of any supported API.
jjg@1359 47 * If you write code that depends on this, you do so at your own risk.
jjg@1359 48 * This code and its internal interfaces are subject to change or
jjg@1359 49 * deletion without notice.</b>
jjg@1359 50 *
duke@1 51 * @author Scott Seligman
duke@1 52 * @since 1.5
duke@1 53 */
duke@1 54 public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
duke@1 55
duke@1 56 TypeVariableImpl(DocEnv env, TypeVar type) {
duke@1 57 super(env, type);
duke@1 58 }
duke@1 59
duke@1 60 /**
duke@1 61 * Return the bounds of this type variable.
duke@1 62 */
duke@1 63 public com.sun.javadoc.Type[] bounds() {
duke@1 64 return TypeMaker.getTypes(env, getBounds((TypeVar)type, env));
duke@1 65 }
duke@1 66
duke@1 67 /**
duke@1 68 * Return the class, interface, method, or constructor within
duke@1 69 * which this type variable is declared.
duke@1 70 */
duke@1 71 public ProgramElementDoc owner() {
duke@1 72 Symbol osym = type.tsym.owner;
duke@1 73 if ((osym.kind & Kinds.TYP) != 0) {
duke@1 74 return env.getClassDoc((ClassSymbol)osym);
duke@1 75 }
jjg@113 76 Names names = osym.name.table.names;
duke@1 77 if (osym.name == names.init) {
duke@1 78 return env.getConstructorDoc((MethodSymbol)osym);
duke@1 79 } else {
duke@1 80 return env.getMethodDoc((MethodSymbol)osym);
duke@1 81 }
duke@1 82 }
duke@1 83
duke@1 84 /**
duke@1 85 * Return the ClassDoc of the erasure of this type variable.
duke@1 86 */
jjg@910 87 @Override
duke@1 88 public ClassDoc asClassDoc() {
duke@1 89 return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
duke@1 90 }
duke@1 91
jjg@910 92 @Override
duke@1 93 public TypeVariable asTypeVariable() {
duke@1 94 return this;
duke@1 95 }
duke@1 96
jjg@910 97 @Override
duke@1 98 public String toString() {
duke@1 99 return typeVarToString(env, (TypeVar)type, true);
duke@1 100 }
duke@1 101
duke@1 102
duke@1 103 /**
duke@1 104 * Return the string form of a type variable along with any
duke@1 105 * "extends" clause. Class names are qualified if "full" is true.
duke@1 106 */
duke@1 107 static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
jjg@910 108 StringBuilder s = new StringBuilder(v.toString());
duke@1 109 List<Type> bounds = getBounds(v, env);
duke@1 110 if (bounds.nonEmpty()) {
duke@1 111 boolean first = true;
duke@1 112 for (Type b : bounds) {
duke@1 113 s.append(first ? " extends " : " & ");
duke@1 114 s.append(TypeMaker.getTypeString(env, b, full));
duke@1 115 first = false;
duke@1 116 }
duke@1 117 }
duke@1 118 return s.toString();
duke@1 119 }
duke@1 120
duke@1 121 /**
duke@1 122 * Get the bounds of a type variable as listed in the "extends" clause.
duke@1 123 */
duke@1 124 private static List<Type> getBounds(TypeVar v, DocEnv env) {
jjg@1521 125 final Type upperBound = v.getUpperBound();
jjg@1521 126 Name boundname = upperBound.tsym.getQualifiedName();
jjg@1521 127 if (boundname == boundname.table.names.java_lang_Object
jjg@1644 128 && !upperBound.isAnnotated()) {
duke@1 129 return List.nil();
duke@1 130 } else {
duke@1 131 return env.types.getBounds(v);
duke@1 132 }
duke@1 133 }
jjg@1521 134
jjg@1521 135 /**
jjg@1521 136 * Get the annotations of this program element.
jjg@1521 137 * Return an empty array if there are none.
jjg@1521 138 */
jjg@1521 139 public AnnotationDesc[] annotations() {
jjg@1644 140 if (!type.isAnnotated()) {
jjg@1521 141 return new AnnotationDesc[0];
jjg@1521 142 }
jjg@1992 143 List<? extends TypeCompound> tas = type.getAnnotationMirrors();
jjg@1521 144 AnnotationDesc res[] = new AnnotationDesc[tas.length()];
jjg@1521 145 int i = 0;
jjg@1521 146 for (Attribute.Compound a : tas) {
jjg@1521 147 res[i++] = new AnnotationDescImpl(env, a);
jjg@1521 148 }
jjg@1521 149 return res;
jjg@1521 150 }
duke@1 151 }

mercurial