mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8033581: Incorrect comment aligment
8033798: javap output has unnecessary trailing whitespace
8033726
: StackMapTable does not unindent properly
Reviewed-by: ksrini
This commit is contained in:
parent
67d15f03e0
commit
29f985089a
4 changed files with 127 additions and 26 deletions
|
@ -603,6 +603,7 @@ public class AttributeWriter extends BasicWriter
|
||||||
indent(+1);
|
indent(+1);
|
||||||
println("offset_delta = " + frame.offset_delta);
|
println("offset_delta = " + frame.offset_delta);
|
||||||
printMap("locals", frame.locals);
|
printMap("locals", frame.locals);
|
||||||
|
indent(-1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -151,12 +151,22 @@ public class BasicWriter {
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case ' ':
|
||||||
|
pendingSpaces++;
|
||||||
|
break;
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
println();
|
println();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (buffer.length() == 0)
|
if (buffer.length() == 0)
|
||||||
indent();
|
indent();
|
||||||
|
if (pendingSpaces > 0) {
|
||||||
|
for (int sp = 0; sp < pendingSpaces; sp++)
|
||||||
|
buffer.append(' ');
|
||||||
|
pendingSpaces = 0;
|
||||||
|
}
|
||||||
buffer.append(c);
|
buffer.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,6 +174,8 @@ public class BasicWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void println() {
|
protected void println() {
|
||||||
|
// ignore/discard pending spaces
|
||||||
|
pendingSpaces = 0;
|
||||||
out.println(buffer);
|
out.println(buffer);
|
||||||
buffer.setLength(0);
|
buffer.setLength(0);
|
||||||
}
|
}
|
||||||
|
@ -173,26 +185,21 @@ public class BasicWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tab() {
|
protected void tab() {
|
||||||
if (buffer.length() == 0)
|
int col = indentCount * indentWidth + tabColumn;
|
||||||
indent();
|
pendingSpaces += (col <= buffer.length() ? 1 : col - buffer.length());
|
||||||
space(indentCount * indentWidth + tabColumn - buffer.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void indent() {
|
private void indent() {
|
||||||
space(indentCount * indentWidth);
|
pendingSpaces += (indentCount * indentWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void space(int n) {
|
private final PrintWriter out;
|
||||||
for (int i = 0; i < n; i++)
|
private final StringBuilder buffer;
|
||||||
buffer.append(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
private PrintWriter out;
|
|
||||||
private StringBuilder buffer;
|
|
||||||
private int indentCount;
|
private int indentCount;
|
||||||
private int indentWidth;
|
private final int indentWidth;
|
||||||
private int tabColumn;
|
private final int tabColumn;
|
||||||
private boolean pendingNewline;
|
private boolean pendingNewline;
|
||||||
|
private int pendingSpaces;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -44,24 +44,24 @@ public class MethodParameters {
|
||||||
static final String Init0_expected =
|
static final String Init0_expected =
|
||||||
(" Foo();\n" +
|
(" Foo();\n" +
|
||||||
" descriptor: ()V\n" +
|
" descriptor: ()V\n" +
|
||||||
" flags: \n" +
|
" flags:\n" +
|
||||||
" Code:\n" +
|
" Code:\n" +
|
||||||
" stack=1, locals=1, args_size=1\n" +
|
" stack=1, locals=1, args_size=1\n" +
|
||||||
" 0: aload_0 \n" +
|
" 0: aload_0\n" +
|
||||||
" 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" +
|
" 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" +
|
||||||
" 4: return \n" +
|
" 4: return\n" +
|
||||||
" LineNumberTable:\n" +
|
" LineNumberTable:\n" +
|
||||||
" line 2: 0").replaceAll(" +", " ");
|
" line 2: 0").replaceAll(" +", " ");
|
||||||
|
|
||||||
static final String Init1_expected =
|
static final String Init1_expected =
|
||||||
(" Foo(int);\n" +
|
(" Foo(int);\n" +
|
||||||
" descriptor: (I)V\n" +
|
" descriptor: (I)V\n" +
|
||||||
" flags: \n" +
|
" flags:\n" +
|
||||||
" Code:\n" +
|
" Code:\n" +
|
||||||
" stack=1, locals=2, args_size=2\n" +
|
" stack=1, locals=2, args_size=2\n" +
|
||||||
" 0: aload_0 \n" +
|
" 0: aload_0\n" +
|
||||||
" 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" +
|
" 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" +
|
||||||
" 4: return \n" +
|
" 4: return\n" +
|
||||||
" LineNumberTable:\n" +
|
" LineNumberTable:\n" +
|
||||||
" line 3: 0\n" +
|
" line 3: 0\n" +
|
||||||
" MethodParameters:\n" +
|
" MethodParameters:\n" +
|
||||||
|
@ -71,25 +71,25 @@ public class MethodParameters {
|
||||||
static final String foo0_expected =
|
static final String foo0_expected =
|
||||||
(" void foo0();\n" +
|
(" void foo0();\n" +
|
||||||
" descriptor: ()V\n" +
|
" descriptor: ()V\n" +
|
||||||
" flags: \n" +
|
" flags:\n" +
|
||||||
" Code:\n" +
|
" Code:\n" +
|
||||||
" stack=0, locals=1, args_size=1\n" +
|
" stack=0, locals=1, args_size=1\n" +
|
||||||
" 0: return \n" +
|
" 0: return\n" +
|
||||||
" LineNumberTable:\n" +
|
" LineNumberTable:\n" +
|
||||||
" line 4: 0").replaceAll(" +", " ");
|
" line 4: 0").replaceAll(" +", " ");
|
||||||
|
|
||||||
static final String foo2_expected =
|
static final String foo2_expected =
|
||||||
(" void foo2(int, int);\n" +
|
(" void foo2(int, int);\n" +
|
||||||
" descriptor: (II)V\n" +
|
" descriptor: (II)V\n" +
|
||||||
" flags: \n" +
|
" flags:\n" +
|
||||||
" Code:\n" +
|
" Code:\n" +
|
||||||
" stack=0, locals=3, args_size=3\n" +
|
" stack=0, locals=3, args_size=3\n" +
|
||||||
" 0: return \n" +
|
" 0: return\n" +
|
||||||
" LineNumberTable:\n" +
|
" LineNumberTable:\n" +
|
||||||
" line 5: 0\n" +
|
" line 5: 0\n" +
|
||||||
" MethodParameters:\n" +
|
" MethodParameters:\n" +
|
||||||
" Name Flags\n" +
|
" Name Flags\n" +
|
||||||
" j \n" +
|
" j\n" +
|
||||||
" k").replaceAll(" +", " ");
|
" k").replaceAll(" +", " ");
|
||||||
|
|
||||||
static final File classesdir = new File("methodparameters");
|
static final File classesdir = new File("methodparameters");
|
||||||
|
|
93
langtools/test/tools/javap/WhitespaceTest.java
Normal file
93
langtools/test/tools/javap/WhitespaceTest.java
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8033581 8033798 8033726
|
||||||
|
* @summary Check whitespace in generated output
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class WhitespaceTest {
|
||||||
|
public static void main(String... args) throws Exception {
|
||||||
|
new WhitespaceTest().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void run() throws Exception {
|
||||||
|
test("-v", "java.lang.String");
|
||||||
|
test("-XDtab:1", "-v", "java.lang.String");
|
||||||
|
|
||||||
|
String testClasses = System.getProperty("test.classes");
|
||||||
|
for (int i = 10; i < 40; i++)
|
||||||
|
test("-XDtab:" + i, "-v", "-classpath", testClasses, "WhitespaceTest$HelloWorld");
|
||||||
|
|
||||||
|
if (errors > 0)
|
||||||
|
throw new Exception(errors + " errors found");
|
||||||
|
}
|
||||||
|
|
||||||
|
void test(String... args) throws Exception {
|
||||||
|
// need to avoid "//" appearing as a constant in the constant pool
|
||||||
|
String slash = "/";
|
||||||
|
String doubleSlash = slash + slash;
|
||||||
|
System.out.println("test: " + Arrays.asList(args));
|
||||||
|
String out = javap(args);
|
||||||
|
for (String line: out.split("[\r\n]+")) {
|
||||||
|
if (line.endsWith(" "))
|
||||||
|
error("line has trailing whitespace: " + line);
|
||||||
|
int comment = line.indexOf(doubleSlash);
|
||||||
|
if (comment > 0 && line.charAt(comment - 1) != ' ')
|
||||||
|
error("no space before comment: " + line);
|
||||||
|
if (line.matches(" +}"))
|
||||||
|
error("bad indentation: " + line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String javap(String... args) throws Exception {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter out = new PrintWriter(sw);
|
||||||
|
int rc = com.sun.tools.javap.Main.run(args, out);
|
||||||
|
out.close();
|
||||||
|
System.out.println(sw.toString());
|
||||||
|
if (rc < 0)
|
||||||
|
throw new Exception("javap exited, rc=" + rc);
|
||||||
|
return sw.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(String msg) {
|
||||||
|
System.out.println("Error: " + msg);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int errors;
|
||||||
|
|
||||||
|
// small class to test repeatedly with different tab values
|
||||||
|
static class HelloWorld {
|
||||||
|
public static void main(String... args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue