Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: icsharpcode/NRefactory
base: 14ca306
...
head fork: icsharpcode/NRefactory
compare: 1576e08
  • 4 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
7 ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
@@ -366,6 +366,13 @@ void AddChildUnsafe (AstNode child, Role role)
lastChild = child;
}
}
+
+ public void InsertChildsBefore<T>(AstNode nextSibling, Role<T> role, params T[] child) where T : AstNode
+ {
+ foreach (var cur in child) {
+ InsertChildBefore(nextSibling, cur, role);
+ }
+ }
public void InsertChildBefore<T> (AstNode nextSibling, T child, Role<T> role) where T : AstNode
{
View
51 ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
@@ -49,11 +49,26 @@ public virtual void VisitCompilationUnit (CompilationUnit unit)
VisitChildren (unit);
}
- public virtual void VisitComment (Comment comment)
+ public virtual void VisitComment(Comment comment)
{
- VisitChildren (comment);
+ VisitChildren(comment);
}
-
+
+ public virtual void VisitNewLine(NewLineNode newLineNode)
+ {
+ VisitChildren(newLineNode);
+ }
+
+ public virtual void VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ VisitChildren(whitespaceNode);
+ }
+
+ public virtual void VisitText(TextNode textNode)
+ {
+ VisitChildren(textNode);
+ }
+
public virtual void VisitDocumentationReference (DocumentationReference documentationReference)
{
VisitChildren (documentationReference);
@@ -637,6 +652,21 @@ public virtual T VisitComment (Comment comment)
return VisitChildren (comment);
}
+ public virtual T VisitNewLine(NewLineNode newLineNode)
+ {
+ return VisitChildren(newLineNode);
+ }
+
+ public virtual T VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ return VisitChildren(whitespaceNode);
+ }
+
+ public virtual T VisitText(TextNode textNode)
+ {
+ return VisitChildren(textNode);
+ }
+
public virtual T VisitDocumentationReference (DocumentationReference documentationReference)
{
return VisitChildren (documentationReference);
@@ -1220,6 +1250,21 @@ public virtual S VisitComment (Comment comment, T data)
return VisitChildren (comment, data);
}
+ public virtual S VisitNewLine(NewLineNode newLineNode, T data)
+ {
+ return VisitChildren(newLineNode, data);
+ }
+
+ public virtual S VisitWhitespace(WhitespaceNode whitespaceNode, T data)
+ {
+ return VisitChildren(whitespaceNode, data);
+ }
+
+ public virtual S VisitText(TextNode textNode, T data)
+ {
+ return VisitChildren(textNode, data);
+ }
+
public virtual S VisitDocumentationReference (DocumentationReference documentationReference, T data)
{
return VisitChildren (documentationReference, data);
View
132 ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs
@@ -0,0 +1,132 @@
+using System;
+namespace ICSharpCode.NRefactory.CSharp
+{
+ public enum NewLineType {
+ Unix,
+ Windows,
+ Mac
+ }
+
+ /// <summary>
+ /// A New line node represents a line break in the text.
+ /// </summary>
+ public abstract class NewLineNode : AstNode
+ {
+ public override NodeType NodeType {
+ get {
+ return NodeType.Whitespace;
+ }
+ }
+
+ public abstract NewLineType NewLineType {
+ get;
+ }
+
+ TextLocation startLocation;
+ public override TextLocation StartLocation {
+ get {
+ return startLocation;
+ }
+ }
+
+ public override TextLocation EndLocation {
+ get {
+ return new TextLocation (startLocation.Line + 1, 1);
+ }
+ }
+
+ public NewLineNode() : this (TextLocation.Empty)
+ {
+ }
+
+ public NewLineNode(TextLocation startLocation)
+ {
+ this.startLocation = startLocation;
+ }
+
+ public override void AcceptVisitor(IAstVisitor visitor)
+ {
+ visitor.VisitNewLine (this);
+ }
+
+ public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
+ {
+ return visitor.VisitNewLine (this);
+ }
+
+ public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
+ {
+ return visitor.VisitNewLine (this, data);
+ }
+ }
+
+ public class UnixNewLine : NewLineNode
+ {
+ public override NewLineType NewLineType {
+ get {
+ return NewLineType.Unix;
+ }
+ }
+
+ public UnixNewLine()
+ {
+ }
+
+ public UnixNewLine(TextLocation startLocation) : base (startLocation)
+ {
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ var o = other as UnixNewLine;
+ return o != null;
+ }
+ }
+
+ public class WindowsNewLine : NewLineNode
+ {
+ public override NewLineType NewLineType {
+ get {
+ return NewLineType.Windows;
+ }
+ }
+
+ public WindowsNewLine()
+ {
+ }
+
+ public WindowsNewLine(TextLocation startLocation) : base (startLocation)
+ {
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ var o = other as WindowsNewLine;
+ return o != null;
+ }
+ }
+
+ public class MacNewLine : NewLineNode
+ {
+ public override NewLineType NewLineType {
+ get {
+ return NewLineType.Mac;
+ }
+ }
+
+ public MacNewLine()
+ {
+ }
+
+ public MacNewLine(TextLocation startLocation) : base (startLocation)
+ {
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ var o = other as MacNewLine;
+ return o != null;
+ }
+ }
+}
+
View
94 ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TextNode.cs
@@ -0,0 +1,94 @@
+//
+// TextNode.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+namespace ICSharpCode.NRefactory.CSharp
+{
+ /// <summary>
+ /// A text node contains text without syntactic or semantic information.
+ /// (non parseable part of a text)
+ /// </summary>
+ public class TextNode : AstNode
+ {
+ public override NodeType NodeType {
+ get {
+ return NodeType.Whitespace;
+ }
+ }
+
+ public string Text {
+ get;
+ set;
+ }
+
+ TextLocation startLocation;
+ public override TextLocation StartLocation {
+ get {
+ return startLocation;
+ }
+ }
+
+ TextLocation endLocation;
+ public override TextLocation EndLocation {
+ get {
+ return endLocation;
+ }
+ }
+
+ public TextNode(string text) : this (text, TextLocation.Empty, TextLocation.Empty)
+ {
+ }
+
+ public TextNode(string text, TextLocation startLocation, TextLocation endLocation)
+ {
+ this.Text = text;
+ this.startLocation = startLocation;
+ this.endLocation = endLocation;
+ }
+
+ public override void AcceptVisitor(IAstVisitor visitor)
+ {
+ visitor.VisitText (this);
+ }
+
+ public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
+ {
+ return visitor.VisitText (this);
+ }
+
+ public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
+ {
+ return visitor.VisitText (this, data);
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ var o = other as TextNode;
+ return o != null && o.Text == Text;
+ }
+ }
+}
+
View
91 ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/WhitespaceNode.cs
@@ -0,0 +1,91 @@
+//
+// WhitespaceNode.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+namespace ICSharpCode.NRefactory.CSharp
+{
+ /// <summary>
+ /// A Whitespace node contains only whitespaces.
+ /// </summary>
+ public class WhitespaceNode : AstNode
+ {
+ public override NodeType NodeType {
+ get {
+ return NodeType.Whitespace;
+ }
+ }
+
+ public string WhiteSpaceText {
+ get;
+ set;
+ }
+
+ TextLocation startLocation;
+ public override TextLocation StartLocation {
+ get {
+ return startLocation;
+ }
+ }
+
+ public override TextLocation EndLocation {
+ get {
+ return new TextLocation (startLocation.Line, startLocation.Column + WhiteSpaceText.Length);
+ }
+ }
+
+ public WhitespaceNode(string whiteSpaceText) : this (whiteSpaceText, TextLocation.Empty)
+ {
+ }
+
+ public WhitespaceNode(string whiteSpaceText, TextLocation startLocation)
+ {
+ this.WhiteSpaceText = WhiteSpaceText;
+ this.startLocation = startLocation;
+ }
+
+ public override void AcceptVisitor(IAstVisitor visitor)
+ {
+ visitor.VisitWhitespace (this);
+ }
+
+ public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
+ {
+ return visitor.VisitWhitespace (this);
+ }
+
+ public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
+ {
+ return visitor.VisitWhitespace (this, data);
+ }
+
+ protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
+ {
+ var o = other as WhitespaceNode;
+ return o != null && o.WhiteSpaceText == WhiteSpaceText;
+ }
+ }
+}
+
View
9 ICSharpCode.NRefactory.CSharp/Ast/IAstVisitor.cs
@@ -137,6 +137,9 @@ public interface IAstVisitor
void VisitPrimitiveType(PrimitiveType primitiveType);
void VisitComment(Comment comment);
+ void VisitNewLine(NewLineNode newLineNode);
+ void VisitWhitespace(WhitespaceNode whitespaceNode);
+ void VisitText(TextNode textNode);
void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
void VisitDocumentationReference(DocumentationReference documentationReference);
@@ -265,6 +268,9 @@ public interface IAstVisitor<out S>
S VisitPrimitiveType(PrimitiveType primitiveType);
S VisitComment(Comment comment);
+ S VisitWhitespace(WhitespaceNode whitespaceNode);
+ S VisitText(TextNode textNode);
+ S VisitNewLine(NewLineNode newLineNode);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
S VisitDocumentationReference(DocumentationReference documentationReference);
@@ -393,6 +399,9 @@ public interface IAstVisitor<in T, out S>
S VisitPrimitiveType(PrimitiveType primitiveType, T data);
S VisitComment(Comment comment, T data);
+ S VisitNewLine(NewLineNode newLineNode, T data);
+ S VisitWhitespace(WhitespaceNode whitespaceNode, T data);
+ S VisitText(TextNode textNode, T data);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data);
S VisitDocumentationReference(DocumentationReference documentationReference, T data);
View
33 ICSharpCode.NRefactory.CSharp/Ast/ObservableAstVisitor.cs
@@ -60,9 +60,38 @@ S VisitChildren (AstNode node, T data)
handler (comment, data);
return VisitChildren (comment, data);
}
-
- public event Action<PreProcessorDirective, T> PreProcessorDirectiveVisited;
+ public event Action<NewLineNode, T> NewLineVisited;
+
+ S IAstVisitor<T, S>.VisitNewLine(NewLineNode newLineNode, T data)
+ {
+ var handler = NewLineVisited;
+ if (handler != null)
+ handler(newLineNode, data);
+ return VisitChildren(newLineNode, data);
+ }
+
+ public event Action<WhitespaceNode, T> WhitespaceVisited;
+
+ S IAstVisitor<T, S>.VisitWhitespace(WhitespaceNode whitespace, T data)
+ {
+ var handler = WhitespaceVisited;
+ if (handler != null)
+ handler(whitespace, data);
+ return VisitChildren(whitespace, data);
+ }
+
+ public event Action<TextNode, T> TextVisited;
+
+ S IAstVisitor<T, S>.VisitText(TextNode textNode, T data)
+ {
+ var handler = TextVisited;
+ if (handler != null)
+ handler(textNode, data);
+ return VisitChildren(textNode, data);
+ }
+
+ public event Action<PreProcessorDirective, T> PreProcessorDirectiveVisited;
S IAstVisitor<T, S>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective, T data)
{
var handler = PreProcessorDirectiveVisited;
View
3  ICSharpCode.NRefactory.CSharp/Ast/Roles.cs
@@ -68,6 +68,9 @@ public static class Roles
public static readonly TokenRole Colon = new TokenRole (":");
public static readonly TokenRole DoubleColon = new TokenRole ("::");
public static readonly Role<Comment> Comment = new Role<Comment> ("Comment");
+ public static readonly Role<NewLineNode> NewLine = new Role<NewLineNode> ("NewLine");
+ public static readonly Role<WhitespaceNode> Whitespace = new Role<WhitespaceNode> ("Whitespace");
+ public static readonly Role<TextNode> Text = new Role<TextNode> ("Text");
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective");
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error");
View
2  ICSharpCode.NRefactory.CSharp/Completion/CSharpParameterCompletionEngine.cs
@@ -173,6 +173,8 @@ public IParameterDataProvider GetParameterDataProvider(int offset, char completi
}
if (invoke.Node is ObjectCreateExpression) {
var createType = ResolveExpression(((ObjectCreateExpression)invoke.Node).Type, invoke.Unit);
+ if (createType.Item1.Type.Kind == TypeKind.Unknown)
+ return null;
return factory.CreateConstructorProvider(document.GetOffset(invoke.Node.StartLocation), createType.Item1.Type);
}
View
211 ICSharpCode.NRefactory.CSharp/Formatter/GeneratedCodeSettings.cs
@@ -0,0 +1,211 @@
+//
+// GeneratedCodeSettings.cs
+//
+// Author:
+// Mike Krüger <mkrueger@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+
+namespace ICSharpCode.NRefactory.CSharp
+{
+ public enum GeneratedCodeMember
+ {
+ Unknown,
+
+ StaticFields,
+ InstanceFields,
+ StaticProperties,
+ InstanceProperties,
+ Indexer,
+ Constructors,
+ StaticMethods,
+ InstanceMethods,
+ StaticEvents,
+ InstanceEvents,
+ Operators,
+ NestedTypes
+ }
+
+ public class GeneratedCodeSettings
+ {
+ List<GeneratedCodeMember> codeMemberOrder;
+
+ public List<GeneratedCodeMember> CodeMemberOrder {
+ get {
+ return codeMemberOrder;
+ }
+ set {
+ codeMemberOrder = value;
+ }
+ }
+
+ public bool GenerateCategoryComments {
+ get;
+ set;
+ }
+
+ public bool SubOrderAlphabetical {
+ get;
+ set;
+ }
+
+ public void Apply (AstNode rootNode)
+ {
+ if (rootNode == null)
+ throw new ArgumentNullException ("rootNode");
+ rootNode.AcceptVisitor (new GenerateCodeVisitior (this));
+ }
+
+ public virtual string GetCategoryLabel(GeneratedCodeMember memberCategory)
+ {
+ switch (memberCategory) {
+ case GeneratedCodeMember.StaticFields:
+ return "Static Fields";
+ case GeneratedCodeMember.InstanceFields:
+ return "Fields";
+ case GeneratedCodeMember.StaticProperties:
+ return "Static Properties";
+ case GeneratedCodeMember.InstanceProperties:
+ return "Properties";
+ case GeneratedCodeMember.Indexer:
+ return "Indexer";
+ case GeneratedCodeMember.Constructors:
+ return "Constructors";
+ case GeneratedCodeMember.StaticMethods:
+ return "Static Methods";
+ case GeneratedCodeMember.InstanceMethods:
+ return "Methods";
+ case GeneratedCodeMember.StaticEvents:
+ return "Static Events";
+ case GeneratedCodeMember.InstanceEvents:
+ return "Events";
+ case GeneratedCodeMember.Operators:
+ return "Operators";
+ case GeneratedCodeMember.NestedTypes:
+ return "Nested Types";
+ }
+ return null;
+ }
+
+ class GenerateCodeVisitior : DepthFirstAstVisitor
+ {
+ GeneratedCodeSettings settings;
+
+ public GenerateCodeVisitior(GeneratedCodeSettings settings)
+ {
+ if (settings == null)
+ throw new ArgumentNullException("settings");
+ this.settings = settings;
+ }
+
+ GeneratedCodeMember GetCodeMemberCategory(EntityDeclaration x)
+ {
+ bool isStatic = x.HasModifier(Modifiers.Static) || x.HasModifier(Modifiers.Const);
+ if (x is FieldDeclaration)
+ return isStatic ? GeneratedCodeMember.StaticFields : GeneratedCodeMember.InstanceFields;
+ if (x is IndexerDeclaration)
+ return GeneratedCodeMember.Indexer;
+ if (x is PropertyDeclaration)
+ return isStatic ? GeneratedCodeMember.StaticProperties : GeneratedCodeMember.InstanceProperties;
+ if (x is ConstructorDeclaration || x is DestructorDeclaration)
+ return GeneratedCodeMember.Constructors;
+ if (x is MethodDeclaration)
+ return isStatic ? GeneratedCodeMember.StaticMethods : GeneratedCodeMember.InstanceMethods;
+ if (x is OperatorDeclaration)
+ return GeneratedCodeMember.Operators;
+ if (x is EventDeclaration)
+ return isStatic ? GeneratedCodeMember.StaticEvents : GeneratedCodeMember.InstanceEvents;
+
+ if (x is TypeDeclaration)
+ return GeneratedCodeMember.NestedTypes;
+
+ return GeneratedCodeMember.Unknown;
+ }
+
+ public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
+ {
+ if (typeDeclaration.ClassType == ClassType.Enum)
+ return;
+ var entities = new List<EntityDeclaration>(typeDeclaration.Members);
+ entities.Sort((x, y) => {
+ int i1 = settings.CodeMemberOrder.IndexOf(GetCodeMemberCategory(x));
+ int i2 = settings.CodeMemberOrder.IndexOf(GetCodeMemberCategory(y));
+ if (i1 != i2)
+ return i1.CompareTo(i2);
+ if (settings.SubOrderAlphabetical)
+ return (x.Name ?? "").CompareTo((y.Name ?? ""));
+ return entities.IndexOf(x).CompareTo(entities.IndexOf(y));
+ });
+ typeDeclaration.Members.Clear();
+ typeDeclaration.Members.AddRange(entities);
+
+ if (settings.GenerateCategoryComments) {
+ var curCat = GeneratedCodeMember.Unknown;
+ foreach (var mem in entities) {
+ var cat = GetCodeMemberCategory(mem);
+ if (cat == curCat)
+ continue;
+ curCat = cat;
+ var label = settings.GetCategoryLabel(curCat);
+ if (string.IsNullOrEmpty(label))
+ continue;
+
+ var cmt = new Comment("", CommentType.SingleLine);
+ var cmt2 = new Comment(" " + label, CommentType.SingleLine);
+ var cmt3 = new Comment("", CommentType.SingleLine);
+ mem.Parent.InsertChildsBefore(mem, Roles.Comment, cmt, cmt2, cmt3);
+ mem.Parent.InsertChildBefore(cmt, new UnixNewLine(), Roles.NewLine);
+ mem.Parent.InsertChildAfter(cmt3, new UnixNewLine(), Roles.NewLine);
+ }
+ }
+ }
+ }
+
+ static Lazy<GeneratedCodeSettings> defaultSettings = new Lazy<GeneratedCodeSettings>(
+ () => new GeneratedCodeSettings() {
+ CodeMemberOrder = new List<GeneratedCodeMember>() {
+ GeneratedCodeMember.StaticFields,
+ GeneratedCodeMember.InstanceFields,
+ GeneratedCodeMember.StaticProperties,
+ GeneratedCodeMember.InstanceProperties,
+ GeneratedCodeMember.Indexer,
+ GeneratedCodeMember.Constructors,
+ GeneratedCodeMember.StaticMethods,
+ GeneratedCodeMember.InstanceMethods,
+ GeneratedCodeMember.StaticEvents,
+ GeneratedCodeMember.InstanceEvents,
+ GeneratedCodeMember.Operators,
+ GeneratedCodeMember.NestedTypes
+ },
+ GenerateCategoryComments = true,
+ SubOrderAlphabetical = true
+ });
+
+ public static GeneratedCodeSettings Default {
+ get {
+ return defaultSettings.Value;
+ }
+ }
+ }
+}
View
4 ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
@@ -364,6 +364,10 @@
<Compile Include="Refactoring\CodeActions\ExtractMethod\StaticVisitor.cs" />
<Compile Include="Refactoring\CodeActions\ExtractMethod\VariableLookupVisitor.cs" />
<Compile Include="Refactoring\CodeActions\SpecializedCodeAction.cs" />
+ <Compile Include="Formatter\GeneratedCodeSettings.cs" />
+ <Compile Include="Ast\GeneralScope\NewLineNode.cs" />
+ <Compile Include="Ast\GeneralScope\WhitespaceNode.cs" />
+ <Compile Include="Ast\GeneralScope\TextNode.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
View
21 ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
@@ -111,7 +111,7 @@ void EndNode(AstNode node)
void WriteSpecials(AstNode start, AstNode end)
{
for (AstNode pos = start; pos != end; pos = pos.NextSibling) {
- if (pos.Role == Roles.Comment || pos.Role == Roles.PreProcessorDirective) {
+ if (pos.Role == Roles.Comment || pos.Role == Roles.NewLine || pos.Role == Roles.PreProcessorDirective) {
pos.AcceptVisitor(this);
}
}
@@ -2376,7 +2376,24 @@ public void VisitComment(Comment comment)
formatter.EndNode(comment);
lastWritten = LastWritten.Whitespace;
}
-
+
+ public void VisitNewLine(NewLineNode newLineNode)
+ {
+ formatter.StartNode(newLineNode);
+ formatter.NewLine();
+ formatter.EndNode(newLineNode);
+ }
+
+ public void VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ // unused
+ }
+
+ public void VisitText(TextNode textNode)
+ {
+ // unused
+ }
+
public void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective)
{
formatter.StartNode(preProcessorDirective);
View
17 ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs
@@ -1244,7 +1244,22 @@ CodeObject IAstVisitor<CodeObject>.VisitComment (Comment comment)
{
return new CodeComment (comment.Content, comment.CommentType == CommentType.Documentation);
}
-
+
+ CodeObject IAstVisitor<CodeObject>.VisitNewLine(NewLineNode newLineNode)
+ {
+ throw new NotSupportedException();
+ }
+
+ CodeObject IAstVisitor<CodeObject>.VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ throw new NotSupportedException();
+ }
+
+ CodeObject IAstVisitor<CodeObject>.VisitText(TextNode textNode)
+ {
+ throw new NotSupportedException();
+ }
+
CodeObject IAstVisitor<CodeObject>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
{
return new CodeComment ("#" + preProcessorDirective.Type.ToString ().ToLower ());
View
15 ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
@@ -3608,6 +3608,21 @@ ResolveResult IAstVisitor<ResolveResult>.VisitComment (Comment comment)
{
return null;
}
+
+ ResolveResult IAstVisitor<ResolveResult>.VisitNewLine (NewLineNode comment)
+ {
+ return null;
+ }
+
+ ResolveResult IAstVisitor<ResolveResult>.VisitWhitespace(WhitespaceNode whitespaceNode)
+ {
+ return null;
+ }
+
+ ResolveResult IAstVisitor<ResolveResult>.VisitText(TextNode textNode)
+ {
+ return null;
+ }
ResolveResult IAstVisitor<ResolveResult>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
{
View
20 ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs
@@ -4951,5 +4951,25 @@ class TestClass
}");
Assert.IsTrue(provider == null || provider.Count == 0);
}
+
+ /// <summary>
+ /// Bug 4323 - Parameter completion exception while attempting to instantiate unknown class
+ /// </summary>
+ [Test()]
+ public void TestBug4323()
+ {
+ // just test for exception
+ ParameterCompletionTests.CreateProvider(
+@"namespace Test
+{
+ class TestClass
+ {
+ public static void Main(string[] args)
+ {
+ $object foo = new Foo($
+ }
+ }
+}");
+ }
}
}
View
10 ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/ParameterCompletionTests.cs
@@ -212,9 +212,9 @@ public bool AllowParameterList (int overload)
}
#region IParameterCompletionDataFactory implementation
- public IParameterDataProvider CreateConstructorProvider (int startOffset, ICSharpCode.NRefactory.TypeSystem.IType type)
+ public IParameterDataProvider CreateConstructorProvider(int startOffset, ICSharpCode.NRefactory.TypeSystem.IType type)
{
-
+ Assert.IsTrue(type.Kind != TypeKind.Unknown);
return new Provider () {
Data = type.GetConstructors (m => m.Accessibility == Accessibility.Public)
};
@@ -227,15 +227,17 @@ public IParameterDataProvider CreateMethodDataProvider (int startOffset, IEnumer
};
}
- public IParameterDataProvider CreateDelegateDataProvider (int startOffset, ICSharpCode.NRefactory.TypeSystem.IType type)
+ public IParameterDataProvider CreateDelegateDataProvider(int startOffset, ICSharpCode.NRefactory.TypeSystem.IType type)
{
+ Assert.IsTrue(type.Kind != TypeKind.Unknown);
return new Provider () {
Data = new [] { type.GetDelegateInvokeMethod () }
};
}
- public IParameterDataProvider CreateIndexerParameterDataProvider (int startOffset, IType type, AstNode resolvedNode)
+ public IParameterDataProvider CreateIndexerParameterDataProvider(int startOffset, IType type, AstNode resolvedNode)
{
+ Assert.IsTrue(type.Kind != TypeKind.Unknown);
if (type.Kind == TypeKind.Array)
return new ArrayProvider ();
return new IndexerProvider () {

No commit comments for this range

Something went wrong with that request. Please try again.