コード例 #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());
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #5
0
ファイル: Visitor.Exception.cs プロジェクト: Dim0N22/Builder
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(usingAliasDeclaration);
     }
 }
コード例 #6
0
        public UnifiedElement VisitUsingAliasDeclaration(
            UsingAliasDeclaration dec, object data)
        {
            var name   = dec.Alias;
            var import = dec.Import.TryAcceptForExpression(this);

            return(UnifiedImport.Create(import, name));
        }
コード例 #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;
		}
コード例 #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);
		}
コード例 #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));
        }
コード例 #11
0
ファイル: Lower.cs プロジェクト: evanw/minisharp
 public void VisitUsingAliasDeclaration(UsingAliasDeclaration node)
 {
     NotSupported(node);
 }
コード例 #12
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration syntax)
 {
     _underlyingVisitor.VisitUsingAliasDeclaration(syntax);
 }
コード例 #13
0
 /// <inheritdoc/>
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration syntax)
 {
     VisitNode(syntax);
 }
コード例 #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);
		}
コード例 #15
0
 public Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     return(CreateDummy(usingAliasDeclaration));
 }
コード例 #16
0
ファイル: AstCsToJson.cs プロジェクト: CompilerKit/CodeWalk
        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();
        }
コード例 #17
0
ファイル: CSharpOutputVisitor.cs プロジェクト: x-strong/ILSpy
		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);
		}
コード例 #18
0
 public virtual Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new System.NotImplementedException();
 }
コード例 #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);
        }
コード例 #20
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw NotSupportedToConsistency();
 }
コード例 #21
0
 IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, ILTranslationContext data)
 => Enumerable.Empty <Syntax>();
コード例 #22
0
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
 }
コード例 #23
0
ファイル: TempEmitter.cs プロジェクト: yctri/Bridge
 public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new NotImplementedException();
 }
コード例 #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;
		}
コード例 #25
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     InvalideXmlComments();
     base.VisitUsingAliasDeclaration(usingDeclaration);
 }
コード例 #26
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     ForceSpacesAfter(usingDeclaration.UsingToken, true);
     ForceSpacesAround(usingDeclaration.AssignToken, policy.SpaceAroundAssignment);
     FixSemicolon(usingDeclaration.SemicolonToken);
 }
コード例 #27
0
 public RedILNode VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, State data)
 {
     throw new System.NotImplementedException();
 }
コード例 #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);
			}
		}
コード例 #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);
     }
 }
コード例 #30
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
     ForceSpacesAfter(usingDeclaration.UsingToken, true);
     FixSemicolon(usingDeclaration.SemicolonToken);
 }
コード例 #31
0
 public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, int data)
 {
     throw new NotSupportedException();
 }
コード例 #32
0
ファイル: CSharpParser.cs プロジェクト: 0xb1dd1e/NRefactory
			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);
			}
コード例 #33
0
 public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
     throw new NotImplementedException();
 }
コード例 #34
0
ファイル: CSharpParser.cs プロジェクト: pgoron/monodevelop
			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);
			}
コード例 #35
0
 public JNode VisitUsingAliasDeclaration(UsingAliasDeclaration node)
 {
     throw new NotImplementedException();
 }
コード例 #36
0
 public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration)
 {
 }
コード例 #37
0
ファイル: Visitor.Empty.cs プロジェクト: txdv/Builder
 public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
 {
 }