Beispiel #1
0
        protected override void OnMappingAdded(int index, IEnumerable <IAssembly> element)
        {
            foreach (var assembly in element)
            {
                if (assembly == null)
                {
                    throw new ArgumentNullException("element", "Element contained a null entry.");
                }

                AssemblyMapping mapping;
                if (!_assemblies.TryGetValue(assembly, out mapping))
                {
                    mapping = new AssemblyMapping(this.Settings);
                    _assemblies.Add(assembly, mapping);
                }
                mapping.AddMapping(index, assembly);

                foreach (var ns in mapping.Namespaces)
                {
                    INamespaceDefinition nspace = ns[index];
                    if (nspace == null)
                    {
                        continue;
                    }

                    NamespaceMapping nsMapping;
                    if (!_namespaces.TryGetValue(nspace, out nsMapping))
                    {
                        nsMapping = new NamespaceMapping(this.Settings, true);
                        _namespaces.Add(nspace, nsMapping);
                    }
                    nsMapping.AddMapping(index, nspace);
                }
            }
        }
Beispiel #2
0
        public override void Visit(INamespaceDefinition ns)
        {
            if (ns != null && string.IsNullOrEmpty(ns.Name.Value))
            {
                base.Visit(ns);
            }
            else
            {
                _declarationWriter.WriteDeclaration(ns);

                using (_syntaxWriter.StartBraceBlock(PutBraceOnNewLine))
                {
                    var types = ns.GetTypes(this.IncludeForwardedTypes);
                    if (ConditionalTypeLists != null)
                    {
                        // in the first pass we want all types *except* the ones in ConditionalTypeLists filters
                        // in the second pass we want *only* the types in ConditionalTypeLists filters
                        var firstPass = _currentTypeListFilter == null;
                        types = types.Where(t => ConditionalTypeLists.Any(c => c.Filter.Include(t) == !firstPass));
                    }

                    Visit(types);
                }
            }

            _syntaxWriter.WriteLine();
        }
Beispiel #3
0
 private static bool TestEquality(INamespaceDefinition a, INamespaceDefinition b)
 {
     //Assert.AreEqual(a.IsAnonymous, b.IsAnonymous);
     //return TestEquality((NamedScope)a, (NamedScope)b);
     return(a.IsAnonymous == b.IsAnonymous &&
            TestEquality((INamedScope)a, (INamedScope)b));
 }
 public virtual void PrintNamespaceDefinitionAttributes(INamespaceDefinition namespaceDefinition)
 {
     foreach (var attribute in SortAttributes(namespaceDefinition.Attributes))
     {
         PrintAttribute(namespaceDefinition, attribute, true, "assembly");
     }
 }
Beispiel #5
0
        /// <summary>
        /// Finds a namespace that matches the <see cref="ImportedNamespace"/> portion of this
        /// alias.
        /// </summary>
        /// <param name="rootScope">the global scope to search from</param>
        /// <returns>namespace definitions rooted at
        /// <paramref name="rootScope"/>that match see cref="ImportedNamespace"/></returns>
        public IEnumerable <INamespaceDefinition> FindMatchingNamespace(INamespaceDefinition rootScope)
        {
            var currentNsUse = this.ImportedNamespace;

            List <INamespaceDefinition> scopes = new List <INamespaceDefinition>();

            scopes.Add(rootScope);

            // we will go through each namespace referenced by the alias
            while (currentNsUse != null)
            {
                // go through all of the scopes and get the children that match currentNsUse on the
                // first iteration, the only thing in scopes will be the global scope on subsequent
                // iterations, scopes will contain matches for the parent of currentNsUse
                int currentLength = scopes.Count;
                for (int i = 0; i < currentLength; i++)
                {
                    scopes.AddRange(scopes[i].GetChildScopesWithId <INamespaceDefinition>(currentNsUse.Name));
                }
                // once we've found matches for currentNsUse, remove the previous scopes from the
                // list and set currentNsUse to its child
                scopes.RemoveRange(0, currentLength);
                currentNsUse = currentNsUse.ChildScopeUse;
            }

            return(scopes);
        }
