use of com.oracle.truffle.api.interop.Message in project graal by oracle.
the class ForeignAccessFactoryGenerator method appendFactoryAccessMessage.
private void appendFactoryAccessMessage(Writer w) throws IOException {
w.append(" @Override").append("\n");
w.append(" public CallTarget accessMessage(Message unknown) {").append("\n");
for (Object m : messageGenerators.keySet()) {
if (!InteropDSLProcessor.KNOWN_MESSAGES.contains(m)) {
String msg = m instanceof Message ? Message.toString((Message) m) : (String) m;
w.append(" if (unknown != null && unknown.getClass().getCanonicalName().equals(\"").append(msg).append("\")) {").append("\n");
w.append(" return Truffle.getRuntime().createCallTarget(").append(messageGenerators.get(m).getRootNodeFactoryInvocation()).append(");").append("\n");
w.append(" }").append("\n");
}
}
w.append(" return null;\n");
w.append(" }").append("\n");
}
use of com.oracle.truffle.api.interop.Message in project graal by oracle.
the class MessageStringTest method testFields.
@Test
public void testFields() throws Exception {
for (Field f : Message.class.getFields()) {
if (f.getType() != Message.class) {
continue;
}
if ((f.getModifiers() & Modifier.STATIC) == 0) {
continue;
}
Message msg = (Message) f.get(null);
String persistent = Message.toString(msg);
assertNotNull("Found name for " + f, persistent);
assertEquals("It is in upper case", persistent, persistent.toUpperCase(Locale.ENGLISH));
Message newMsg = Message.valueOf(persistent);
assertSame("Same for " + f, msg, newMsg);
assertEquals("Same toString()", persistent, msg.toString());
}
}
use of com.oracle.truffle.api.interop.Message in project graal by oracle.
the class MessageStringTest method specialMessagePersitance.
@Test
public void specialMessagePersitance() {
SpecialMsg msg = new SpecialMsg();
String persistent = Message.toString(msg);
Message newMsg = Message.valueOf(persistent);
assertEquals("Message reconstructed", msg, newMsg);
}
use of com.oracle.truffle.api.interop.Message in project graal by oracle.
the class ObjectProxyHandler method findMessage.
protected static Message findMessage(Method method) {
CompilerAsserts.neverPartOfCompilation();
MethodMessage mm = method.getAnnotation(MethodMessage.class);
if (mm == null) {
return null;
}
Message message = Message.valueOf(mm.message());
if (message == Message.WRITE && method.getParameterTypes().length != 1) {
throw new IllegalStateException("Method needs to have a single argument to handle WRITE message " + method);
}
return message;
}
use of com.oracle.truffle.api.interop.Message in project graal by oracle.
the class MessageStringTest method testFactoryMethods.
@Test
public void testFactoryMethods() throws Exception {
for (Method m : Message.class.getMethods()) {
if (m.getReturnType() != Message.class) {
continue;
}
if (!m.getName().startsWith("create")) {
continue;
}
if ((m.getModifiers() & Modifier.STATIC) == 0) {
continue;
}
Message msg = (Message) m.invoke(null, 0);
String persistent = Message.toString(msg);
assertNotNull("Found name for " + m, persistent);
assertEquals("It is in upper case", persistent, persistent.toUpperCase(Locale.ENGLISH));
Message newMsg = Message.valueOf(persistent);
assertEquals("Same for " + m, msg, newMsg);
assertEquals("Same toString()", persistent, msg.toString());
assertEquals("Same toString() for new one", persistent, newMsg.toString());
}
}
Aggregations