Ejemplo n.º 1
0
        public void UsingAliasDeclarationTest()
        {
            string program = "using TESTME=System;\n" +
                             "using myAlias=My.Name.Space;\n" +
                             "using StringCollection = System.Collections.Generic.List<string>;\n";
            CSharpParser    parser = new CSharpParser();
            CompilationUnit cu     = parser.Parse(new StringReader(program));

            Assert.IsFalse(parser.HasErrors);

            Assert.AreEqual(3, cu.Children.Count());

            Assert.IsTrue(cu.Children.ElementAt(0) is UsingAliasDeclaration);
            UsingAliasDeclaration ud = (UsingAliasDeclaration)cu.Children.ElementAt(0);

            Assert.AreEqual("TESTME", ud.Alias);
            Assert.AreEqual("System", ud.Import.ToString());

            Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration);
            ud = (UsingAliasDeclaration)cu.Children.ElementAt(1);
            Assert.AreEqual("myAlias", ud.Alias);
            Assert.AreEqual("My.Name.Space", ud.Import.ToString());

            Assert.IsTrue(cu.Children.ElementAt(2) is UsingAliasDeclaration);
            ud = (UsingAliasDeclaration)cu.Children.ElementAt(2);
            Assert.AreEqual("StringCollection", ud.Alias);
            Assert.AreEqual("System.Collections.Generic.List<string>", ud.Import.ToString());
        }
Ejemplo n.º 2
0
        public void UsingWithAliasing()
        {
            string program = "using global::System;\n" +
                             "using myAlias=global::My.Name.Space;\n" +
                             "using a::b.c;\n";
            CSharpParser    parser = new CSharpParser();
            CompilationUnit cu     = parser.Parse(new StringReader(program));

            Assert.IsFalse(parser.HasErrors);

            Assert.AreEqual(3, cu.Children.Count());

            Assert.IsTrue(cu.Children.ElementAt(0) is UsingDeclaration);
            Assert.IsFalse(cu.Children.ElementAt(0) is UsingAliasDeclaration);
            UsingDeclaration ud = (UsingDeclaration)cu.Children.ElementAt(0);

            Assert.AreEqual("global::System", ud.Namespace);

            Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration);
            UsingAliasDeclaration uad = (UsingAliasDeclaration)cu.Children.ElementAt(1);

            Assert.AreEqual("myAlias", uad.Alias);
            Assert.AreEqual("global::My.Name.Space", uad.Import.ToString());

            Assert.IsTrue(cu.Children.ElementAt(2) is UsingDeclaration);
            Assert.IsFalse(cu.Children.ElementAt(2) is UsingAliasDeclaration);
            ud = (UsingDeclaration)cu.Children.ElementAt(2);
            Assert.AreEqual("a::b.c", ud.Namespace);
        }
Ejemplo n.º 3
0
        public void UsingWithAliasing()
        {
            string program = "using global::System;\n" +
                             "using myAlias=global::My.Name.Space;\n" +
                             "using a::b.c;\n";
            CSharpParser parser     = new CSharpParser();
            SyntaxTree   syntaxTree = parser.Parse(program);

            Assert.IsFalse(parser.HasErrors);

            Assert.IsTrue(3 <= syntaxTree.Children.Count());

            Assert.IsTrue(syntaxTree.Children.ElementAt(0) is UsingDeclaration);
            Assert.IsFalse(syntaxTree.Children.ElementAt(0) is UsingAliasDeclaration);
            UsingDeclaration ud = (UsingDeclaration)syntaxTree.Children.ElementAt(0);

            Assert.AreEqual("global::System", ud.Namespace);

            Assert.IsTrue(syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(1) is UsingAliasDeclaration);
            UsingAliasDeclaration uad = (UsingAliasDeclaration)syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(1);

            Assert.AreEqual("myAlias", uad.Alias);
            Assert.AreEqual("global::My.Name.Space", uad.Import.ToString());

            Assert.IsTrue(syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(2) is UsingDeclaration);
            Assert.IsFalse(syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(2) is UsingAliasDeclaration);
            ud = (UsingDeclaration)syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(2);
            Assert.AreEqual("a::b.c", ud.Namespace);
        }
