public Type asType(boolean nullable, com.google.dart.compiler.type.Type type) { switch (type.getKind()) { case VOID: return CoreTypeRepository.VOID_TYPE; case DYNAMIC: return nullable ? CoreTypeRepository.DYNAMIC_TYPE : CoreTypeRepository.DYNAMIC_NON_NULL_TYPE; case VARIABLE: // return typeRepository.findType(nullable, (ClassElement) // type.getElement()); if (!(type.getElement() instanceof ClassElement)) { return DYNAMIC_NON_NULL_TYPE; } case INTERFACE: return typeRepository.findType(nullable, (ClassElement) type.getElement()); case FUNCTION: return asFunctionType(nullable, (com.google.dart.compiler.type.FunctionType) type); case FUNCTION_ALIAS: return asFunctionType(nullable, ((FunctionAliasType) type).getElement().getFunctionType()); case NONE: default: throw new AssertionError("asType: " + type.getKind() + " must be implemented"); } }
/** @return js The expression used to lookup the RTT for the given type. */ private JsExpression buildTypeLookupExpression( Type type, List<? extends Type> list, JsExpression contextTypeArgs) { switch (TypeKind.of(type)) { case INTERFACE: InterfaceType interfaceType = (InterfaceType) type; JsInvocation callLookup = call(null, getRTTLookupMethodName(interfaceType.getElement())); if (hasTypeParameters(interfaceType.getElement()) && !interfaceType.hasDynamicTypeArgs()) { JsArrayLiteral typeArgs = new JsArrayLiteral(); for (Type arg : interfaceType.getArguments()) { typeArgs.getExpressions().add(buildTypeLookupExpression(arg, list, contextTypeArgs)); } callLookup.getArguments().add(typeArgs); } return callLookup; case FUNCTION_ALIAS: // TODO(johnlenz): implement this return newQualifiedNameRef("RTT.placeholderType"); case VARIABLE: TypeVariable var = (TypeVariable) type; JsProgram program = translationContext.getProgram(); int varIndex = 0; for (Type t : list) { if (t.equals(type)) { return call( null, newQualifiedNameRef("RTT.getTypeArg"), Cloner.clone(contextTypeArgs), program.getNumberLiteral(varIndex)); } varIndex++; } throw new AssertionError("unresolved type variable:" + var); default: throw new AssertionError("unexpected type kind:" + type.getKind()); } }