use of com.oracle.truffle.dsl.processor.java.model.CodeVariableElement in project graal by oracle.
the class InstrumentableProcessor method generateFactory.
@SuppressWarnings("deprecation")
private static CodeTypeElement generateFactory(ProcessorContext context, Element e, CodeTypeElement wrapper) {
TypeElement sourceType = (TypeElement) e;
PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(sourceType);
Set<Modifier> typeModifiers = ElementUtils.modifiers(Modifier.PUBLIC, Modifier.FINAL);
CodeTypeElement factory = new CodeTypeElement(typeModifiers, ElementKind.CLASS, pack, createWrapperClassName(sourceType));
TypeMirror factoryType = context.reloadType(context.getType(com.oracle.truffle.api.instrumentation.InstrumentableFactory.class));
factory.getImplements().add(new CodeTypeMirror.DeclaredCodeTypeMirror(ElementUtils.fromTypeMirror(factoryType), Arrays.asList(sourceType.asType())));
addGeneratedBy(context, factory, sourceType);
TypeMirror returnType = context.getType(com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode.class);
CodeExecutableElement createMethod = new CodeExecutableElement(ElementUtils.modifiers(Modifier.PUBLIC), returnType, "createWrapper");
createMethod.addParameter(new CodeVariableElement(sourceType.asType(), FIELD_DELEGATE));
createMethod.addParameter(new CodeVariableElement(context.getType(ProbeNode.class), FIELD_PROBE));
CodeTreeBuilder builder = createMethod.createBuilder();
ExecutableElement constructor = ElementFilter.constructorsIn(wrapper.getEnclosedElements()).iterator().next();
String firstParameterReference = null;
if (constructor.getParameters().size() > 2) {
TypeMirror firstParameter = constructor.getParameters().get(0).asType();
if (ElementUtils.typeEquals(firstParameter, sourceType.asType())) {
firstParameterReference = FIELD_DELEGATE;
} else if (ElementUtils.typeEquals(firstParameter, context.getType(SourceSection.class))) {
firstParameterReference = FIELD_DELEGATE + ".getSourceSection()";
}
}
builder.startReturn().startNew(wrapper.asType());
if (firstParameterReference != null) {
builder.string(firstParameterReference);
}
builder.string(FIELD_DELEGATE).string(FIELD_PROBE);
builder.end().end();
factory.add(createMethod);
return factory;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeVariableElement in project graal by oracle.
the class InstrumentableProcessor method createNodeChild.
private static CodeVariableElement createNodeChild(ProcessorContext context, TypeMirror type, String name) {
CodeVariableElement var = new CodeVariableElement(ElementUtils.modifiers(Modifier.PRIVATE), type, name);
var.addAnnotationMirror(new CodeAnnotationMirror((DeclaredType) context.getType(Child.class)));
return var;
}
Aggregations