Beispiel #6
0
        private static INestedUnitNamespace /*?*/ GetNamespace(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, ref int offset)
        {
            Contract.Requires(nameTable != null);
            Contract.Requires(namespaceDefinition != null);
            Contract.Requires(typeName != null);
            Contract.Requires(offset >= 0);
            Contract.Ensures(offset >= 0);

            int len = typeName.Length;

            if (offset >= len)
            {
                return(null);
            }
            int dotPos = typeName.IndexOf('.', offset);

            if (dotPos < 0)
            {
                return(null);
            }
            Contract.Assume(dotPos >= offset); //if a dot has been found, it must be at offset or later
            IName neName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset));

            foreach (var member in namespaceDefinition.GetMembersNamed(neName, false))
            {
                var nestedNamespace = member as INestedUnitNamespace;
                if (nestedNamespace == null)
                {
                    continue;
                }
                offset = dotPos + 1;
                return(nestedNamespace);
            }
            return(null);
        }
        public void TestMethodCallToParentType_CSharp()
        {
            //class A { void Foo() { } }
            string a_xml = @"<class>class <name>A</name> <block>{ <function><type><name>void</name></type> <name>Foo</name><parameter_list>()</parameter_list> <block>{ }</block></function> }</block></class>";

            //class B : A { void Bar() { Foo() } }
            string b_xml = @"<class>class <name>B</name> <super>: <name>A</name></super> <block>{ <function><type><name>void</name></type> <name>Bar</name><parameter_list>()</parameter_list> <block>{ <expr_stmt><expr><call><name>Foo</name><argument_list>()</argument_list></call></expr></expr_stmt> }</block></function> }</block></class>";

            var aUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a_xml, "A.cs");
            var bUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(b_xml, "B.cs");

            INamespaceDefinition globalScope = CodeParser[Language.CSharp].ParseFileUnit(aUnit);

            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(bUnit)) as INamespaceDefinition;

            var typeA = globalScope.GetChildScopesWithId <ITypeDefinition>("A").FirstOrDefault();
            var typeB = globalScope.GetChildScopesWithId <ITypeDefinition>("B").FirstOrDefault();

            Assert.IsNotNull(typeA, "could not find class A");
            Assert.IsNotNull(typeB, "could not find class B");

            var aDotFoo = typeA.GetChildScopesWithId <IMethodDefinition>("Foo").FirstOrDefault();
            var bDotBar = typeB.GetChildScopesWithId <IMethodDefinition>("Bar").FirstOrDefault();

            Assert.IsNotNull(aDotFoo, "could not find method A.Foo()");
            Assert.IsNotNull(bDotBar, "could not find method B.Bar()");

            var callToFooFromB = bDotBar.MethodCalls.FirstOrDefault();

            Assert.IsNotNull(callToFooFromB, "could not find any calls in B.Bar()");
            Assert.AreEqual("Foo", callToFooFromB.Name);

            Assert.AreEqual(aDotFoo, callToFooFromB.FindMatches().FirstOrDefault());
        }
        public void TestVariableDeclaredInCallingObjectWithParentClass_CSharp()
        {
            //class A { B b; }
            string a_xml = @"<class>class <name>A</name> <block>{ <decl_stmt><decl><type><name>B</name></type> <name>b</name></decl>;</decl_stmt> }</block></class>";

            //class B { void Foo() { } }
            string b_xml = @"<class>class <name>B</name> <block>{ <function><type><name>void</name></type> <name>Foo</name><parameter_list>()</parameter_list> <block>{ }</block></function> }</block></class>";

            //class C : A { }
            string c_xml = @"<class>class <name>C</name> <super>: <name>A</name></super> <block>{ }</block></class>";

            //class D {
            //	C c;
            //	void Bar() { c.b.Foo(); }
            //}
            string d_xml = @"<class>class <name>D</name> <block>{
	<decl_stmt><decl><type><name>C</name></type> <name>c</name></decl>;</decl_stmt>
	<function><type><name>void</name></type> <name>Bar</name><parameter_list>()</parameter_list> <block>{ <expr_stmt><expr><call><name><name>c</name><op:operator>.</op:operator><name>b</name><op:operator>.</op:operator><name>Foo</name></name><argument_list>()</argument_list></call></expr>;</expr_stmt> }</block></function>
}</block></class>";

            var aUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a_xml, "A.cs");
            var bUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(b_xml, "B.cs");
            var cUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(c_xml, "C.cs");
            var dUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(d_xml, "D.cs");

            INamespaceDefinition globalScope = CodeParser[Language.CSharp].ParseFileUnit(aUnit);

            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(bUnit)) as INamespaceDefinition;
            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(cUnit)) as INamespaceDefinition;
            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(dUnit)) as INamespaceDefinition;

            var typeA = globalScope.GetChildScopesWithId <ITypeDefinition>("A").FirstOrDefault();
            var typeB = globalScope.GetChildScopesWithId <ITypeDefinition>("B").FirstOrDefault();
            var typeC = globalScope.GetChildScopesWithId <ITypeDefinition>("C").FirstOrDefault();
            var typeD = globalScope.GetChildScopesWithId <ITypeDefinition>("D").FirstOrDefault();

            Assert.IsNotNull(typeA, "could not find class A");
            Assert.IsNotNull(typeB, "could not find class B");
            Assert.IsNotNull(typeC, "could not find class C");
            Assert.IsNotNull(typeD, "could not find class D");

            var adotB = typeA.DeclaredVariables.FirstOrDefault();

            Assert.IsNotNull(adotB, "could not find variable A.b");
            Assert.AreEqual("b", adotB.Name);

            var bDotFoo = typeB.GetChildScopesWithId <IMethodDefinition>("Foo").FirstOrDefault();

            Assert.IsNotNull(bDotFoo, "could not method B.Foo()");

            var dDotBar = typeD.GetChildScopesWithId <IMethodDefinition>("Bar").FirstOrDefault();

            Assert.IsNotNull(dDotBar, "could not find method D.Bar()");

            var callToFoo = dDotBar.MethodCalls.FirstOrDefault();

            Assert.IsNotNull(callToFoo, "could not find any method calls in D.Bar()");

            Assert.AreEqual(bDotFoo, callToFoo.FindMatches().FirstOrDefault());
        }
