@Override
 public FunctionTypeImpl substitute(Type[] argumentTypes, Type[] parameterTypes) {
   if (argumentTypes.length != parameterTypes.length) {
     throw new IllegalArgumentException(
         "argumentTypes.length ("
             + argumentTypes.length
             + ") != parameterTypes.length ("
             + parameterTypes.length
             + ")");
   }
   if (argumentTypes.length == 0) {
     return this;
   }
   Element element = getElement();
   FunctionTypeImpl newType =
       (element instanceof ExecutableElement)
           ? new FunctionTypeImpl((ExecutableElement) element)
           : new FunctionTypeImpl((FunctionTypeAliasElement) element);
   newType.setReturnType(returnType.substitute(argumentTypes, parameterTypes));
   newType.setNormalParameterTypes(
       substitute(normalParameterTypes, argumentTypes, parameterTypes));
   newType.setOptionalParameterTypes(
       substitute(optionalParameterTypes, argumentTypes, parameterTypes));
   newType.namedParameterTypes = substitute(namedParameterTypes, argumentTypes, parameterTypes);
   return newType;
 }
Example #2
0
  @Override
  public Void visitClassTypeAlias(ClassTypeAlias node) {
    ElementHolder holder = new ElementHolder();
    functionTypesToFix = new ArrayList<FunctionTypeImpl>();
    visitChildren(holder, node);

    SimpleIdentifier className = node.getName();
    ClassElementImpl element = new ClassElementImpl(className);
    element.setAbstract(node.getAbstractKeyword() != null);
    element.setTypedef(true);
    TypeParameterElement[] typeParameters = holder.getTypeParameters();
    element.setTypeParameters(typeParameters);

    Type[] typeArguments = createTypeParameterTypes(typeParameters);
    InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element);
    interfaceType.setTypeArguments(typeArguments);
    element.setType(interfaceType);

    // set default constructor
    element.setConstructors(createDefaultConstructors(interfaceType));

    for (FunctionTypeImpl functionType : functionTypesToFix) {
      functionType.setTypeArguments(typeArguments);
    }
    functionTypesToFix = null;
    currentHolder.addType(element);
    className.setStaticElement(element);
    holder.validate();
    return null;
  }
 @Override
 public boolean equals(Object object) {
   if (!(object instanceof FunctionTypeImpl)) {
     return false;
   }
   FunctionTypeImpl otherType = (FunctionTypeImpl) object;
   return ObjectUtilities.equals(getElement(), otherType.getElement())
       && Arrays.equals(normalParameterTypes, otherType.normalParameterTypes)
       && Arrays.equals(optionalParameterTypes, otherType.optionalParameterTypes)
       && equals(namedParameterTypes, otherType.namedParameterTypes)
       && ObjectUtilities.equals(returnType, otherType.returnType);
 }
Example #4
0
  @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;
  }
Example #5
0
  @Override
  public Void visitFunctionTypeAlias(FunctionTypeAlias node) {
    ElementHolder holder = new ElementHolder();
    visitChildren(holder, node);

    SimpleIdentifier aliasName = node.getName();
    ParameterElement[] parameters = holder.getParameters();
    TypeParameterElement[] typeParameters = holder.getTypeParameters();
    FunctionTypeAliasElementImpl element = new FunctionTypeAliasElementImpl(aliasName);
    element.setParameters(parameters);
    element.setTypeParameters(typeParameters);

    FunctionTypeImpl type = new FunctionTypeImpl(element);
    type.setTypeArguments(createTypeParameterTypes(typeParameters));
    element.setType(type);

    currentHolder.addTypeAlias(element);
    aliasName.setStaticElement(element);
    holder.validate();
    return null;
  }