def link(ast, env): '''Actually sets the definition for an ASTType node''' if ast is None or ast.is_primitive: # Don't need to link primitive types. return definition = env.lookup_type(ast.name) if definition is None: raise TypeLinkerError('Type name {0} not found'.format(ast.name)) # We have to make sure no prefix of this name is valid in this context. for p in utils.prefixes(ast.name): if env.lookup_type(p) is not None: raise TypeLinkerError('Prefix {0} of name {1} found'.format( p, ast.name)) ast.definition = definition
def check_package_names(self): # Check that no prefix of a fully qualified type resolves to a type. for name in self.names: # We must do lookups in the fully qualified type's file's environment to # avoid collisions with short canonical names. type_ = self.lookup_type(name) type_env = type_.environment prefixes = utils.prefixes(name) for prefix in prefixes: # We avoid a collision with the fully qualified type here and # java.lang.* types. We do not need to worry about this case because # if a short name was in the environment it would error out from a # collision. if prefix.find('.') == -1: continue t = type_env.lookup_type(prefix) if t and t != type_: raise CanonicalEnvironmentError( 'Prefix {0} of {1} also resolves to a type'.format(prefix, name))