Recursively builds a type where all references have been resolved
961805
function resolveType(x) {
	if (x instanceof TReference) {
		return resolveReference(x)
	} else if (x instanceof TMember) {
		return resolveReference(x)
	} else if (x instanceof TObject) {
        if (x.qname)
            return new TQualifiedReference(x.qname) // can happen if a qname was synthesized by resolveReference
		return resolveObject(x);
	} else if (x instanceof TQualifiedReference) {
		return x;
	} else if (x instanceof TTypeParam) {
		return new TTypeParam(x.name, x.constraint && resolveType(x.constraint))
	} else if (x instanceof TGeneric) {
		return new TGeneric(resolveType(x.base), x.args.map(resolveType))
	} else if (x instanceof TString) {
		return x;
	} else if (x instanceof TBuiltin) {
		return x;
	} else if (x instanceof TTypeQuery) {
        return resolveReference(x);
    } else if (x instanceof TEnum) {
        return x;
    }
	var msg;
	if (x.constructor.name === 'Object')
		msg = util.inspect(x)
	else
		msg = '' + x;
	throw new TypeError("Cannot canonicalize reference to " + (x && x.constructor.name + ': ' + msg))
}
1346619
function buildType(t, typeClassification) {
            let typeDef;
            switch (typeClassification) {
                case 'primative':
                    typeDef = {
                        interface: t,
                        builder: t
                    };
                    break;
                case 'message':
                    typeDef = {
                        interface: '$Subtype<' + t + 'Interface>',
                        builder: t + 'Builder'
                    };
                    break;
                case 'enum':
                    typeDef = {
                        interface: t + 'Values',
                        builder: t + 'Values'
                    };
                    break;
                default:
                    throw new Error('Unhandled classification case :: ' + typeClassification);
            }
            if (repeated) {
                for (const key in typeDef) {
                    typeDef[key] = 'Array<' + typeDef[key] + '>';
                }
            }
            return typeDef;
        }
732578
function resolveRef( ref, lookupPath ) {
      const parts = ref.split( ':', 2 );
      const path = parts.pop();
      const scheme = parts[ 0 ] || 'default';

      return lookup[ scheme ]( path, lookupPath );
   }
265544
def compile(self):
        '''
        
        '''
        self._prune()
        self._resolve_duplicates()
        self._fix_shapes()
        self._infer_all_types()
        self._check_structure()
1273710
function _determineActualTypes(
    env,            // :: Array Type
    seen,           // :: Array Object
    values          // :: Array Any
  ) {
    var expandUnknown4 = expandUnknown (env);

    function refine(types, value) {
      var seen$;
      if (typeof value === 'object' && value != null ||
          typeof value === 'function') {
        //  Abort if a circular reference is encountered; add the current
        //  object to the array of seen objects otherwise.
        if (seen.indexOf (value) >= 0) return [];
        seen$ = Z.concat (seen, [value]);
      } else {
        seen$ = seen;
      }
      var expandUnknown2 = expandUnknown4 (seen$) (value);
      return Z.chain (function(t) {
        return (
          (t.validate (env) (value)).isLeft ?
            [] :
          t.type === UNARY ?
            Z.map (fromUnaryType (t),
                   expandUnknown2 (t.extractors.$1) (t.types.$1)) :
          t.type === BINARY ?
            Z.lift2 (fromBinaryType (t),
                     expandUnknown2 (t.extractors.$1) (t.types.$1),
                     expandUnknown2 (t.extractors.$2) (t.types.$2)) :
          // else
            [t]
        );
      }, types);
    }

    return isEmpty (values) ?
      [Unknown] :
      or (Z.reduce (refine, env, values), [Inconsistent]);
  }
964108
def all_derived (type):
    
    assert isinstance(type, basestring)
    result = [type]
    for d in __types [type]['derived']:
        result.extend (all_derived (d))

    return result
1171836
def recursive_derived(self):
        """"""
        if self._recursive_derived is None:
            to_go = self.derived[:]
            all_derived = []
            while to_go:
                derive = to_go.pop()
                if derive not in all_derived:
                    all_derived.append(derive)
                    to_go.extend(derive.related_class.derived)
            self._recursive_derived = all_derived
        return self._recursive_derived
412556
String resolveTypeName(TypeMirror type) {
        Object reference = resolveTypeReference(type);
        if (reference instanceof Class) {
            return ((Class) reference).getName();
        }
        return reference.toString();
    }
688429
function builtInReferenceAction(referenceNames, skipCache = false) {
    return () => {
        if (!referenceNames) {
            return undefined;
        }
        return Promise.all(loadManyReferenceList(referenceNames, skipCache))
            .then(function successReferenceLoading(data) {
                //Rebuilt a constructed information from the map.
                const reconstructedData = data.reduce((acc, item) => { acc[item.name] = item.dataList; return acc; }, {})
                dispatcher.handleViewAction({ data: reconstructedData, type: 'update', subject: 'reference' });
            }, function errorReferenceLoading(err) {
                dispatcher.handleViewAction({ data: err, type: 'error' });
            });
    };
}
727037
def _initialize_references(model_class, name, bases, attrs):
    """"""
    model_class._references = {}
    h = {}
    deferred = []
    for k, v in attrs.iteritems():
        if isinstance(v, ReferenceField):
            model_class._references[k] = v
            v.name = v.name or k
            att = Attribute(name=v.attname)
            h[v.attname] = att
            setattr(model_class, v.attname, att)
            refd = _initialize_referenced(model_class, v)
            if refd:
                deferred.append(refd)
    attrs.update(h)
    return deferred