Beispiel #9
0
        public override void Visit(INamespaceDefinition @namespace)
        {
            IEnumerable <INamespaceDefinition>     namespaces = @namespace.Members.OfType <INamespaceDefinition>();
            IEnumerable <INamespaceTypeDefinition> types      = @namespace.Members.OfType <INamespaceTypeDefinition>();

            if (types.Count() > 0)
            {
                EmitKeyword("namespace");
                Emit(TypeHelper.GetNamespaceName((IUnitNamespaceReference)@namespace, NameFormattingOptions.None));
                EmitNewLine();
                using (EmitBlock(true))
                {
                    foreach (var type in types)
                    {
                        Visit(type);
                    }
                }
                EmitNewLine();
            }

            foreach (var nestedNamespace in namespaces)
            {
                Visit(nestedNamespace);
            }
        }
Beispiel #10
0
        private static INamedTypeDefinition /*?*/ GetType(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, int genericParameterCount, ref int offset)
        {
            int savedOffset = offset;
            var nestedNamespaceDefinition = GetNamespace(nameTable, namespaceDefinition, typeName, ref offset);

            if (nestedNamespaceDefinition != null)
            {
                var naType = GetType(nameTable, nestedNamespaceDefinition, typeName, genericParameterCount, ref offset);
                if (naType != null)
                {
                    return(naType);
                }
            }
            offset = savedOffset;
            var nsType = GetNamespaceType(nameTable, namespaceDefinition, typeName, genericParameterCount, ref offset);

            if (nsType == null)
            {
                return(null);
            }
            if (offset >= typeName.Length)
            {
                return(nsType);
            }
            return(GetNestedType(nameTable, nsType, typeName, genericParameterCount, ref offset));
        }
Beispiel #11
0
        private static INestedUnitNamespace /*?*/ GetNamespace(INameTable nameTable, INamespaceDefinition namespaceDefinition, string typeName, ref int offset)
        {
            int len = typeName.Length;

            if (offset >= len)
            {
                return(null);
            }
            int dotPos = typeName.IndexOf('.', offset);

            if (dotPos < 0)
            {
                return(null);
            }
            IName neName = nameTable.GetNameFor(typeName.Substring(offset, dotPos - offset));

            foreach (var member in namespaceDefinition.GetMembersNamed(neName, false))
            {
                var nestedNamespace = member as INestedUnitNamespace;
                if (nestedNamespace == null)
                {
                    continue;
                }
                offset = dotPos + 1;
                return(nestedNamespace);
            }
            return(null);
        }
 public override void Visit(INamespaceDefinition namespaceDefinition)
 {
     if (Process(namespaceDefinition))
     {
         visitor.Visit(namespaceDefinition);
     }
     base.Visit(namespaceDefinition);
 }
