src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/links/LinkFactory.java
changeset 54060 53a95878619f
parent 50810 0358dad944c7
equal deleted inserted replaced
54059:1bc8513104f2 54060:53a95878619f
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    79                 Content link = newContent();
    79                 Content link = newContent();
    80 
    80 
    81                 // handles primitives, no types and error types
    81                 // handles primitives, no types and error types
    82                 @Override
    82                 @Override
    83                 protected Content defaultAction(TypeMirror type, LinkInfo linkInfo) {
    83                 protected Content defaultAction(TypeMirror type, LinkInfo linkInfo) {
    84                     link.addContent(utils.getTypeName(type, false));
    84                     link.add(utils.getTypeName(type, false));
    85                     return link;
    85                     return link;
    86                 }
    86                 }
    87 
    87 
    88                 int currentDepth = 0;
    88                 int currentDepth = 0;
    89                 @Override
    89                 @Override
    94                     linkInfo.type = type.getComponentType();
    94                     linkInfo.type = type.getComponentType();
    95                     visit(linkInfo.type, linkInfo);
    95                     visit(linkInfo.type, linkInfo);
    96                     currentDepth--;
    96                     currentDepth--;
    97                     if (utils.isAnnotated(type)) {
    97                     if (utils.isAnnotated(type)) {
    98                         linkInfo.type = type;
    98                         linkInfo.type = type;
    99                         link.addContent(" ");
    99                         link.add(" ");
   100                         link.addContent(getTypeAnnotationLinks(linkInfo));
   100                         link.add(getTypeAnnotationLinks(linkInfo));
   101                     }
   101                     }
   102                     // use vararg if required
   102                     // use vararg if required
   103                     if (linkInfo.isVarArg && currentDepth == 0) {
   103                     if (linkInfo.isVarArg && currentDepth == 0) {
   104                         link.addContent("...");
   104                         link.add("...");
   105                     } else {
   105                     } else {
   106                         link.addContent("[]");
   106                         link.add("[]");
   107                     }
   107                     }
   108                     return link;
   108                     return link;
   109                 }
   109                 }
   110 
   110 
   111                 @Override
   111                 @Override
   112                 public Content visitWildcard(WildcardType type, LinkInfo linkInfo) {
   112                 public Content visitWildcard(WildcardType type, LinkInfo linkInfo) {
   113                     linkInfo.isTypeBound = true;
   113                     linkInfo.isTypeBound = true;
   114                     link.addContent("?");
   114                     link.add("?");
   115                     TypeMirror extendsBound = type.getExtendsBound();
   115                     TypeMirror extendsBound = type.getExtendsBound();
   116                     if (extendsBound != null) {
   116                     if (extendsBound != null) {
   117                         link.addContent(" extends ");
   117                         link.add(" extends ");
   118                         setBoundsLinkInfo(linkInfo, extendsBound);
   118                         setBoundsLinkInfo(linkInfo, extendsBound);
   119                         link.addContent(getLink(linkInfo));
   119                         link.add(getLink(linkInfo));
   120                     }
   120                     }
   121                     TypeMirror superBound = type.getSuperBound();
   121                     TypeMirror superBound = type.getSuperBound();
   122                     if (superBound != null) {
   122                     if (superBound != null) {
   123                         link.addContent(" super ");
   123                         link.add(" super ");
   124                         setBoundsLinkInfo(linkInfo, superBound);
   124                         setBoundsLinkInfo(linkInfo, superBound);
   125                         link.addContent(getLink(linkInfo));
   125                         link.add(getLink(linkInfo));
   126                     }
   126                     }
   127                     return link;
   127                     return link;
   128                 }
   128                 }
   129 
   129 
   130                 @Override
   130                 @Override
   131                 public Content visitTypeVariable(TypeVariable type, LinkInfo linkInfo) {
   131                 public Content visitTypeVariable(TypeVariable type, LinkInfo linkInfo) {
   132                     link.addContent(getTypeAnnotationLinks(linkInfo));
   132                     link.add(getTypeAnnotationLinks(linkInfo));
   133                     linkInfo.isTypeBound = true;
   133                     linkInfo.isTypeBound = true;
   134                     TypeVariable typevariable = (utils.isArrayType(type))
   134                     TypeVariable typevariable = (utils.isArrayType(type))
   135                             ? (TypeVariable) componentType
   135                             ? (TypeVariable) componentType
   136                             : type;
   136                             : type;
   137                     Element owner = typevariable.asElement().getEnclosingElement();
   137                     Element owner = typevariable.asElement().getEnclosingElement();
   138                     if ((!linkInfo.excludeTypeParameterLinks) && utils.isTypeElement(owner)) {
   138                     if ((!linkInfo.excludeTypeParameterLinks) && utils.isTypeElement(owner)) {
   139                         linkInfo.typeElement = (TypeElement) owner;
   139                         linkInfo.typeElement = (TypeElement) owner;
   140                         Content label = newContent();
   140                         Content label = newContent();
   141                         label.addContent(utils.getTypeName(type, false));
   141                         label.add(utils.getTypeName(type, false));
   142                         linkInfo.label = label;
   142                         linkInfo.label = label;
   143                         link.addContent(getClassLink(linkInfo));
   143                         link.add(getClassLink(linkInfo));
   144                     } else {
   144                     } else {
   145                         // No need to link method type parameters.
   145                         // No need to link method type parameters.
   146                         link.addContent(utils.getTypeName(typevariable, false));
   146                         link.add(utils.getTypeName(typevariable, false));
   147                     }
   147                     }
   148 
   148 
   149                     if (!linkInfo.excludeTypeBounds) {
   149                     if (!linkInfo.excludeTypeBounds) {
   150                         linkInfo.excludeTypeBounds = true;
   150                         linkInfo.excludeTypeBounds = true;
   151                         TypeParameterElement tpe = ((TypeParameterElement) typevariable.asElement());
   151                         TypeParameterElement tpe = ((TypeParameterElement) typevariable.asElement());
   157                             if (bounds.size() == 1 &&
   157                             if (bounds.size() == 1 &&
   158                                     bound.equals(utils.getObjectType()) &&
   158                                     bound.equals(utils.getObjectType()) &&
   159                                     !utils.isAnnotated(bound)) {
   159                                     !utils.isAnnotated(bound)) {
   160                                 continue;
   160                                 continue;
   161                             }
   161                             }
   162                             link.addContent(more ? " & " : " extends ");
   162                             link.add(more ? " & " : " extends ");
   163                             setBoundsLinkInfo(linkInfo, bound);
   163                             setBoundsLinkInfo(linkInfo, bound);
   164                             link.addContent(getLink(linkInfo));
   164                             link.add(getLink(linkInfo));
   165                             more = true;
   165                             more = true;
   166                         }
   166                         }
   167                     }
   167                     }
   168                     return link;
   168                     return link;
   169                 }
   169                 }
   171                 @Override
   171                 @Override
   172                 public Content visitDeclared(DeclaredType type, LinkInfo linkInfo) {
   172                 public Content visitDeclared(DeclaredType type, LinkInfo linkInfo) {
   173                     if (linkInfo.isTypeBound && linkInfo.excludeTypeBoundsLinks) {
   173                     if (linkInfo.isTypeBound && linkInfo.excludeTypeBoundsLinks) {
   174                         // Since we are excluding type parameter links, we should not
   174                         // Since we are excluding type parameter links, we should not
   175                         // be linking to the type bound.
   175                         // be linking to the type bound.
   176                         link.addContent(utils.getTypeName(type, false));
   176                         link.add(utils.getTypeName(type, false));
   177                         link.addContent(getTypeParameterLinks(linkInfo));
   177                         link.add(getTypeParameterLinks(linkInfo));
   178                         return link;
   178                         return link;
   179                     } else {
   179                     } else {
   180                         link = newContent();
   180                         link = newContent();
   181                         link.addContent(getTypeAnnotationLinks(linkInfo));
   181                         link.add(getTypeAnnotationLinks(linkInfo));
   182                         linkInfo.typeElement = utils.asTypeElement(type);
   182                         linkInfo.typeElement = utils.asTypeElement(type);
   183                         link.addContent(getClassLink(linkInfo));
   183                         link.add(getClassLink(linkInfo));
   184                         if (linkInfo.includeTypeAsSepLink) {
   184                         if (linkInfo.includeTypeAsSepLink) {
   185                             link.addContent(getTypeParameterLinks(linkInfo, false));
   185                             link.add(getTypeParameterLinks(linkInfo, false));
   186                         }
   186                         }
   187                     }
   187                     }
   188                     return link;
   188                     return link;
   189                 }
   189                 }
   190             };
   190             };
   191             return linkVisitor.visit(linkInfo.type, linkInfo);
   191             return linkVisitor.visit(linkInfo.type, linkInfo);
   192         } else if (linkInfo.typeElement != null) {
   192         } else if (linkInfo.typeElement != null) {
   193             Content link = newContent();
   193             Content link = newContent();
   194             link.addContent(getClassLink(linkInfo));
   194             link.add(getClassLink(linkInfo));
   195             if (linkInfo.includeTypeAsSepLink) {
   195             if (linkInfo.includeTypeAsSepLink) {
   196                 link.addContent(getTypeParameterLinks(linkInfo, false));
   196                 link.add(getTypeParameterLinks(linkInfo, false));
   197             }
   197             }
   198             return link;
   198             return link;
   199         } else {
   199         } else {
   200             return null;
   200             return null;
   201         }
   201         }