1 /* |
1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 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. |
27 * @summary IllegalStateException from Trees.getScope when called from JSR 199 |
27 * @summary IllegalStateException from Trees.getScope when called from JSR 199 |
28 */ |
28 */ |
29 |
29 |
30 import com.sun.source.tree.IdentifierTree; |
30 import com.sun.source.tree.IdentifierTree; |
31 import java.io.File; |
31 import java.io.File; |
|
32 import java.io.IOException; |
32 import java.util.Arrays; |
33 import java.util.Arrays; |
33 import java.util.Collections; |
34 import java.util.Collections; |
34 import java.util.List; |
35 import java.util.List; |
35 import java.util.Set; |
36 import java.util.Set; |
36 import javax.annotation.processing.AbstractProcessor; |
37 import javax.annotation.processing.AbstractProcessor; |
49 import javax.annotation.processing.SupportedAnnotationTypes; |
50 import javax.annotation.processing.SupportedAnnotationTypes; |
50 import javax.lang.model.SourceVersion; |
51 import javax.lang.model.SourceVersion; |
51 |
52 |
52 @SupportedAnnotationTypes("*") |
53 @SupportedAnnotationTypes("*") |
53 public class TestGetScope extends AbstractProcessor { |
54 public class TestGetScope extends AbstractProcessor { |
54 public static void main(String... args) { |
55 public static void main(String... args) throws IOException { |
55 new TestGetScope().run(); |
56 new TestGetScope().run(); |
56 } |
57 } |
57 |
58 |
58 public void run() { |
59 public void run() throws IOException { |
59 File srcDir = new File(System.getProperty("test.src")); |
60 File srcDir = new File(System.getProperty("test.src")); |
60 File thisFile = new File(srcDir, getClass().getName() + ".java"); |
61 File thisFile = new File(srcDir, getClass().getName() + ".java"); |
61 |
62 |
62 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
63 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
63 StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); |
64 try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) { |
64 |
65 |
65 List<String> opts = Arrays.asList("-proc:only", "-doe"); |
66 List<String> opts = Arrays.asList("-proc:only", "-doe"); |
66 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); |
67 Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); |
67 JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); |
68 JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); |
68 t.setProcessors(Collections.singleton(this)); |
69 t.setProcessors(Collections.singleton(this)); |
69 boolean ok = t.call(); |
70 boolean ok = t.call(); |
70 if (!ok) |
71 if (!ok) |
71 throw new Error("compilation failed"); |
72 throw new Error("compilation failed"); |
|
73 } |
72 } |
74 } |
73 |
75 |
74 @Override |
76 @Override |
75 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
77 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
76 Trees trees = Trees.instance(processingEnv); |
78 Trees trees = Trees.instance(processingEnv); |