Ejemplo n.º 1
0
        public void ShowEntry_PassedImportAllNamespaceEntryWhenHasFromAndImportIsTrue_ReturnsTrue()
        {
            PythonImportExpressionContext context = new PythonImportExpressionContext();

            context.HasFromAndImport = true;
            NamespaceEntry entry  = new NamespaceEntry("*");
            bool           result = context.ShowEntry(entry);

            Assert.IsTrue(result);
        }
Ejemplo n.º 2
0
 //-----------------------------------------------------------------------------
 // The symbol is undefined in the namespace.
 //-----------------------------------------------------------------------------
 public static SymbolErrorException UndefinedSymbolInNamespace(
     NamespaceEntry n,
     Identifier idMissingSymbol
     )
 {
     return(new SymbolErrorException(
                Code.cSymbolNotInNamespace,
                idMissingSymbol.Location,
                "'" + idMissingSymbol.Text + "' is not defined in the namespace '" +
                n.FullName + "'. (Are you missing an assembly reference?)"));
 }
        private NamespaceEntry CreateNamespaceEntry(string prefix, string namespaceUri, bool render)
        {
            NamespaceEntry entry = _pool.Take();

            if (entry == null)
            {
                entry = new NamespaceEntry();
            }
            entry.Init(prefix, namespaceUri, render);
            return(entry);
        }
        private NamespaceEntry CloneNamespaceEntryToRender(NamespaceEntry ne)
        {
            NamespaceEntry entry = _pool.Take();

            if (entry == null)
            {
                entry = new NamespaceEntry();
            }
            entry.CopyAndSetToRender(ne);
            return(entry);
        }
        public void GetCompletionData_WhenImportNameIsEmptyString_ReturnsStandardMathPythonModule()
        {
            PythonImportExpression          expression = new PythonImportExpression(String.Empty);
            PythonImportModuleResolveResult result     = new PythonImportModuleResolveResult(expression);
            MockProjectContent projectContent          = new MockProjectContent();

            List <ICompletionEntry> completionItems             = result.GetCompletionData(projectContent);
            NamespaceEntry          mathNamespaceCompletionItem = new NamespaceEntry("math");

            Assert.Contains(mathNamespaceCompletionItem, completionItems);
        }
 public string LookupNamespace(string prefix)
 {
     for (int i = _namespaceContext.Count - 1; i >= 0; i--)
     {
         NamespaceEntry n = _namespaceContext[i];
         if (n != null && n.Prefix == prefix)
         {
             return(n.NamespaceUri);
         }
     }
     return(null);
 }
        public void GetCompletionData_ClonedPythonModuleResult_ReturnsSameCompletionItems()
        {
            PythonImportExpression          expression = new PythonImportExpression(String.Empty);
            PythonImportModuleResolveResult result     = new PythonImportModuleResolveResult(expression);
            ResolveResult      clonedResult            = result.Clone();
            MockProjectContent projectContent          = new MockProjectContent();

            List <ICompletionEntry> completionItems             = clonedResult.GetCompletionData(projectContent);
            NamespaceEntry          mathNamespaceCompletionItem = new NamespaceEntry("math");

            Assert.Contains(mathNamespaceCompletionItem, completionItems);
        }
Ejemplo n.º 8
0
        public Class(NamespaceEntry ns, DeclSpace parent, MemberName name, Modifiers mod,
            Attributes attrs)
            : base(ns, parent, name, attrs, MemberKind.Class)
        {
            var accmods = (Parent == null || Parent.Parent == null) ? Modifiers.INTERNAL : Modifiers.PRIVATE;
            this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod, accmods, Location, Report);
            spec = new TypeSpec (Kind, null, this, null, ModFlags);

            if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
                Report.FeatureIsNotAvailable (Location, "static classes");
            }
        }
 private bool IsNonRedundantNamespaceDeclaration(string prefix, string namespaceUri)
 {
     for (int i = _namespaceContext.Count - 1; i >= 0; i--)
     {
         NamespaceEntry ne = _namespaceContext[i];
         if (ne != null && ne.Prefix == prefix)
         {
             return(ne.NamespaceUri != namespaceUri);
         }
     }
     return(!C14nUtil.IsEmptyDefaultNamespaceDeclaration(prefix, namespaceUri) &&
            !C14nUtil.IsXmlPrefixDeclaration(prefix, namespaceUri));
 }
