示例#1
0
        private bool HandledAsDuplicatedNamespace(Import import, IEntity resolvedEntity)
        {
            var actualName = EffectiveNameForImportedNamespace(import);
            //only add unique namespaces
            var cachedImport = _namespaces[actualName] as Import;

            if (cachedImport == null)
            {
                _namespaces[actualName] = import;
                return(false);
            }

            //ignore for partial classes in separate files
            if (cachedImport.LexicalInfo.FileName == import.LexicalInfo.FileName)
            {
                Warnings.Add(CompilerWarningFactory.DuplicateNamespace(import, import.Namespace));
            }

            BindError(import);
            return(true);
        }
示例#2
0
        private bool HandledAsDuplicatedNamespace(Import import)
        {
            var actualName = EffectiveNameForImportedNamespace(import);

            //only add unique namespaces
            Import cachedImport;

            if (!_namespaces.TryGetValue(actualName, out cachedImport))
            {
                _namespaces[actualName] = import;
                return(false);
            }

            //ignore for partial classes in separate files
            if (cachedImport.LexicalInfo.FileName == import.LexicalInfo.FileName)
            {
                Warnings.Add(CompilerWarningFactory.DuplicateNamespace(import, import.Namespace));
            }

            BindError(import);
            return(true);
        }
示例#3
0
        public override void OnImport(Boo.Lang.Compiler.Ast.Import import)
        {
            INamespace oldns  = NameResolutionService.CurrentNamespace;
            IEntity    entity = null;

            try
            {
                NameResolutionService.EnterNamespace(NameResolutionService.CurrentNamespace.ParentNamespace);
                entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
            }
            finally
            {
                NameResolutionService.EnterNamespace(oldns);
            }

            if (null == entity)
            {
                entity = NameResolutionService.ResolveQualifiedName(import.Namespace);
            }

            //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;
        }