Beispiel #13
0
        private static string GetName(INamespaceDefinition namespaceName)
        {
            var name = namespaceName.ToString();

            return(string.IsNullOrEmpty(name)
                       ? "-"
                       : name);
        }
 public override void TraverseChildren(INamespaceDefinition namespaceDefinition)
 {
     if (!_filter.Include(namespaceDefinition))
     {
         return;
     }
     base.TraverseChildren(namespaceDefinition);
 }
        public override void Visit(INamespaceDefinition ns)
        {
            _declarationWriter.WriteDeclaration(ns);

            using (_syntaxWriter.StartBraceBlock())
            {
                base.Visit(ns);
            }
        }
        public override void Visit(INamespaceDefinition ns)
        {
            if ((_kinds & DocIdKinds.Namespace) != 0)
            {
                _writer.WriteLine(ns.DocId());
            }

            base.Visit(ns);
        }
Beispiel #17
0
        public void WriteDeclaration(IDefinition definition)
        {
            if (definition == null)
            {
                return;
            }

            IAssembly assembly = definition as IAssembly;

            if (assembly != null)
            {
                WriteAssemblyDeclaration(assembly);
                return;
            }

            INamespaceDefinition ns = definition as INamespaceDefinition;

            if (ns != null)
            {
                WriteNamespaceDeclaration(ns);
                return;
            }

            ITypeDefinition type = definition as ITypeDefinition;

            if (type != null)
            {
                WriteTypeDeclaration(type);
                return;
            }

            ITypeDefinitionMember member = definition as ITypeDefinitionMember;

            if (member != null)
            {
                WriteMemberDeclaration(member);
                return;
            }

            DummyInternalConstructor ctor = definition as DummyInternalConstructor;

            if (ctor != null)
            {
                WritePrivateConstructor(ctor.ContainingType);
                return;
            }

            INamedEntity named = definition as INamedEntity;

            if (named != null)
            {
                WriteIdentifier(named.Name);
                return;
            }

            _writer.Write("Unknown definition type {0}", definition.ToString());
        }
Beispiel #18
0
        public virtual void PrintNamespaceDefinitionAttributes(INamespaceDefinition namespaceDefinition)
        {
            Contract.Requires(namespaceDefinition != null);

            foreach (var attribute in SortAttributes(namespaceDefinition.Attributes))
            {
                PrintAttribute(namespaceDefinition, attribute, true, "assembly");
            }
        }
Beispiel #19
0
        public override void Visit(INamespaceDefinition ns)
        {
            _declarationWriter.WriteDeclaration(ns);

            using (_syntaxWriter.StartBraceBlock())
            {
                base.Visit(ns);
            }
        }
 public virtual void PrintNamespaceDefinition(INamespaceDefinition namespaceDefinition)
 {
     PrintNamespaceDefinitionAttributes(namespaceDefinition);
     PrintToken(CSharpToken.Indent);
     PrintKeywordNamespace();
     PrintNamespaceDefinitionName(namespaceDefinition);
     PrintNamespaceDefinitionLeftCurly(namespaceDefinition);
     this.Traverse(namespaceDefinition.Members);
     PrintNamespaceDefinitionRightCurly(namespaceDefinition);
 }
Beispiel #21
0
        public override void TraverseChildren(INamespaceDefinition namespaceDefinition)
        {
            var members = new List <INamespaceMember>(namespaceDefinition.Members);

            members.Sort((x, y) => string.CompareOrdinal(x.Name.Value, y.Name.Value));
            foreach (var member in members)
            {
                this.Traverse(member);
            }
        }
        public bool Include(INamespaceDefinition ns)
        {
            // Only include non-empty namespaces
            if (!ns.GetTypes().Any(Include))
            {
                return(false);
            }

            string namespaceId = ns.DocId();

            return(_docIds.Contains(namespaceId));
        }
