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()));
}
}
Aggregations