Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/TruffleProcessorTest.java @ 21420:fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Tue, 19 May 2015 12:30:51 +0200 |
parents | |
children | 24d12404e70a |
rev | line source |
---|---|
21420
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * questions. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 */ |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test.processor; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.dsl.processor.verify.VerifyTruffleProcessor; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 import java.util.Locale; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 import java.util.ServiceLoader; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
28 import javax.annotation.processing.Processor; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
29 import javax.tools.Diagnostic; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import javax.tools.JavaFileObject; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import static org.junit.Assert.*; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 import org.junit.Test; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
33 |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
34 /** |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 * Verify errors emitted by the processor. |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
36 * |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 * @author Jaroslav Tulach |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 */ |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 public class TruffleProcessorTest { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 @Test |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 public void childCannotBeFinal() throws Exception { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 // @formatter:off |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 String code = "package x.y.z;\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 "import com.oracle.truffle.api.nodes.Node;\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
45 "abstract class MyNode extends Node {\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
46 " @Child final MyNode first;\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
47 " MyNode(MyNode n) {\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
48 " this.first = n;\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
49 " };\n" + |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
50 "}\n"; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
51 // @formatter:on |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 Compile c = Compile.create(VerifyTruffleProcessor.class, code); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 c.assertErrors(); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
55 boolean ok = false; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
56 StringBuilder msgs = new StringBuilder(); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
57 for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
58 String msg = e.getMessage(Locale.ENGLISH); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
59 if (msg.contains("cannot be final")) { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 ok = true; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
61 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 msgs.append("\n").append(msg); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
63 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
64 if (!ok) { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
65 fail("Should contain warning about final:" + msgs); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
66 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
68 |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
69 @Test |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
70 public void workAroundCannonicalDependency() throws Exception { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 Class<?> myProc = VerifyTruffleProcessor.class; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 assertNotNull(myProc); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 StringBuilder sb = new StringBuilder(); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
74 sb.append("Cannot find ").append(myProc); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
75 for (Processor load : ServiceLoader.load(Processor.class)) { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
76 sb.append("Found ").append(load); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 if (myProc.isInstance(load)) { |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
78 return; |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
79 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
80 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 fail(sb.toString()); |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 } |
fb17e716b03c
The annotation processor should verify proper use of @Child annotation during compilation time and prevent usage of final.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 } |