Beispiel #23
0
        private static IUnitNamespace GetUnitNamespace(INamespaceDefinition containingNamespace)
        {
            INestedUnitNamespace nestedUnitNamespace = containingNamespace as INestedUnitNamespace;

            if (nestedUnitNamespace != null)
            {
                containingNamespace = nestedUnitNamespace.ContainingUnitNamespace;
            }
            IUnitNamespace unitNamespace = containingNamespace as IUnitNamespace;

            return(unitNamespace);
        }
        public void TestMethodCallToParentOfCallingObject_CSharp()
        {
            //class A { void Foo() { } }
            string a_xml = @"<class>class <name>A</name> <block>{ <function><type><name>void</name></type> <name>Foo</name><parameter_list>()</parameter_list> <block>{ }</block></function> }</block></class>";

            //class B : A { void Bar() { } }
            string b_xml = @"<class>class <name>B</name> <super>: <name>A</name></super> <block>{ <function><type><name>void</name></type> <name>Bar</name><parameter_list>()</parameter_list> <block>{ }</block></function> }</block></class>";

            //class C {
            //	private B b;
            //	void main() {
            //		b.Foo();
            //	}
            //}
            string c_xml = @"<class>class <name>C</name> <block>{
	<decl_stmt><decl><type><specifier>private</specifier> <name>B</name></type> <name>b</name></decl>;</decl_stmt>
	<function><type><name>void</name></type> <name>main</name><parameter_list>()</parameter_list> <block>{
		<expr_stmt><expr><call><name><name>b</name><op:operator>.</op:operator><name>Foo</name></name><argument_list>()</argument_list></call></expr>;</expr_stmt>
	}</block></function>
}</block></class>";

            var aUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a_xml, "A.cs");
            var bUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(b_xml, "B.cs");
            var cUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(c_xml, "C.cs");

            INamespaceDefinition globalScope = CodeParser[Language.CSharp].ParseFileUnit(aUnit);

            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(bUnit)) as INamespaceDefinition;
            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(cUnit)) as INamespaceDefinition;

            var typeA = globalScope.GetChildScopesWithId <ITypeDefinition>("A").FirstOrDefault();
            var typeB = globalScope.GetChildScopesWithId <ITypeDefinition>("B").FirstOrDefault();
            var typeC = globalScope.GetChildScopesWithId <ITypeDefinition>("C").FirstOrDefault();

            Assert.IsNotNull(typeA, "could not find class A");
            Assert.IsNotNull(typeB, "could not find class B");
            Assert.IsNotNull(typeC, "could not find class C");

            var aDotFoo  = typeA.GetChildScopesWithId <IMethodDefinition>("Foo").FirstOrDefault();
            var cDotMain = typeC.GetChildScopesWithId <IMethodDefinition>("main").FirstOrDefault();

            Assert.IsNotNull(aDotFoo, "could not find method A.Foo()");
            Assert.IsNotNull(cDotMain, "could not find method C.main()");

            var callToFooFromC = cDotMain.MethodCalls.FirstOrDefault();

            Assert.IsNotNull(callToFooFromC, "could not find any calls in C.main()");
            Assert.AreEqual("Foo", callToFooFromC.Name);
            Assert.AreEqual("b", (callToFooFromC.CallingObject as IVariableUse).Name);

            Assert.AreEqual(typeB, callToFooFromC.CallingObject.FindFirstMatchingType());
            Assert.AreEqual(aDotFoo, callToFooFromC.FindMatches().FirstOrDefault());
        }
Beispiel #25
0
        // handles nested types
        // Only resolves type definitions, i.e. no arrays, refs, ptrs, or instantiated generic types
        public INamedTypeDefinition LoadFullyQualifiedTypeDef(string fqtn, IAssembly containingAssembly)
        {
            if (fqtn.Equals("<Module>")) // Special case "<Module>" class since it isn't visible in the UnitNamespaceRoot
            {
                foreach (INamedTypeDefinition typeDef in ((IModule)containingAssembly).GetAllTypes())
                {
                    return(typeDef); // The "<Module>" class is always the first value in IModule.GetAllTypes()
                }
            }
            INamespaceDefinition rootNS = containingAssembly.UnitNamespaceRoot;

            return(LoadFullyQualifiedTypeDef(fqtn, rootNS));
        }
Beispiel #26
0
        public bool Include(INamespaceDefinition ns)
        {
            // Only include non-empty namespaces
            if (!ns.GetTypes().Any(Include))
            {
                return(false);
            }

            string namespaceId = ns.DocId();

            // include so long as it isn't in the exclude list.
            return(!_docIds.Contains(namespaceId));
        }
