author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 10200 | 56cc93e7b6ef |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10200
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
1 |
/* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
4 |
* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
8 |
* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
14 |
* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
18 |
* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
21 |
* questions. |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
22 |
*/ |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
23 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
24 |
/* |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
25 |
* @test |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
26 |
* @bug 7068902 |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
27 |
* @summary verify that string folding can be enabled or disabled |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
28 |
*/ |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
29 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
30 |
import com.sun.source.tree.CompilationUnitTree; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
31 |
import com.sun.source.util.JavacTask; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
32 |
import java.io.File; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
33 |
import java.io.IOException; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
34 |
import java.net.URI; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
37 |
import java.util.List; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
38 |
import javax.tools.JavaCompiler; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
39 |
import javax.tools.JavaFileObject; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
40 |
import javax.tools.SimpleJavaFileObject; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
41 |
import javax.tools.ToolProvider; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
42 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
43 |
public class StringFoldingTest { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
44 |
final JavaCompiler tool; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
45 |
final JavaSource source; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
46 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
47 |
public StringFoldingTest() { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
48 |
tool = ToolProvider.getSystemJavaCompiler(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
49 |
source = new JavaSource(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
50 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
51 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
52 |
static class JavaSource extends SimpleJavaFileObject { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
53 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
54 |
final static String source = |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
55 |
"class C {String X=\"F\" + \"O\" + \"L\" + \"D\" + \"E\" + \"D\";}"; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
56 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
57 |
JavaSource() { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
58 |
super(URI.create("myfo:/C.java"), JavaFileObject.Kind.SOURCE); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
59 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
60 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
61 |
@Override |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
62 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
63 |
return source; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
64 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
65 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
66 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
67 |
public static void main(String... args) throws IOException { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
68 |
StringFoldingTest t = new StringFoldingTest(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
69 |
t.run(false); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
70 |
t.run(true); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
71 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
72 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
73 |
void run(boolean disableStringFolding) throws IOException { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
74 |
List<String> argsList = new ArrayList<String>(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
75 |
if (disableStringFolding) { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
76 |
argsList.add("-XDallowStringFolding=false"); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
77 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
78 |
JavacTask ct = (JavacTask)tool.getTask(null, null, null, |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
79 |
argsList, |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
80 |
null, |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
81 |
Arrays.asList(source)); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
82 |
Iterable<? extends CompilationUnitTree> trees = ct.parse(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
83 |
String text = trees.toString(); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
84 |
System.out.println(text); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
85 |
|
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
86 |
if (disableStringFolding) { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
87 |
if (text.contains("FOLDED")) { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
88 |
throw new AssertionError("Expected string folding"); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
89 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
90 |
} else { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
91 |
if (!text.contains("FOLDED")) { |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
92 |
throw new AssertionError("Expected no string folding"); |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
93 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
94 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
95 |
} |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
diff
changeset
|
96 |
} |