Ejemplo n.º 4
0
        public void UsingAliasDeclarationTest()
        {
            string program = "using TESTME=System;\n" +
                             "using myAlias=My.Name.Space;\n" +
                             "using StringCollection = System.Collections.Generic.List<string>;\n";
            CSharpParser parser     = new CSharpParser();
            SyntaxTree   syntaxTree = parser.Parse(program);

            Assert.IsFalse(parser.HasErrors);

            Assert.IsTrue(3 <= syntaxTree.Children.Count());

            Assert.IsTrue(syntaxTree.Children.ElementAt(0) is UsingAliasDeclaration);
            UsingAliasDeclaration ud = (UsingAliasDeclaration)syntaxTree.Children.ElementAt(0);

            Assert.AreEqual("TESTME", ud.Alias);
            Assert.AreEqual("System", ud.Import.ToString());

            Assert.IsTrue(syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(1) is UsingAliasDeclaration);
            ud = (UsingAliasDeclaration)syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(1);
            Assert.AreEqual("myAlias", ud.Alias);
            Assert.AreEqual("My.Name.Space", ud.Import.ToString());

            Assert.IsTrue(syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(2) is UsingAliasDeclaration);
            ud = (UsingAliasDeclaration)syntaxTree.Children.Where(c => c.Role != Roles.NewLine).ElementAt(2);
            Assert.AreEqual("StringCollection", ud.Alias);
            Assert.AreEqual("System.Collections.Generic.List<string>", ud.Import.ToString());
        }
Ejemplo n.º 5
0
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(usingAliasDeclaration);
     }
 }
Ejemplo n.º 6
0
        public UnifiedElement VisitUsingAliasDeclaration(
            UsingAliasDeclaration dec, object data)
        {
            var name   = dec.Alias;
            var import = dec.Import.TryAcceptForExpression(this);

            return(UnifiedImport.Create(import, name));
        }
Ejemplo n.º 7
0
		public override IUnresolvedEntity VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration, object data)
		{
			TypeOrNamespaceReference u = usingDeclaration.Import.ToTypeReference(SimpleNameLookupMode.TypeInUsingDeclaration) as TypeOrNamespaceReference;
			if (u != null) {
				if (interningProvider != null)
					u = interningProvider.Intern(u);
				usingScope.UsingAliases.Add(new KeyValuePair<string, TypeOrNamespaceReference>(usingDeclaration.Alias, u));
			}
			return null;
		}
Ejemplo n.º 8
0
 private void handleUsing(UsingAliasDeclaration alias)
 {
     _writer.WriteUsingAlias(
         new UsingAlias(
             _file,
             alias.Alias,
             signatureFrom(alias.Import),
             alias.Import.StartLocation.Line,
             alias.Import.StartLocation.Column)
         .SetEndPosition(
             alias.SemicolonToken.EndLocation.Line,
             alias.SemicolonToken.EndLocation.Column));
 }
		public virtual void VisitUsingAliasDeclaration (UsingAliasDeclaration usingDeclaration)
		{
			VisitChildren (usingDeclaration);
		}
Ejemplo n.º 10
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            UsingAliasDeclaration o = other as UsingAliasDeclaration;

            return(o != null && MatchString(this.Alias, o.Alias) && this.Import.DoMatch(o.Import, match));
        }
Ejemplo n.º 11
0
 public void VisitUsingAliasDeclaration(UsingAliasDeclaration node)
 {
     NotSupported(node);
 }
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration syntax)
 {
     _underlyingVisitor.VisitUsingAliasDeclaration(syntax);
 }
 /// <inheritdoc/>
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration syntax)
 {
     VisitNode(syntax);
 }
Ejemplo n.º 14
0
		public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
		{
			StartNode(usingAliasDeclaration);
			WriteKeyword(UsingAliasDeclaration.UsingKeywordRole);
			WriteIdentifier(usingAliasDeclaration.GetChildByRole(UsingAliasDeclaration.AliasRole), BoxedTextColor.Text);
			Space(policy.SpaceAroundEqualityOperator);
			WriteToken(Roles.Assign, BoxedTextColor.Operator);
			Space(policy.SpaceAroundEqualityOperator);
			usingAliasDeclaration.Import.AcceptVisitor(this);
			SaveDeclarationOffset();
			Semicolon();
			EndNode(usingAliasDeclaration);
		}
Ejemplo n.º 15
0
 public Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     return(CreateDummy(usingAliasDeclaration));
 }
Ejemplo n.º 16
0
        public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
        {
            JsonObject declaration = new JsonObject();
            declaration.Comment = "VisitUsingAliasDeclaration";

            AddKeyword(declaration, UsingAliasDeclaration.UsingKeywordRole);
            declaration.AddJsonValue("identifier", GetIdentifier(usingAliasDeclaration.GetChildByRole(UsingAliasDeclaration.AliasRole)));
            declaration.AddJsonValue("assign-token", GetKeyword(Roles.Assign));
            declaration.AddJsonValue("import", GenTypeInfo(usingAliasDeclaration.Import));

            Push(declaration);
            //implement already, but not tested
            throw new FirstTimeUseException();
        }
