author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 6152 | 111b884a19a7 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
6152
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
1 |
/* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
4 |
* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
8 |
* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
14 |
* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
18 |
* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
21 |
* questions. |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
22 |
*/ |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
23 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
24 |
/* |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
25 |
* @test |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
26 |
* @bug 6972327 |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
27 |
* @summary JCTree.pos incorrect for annotations without modifiers and package |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
28 |
*/ |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
29 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
30 |
import com.sun.source.tree.*; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
31 |
import com.sun.source.util.Trees; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
32 |
import com.sun.tools.javac.api.*; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
33 |
import com.sun.tools.javac.tree.*; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.tree.JCTree.*; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
35 |
import java.net.URI; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
37 |
import javax.tools.*; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
38 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
39 |
public class T6972327 { |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
40 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
42 |
final String bootPath = System.getProperty("sun.boot.class.path"); //NOI18N |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
43 |
final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
44 |
assert tool != null; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
45 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
46 |
String code = "\n@interface Test {}"; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
47 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
48 |
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
49 |
Arrays.asList("-bootclasspath", bootPath, "-Xjcov"), null, Arrays.asList(new MyFileObject(code))); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
50 |
CompilationUnitTree cut = ct.parse().iterator().next(); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
51 |
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
52 |
Trees t = Trees.instance(ct); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
53 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
54 |
long pos = t.getSourcePositions().getStartPosition(cut, clazz); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
55 |
if (pos != code.indexOf(code.trim())) |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
56 |
throw new IllegalStateException("Unexpected position=" + pos); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
57 |
} |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
58 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
59 |
static class MyFileObject extends SimpleJavaFileObject { |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
60 |
private String text; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
61 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
62 |
public MyFileObject(String text) { |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
63 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
64 |
this.text = text; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
65 |
} |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
66 |
|
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
67 |
@Override |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
68 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
69 |
return text; |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
70 |
} |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
71 |
} |
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
diff
changeset
|
72 |
} |