public AliasNamespaceReference(string identifier, UsingScope parentUsingScope)
		{
			if (identifier == null)
				throw new ArgumentNullException("identifier");
			this.identifier = identifier;
			this.parentUsingScope = parentUsingScope;
		}
Ejemplo n.º 2
0
        ResolvedUsingScope MakeUsingScope(string namespaceName = "", string[] usings = null, KeyValuePair <string, string>[] usingAliases = null)
        {
            UsingScope usingScope = new UsingScope();

            if (!string.IsNullOrEmpty(namespaceName))
            {
                foreach (string element in namespaceName.Split('.'))
                {
                    usingScope = new UsingScope(usingScope, string.IsNullOrEmpty(usingScope.NamespaceName) ? element : usingScope.NamespaceName + "." + element);
                }
            }
            if (usings != null)
            {
                foreach (string u in usings)
                {
                    usingScope.Usings.Add(MakeReference(u));
                }
            }
            if (usingAliases != null)
            {
                foreach (var pair in usingAliases)
                {
                    usingScope.UsingAliases.Add(new KeyValuePair <string, TypeOrNamespaceReference>(pair.Key, MakeReference(pair.Value)));
                }
            }
            return(usingScope.Resolve(compilation));
        }
Ejemplo n.º 3
0
		public ParsedFile(string fileName, UsingScope rootUsingScope)
		{
			if (fileName == null)
				throw new ArgumentNullException("fileName");
			if (rootUsingScope == null)
				throw new ArgumentNullException("rootUsingScope");
			this.fileName = fileName;
			this.rootUsingScope = rootUsingScope;
		}
