Search in sources :

Example 1 with TruffleInstrument

use of com.oracle.truffle.api.instrumentation.TruffleInstrument in project graal by oracle.

the class DebuggerExampleTest method setupDebugger.

@Before
public void setupDebugger() throws IOException {
    // BEGIN: DebuggerExampleTest
    Instrument instrument = engine.getInstruments().get(DebuggerExample.ID);
    assert !isCreated(instrument) : "Not enabled yet";
    debugger = instrument.lookup(DebuggerController.class);
    assert isCreated(instrument) : "Got enabled";
    assert debugger != null : "We can control the debugger";
    // END: DebuggerExampleTest
    assertTrue("Enabled by requesting registered services class", isCreated(instrument));
    assertNotNull("Debugger interface found", debugger);
    DebuggerExample itself = instrument.lookup(DebuggerExample.class);
    assertNull("Debugger instrument itself isn't found", itself);
    TruffleInstrument instr = instrument.lookup(TruffleInstrument.class);
    assertNull("Instrument itself isn't found", instr);
    // ensure debugger gets loaded
    assertEvalOut("", "");
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Instrument(org.graalvm.polyglot.Instrument) TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) Before(org.junit.Before)

Example 2 with TruffleInstrument

use of com.oracle.truffle.api.instrumentation.TruffleInstrument in project graal by oracle.

the class InstrumentRegistrationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        generateFile(registrations);
        registrations.clear();
        return true;
    }
    for (Element e : roundEnv.getElementsAnnotatedWith(Registration.class)) {
        Registration annotation = e.getAnnotation(Registration.class);
        if (annotation != null && e.getKind() == ElementKind.CLASS) {
            if (!e.getModifiers().contains(Modifier.PUBLIC)) {
                emitError("Registered instrument class must be public", e);
                continue;
            }
            if (e.getEnclosingElement().getKind() != ElementKind.PACKAGE && !e.getModifiers().contains(Modifier.STATIC)) {
                emitError("Registered instrument inner-class must be static", e);
                continue;
            }
            TypeMirror truffleLang = processingEnv.getTypeUtils().erasure(processingEnv.getElementUtils().getTypeElement(TruffleInstrument.class.getName()).asType());
            if (!processingEnv.getTypeUtils().isAssignable(e.asType(), truffleLang)) {
                emitError("Registered instrument class must subclass TruffleInstrument", e);
                continue;
            }
            assertNoErrorExpected(e);
            registrations.add((TypeElement) e);
        }
    }
    return true;
}
Also used : TruffleInstrument(com.oracle.truffle.api.instrumentation.TruffleInstrument) TypeMirror(javax.lang.model.type.TypeMirror) Registration(com.oracle.truffle.api.instrumentation.TruffleInstrument.Registration) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element)

Aggregations

TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)2 Registration (com.oracle.truffle.api.instrumentation.TruffleInstrument.Registration)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Instrument (org.graalvm.polyglot.Instrument)1 Before (org.junit.Before)1