Inheritance: IEntity, INamespace
Exemplo n.º 1
0
        public override void OnImport(Boo.Lang.Compiler.Ast.Import import)
        {
            IEntity entity = ResolveImport(import);

            //if 'import X', try 'import X from X'
            //comment out next if block if this is not wanted
            if (null == entity && null == import.AssemblyReference)
            {
                if (TryAutoAddAssemblyReference(import))
                {
                    entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
                }
            }

            if (null == entity)
            {
                Errors.Add(CompilerErrorFactory.InvalidNamespace(import));
                entity = TypeSystemServices.ErrorEntity;
            }
            else
            {
                if (!IsValidNamespace(entity))
                {
                    Errors.Add(CompilerErrorFactory.NotANamespace(import, entity.FullName));
                    entity = TypeSystemServices.ErrorEntity;
                }
                else
                {
                    string name = entity.FullName;
                    if (null != import.AssemblyReference)
                    {
                        NamespaceEntity nsInfo = entity as NamespaceEntity;
                        if (null != nsInfo)
                        {
                            entity = new AssemblyQualifiedNamespaceEntity(GetBoundAssembly(import.AssemblyReference), nsInfo);
                        }
                    }

                    if (null != import.Alias)
                    {
                        entity = new AliasedNamespace(import.Alias.Name, entity);
                        import.Alias.Entity = entity;
                        name = entity.Name; //use alias name instead of namespace name
                    }

                    //only add unique namespaces
                    Import cachedImport = nameSpaces[name] as Import;
                    if (cachedImport == null)
                    {
                        nameSpaces[name] = import;
                    }
                    else
                    {
                        //ignore for partial classes in separate files
                        if (cachedImport.LexicalInfo.FileName == import.LexicalInfo.FileName)
                        {
                            Warnings.Add(
                                CompilerWarningFactory.DuplicateNamespace(import, import.Namespace));
                        }
                        RemoveCurrentNode();
                        return;
                    }
                }
            }

            _context.TraceInfo("{1}: import reference '{0}' bound to {2}.", import, import.LexicalInfo, entity.FullName);
            import.Entity = entity;
        }
Exemplo n.º 2
0
 private INamespace AliasedNamespaceFor(IEntity entity, Import import)
 {
     INamespace aliasedNamespace = new AliasedNamespace(import.Alias.Name, entity);
     import.Alias.Entity = aliasedNamespace;
     return aliasedNamespace;
 }