Ejemplo n.º 10
0
 void RemoveNamespaceIfPossible(Dictionary <string, NamespaceEntry> dict, NamespaceEntry ns)
 {
     while (ns.ClassCount == 0 && ns.SubNamespaceCount == 0)
     {
         dict.Remove(ns.Name);
         ns = ns.Parent;
         if (ns == null)
         {
             break;
         }
         ns.SubNamespaceCount--;
     }
 }
Ejemplo n.º 11
0
        private static ClassDeclarationSyntax CreateClassDeclaration_Namespace(NamespaceEntry @namespace)
        {
            var comment    = SyntaxFactoryUtils.Comment("// Namespace: {0}", @namespace.Name);
            var name       = CreatePropertyDeclaration_Name(@namespace.Name);
            var properties = @namespace.Groups.Select(CreatePropertyDeclaration_Group).ToArray();
            var classes    = @namespace.Groups.Select(CreateClassDeclaration_Group).ToArray();

            return
                (SyntaxFactoryUtils.ClassDeclaration(@namespace.Type, "NamespaceArchNode")
                 .WithLeadingTrivia(comment)
                 .AddMembers(name)
                 .AddMembers(properties)
                 .AddMembers(classes));
        }
        public IEnumerable<TypeEntry> GetTypes(NamespaceEntry namespaceEntry, string assemblyPath, bool defaultIsChecked)
        {
            Argument.IsNotNullOrWhitespace("assemblyPath", assemblyPath);

            var types = GetTypesFromAssembly(assemblyPath);
            return types.Where(x => string.Equals(x.GetNamespace(), namespaceEntry.Name))
                .Select(x => new TypeEntry(namespaceEntry)
                {
                    Path = assemblyPath,
                    TypeFullName = x.FullName,
                    Name = x.GetFriendlyName(),
                    IsChecked = defaultIsChecked,
                    Description = string.Format("{0}\n{1}", x.GetNamespace(), x.GetFriendlyName())
                }).OrderBy(e => e.Name).ToList();
        }
        public void Reset()
        {
            _localNamespacesToRender.Clear();
            int count = _namespaceContext.Count;

            for (int i = count - 1; i >= 0; i--)
            {
                NamespaceEntry ne = _namespaceContext[i];
                _namespaceContext.RemoveAt(i);
                if (ne != null)
                {
                    ne.Clear();
                    _pool.Return(ne);
                }
            }
        }
Ejemplo n.º 14
0
        Dictionary <string, NamespaceEntry> GetNamespaceDictionary(StringComparer nameComparer)
        {
            // Gets the dictionary for the specified comparer, creating it if necessary.
            // New dictionaries might be added during read accesses, so this method needs to be thread-safe,
            // as we allow concurrent read-accesses.
            var namespaceDicts = this._namespaceDicts;

            foreach (var dict in namespaceDicts)
            {
                if (dict.Comparer == nameComparer)
                {
                    return(dict);
                }
            }

            // ensure that no other thread can try to lazy-create this (or another) dict
            lock (dictsLock) {
                namespaceDicts = this._namespaceDicts;                 // fetch fresh value after locking
                // try looking for it again, maybe it was added while we were waiting for a lock
                // (double-checked locking pattern)
                foreach (var dict in namespaceDicts)
                {
                    if (dict.Comparer == nameComparer)
                    {
                        return(dict);
                    }
                }

                // now create new dict
                var newDict = new Dictionary <string, NamespaceEntry>(nameComparer);
                foreach (ITypeDefinition type in _typeDicts[0].Values)
                {
                    NamespaceEntry ne = GetOrCreateNamespaceEntry(newDict, type.Namespace);
                    ne.ClassCount++;
                }

                // add the new dict to the array of dicts
                var newNamespaceDicts = new Dictionary <string, NamespaceEntry> [namespaceDicts.Length + 1];
                Array.Copy(namespaceDicts, 0, newNamespaceDicts, 0, namespaceDicts.Length);
                newNamespaceDicts[namespaceDicts.Length] = newDict;
                this._namespaceDicts = newNamespaceDicts;
                return(newDict);
            }
        }
        public void ExitElementContext()
        {
            int count = _namespaceContext.Count;

            for (int i = count - 1; i >= 0; i--)
            {
                NamespaceEntry ne = _namespaceContext[i];
                _namespaceContext.RemoveAt(i);
                if (ne != null)
                {
                    ne.Clear();
                    _pool.Return(ne);
                }
                else
                {
                    break;
                }
            }
        }
 public string LookupPrefix(string ne, bool isForAttribute)
 {
     for (int i = _namespaceContext.Count - 1; i >= 0; i--)
     {
         NamespaceEntry n = _namespaceContext[i];
         if (n != null && n.NamespaceUri == ne && (!isForAttribute || n.Prefix.Length > 0))
         {
             string prefix = n.Prefix;
             for (int j = i + 1; j < _namespaceContext.Count; j++)
             {
                 NamespaceEntry m = _namespaceContext[j];
                 if (m != null && m.Prefix == prefix)
                 {
                     // redefined later
                     return(null);
                 }
             }
             return(prefix);
         }
     }
     return(null);
 }
