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()); }
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); }
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); }
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()); }
public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { if (this.ThrowException) { throw (Exception)this.CreateException(usingAliasDeclaration); } }
public UnifiedElement VisitUsingAliasDeclaration( UsingAliasDeclaration dec, object data) { var name = dec.Alias; var import = dec.Import.TryAcceptForExpression(this); return(UnifiedImport.Create(import, name)); }
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; }
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); }
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)); }
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); }
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); }
public Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { return(CreateDummy(usingAliasDeclaration)); }
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(); }
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); }
public virtual Node VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { throw new System.NotImplementedException(); }
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(); }
IEnumerable <Syntax> IAstVisitor <ILTranslationContext, IEnumerable <Syntax> > .VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, ILTranslationContext data) => Enumerable.Empty <Syntax>();
public virtual void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { }
public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { throw new NotImplementedException(); }
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 usingDeclaration) { InvalideXmlComments(); base.VisitUsingAliasDeclaration(usingDeclaration); }
public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration) { ForceSpacesAfter(usingDeclaration.UsingToken, true); ForceSpacesAround(usingDeclaration.AssignToken, policy.SpaceAroundAssignment); FixSemicolon(usingDeclaration.SemicolonToken); }
public RedILNode VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, State data) { throw new System.NotImplementedException(); }
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); } }
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); } }
public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration) { ForceSpacesAfter(usingDeclaration.UsingToken, true); FixSemicolon(usingDeclaration.SemicolonToken); }
public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, int data) { throw new NotSupportedException(); }
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); }
public StringBuilder VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { throw new NotImplementedException(); }
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); }
public JNode VisitUsingAliasDeclaration(UsingAliasDeclaration node) { throw new NotImplementedException(); }
public override void VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration) { }