Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/processor/LanguageRegistrationTest.java @ 21481:bb51b9a142b3
Enforcing public, one parameter constructor for each TruffleLanguage by annotation processor and required call to super.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 25 May 2015 12:26:53 +0200 |
parents | |
children | f5b49d881909 b1530a6cce8c |
comparison
equal
deleted
inserted
replaced
21480:c2b006c5e15f | 21481:bb51b9a142b3 |
---|---|
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.api.TruffleLanguage; | |
26 import com.oracle.truffle.api.dsl.ExpectError; | |
27 import com.oracle.truffle.api.source.Source; | |
28 import java.io.IOException; | |
29 | |
30 public class LanguageRegistrationTest { | |
31 | |
32 @ExpectError("Registered language class must be public") | |
33 @TruffleLanguage.Registration(name = "myLang", mimeType = "text/x-my") | |
34 private static final class MyLang { | |
35 } | |
36 | |
37 @ExpectError("Registered language inner-class must be static") | |
38 @TruffleLanguage.Registration(name = "myLangNonStatic", mimeType = "text/x-my") | |
39 public final class MyLangNonStatic { | |
40 } | |
41 | |
42 @ExpectError("Registered language class must subclass TruffleLanguage") | |
43 @TruffleLanguage.Registration(name = "myLang", mimeType = "text/x-my") | |
44 public static final class MyLangNoSubclass { | |
45 } | |
46 | |
47 @ExpectError("Language must have a public constructor accepting TruffleLanguage.Env as parameter") | |
48 @TruffleLanguage.Registration(name = "myLangNoCnstr", mimeType = "text/x-my") | |
49 public static final class MyLangWrongConstr extends TruffleLanguage { | |
50 private MyLangWrongConstr() { | |
51 super(null); | |
52 } | |
53 | |
54 @Override | |
55 protected Object eval(Source code) throws IOException { | |
56 return null; | |
57 } | |
58 | |
59 @Override | |
60 protected Object findExportedSymbol(String globalName) { | |
61 return null; | |
62 } | |
63 | |
64 @Override | |
65 protected Object getLanguageGlobal() { | |
66 return null; | |
67 } | |
68 | |
69 @Override | |
70 protected boolean isObjectOfLanguage(Object object) { | |
71 return false; | |
72 } | |
73 } | |
74 | |
75 @ExpectError("Language must have a public constructor accepting TruffleLanguage.Env as parameter") | |
76 @TruffleLanguage.Registration(name = "myLangNoCnstr", mimeType = "text/x-my") | |
77 public static final class MyLangNoConstr extends TruffleLanguage { | |
78 public MyLangNoConstr() { | |
79 super(null); | |
80 } | |
81 | |
82 @Override | |
83 protected Object eval(Source code) throws IOException { | |
84 return null; | |
85 } | |
86 | |
87 @Override | |
88 protected Object findExportedSymbol(String globalName) { | |
89 return null; | |
90 } | |
91 | |
92 @Override | |
93 protected Object getLanguageGlobal() { | |
94 return null; | |
95 } | |
96 | |
97 @Override | |
98 protected boolean isObjectOfLanguage(Object object) { | |
99 return false; | |
100 } | |
101 } | |
102 | |
103 @TruffleLanguage.Registration(name = "myLangGood", mimeType = "text/x-my") | |
104 public static final class MyLangGood extends TruffleLanguage { | |
105 public MyLangGood(TruffleLanguage.Env env) { | |
106 super(env); | |
107 } | |
108 | |
109 @Override | |
110 protected Object eval(Source code) throws IOException { | |
111 return null; | |
112 } | |
113 | |
114 @Override | |
115 protected Object findExportedSymbol(String globalName) { | |
116 return null; | |
117 } | |
118 | |
119 @Override | |
120 protected Object getLanguageGlobal() { | |
121 return null; | |
122 } | |
123 | |
124 @Override | |
125 protected boolean isObjectOfLanguage(Object object) { | |
126 return false; | |
127 } | |
128 } | |
129 } |