1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2014, 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. |
7 * published by the Free Software Foundation. |
44 |
44 |
45 void run() throws Exception { |
45 void run() throws Exception { |
46 File testSrc = new File(System.getProperty("test.src")); |
46 File testSrc = new File(System.getProperty("test.src")); |
47 File thisFile = new File(testSrc, getClass().getName() + ".java"); |
47 File thisFile = new File(testSrc, getClass().getName() + ".java"); |
48 JavacTool tool = JavacTool.create(); |
48 JavacTool tool = JavacTool.create(); |
49 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
49 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
50 JavacTask task = tool.getTask(null, fm, null, null, null, |
50 JavacTask task = tool.getTask(null, fm, null, null, null, |
51 fm.getJavaFileObjects(thisFile)); |
51 fm.getJavaFileObjects(thisFile)); |
52 Iterable<? extends CompilationUnitTree> trees = task.parse(); |
52 Iterable<? extends CompilationUnitTree> trees = task.parse(); |
53 CompilationUnitTree thisTree = trees.iterator().next(); |
53 CompilationUnitTree thisTree = trees.iterator().next(); |
54 |
54 |
55 { // test default |
55 { // test default |
56 String thisSrc = Pretty.toSimpleString((JCTree) thisTree); |
56 String thisSrc = Pretty.toSimpleString((JCTree) thisTree); |
57 System.err.println(thisSrc); |
57 System.err.println(thisSrc); |
58 String expect = "import jav[...]} } }"; |
58 String expect = "import jav[...]} } }"; |
59 if (!thisSrc.equals(expect)) { |
59 if (!thisSrc.equals(expect)) { |
60 throw new Exception("unexpected result"); |
60 throw new Exception("unexpected result"); |
|
61 } |
61 } |
62 } |
62 } |
|
63 |
63 |
64 { // test explicit length |
64 { // test explicit length |
65 String thisSrc = Pretty.toSimpleString((JCTree) thisTree, 32); |
65 String thisSrc = Pretty.toSimpleString((JCTree) thisTree, 32); |
66 System.err.println(thisSrc); |
66 System.err.println(thisSrc); |
67 String expect = "import java.io.Fil[...]; } } } }"; |
67 String expect = "import java.io.Fil[...]} } } } }"; |
68 if (!thisSrc.equals(expect)) { |
68 if (!thisSrc.equals(expect)) { |
69 throw new Exception("unexpected result"); |
69 throw new Exception("unexpected result"); |
|
70 } |
70 } |
71 } |
71 } |
72 } |
72 } |
73 } |
73 } |
74 } |