23817
function toTypeRefName(Type) {
    var ref = toTypeRef(Type);
    return ref instanceof Function ? ref.name : ref;
  }
1250910
function(fullSchema, schema, seenObjects, path, options) {
  // Top level reference, dereference it
  if(schema['$ref']) {
    // Dereference
    var dereference = deref(fullSchema, '', schema["$ref"], seenObjects, options);
    // Delete the tag
    delete(schema['$ref']);
    // Merge the dereferenced value
    for(var name in dereference) {
      schema[name] = dereference[name];
    }
  }

  for(var name in schema) {
    var value = schema[name];
    path.push(name);

    if(value instanceof Object) {
      // Extract the path
      if(value["$ref"]) {
        // Get the reference
        var reference = value["$ref"];
        // Unroll the reference
        var dereference = deref(fullSchema, name, reference, seenObjects, path, options);
        // Add the dereferenced value
        schema[name] = dereference;
      } else {
        extractReferences(fullSchema, value, seenObjects, path, options);
      }
    }

    path.pop();
  }
}
1045184
def schema_resolve_refs(schema, ref_resolver=None, root=None):
    
    # FIXME more stable implementation that only attempts to resolve {"$ref"} objects where they are allowed.
    if isinstance(schema, dict):
        if len(schema) == 1 and "$ref" in schema and isinstance(schema["$ref"], six.string_types):
            reference = schema["$ref"]
            if reference.startswith("#"):
                # TODO should also resolve any paths within the reference, which would need to be deferred.
                return root
            return ref_resolver(reference)

        resolved = {}
        for k, v in schema.items():
            resolved[k] = schema_resolve_refs(v,
                                              ref_resolver=ref_resolver,
                                              root=root if root is not None else resolved)
        return resolved
    if isinstance(schema, (list, tuple)):
        return [schema_resolve_refs(v, ref_resolver=ref_resolver, root=root) for v in schema]
    return schema
384576
function createTypedef(context, typeName, value) {
  if (value instanceof Reference) {
    value = value.resolve(context);
  }
  context.results[typeName] = value;
  return value;
}
1267734
def _resolve_default(data_type, listify=False):
    """"""
    if isinstance(data_type, _ATOMIC):
        # A Python's object type needs to be left as is instead of being
        # wrapped into a NumPy type.
        out = (data_type.default if isinstance(data_type, Object)
               else _get_atomic_dtype(data_type)(data_type.default))
    elif isinstance(data_type, Array):
        element_default = _resolve_default(data_type.element_type,
                                           listify=listify)
        Sequence = list if listify else tuple
        shape = ((data_type.shape,) if isinstance(data_type.shape, int)
                 else data_type.shape)
        out = element_default
        for dimension in shape:
            out = Sequence(copy.deepcopy(out) for _ in _range(dimension))
    elif isinstance(data_type, Structure):
        if listify:
            out = [_resolve_default(field.type, listify=listify)
                   for field in data_type.fields]
        else:
            field_defaults = collections.OrderedDict(
                (field.name, _resolve_default(field.type, listify=listify))
                for field in data_type.fields)
            name = ('StructureDefault_%s' % (data_type.name,)
                    if data_type.name else 'StructureDefault')
            struct = collections.namedtuple(name, field_defaults.keys())
            out = struct(**field_defaults)

    return out
1359309
def p_type_ref(self, p):
        ''
        p[0] = AstTypeRef(
            path=self.path,
            lineno=p.lineno(1),
            lexpos=p.lexpos(1),
            name=p[1],
            args=p[2],
            nullable=p[3],
            ns=None,
        )
765958
private static void populateTypeArgs(ParameterizedType type, Map<TypeVariable<?>, Type> map, boolean depthFirst) {
    if (type.getRawType() instanceof Class) {
      TypeVariable<?>[] typeVariables = ((Class<?>) type.getRawType()).getTypeParameters();
      Type[] typeArguments = type.getActualTypeArguments();

      if (type.getOwnerType() != null) {
        Type owner = type.getOwnerType();
        if (owner instanceof ParameterizedType)
          populateTypeArgs((ParameterizedType) owner, map, depthFirst);
      }

      for (int i = 0; i < typeArguments.length; i++) {
        TypeVariable<?> variable = typeVariables[i];
        Type typeArgument = typeArguments[i];

        if (typeArgument instanceof Class) {
          map.put(variable, typeArgument);
        } else if (typeArgument instanceof GenericArrayType) {
          map.put(variable, typeArgument);
        } else if (typeArgument instanceof ParameterizedType) {
          map.put(variable, typeArgument);
        } else if (typeArgument instanceof TypeVariable) {
          TypeVariable<?> typeVariableArgument = (TypeVariable<?>) typeArgument;
          if (depthFirst) {
            Type existingType = map.get(variable);
            if (existingType != null) {
              map.put(typeVariableArgument, existingType);
              continue;
            }
          }

          Type resolvedType = map.get(typeVariableArgument);
          if (resolvedType == null)
            resolvedType = resolveBound(typeVariableArgument);
          map.put(variable, resolvedType);
        }
      }
    }
  }