Ejemplo n.º 17
0
        NamespaceEntry GetOrCreateNamespaceEntry(Dictionary <string, NamespaceEntry> dict, string ns)
        {
            NamespaceEntry ne;

            if (!dict.TryGetValue(ns, out ne))
            {
                NamespaceEntry parentEntry;
                if (string.IsNullOrEmpty(ns))
                {
                    parentEntry = null;
                }
                else
                {
                    int    pos      = ns.LastIndexOf('.');
                    string parentNS = pos < 0 ? string.Empty : ns.Substring(0, pos);
                    parentEntry = GetOrCreateNamespaceEntry(dict, parentNS);
                    parentEntry.SubNamespaceCount++;
                }
                ne = new NamespaceEntry(parentEntry, ns);
                dict.Add(ns, ne);
            }
            return(ne);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Adds the type definition to this project content.
        /// Replaces existing type definitions with the same name.
        /// </summary>
        public void UpdateType(ITypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
            // Set isNew on addition in the ordinal comparison.
            // This keeps the ClassCount consistent when there are name clashes.
            bool isNew = !_typeDicts[0].ContainsKey(key);

            foreach (var dict in _typeDicts)
            {
                dict[key] = typeDefinition;
            }
            if (isNew)
            {
                foreach (var dict in _namespaceDicts)
                {
                    NamespaceEntry ns = GetOrCreateNamespaceEntry(dict, typeDefinition.Namespace);
                    ++ns.ClassCount;
                }
            }
        }
Ejemplo n.º 19
0
		public Class (NamespaceEntry ns, DeclSpace parent, MemberName name, int mod,
			      Attributes attrs)
			: base (ns, parent, name, attrs, Kind.Class)
		{
			int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location, Report);

			if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
				Report.FeatureIsNotAvailable (Location, "static classes");
			}
		}
Ejemplo n.º 20
0
		public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
		{
			return null;
		}
Ejemplo n.º 21
0
		public RootDeclSpace (ModuleContainer module, NamespaceEntry ns)
			: base (ns, null, MemberName.Null, null, 0)
		{
			PartialContainer = module;
		}
