コード例 #1
0
  @Override
  public Void visitTypeAlias(TypeAlias node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    TypeAliasElementImpl element = new TypeAliasElementImpl(node.getName());
    if (holder.getParameters() != null) {
      element.setParameters(holder.getParameters());
    }
    element.setTypeVariables(holder.getTypeVariables());
    currentHolder.addTypeAlias(element);
    return null;
  }
コード例 #2
0
ファイル: ElementBuilder.java プロジェクト: aam/dartdev
  @Override
  public Void visitFunctionTypeAlias(FunctionTypeAlias node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    SimpleIdentifier aliasName = node.getName();
    ParameterElement[] parameters = holder.getParameters();
    TypeAliasElementImpl element = new TypeAliasElementImpl(aliasName);
    element.setParameters(parameters);
    element.setTypeVariables(holder.getTypeVariables());

    ArrayList<Type> normalParameterTypes = new ArrayList<Type>();
    ArrayList<Type> optionalParameterTypes = new ArrayList<Type>();
    LinkedHashMap<String, Type> namedParameterTypes = new LinkedHashMap<String, Type>();
    for (ParameterElement parameter : parameters) {
      switch (parameter.getParameterKind()) {
        case REQUIRED:
          normalParameterTypes.add(parameter.getType());
          break;
        case POSITIONAL:
          optionalParameterTypes.add(parameter.getType());
          break;
        case NAMED:
          namedParameterTypes.put(parameter.getName(), parameter.getType());
          break;
      }
    }
    TypeName returnType = node.getReturnType();
    FunctionTypeImpl functionType = new FunctionTypeImpl(element);
    functionType.setNormalParameterTypes(
        normalParameterTypes.toArray(new Type[normalParameterTypes.size()]));
    functionType.setOptionalParameterTypes(
        optionalParameterTypes.toArray(new Type[optionalParameterTypes.size()]));
    functionType.setNamedParameterTypes(namedParameterTypes);
    if (returnType != null) {
      functionType.setReturnType(returnType.getType());
    }
    element.setType(functionType);

    currentHolder.addTypeAlias(element);
    aliasName.setElement(element);
    return null;
  }