Search in sources :

Example 1 with CodeTypeMirror

use of com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror in project graal by oracle.

the class DSLExpressionResolver method visitVariable.

public void visitVariable(Variable variable) {
    List<VariableElement> lookupVariables;
    DSLExpression receiver = variable.getReceiver();
    if (variable.getName().equals("null")) {
        variable.setResolvedVariable(new CodeVariableElement(new CodeTypeMirror(TypeKind.NULL), "null"));
    } else {
        if (receiver == null) {
            lookupVariables = this.variables;
        } else {
            TypeMirror type = receiver.getResolvedType();
            if (type.getKind() == TypeKind.DECLARED) {
                // ensure ECJ has the type loaded
                type = context.reloadType(type);
                lookupVariables = new ArrayList<>();
                variablesIn(lookupVariables, context.getEnvironment().getElementUtils().getAllMembers((TypeElement) ((DeclaredType) type).asElement()), true);
            } else if (type.getKind() == TypeKind.ARRAY) {
                lookupVariables = Arrays.<VariableElement>asList(new CodeVariableElement(context.getType(int.class), "length"));
            } else {
                lookupVariables = Collections.emptyList();
            }
        }
        for (VariableElement variableElement : lookupVariables) {
            if (variableElement.getSimpleName().toString().equals(variable.getName())) {
                variable.setResolvedVariable(variableElement);
                break;
            }
        }
    }
    if (variable.getResolvedVariable() == null) {
        throw new InvalidExpressionException(String.format("%s cannot be resolved.", variable.getName()));
    }
}
Also used : CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) VariableElement(javax.lang.model.element.VariableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)

Aggregations

CodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1