Ejemplo n.º 22
0
        public void ExpressionResultContextShowItemReturnsTrueForNamespaceEntry()
        {
            NamespaceEntry entry = new NamespaceEntry("abc");

            Assert.IsTrue(expressionResult.Context.ShowEntry(entry));
        }
        private bool MarkToRender(string prefix, bool searchOuterContext, IAncestralNamespaceContextProvider context, bool isInclusivePrefix)
        {
            if (prefix == "xml")
            {
                return(true);
            }
            bool currentFrame = true;

            for (int i = _namespaceContext.Count - 1; i >= 0; i--)
            {
                NamespaceEntry ne = _namespaceContext[i];
                if (ne == null)
                {
                    if (isInclusivePrefix)
                    {
                        break;
                    }
                    currentFrame = false;
                }
                else if (ne.Prefix == prefix)
                {
                    if (ne.Rendered)
                    {
                        return(true);
                    }
                    bool shouldRender;
                    if (prefix.Length > 0 || ne.NamespaceUri.Length > 0)
                    {
                        shouldRender = true;
                    }
                    else
                    {
                        NamespaceEntry match = null;
                        for (int j = i - 1; j >= 0; j--)
                        {
                            NamespaceEntry p = _namespaceContext[j];
                            if (p != null && p.Rendered && p.Prefix.Length == 0)
                            {
                                match = p;
                                break;
                            }
                        }
                        shouldRender = match != null && match.NamespaceUri.Length > 0;
                    }
                    if (shouldRender)
                    {
                        if (currentFrame)
                        {
                            ne.Rendered = true;
                        }
                        else
                        {
                            _namespaceContext.Add(CloneNamespaceEntryToRender(ne));
                        }
                    }
                    return(true);
                }
            }

            if (searchOuterContext)
            {
                string namespaceUri;
                if (context != null)
                {
                    namespaceUri = context.LookupNamespace(prefix);
                }
                else
                {
                    namespaceUri = null;
                }
                if (namespaceUri != null && namespaceUri.Length > 0)
                {
                    _namespaceContext.Add(CreateNamespaceEntry(prefix, namespaceUri, true));
                    return(true);
                }
                else
                {
                    return(prefix.Length == 0 || isInclusivePrefix);
                }
            }
            return(true);
        }
 public void CopyAndSetToRender(NamespaceEntry src)
 {
     Init(src._prefix, src._namespaceUri, true);
 }
Ejemplo n.º 25
0
 public NamespaceCompletionItem(NamespaceEntry entry) : base(entry.Name)
 {
 }
Ejemplo n.º 26
0
		public RootDeclSpace (NamespaceEntry ns)
			: base (ns, null, MemberName.Null, null, 0)
		{
			PartialContainer = RootContext.ToplevelTypes;
		}
Ejemplo n.º 27
0
		public Interface (NamespaceEntry ns, DeclSpace parent, MemberName name, Modifiers mod,
				  Attributes attrs)
			: base (ns, parent, name, attrs, MemberKind.Interface)
		{
			var accmods = parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;

			this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod, accmods, name.Location, Report);
			spec = new TypeSpec (Kind, null, this, null, ModFlags);
		}
Ejemplo n.º 28
0
		public override IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
		{
			DeclSpace top_level = Parent;
			if (top_level != null) {
				while (top_level.Parent != null)
					top_level = top_level.Parent;

				var candidates = NamespaceEntry.NS.LookupExtensionMethod (extensionType, this, name, arity);
				if (candidates != null) {
					scope = NamespaceEntry;
					return candidates;
				}
			}

			return NamespaceEntry.LookupExtensionMethod (extensionType, name, arity, ref scope);
		}
Ejemplo n.º 29
0
		public TypeContainer (NamespaceEntry ns, DeclSpace parent, MemberName name,
				      Attributes attrs, MemberKind kind)
			: base (ns, parent, name, attrs)
		{
			if (parent != null && parent.NamespaceEntry != ns)
				throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");

			this.Kind = kind;
			this.PartialContainer = this;
		}
Ejemplo n.º 30
0
		public ClassOrStruct (NamespaceEntry ns, DeclSpace parent,
				      MemberName name, Attributes attrs, MemberKind kind)
			: base (ns, parent, name, attrs, kind)
		{
		}
Ejemplo n.º 31
0
 public NamespaceEntry(NamespaceEntry parent, string name)
 {
     this.Parent = parent;
     this.Name   = name;
 }
Ejemplo n.º 32
0
		public Interface (NamespaceEntry ns, DeclSpace parent, MemberName name, int mod,
				  Attributes attrs)
			: base (ns, parent, name, attrs, Kind.Interface)
		{
			int accmods;

			if (parent.Parent == null)
				accmods = Modifiers.INTERNAL;
			else
				accmods = Modifiers.PRIVATE;

			this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, name.Location, Report);
		}