export function getTypeDeclaration()

in packages/codemodel.go/src/type.ts [298:334]


export function getTypeDeclaration(type: PossibleType, pkgName?: string): string {
  if (isPrimitiveType(type)) {
    return type.typeName;
  } else if (isQualifiedType(type)) {
    let pkg = type.packageName;
    const pathChar = pkg.lastIndexOf('/');
    if (pathChar) {
      pkg = pkg.substring(pathChar+1);
    }
    return pkg + '.' + type.exportName;
  } else if (isConstantType(type) || isInterfaceType(type) || isModelType(type) || isPolymorphicType(type)) {
    if (pkgName) {
      return `${pkgName}.${type.name}`;
    }
    return type.name;
  } else if (isBytesType(type)) {
    return '[]byte';
  } else if (isLiteralValue(type)) {
    return getTypeDeclaration(type.type, pkgName);
  } else if (isMapType(type)) {
    let pointer = '*';
    if (type.valueTypeByValue) {
      pointer = '';
    }
    return `map[string]${pointer}` + getTypeDeclaration(type.valueType, pkgName);
  } else if (isSliceType(type)) {
    let pointer = '*';
    if (type.elementTypeByValue) {
      pointer = '';
    }
    return `[]${pointer}` + getTypeDeclaration(type.elementType, pkgName);
  } else if (isTimeType(type)) {
    return 'time.Time';
  } else {
    throw new CodeModelError(`unhandled type ${typeof(type)}`);
  }
}