Beispiel #27
0
        public static IEnumerable <INamespaceDefinition> GetNamespaces(this INamespaceDefinition ns, bool recursive = true)
        {
            foreach (var nestedNs in ns.Members.OfType <INamespaceDefinition>())
            {
                yield return(nestedNs);

                if (recursive)
                {
                    foreach (var nn in nestedNs.GetNamespaces(recursive))
                    {
                        yield return(nn);
                    }
                }
            }
        }
        public void TestVariableDeclaredInParentClass()
        {
            //class A { void Foo() { } }
            string a_xml = @"<class>class <name>A</name> <block>{ <function><type><name>void</name></type> <name>Foo</name><parameter_list>()</parameter_list> <block>{ }</block></function> }</block></class>";

            //class B { protected A a; }
            string b_xml = @"<class>class <name>B</name> <block>{ <decl_stmt><decl><type><specifier>protected</specifier> <name>A</name></type> <name>a</name></decl>;</decl_stmt> }</block></class>";

            //class C : B { void Bar() { a.Foo(); } }
            string c_xml = @"<class>class <name>C</name> <super>: <name>B</name></super> <block>{ <function><type><name>void</name></type> <name>Bar</name><parameter_list>()</parameter_list> <block>{ <expr_stmt><expr><call><name><name>a</name><op:operator>.</op:operator><name>Foo</name></name><argument_list>()</argument_list></call></expr>;</expr_stmt> }</block></function> }</block></class>";

            var aUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(a_xml, "A.cs");
            var bUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(b_xml, "B.cs");
            var cUnit = FileUnitSetup[Language.CSharp].GetFileUnitForXmlSnippet(c_xml, "C.cs");

            INamespaceDefinition globalScope = CodeParser[Language.CSharp].ParseFileUnit(aUnit);

            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(bUnit)) as INamespaceDefinition;
            globalScope = globalScope.Merge(CodeParser[Language.CSharp].ParseFileUnit(cUnit)) as INamespaceDefinition;

            var typeA = globalScope.GetChildScopesWithId <ITypeDefinition>("A").FirstOrDefault();
            var typeB = globalScope.GetChildScopesWithId <ITypeDefinition>("B").FirstOrDefault();
            var typeC = globalScope.GetChildScopesWithId <ITypeDefinition>("C").FirstOrDefault();

            Assert.IsNotNull(typeA, "could not find class A");
            Assert.IsNotNull(typeB, "could not find class B");
            Assert.IsNotNull(typeC, "could not find class C");

            var aDotFoo = typeA.GetChildScopesWithId <IMethodDefinition>("Foo").FirstOrDefault();

            Assert.IsNotNull(aDotFoo, "could not find method A.Foo()");

            var cDotBar = typeC.GetChildScopesWithId <IMethodDefinition>("Bar").FirstOrDefault();

            Assert.IsNotNull(cDotBar, "could not find method C.Bar()");

            var bDotA = typeB.DeclaredVariables.FirstOrDefault();

            Assert.IsNotNull(bDotA, "could not find variable B.a");
            Assert.AreEqual("a", bDotA.Name);

            var callToFoo = cDotBar.MethodCalls.FirstOrDefault();

            Assert.IsNotNull(callToFoo, "could not find any method calls in C.Bar()");
            Assert.AreEqual("Foo", callToFoo.Name);

            Assert.AreEqual(aDotFoo, callToFoo.FindMatches().FirstOrDefault());
        }
