use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class NodeFactoryFactory method createCreateGetNodeSignatures.
private CodeExecutableElement createCreateGetNodeSignatures() {
TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(List.class)));
CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getNodeSignatures");
CodeTreeBuilder builder = method.createBuilder();
builder.startReturn();
builder.startGroup();
builder.startStaticCall(context.getType(Arrays.class), "asList");
List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType());
for (ExecutableElement constructor : constructors) {
builder.startGroup();
builder.startStaticCall(context.getType(Arrays.class), "asList");
for (VariableElement var : constructor.getParameters()) {
builder.typeLiteral(var.asType());
}
builder.end();
builder.end();
}
builder.end();
builder.end();
builder.end();
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class NodeFactoryFactory method createCreateGetNodeClass.
private CodeExecutableElement createCreateGetNodeClass() {
TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(Class.class)), node.getNodeType());
CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getNodeClass");
method.createBuilder().startReturn().typeLiteral(node.getNodeType()).end();
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class NodeFactoryFactory method createGetInstanceMethod.
private ExecutableElement createGetInstanceMethod(Modifier visibility) {
TypeElement nodeFactoryType = ElementUtils.fromTypeMirror(context.getType(NodeFactory.class));
TypeMirror returnType = ElementUtils.getDeclaredType(nodeFactoryType, node.getNodeType());
CodeExecutableElement method = new CodeExecutableElement(modifiers(), returnType, "getInstance");
if (visibility != null) {
method.getModifiers().add(visibility);
}
method.getModifiers().add(Modifier.STATIC);
String varName = instanceVarName(node);
CodeTreeBuilder builder = method.createBuilder();
builder.startIf();
builder.string(varName).string(" == null");
builder.end().startBlock();
builder.startStatement();
builder.string(varName);
builder.string(" = ");
builder.startNew(factoryClassName(node)).end();
builder.end();
builder.end();
builder.startReturn().string(varName).end();
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class TypeSystemCodeGenerator method createExpectMethod.
static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) {
TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal);
TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal);
if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) {
return null;
}
CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType));
method.setVisibility(visibility);
method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE));
method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException());
CodeTreeBuilder body = method.createBuilder();
body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock();
body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end();
body.end();
body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end();
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class NodeParser method importPublicStaticMembers.
@SuppressWarnings("unchecked")
private List<Element> importPublicStaticMembers(TypeElement importGuardClass, boolean includeConstructors) {
// hack to reload type is necessary for incremental compiling in eclipse.
// otherwise methods inside of import guard types are just not found.
TypeElement typeElement = ElementUtils.fromTypeMirror(context.reloadType(importGuardClass.asType()));
List<Element> members = new ArrayList<>();
List<Element> typeElementMembers = (List<Element>) processingEnv.getElementUtils().getAllMembers(typeElement);
// add default constructor
if (typeElement.getModifiers().contains(Modifier.PUBLIC) && ElementFilter.constructorsIn(typeElementMembers).isEmpty()) {
typeElementMembers = new ArrayList<>(typeElementMembers);
typeElementMembers.add(new CodeExecutableElement(ElementUtils.modifiers(Modifier.PUBLIC), typeElement.asType(), null));
}
for (Element importElement : typeElementMembers) {
if (!importElement.getModifiers().contains(Modifier.PUBLIC)) {
continue;
}
if (includeConstructors && importElement.getKind() == ElementKind.CONSTRUCTOR) {
members.add(importElement);
}
if (!importElement.getModifiers().contains(Modifier.STATIC)) {
continue;
}
ElementKind kind = importElement.getKind();
if (kind.isField() || kind == ElementKind.METHOD) {
members.add(importElement);
}
}
/*
* Sort elements by enclosing type to ensure that duplicate static methods are used from the
* most concrete subtype.
*/
Collections.sort(members, new Comparator<Element>() {
Map<TypeMirror, Set<String>> cachedQualifiedNames = new HashMap<>();
public int compare(Element o1, Element o2) {
TypeMirror e1 = o1.getEnclosingElement() != null ? o1.getEnclosingElement().asType() : null;
TypeMirror e2 = o2.getEnclosingElement() != null ? o2.getEnclosingElement().asType() : null;
Set<String> e1SuperTypes = getCachedSuperTypes(e1);
Set<String> e2SuperTypes = getCachedSuperTypes(e2);
return ElementUtils.compareByTypeHierarchy(e1, e1SuperTypes, e2, e2SuperTypes);
}
private Set<String> getCachedSuperTypes(TypeMirror e) {
if (e == null) {
return Collections.emptySet();
}
Set<String> superTypes = cachedQualifiedNames.get(e);
if (superTypes == null) {
superTypes = new HashSet<>(ElementUtils.getQualifiedSuperTypeNames(ElementUtils.fromTypeMirror(e)));
cachedQualifiedNames.put(e, superTypes);
}
return superTypes;
}
});
return members;
}
Aggregations