8062647: Wrong indentation of arguments of annotated methods
authorigerasim
Fri, 31 Jul 2015 01:36:56 +0300
changeset 31943 72b69ab429c9
parent 31942 8ab03f64ccac
child 31944 222a831dd495
8062647: Wrong indentation of arguments of annotated methods Reviewed-by: jjg, bpatel
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java
langtools/test/com/sun/javadoc/testIndentation/TestIndentation.java
langtools/test/com/sun/javadoc/testIndentation/p/IndentAnnot.java
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java	Thu Jul 30 15:22:56 2015 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/ConstructorWriterImpl.java	Fri Jul 31 01:36:56 2015 +0300
@@ -135,6 +135,7 @@
     public Content getSignature(ConstructorDoc constructor) {
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(constructor, pre);
+        int annotationLength = pre.charCount();
         addModifiers(constructor, pre);
         if (configuration.linksource) {
             Content constructorName = new StringContent(constructor.name());
@@ -142,7 +143,7 @@
         } else {
             addName(constructor.name(), pre);
         }
-        int indent = pre.charCount();
+        int indent = pre.charCount() - annotationLength;
         addParameters(constructor, pre, indent);
         addExceptions(constructor, pre, indent);
         return pre;
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Thu Jul 30 15:22:56 2015 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Fri Jul 31 01:36:56 2015 +0300
@@ -1936,7 +1936,9 @@
         for (Content annotation: annotations) {
             htmltree.addContent(sep);
             htmltree.addContent(annotation);
-            sep = " ";
+            if (!lineBreak) {
+                sep = " ";
+            }
         }
         return true;
     }
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Thu Jul 30 15:22:56 2015 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Fri Jul 31 01:36:56 2015 +0300
@@ -128,6 +128,7 @@
     public Content getSignature(MethodDoc method) {
         Content pre = new HtmlTree(HtmlTag.PRE);
         writer.addAnnotationInfo(method, pre);
+        int annotationLength = pre.charCount();
         addModifiers(method, pre);
         addTypeParameters(method, pre);
         addReturnType(method, pre);
@@ -137,7 +138,7 @@
         } else {
             addName(method.name(), pre);
         }
-        int indent = pre.charCount();
+        int indent = pre.charCount() - annotationLength;
         addParameters(method, pre, indent);
         addExceptions(method, pre, indent);
         return pre;
--- a/langtools/test/com/sun/javadoc/testIndentation/TestIndentation.java	Thu Jul 30 15:22:56 2015 -0700
+++ b/langtools/test/com/sun/javadoc/testIndentation/TestIndentation.java	Fri Jul 31 01:36:56 2015 +0300
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug      8011288
+ * @bug      8011288 8062647
  * @summary  Erratic/inconsistent indentation of signatures
  * @library  ../lib
  * @modules jdk.javadoc
@@ -51,5 +51,12 @@
                 + "                  T t2)",
                 "\n"
                 + "           throws java.lang.Exception");
+
+        // Test indentation of annotations and annotated method arguments
+        checkOutput("p/IndentAnnot.html", false,
+                " @Deprecated",
+                "                int b)",
+                "                java.lang.Object... b)");
+
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/com/sun/javadoc/testIndentation/p/IndentAnnot.java	Fri Jul 31 01:36:56 2015 +0300
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+public class IndentAnnot {
+    public void f1(int a, int b) {}
+
+    public void f2(int a, Object... b) {}
+
+    @Deprecated
+    public void f3(int a, int b) {}
+
+    @SafeVarargs
+    public void f4(int a, Object... b) {}
+
+    @SafeVarargs
+    @Deprecated
+    public void f5(int a, Object... b) {}
+}