Beispiel #29
0
        // This ignores parameter types, which we'll need at some point
        internal static bool MethodMatchesFullyQualifiedName(string fullyQualifiedName, IMethodDefinition definition)
        {
            string[] nameComponents = fullyQualifiedName.Split('.');


            INamedEntity nameIterator = definition;

            for (int componentIndex = nameComponents.Length - 1; componentIndex >= 0; componentIndex--)
            {
                string nameComponent = nameComponents[componentIndex];

                if (nameIterator.Name.Value.Equals(nameComponent))
                {
                    if (nameIterator is ITypeDefinitionMember)
                    {
                        ITypeDefinition containingTypeDefinition = ((ITypeDefinitionMember)nameIterator).ContainingTypeDefinition;

                        if (containingTypeDefinition is INamedTypeDefinition)
                        {
                            nameIterator = ((INamedTypeDefinition)containingTypeDefinition);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (nameIterator is INamespaceMember)
                    {
                        INamespaceDefinition containingNamespace = ((INamespaceMember)nameIterator).ContainingNamespace;

                        nameIterator = containingNamespace;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #30
0
        public override void Visit(INamespaceDefinition ns)
        {
            if (ns != null && string.IsNullOrEmpty(ns.Name.Value))
            {
                base.Visit(ns);
            }
            else
            {
                _declarationWriter.WriteDeclaration(ns);

                using (_syntaxWriter.StartBraceBlock(PutBraceOnNewLine))
                {
                    base.Visit(ns);
                }
            }

            _syntaxWriter.WriteLine();
        }
Beispiel #31
0
 /// <summary>
 /// Appends all of the type members of the given namespace (as well as those of its nested namespaces and types) to
 /// the given list of types.
 /// </summary>
 /// <param name="nameSpace">The namespace to (recursively) traverse to find nested types.</param>
 /// <param name="typeList">A mutable list of types to which any types found inside the given namespace will be appended.</param>
 internal static void FillInWithTypes(INamespaceDefinition nameSpace, List <INamedTypeDefinition> typeList)
 {
     foreach (INamespaceMember member in nameSpace.Members)
     {
         INamedTypeDefinition /*?*/ type = member as INamedTypeDefinition;
         if (type != null)
         {
             FillInWithNestedTypes(type, typeList);
         }
         else
         {
             INamespaceDefinition /*?*/ ns = member as INamespaceDefinition;
             if (ns != null)
             {
                 FillInWithTypes(ns, typeList);
             }
         }
     }
 }
Beispiel #32
0
        public override void Visit(INamespaceDefinition @namespace)
        {
            IEnumerable<INamespaceDefinition> namespaces = @namespace.Members.OfType<INamespaceDefinition>();
            IEnumerable<INamespaceTypeDefinition> types = @namespace.Members.OfType<INamespaceTypeDefinition>();

            if (types.Count() > 0)
            {
                EmitKeyword("namespace");
                Emit(TypeHelper.GetNamespaceName((IUnitNamespaceReference)@namespace, NameFormattingOptions.None));
                EmitNewLine();
                using (EmitBlock(true))
                {
                    foreach (var type in types)
                        Visit(type);
                }
                EmitNewLine();
            }

            foreach (var nestedNamespace in namespaces)
                Visit(nestedNamespace);
        }
Beispiel #33
0
 /// <summary>
 /// Traverses the namespace definition.
 /// </summary>
 public void Traverse(INamespaceDefinition namespaceDefinition)
 {
     Contract.Requires(namespaceDefinition != null);
       namespaceDefinition.Dispatch(this.dispatchingVisitor);
 }
Beispiel #34
0
 /// <summary>
 /// Visits the specified namespace definition.
 /// </summary>
 public virtual void Visit(INamespaceDefinition namespaceDefinition)
 {
     //INamespaceDefinition is a base interface that should never be implemented directly.
       //Get namespaceDefinition to call the most type specific visitor.
       namespaceDefinition.Dispatch(this);
 }
Beispiel #35
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Visits the specified namespace definition.
 /// </summary>
 /// <param name="namespaceDefinition">The namespace definition.</param>
 public virtual void Visit(INamespaceDefinition namespaceDefinition)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(namespaceDefinition);
       this.Visit(namespaceDefinition.Members);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
       namespaceDefinition.Dispatch(this);
 }
Beispiel #36
0
 public virtual bool Include(INamespaceDefinition ns)
 {
     // Only include non-empty namespaces
     return ns.GetTypes(this.IncludeForwardedTypes).Any(Include);
 }
Beispiel #37
0
 /// <summary>
 /// Traverses the specified namespace definition.
 /// </summary>
 public virtual void TraverseChildren(INamespaceDefinition namespaceDefinition)
 {
     this.Traverse(namespaceDefinition.Members);
 }
Beispiel #38
0
 private static INamespaceDefinition GetCorresponding(this IUnit unit, INamespaceDefinition nsd)
 {
   INestedUnitNamespace nested = nsd as INestedUnitNamespace;
   if (nested != null)
   {
     var parent = unit.GetCorresponding(nested.ContainingNamespace);
     if (parent == null) return null;
     foreach (var candidate in parent.GetMembersNamed(nested.Name, false)) {
       INamespaceDefinition result = candidate as INamespaceDefinition;
       if (result != null) return result;
     }
     return null;
   }
   // must be the root
   return unit.UnitNamespaceRoot;
 }
 public override void TraverseChildren(INamespaceDefinition namespaceDefinition) {
   var members = new List<INamespaceMember>(namespaceDefinition.Members);
   members.Sort((x, y) => string.CompareOrdinal(x.Name.Value, y.Name.Value));
   foreach (var member in members)
     this.Traverse(member);
 }
 public override void TraverseChildren(INamespaceDefinition namespaceDefinition)
 {
     if (!_filter.Include(namespaceDefinition))
         return;
     base.TraverseChildren(namespaceDefinition);
 }
 public bool Include(INamespaceDefinition ns)
 {
     // Only include non-empty namespaces
     return ns.GetTypes().Any(Include);
 }
 public virtual bool Include(INamespaceDefinition ns)
 {
     return IsNotMarkedWithAttribute(ns);
 }
 public virtual void Visit(INamespaceDefinition ns)
 {
     Visit(ns.GetTypes(this.IncludeForwardedTypes));
 }
 public override string GetKey(INamespaceDefinition ns)
 {
     return RemapName(base.GetKey(ns));
 }
        public override void TraverseChildren(INamespaceDefinition namespaceDefinition)
{ MethodEnter(namespaceDefinition);
            base.TraverseChildren(namespaceDefinition);
     MethodExit();   }
Beispiel #46
0
 /// <summary>
 /// Traverses the specified namespace definition.
 /// </summary>
 public virtual void TraverseChildren(INamespaceDefinition namespaceDefinition)
 {
     Contract.Requires(namespaceDefinition != null);
       this.Traverse(namespaceDefinition.Members);
 }
 public void WriteNamespaceDeclaration(INamespaceDefinition ns)
 {
     WriteKeyword("namespace");
     WriteIdentifier(TypeHelper.GetNamespaceName((IUnitNamespace)ns, NameFormattingOptions.None));
 }
Beispiel #48
0
 public bool Include(INamespaceDefinition ns)
 {
     return true;
 }
Beispiel #49
0
        private INamedTypeDefinition LoadFullyQualifiedTypeDef(string name, INamespaceDefinition parentNs)
        {
            int dotIdx = name.IndexOf('.');
            if (dotIdx > 0)
            {
                string firstNs = name.Substring(0, dotIdx);
                string remainingName = name.Substring(dotIdx + 1);
                INamespaceDefinition ns = null;

                IName firstINs = NameTable.GetNameFor(firstNs);
                foreach (INamespaceMember member in parentNs.GetMembersNamed(firstINs, false))
                {
                    ns = member as INamespaceDefinition;
                    if (ns != null) break;
                }

                if (ns != null)
                {
                    return LoadFullyQualifiedTypeDef(remainingName, ns);
                }
                else
                    throw new Exception("Cannot find the namespace: " + firstNs);
            }
            else if (dotIdx < 0)
            {
                return LoadTypeDef(name, parentNs);
            }
            else /* dotIdx == 0 */
            {
                throw new Exception("Invalid type def name");
            }
        }
 /// <summary>
 /// Rewrites the namespace definition.
 /// </summary>
 public virtual INamespaceDefinition Rewrite(INamespaceDefinition namespaceDefinition)
 {
     return namespaceDefinition;
 }
Beispiel #51
0
 /// <summary>
 /// Visits the specified namespace definition.
 /// </summary>
 public void Visit(INamespaceDefinition namespaceDefinition)
 {
 }
 public override void Visit(INamespaceDefinition namespaceDefinition)
 {
     if(Process(namespaceDefinition)){visitor.Visit(namespaceDefinition);}
     base.Visit(namespaceDefinition);
 }
Beispiel #53
0
 private static IUnitNamespace GetUnitNamespace(INamespaceDefinition containingNamespace)
 {
     INestedUnitNamespace nestedUnitNamespace = containingNamespace as INestedUnitNamespace;
     if (nestedUnitNamespace != null)
     {
         containingNamespace = nestedUnitNamespace.ContainingUnitNamespace;
     }
     IUnitNamespace unitNamespace = containingNamespace as IUnitNamespace;
     return unitNamespace;
 }
 public virtual string GetNamespaceKey(INamespaceDefinition ns)
 {
     return ns.UniqueId();
 }
 public bool Include(INamespaceDefinition ns)
 {
     return Filters.All(filter => filter.Include(ns));
 }
Beispiel #56
0
 /// <summary>
 /// Traverses the namespace definition.
 /// </summary>
 public void Traverse(INamespaceDefinition namespaceDefinition)
 {
     namespaceDefinition.Dispatch(this.dispatchingVisitor);
 }