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

changeset 1722
38c4bade0ec1
parent 1359
25e14ad23cef
child 2525
2eb010b6cb22
     1.1 --- a/src/share/classes/com/sun/tools/javadoc/Comment.java	Fri May 03 09:56:56 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javadoc/Comment.java	Fri May 03 10:17:12 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,6 +25,8 @@
    1.11  
    1.12  package com.sun.tools.javadoc;
    1.13  
    1.14 +import java.util.regex.Matcher;
    1.15 +import java.util.regex.Pattern;
    1.16  import com.sun.javadoc.*;
    1.17  import com.sun.tools.javac.util.ListBuffer;
    1.18  
    1.19 @@ -296,6 +298,7 @@
    1.20      static Tag[] getInlineTags(DocImpl holder, String inlinetext) {
    1.21          ListBuffer<Tag> taglist = new ListBuffer<Tag>();
    1.22          int delimend = 0, textstart = 0, len = inlinetext.length();
    1.23 +        boolean inPre = false;
    1.24          DocEnv docenv = holder.env;
    1.25  
    1.26          if (len == 0) {
    1.27 @@ -309,6 +312,7 @@
    1.28                                             inlinetext.substring(textstart)));
    1.29                  break;
    1.30              } else {
    1.31 +                inPre = scanForPre(inlinetext, textstart, linkstart, inPre);
    1.32                  int seetextstart = linkstart;
    1.33                  for (int i = linkstart; i < inlinetext.length(); i++) {
    1.34                      char c = inlinetext.charAt(i);
    1.35 @@ -319,18 +323,20 @@
    1.36                       }
    1.37                  }
    1.38                  String linkName = inlinetext.substring(linkstart+2, seetextstart);
    1.39 -                //Move past the white space after the inline tag name.
    1.40 -                while (Character.isWhitespace(inlinetext.
    1.41 -                                                  charAt(seetextstart))) {
    1.42 -                    if (inlinetext.length() <= seetextstart) {
    1.43 -                        taglist.append(new TagImpl(holder, "Text",
    1.44 -                                                   inlinetext.substring(textstart, seetextstart)));
    1.45 -                        docenv.warning(holder,
    1.46 -                                       "tag.Improper_Use_Of_Link_Tag",
    1.47 -                                       inlinetext);
    1.48 -                        return taglist.toArray(new Tag[taglist.length()]);
    1.49 -                    } else {
    1.50 -                        seetextstart++;
    1.51 +                if (!(inPre && (linkName.equals("code") || linkName.equals("literal")))) {
    1.52 +                    //Move past the white space after the inline tag name.
    1.53 +                    while (Character.isWhitespace(inlinetext.
    1.54 +                                                      charAt(seetextstart))) {
    1.55 +                        if (inlinetext.length() <= seetextstart) {
    1.56 +                            taglist.append(new TagImpl(holder, "Text",
    1.57 +                                                       inlinetext.substring(textstart, seetextstart)));
    1.58 +                            docenv.warning(holder,
    1.59 +                                           "tag.Improper_Use_Of_Link_Tag",
    1.60 +                                           inlinetext);
    1.61 +                            return taglist.toArray(new Tag[taglist.length()]);
    1.62 +                        } else {
    1.63 +                            seetextstart++;
    1.64 +                        }
    1.65                      }
    1.66                  }
    1.67                  taglist.append(new TagImpl(holder, "Text",
    1.68 @@ -366,6 +372,17 @@
    1.69          return taglist.toArray(new Tag[taglist.length()]);
    1.70      }
    1.71  
    1.72 +    /** regex for case-insensitive match for {@literal <pre> } and  {@literal </pre> }. */
    1.73 +    private static final Pattern prePat = Pattern.compile("(?i)<(/?)pre>");
    1.74 +
    1.75 +    private static boolean scanForPre(String inlinetext, int start, int end, boolean inPre) {
    1.76 +        Matcher m = prePat.matcher(inlinetext).region(start, end);
    1.77 +        while (m.find()) {
    1.78 +            inPre = m.group(1).isEmpty();
    1.79 +        }
    1.80 +        return inPre;
    1.81 +    }
    1.82 +
    1.83      /**
    1.84       * Recursively find the index of the closing '}' character for an inline tag
    1.85       * and return it.  If it can't be found, return -1.

mercurial