Ejemplo n.º 17
0
		public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
		{
			StartNode(usingAliasDeclaration);
			WriteKeyword(UsingAliasDeclaration.UsingKeywordRole);
			WriteIdentifier(usingAliasDeclaration.Alias, UsingAliasDeclaration.AliasRole);
			Space(policy.SpaceAroundEqualityOperator);
			WriteToken(Roles.Assign);
			Space(policy.SpaceAroundEqualityOperator);
			usingAliasDeclaration.Import.AcceptVisitor(this);
			Semicolon();
			EndNode(usingAliasDeclaration);
		}
Ejemplo n.º 18
0
 public virtual Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 19
0
        public override List <Change> PerformChanges(RefactoringOptions options, object properties)
        {
            List <Change>    result          = new List <Change> ();
            ICompilationUnit compilationUnit = options.ParseDocument().CompilationUnit;

            Mono.TextEditor.TextEditorData textEditorData = options.GetTextEditorData();
            int minOffset = int.MaxValue;

            foreach (IUsing u in compilationUnit.Usings)
            {
                if (u.IsFromNamespace)
                {
                    continue;
                }
                int offset = textEditorData.Document.LocationToOffset(u.Region.Start.Line, u.Region.Start.Column);
                TextReplaceChange change = new TextReplaceChange()
                {
                    FileName     = options.Document.FileName,
                    Offset       = offset,
                    RemovedChars = textEditorData.Document.LocationToOffset(u.Region.End.Line, u.Region.End.Column) - offset
                };
                Mono.TextEditor.LineSegment line = textEditorData.Document.GetLineByOffset(change.Offset);
                if (line != null && line.EditableLength == change.RemovedChars)
                {
                    change.RemovedChars += line.DelimiterLength;
                }
                result.Add(change);
                minOffset = Math.Min(minOffset, offset);
            }
            StringBuilder output = new StringBuilder();
            List <IUsing> usings = new List <IUsing> (compilationUnit.Usings);

            usings.Sort(UsingComparer);
            INRefactoryASTProvider astProvider = options.GetASTProvider();

            foreach (IUsing u in usings)
            {
                AstNode declaration;
                if (u.IsFromNamespace)
                {
                    continue;
                }
                if (u.Aliases.Any())
                {
                    KeyValuePair <string, IReturnType> alias = u.Aliases.First();
                    declaration = new UsingAliasDeclaration(alias.Key, alias.Value.ConvertToTypeReference());
                }
                else
                {
                    declaration = new UsingDeclaration(u.Namespaces.First());
                }
                output.Append(astProvider.OutputNode(options.Dom, declaration));
            }
            TextReplaceChange insertSortedUsings = new TextReplaceChange()
            {
                FileName     = options.Document.FileName,
                Offset       = minOffset,
                InsertedText = output.ToString()
            };

            result.Add(insertSortedUsings);
            return(result);
        }
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw NotSupportedToConsistency();
 }
Ejemplo n.º 21
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, ILTranslationContext data)
 => Enumerable.Empty <Syntax>();
Ejemplo n.º 22
0
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
 }
Ejemplo n.º 23
0
 public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 24
0
		public override List<Change> PerformChanges (RefactoringOptions options, object properties)
		{
			List<Change> result = new List<Change> ();
			ICompilationUnit compilationUnit = options.ParseDocument ().CompilationUnit;
			Mono.TextEditor.TextEditorData textEditorData = options.GetTextEditorData ();
			int minOffset = int.MaxValue;
			foreach (IUsing u in compilationUnit.Usings) {
				if (u.IsFromNamespace)
					continue;
				int offset = textEditorData.Document.LocationToOffset (u.Region.Start.Line, u.Region.Start.Column);
				TextReplaceChange change = new TextReplaceChange () {
					FileName = options.Document.FileName,
					Offset = offset,
					RemovedChars = textEditorData.Document.LocationToOffset (u.Region.End.Line, u.Region.End.Column) - offset
				};
				Mono.TextEditor.LineSegment line = textEditorData.Document.GetLineByOffset (change.Offset);
				if (line != null && line.EditableLength == change.RemovedChars)
					change.RemovedChars += line.DelimiterLength;
				result.Add (change);
				minOffset = Math.Min (minOffset, offset);
			}
			StringBuilder output = new StringBuilder ();
			List<IUsing> usings = new List<IUsing> (compilationUnit.Usings);
			usings.Sort (UsingComparer);
			INRefactoryASTProvider astProvider = options.GetASTProvider ();
			foreach (IUsing u in usings) {
				AstNode declaration;
				if (u.IsFromNamespace)
					continue;
				if (u.Aliases.Any ()) {
					KeyValuePair<string, IReturnType> alias = u.Aliases.First ();
					declaration = new UsingAliasDeclaration (alias.Key, alias.Value.ConvertToTypeReference ());
				} else {
					declaration = new UsingDeclaration (u.Namespaces.First ());
				}
				output.Append (astProvider.OutputNode (options.Dom, declaration));
			}
			TextReplaceChange insertSortedUsings = new TextReplaceChange () {
				FileName = options.Document.FileName,
				Offset = minOffset,
				InsertedText = output.ToString ()
			};
			result.Add (insertSortedUsings);
			return result;
		}
