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

Fri, 16 Sep 2011 16:18:46 -0700

author
jjg
date
Fri, 16 Sep 2011 16:18:46 -0700
changeset 1094
dea82aa3ca4f
parent 910
ebf7c13df6c0
child 1357
c75be5bc5283
permissions
-rw-r--r--

7091528: javadoc attempts to parse .class files
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     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
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    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  *
    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.
    24  */
    26 package com.sun.tools.javadoc;
    29 import com.sun.javadoc.*;
    31 import com.sun.tools.javac.code.Symbol.ClassSymbol;
    32 import com.sun.tools.javac.code.Type;
    33 import com.sun.tools.javac.util.List;
    36 /**
    37  * Implementation of <code>WildcardType</code>, which
    38  * represents a wildcard type.
    39  *
    40  * @author Scott Seligman
    41  * @since 1.5
    42  */
    43 public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
    45     WildcardTypeImpl(DocEnv env, Type.WildcardType type) {
    46         super(env, type);
    47     }
    49     /**
    50      * Return the upper bounds of this wildcard type argument
    51      * as given by the <i>extends</i> clause.
    52      * Return an empty array if no such bounds are explicitly given.
    53      */
    54     public com.sun.javadoc.Type[] extendsBounds() {
    55         return TypeMaker.getTypes(env, getExtendsBounds((Type.WildcardType)type));
    56     }
    58     /**
    59      * Return the lower bounds of this wildcard type argument
    60      * as given by the <i>super</i> clause.
    61      * Return an empty array if no such bounds are explicitly given.
    62      */
    63     public com.sun.javadoc.Type[] superBounds() {
    64         return TypeMaker.getTypes(env, getSuperBounds((Type.WildcardType)type));
    65     }
    67     /**
    68      * Return the ClassDoc of the erasure of this wildcard type.
    69      */
    70     @Override
    71     public ClassDoc asClassDoc() {
    72         return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
    73     }
    75     @Override
    76     public WildcardType asWildcardType() {
    77         return this;
    78     }
    80     @Override
    81     public String typeName()            { return "?"; }
    82     @Override
    83     public String qualifiedTypeName()   { return "?"; }
    84     @Override
    85     public String simpleTypeName()      { return "?"; }
    87     @Override
    88     public String toString() {
    89         return wildcardTypeToString(env, (Type.WildcardType)type, true);
    90     }
    93     /**
    94      * Return the string form of a wildcard type ("?") along with any
    95      * "extends" or "super" clause.  Delimiting brackets are not
    96      * included.  Class names are qualified if "full" is true.
    97      */
    98     static String wildcardTypeToString(DocEnv env,
    99                                        Type.WildcardType wildThing, boolean full) {
   100         if (env.legacyDoclet) {
   101             return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
   102         }
   103         StringBuilder s = new StringBuilder("?");
   104         List<Type> bounds = getExtendsBounds(wildThing);
   105         if (bounds.nonEmpty()) {
   106             s.append(" extends ");
   107         } else {
   108             bounds = getSuperBounds(wildThing);
   109             if (bounds.nonEmpty()) {
   110                 s.append(" super ");
   111             }
   112         }
   113         boolean first = true;   // currently only one bound is allowed
   114         for (Type b : bounds) {
   115             if (!first) {
   116                 s.append(" & ");
   117             }
   118             s.append(TypeMaker.getTypeString(env, b, full));
   119             first = false;
   120         }
   121         return s.toString();
   122     }
   124     private static List<Type> getExtendsBounds(Type.WildcardType wild) {
   125         return wild.isSuperBound()
   126                 ? List.<Type>nil()
   127                 : List.of(wild.type);
   128     }
   130     private static List<Type> getSuperBounds(Type.WildcardType wild) {
   131         return wild.isExtendsBound()
   132                 ? List.<Type>nil()
   133                 : List.of(wild.type);
   134     }
   135 }

mercurial