Ejemplo n.º 4
0
 public AliasNamespaceReference(string identifier, UsingScope parentUsingScope)
 {
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     this.identifier       = identifier;
     this.parentUsingScope = parentUsingScope;
 }
		public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration = false)
		{
			if (identifier == null)
				throw new ArgumentNullException("identifier");
			this.identifier = identifier;
			this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
			this.parentTypeDefinition = parentTypeDefinition;
			this.parentUsingScope = parentUsingScope;
			this.isInUsingDeclaration = isInUsingDeclaration;
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Creates a new nested using scope.
		/// </summary>
		/// <param name="parent">The parent using scope.</param>
		/// <param name="namespaceName">The full namespace name.</param>
		public UsingScope(UsingScope parent, string namespaceName)
		{
			if (parent == null)
				throw new ArgumentNullException("parent");
			if (namespaceName == null)
				throw new ArgumentNullException("namespaceName");
			this.parent = parent;
			this.projectContent = parent.projectContent;
			this.namespaceName = namespaceName;
		}
		public SimpleTypeOrNamespaceReference(string identifier, IList<ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
		{
			if (identifier == null)
				throw new ArgumentNullException("identifier");
			this.identifier = identifier;
			this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
			this.parentTypeDefinition = parentTypeDefinition;
			this.parentUsingScope = parentUsingScope;
			this.lookupMode = lookupMode;
		}
Ejemplo n.º 8
0
		public void AliasToImportedType2()
		{
			UsingScope mainUsingScope = new UsingScope();
			mainUsingScope.Usings.Add(MakeReference("System"));
			UsingScope nestedUsingScope = new UsingScope(mainUsingScope, "SomeNamespace");
			nestedUsingScope.UsingAliases.Add(new KeyValuePair<string, TypeOrNamespaceReference>("x", MakeReference("String")));
			var resolverWithUsing = resolver.WithCurrentUsingScope(nestedUsingScope.Resolve(compilation));
			
			TypeResolveResult trr = (TypeResolveResult)resolverWithUsing.ResolveSimpleName("x", new IType[0]);
			Assert.AreEqual("System.String", trr.Type.FullName);
		}
Ejemplo n.º 9
0
 public SimpleTypeOrNamespaceReference(string identifier, IList <ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, bool isInUsingDeclaration = false)
 {
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     this.identifier           = identifier;
     this.typeArguments        = typeArguments ?? EmptyList <ITypeReference> .Instance;
     this.parentTypeDefinition = parentTypeDefinition;
     this.parentUsingScope     = parentUsingScope;
     this.isInUsingDeclaration = isInUsingDeclaration;
 }
		public MemberTypeOrNamespaceReference(ITypeOrNamespaceReference target, string identifier, IList<ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope)
		{
			if (target == null)
				throw new ArgumentNullException("target");
			if (identifier == null)
				throw new ArgumentNullException("identifier");
			this.target = target;
			this.identifier = identifier;
			this.typeArguments = typeArguments ?? EmptyList<ITypeReference>.Instance;
			this.parentTypeDefinition = parentTypeDefinition;
			this.parentUsingScope = parentUsingScope;
		}
 public SimpleTypeOrNamespaceReference(string identifier, IList <ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope, SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type)
 {
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     this.identifier           = identifier;
     this.typeArguments        = typeArguments ?? EmptyList <ITypeReference> .Instance;
     this.parentTypeDefinition = parentTypeDefinition;
     this.parentUsingScope     = parentUsingScope;
     this.lookupMode           = lookupMode;
 }
Ejemplo n.º 12
0
        protected UsingScope MakeUsingScope(string namespaceName)
        {
            UsingScope u = new UsingScope(project);

            if (!string.IsNullOrEmpty(namespaceName))
            {
                foreach (string element in namespaceName.Split('.'))
                {
                    u = new UsingScope(u, string.IsNullOrEmpty(u.NamespaceName) ? element : u.NamespaceName + "." + element);
                }
            }
            return(u);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new nested using scope.
 /// </summary>
 /// <param name="parent">The parent using scope.</param>
 /// <param name="namespaceName">The full namespace name.</param>
 public UsingScope(UsingScope parent, string namespaceName)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     if (namespaceName == null)
     {
         throw new ArgumentNullException("namespaceName");
     }
     this.parent         = parent;
     this.projectContent = parent.projectContent;
     this.namespaceName  = namespaceName;
 }
Ejemplo n.º 14
0
 public MemberTypeOrNamespaceReference(ITypeOrNamespaceReference target, string identifier, IList <ITypeReference> typeArguments, ITypeDefinition parentTypeDefinition, UsingScope parentUsingScope)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     this.target               = target;
     this.identifier           = identifier;
     this.typeArguments        = typeArguments ?? EmptyList <ITypeReference> .Instance;
     this.parentTypeDefinition = parentTypeDefinition;
     this.parentUsingScope     = parentUsingScope;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Gets all candidate extension methods.
 /// </summary>
 /// <remarks>
 /// The results are stored in nested lists because they are grouped by using scope.
 /// That is, for "using SomeExtensions; namespace X { using MoreExtensions; ... }",
 /// the return value will be
 /// new List {
 ///    new List { all extensions from MoreExtensions },
 ///    new List { all extensions from SomeExtensions }
 /// }
 /// </remarks>
 public IList <List <IMethod> > GetExtensionMethods()
 {
     if (resolver != null)
     {
         Debug.Assert(extensionMethods == null);
         UsingScope oldUsingScope = resolver.CurrentUsingScope;
         try {
             resolver.CurrentUsingScope = usingScope;
             extensionMethods           = resolver.GetExtensionMethods(this.TargetType, methodName, typeArguments);
         } finally {
             resolver.CurrentUsingScope = oldUsingScope;
             resolver   = null;
             usingScope = null;
         }
     }
     return(extensionMethods ?? EmptyList <List <IMethod> > .Instance);
 }
Ejemplo n.º 16
0
        protected ResolveResult Resolve(string code)
        {
            CompilationUnit cu = new CSharpParser().Parse(new StringReader(code.Replace("$", "")));

            AstLocation[] dollars = FindDollarSigns(code).ToArray();
            Assert.AreEqual(2, dollars.Length, "Expected 2 dollar signs marking start+end of desired node");

            UsingScope rootUsingScope = resolver.UsingScope;

            while (rootUsingScope.Parent != null)
            {
                rootUsingScope = rootUsingScope.Parent;
            }

            ParsedFile parsedFile = new ParsedFile("test.cs", rootUsingScope);
            TypeSystemConvertVisitor convertVisitor = new TypeSystemConvertVisitor(parsedFile, resolver.UsingScope, null);

            cu.AcceptVisitor(convertVisitor, null);
            project.UpdateProjectContent(null, convertVisitor.ParsedFile.TopLevelTypeDefinitions, null, null);

            FindNodeVisitor fnv = new FindNodeVisitor(dollars[0], dollars[1]);

            cu.AcceptVisitor(fnv, null);
            Assert.IsNotNull(fnv.ResultNode, "Did not find DOM node at the specified location");

            var           navigator = new NodeListResolveVisitorNavigator(new[] { fnv.ResultNode });
            ResolveResult rr;

            using (var context = this.context.Synchronize()) {
                ResolveVisitor rv = new ResolveVisitor(new CSharpResolver(context), convertVisitor.ParsedFile, navigator);
                rv.Scan(cu);
                rr = rv.GetResolveResult(fnv.ResultNode);
            }
            Assert.IsNotNull(rr, "ResolveResult is null - did something go wrong while navigating to the target node?");
            return(rr);
        }