Ejemplo n.º 25
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     InvalideXmlComments();
     base.VisitUsingAliasDeclaration(usingDeclaration);
 }
Ejemplo n.º 26
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     ForceSpacesAfter(usingDeclaration.UsingToken, true);
     ForceSpacesAround(usingDeclaration.AssignToken, policy.SpaceAroundAssignment);
     FixSemicolon(usingDeclaration.SemicolonToken);
 }
Ejemplo n.º 27
0
 public RedILNode VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, State data)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 28
0
		public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
		{
			if (!(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling  is UsingAliasDeclaration)) {
				EnsureBlankLinesBefore(usingDeclaration, policy.BlankLinesBeforeUsings);
			}
			if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling  is UsingAliasDeclaration)) {
				EnsureBlankLinesAfter(usingDeclaration, policy.BlankLinesAfterUsings);
			}
		}
Ejemplo n.º 29
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     if (usingDeclaration.PrevSibling != null && !(usingDeclaration.PrevSibling is UsingDeclaration || usingDeclaration.PrevSibling  is UsingAliasDeclaration)) {
         EnsureBlankLinesBefore(usingDeclaration, policy.BlankLinesBeforeUsings);
     } else if (!(usingDeclaration.NextSibling is UsingDeclaration || usingDeclaration.NextSibling  is UsingAliasDeclaration)) {
         FixIndentationForceNewLine(usingDeclaration.StartLocation);
         EnsureBlankLinesAfter(usingDeclaration, policy.BlankLinesAfterUsings);
     } else {
         FixIndentationForceNewLine(usingDeclaration.StartLocation);
     }
 }
Ejemplo n.º 30
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     ForceSpacesAfter(usingDeclaration.UsingToken, true);
     FixSemicolon(usingDeclaration.SemicolonToken);
 }
Ejemplo n.º 31
0
 public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, int data)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 32
0
			public override void Visit(UsingAliasNamespace uan)
			{
				var ud = new UsingAliasDeclaration();
				var loc = LocationsBag.GetLocations(uan);
				
				ud.AddChild(new CSharpTokenNode(Convert(uan.Location), UsingAliasDeclaration.UsingKeywordRole), UsingAliasDeclaration.UsingKeywordRole);
				ud.AddChild(Identifier.Create(uan.Alias.Value, Convert(uan.Alias.Location)), UsingAliasDeclaration.AliasRole);
				if (loc != null)
					ud.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Assign), Roles.Assign);
				if (uan.NamespaceExpression != null)
					ud.AddChild(ConvertToType(uan.NamespaceExpression), UsingAliasDeclaration.ImportRole);
				if (loc != null && loc.Count > 1)
					ud.AddChild(new CSharpTokenNode(Convert(loc [1]), Roles.Semicolon), Roles.Semicolon);
				AddToNamespace(ud);
			}
Ejemplo n.º 33
0
 public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 34
0
			public override void Visit (UsingsBag.AliasUsing u)
			{
				UsingAliasDeclaration ud = new UsingAliasDeclaration ();
				ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingAliasDeclaration.Roles.Keyword);
				ud.AddChild (new Identifier (u.Identifier.Value, Convert (u.Identifier.Location)), UsingAliasDeclaration.AliasRole);
				ud.AddChild (new CSharpTokenNode (Convert (u.AssignLocation), 1), UsingAliasDeclaration.Roles.Assign);
				ud.AddChild (new Identifier (u.Nspace.Name, Convert (u.Nspace.Location)), UsingAliasDeclaration.Roles.Identifier);
				ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon);
				AddToNamespace (ud);
			}
Ejemplo n.º 35
0
 public JNode VisitUsingAliasDeclaration(UsingAliasDeclaration node)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 36
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
 }
Ejemplo n.º 37
0
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
 }