Search in sources :

Example 1 with Message

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");
}
Also used : Message(com.oracle.truffle.api.interop.Message) JavaFileObject(javax.tools.JavaFileObject)

Example 2 with Message

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());
    }
}
Also used : Field(java.lang.reflect.Field) Message(com.oracle.truffle.api.interop.Message) Test(org.junit.Test)

Example 3 with Message

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);
}
Also used : Message(com.oracle.truffle.api.interop.Message) Test(org.junit.Test)

Example 4 with Message

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;
}
Also used : Message(com.oracle.truffle.api.interop.Message)

Example 5 with 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());
    }
}
Also used : Message(com.oracle.truffle.api.interop.Message) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Message (com.oracle.truffle.api.interop.Message)5 Test (org.junit.Test)3 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 JavaFileObject (javax.tools.JavaFileObject)1