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