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