Browse Source

Fixed stub mechanic.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
c51a5f6222
  1. 11
      ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
  3. 69
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  4. 2
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs

11
ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -273,6 +273,17 @@ namespace ICSharpCode.NRefactory.CSharp @@ -273,6 +273,17 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
/// <summary>
/// Gets the ancestors of this node (including this node itself)
/// </summary>
public IEnumerable<AstNode> AncestorsAndSelf {
get {
for (AstNode cur = this; cur != null; cur = cur.parent) {
yield return cur;
}
}
}
/// <summary>
/// Gets all descendants of this node (excluding this node itself).
/// </summary>

3
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -177,7 +177,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -177,7 +177,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (expr == null) {
return null;
}
// do not complete <number>. (but <number>.<number>.)
// do not complete <number>. (but <number>.<number>.)
if (expr.Node is PrimitiveExpression) {
var pexpr = (PrimitiveExpression)expr.Node;
if (!(pexpr.Value is string || pexpr.Value is char) && !pexpr.LiteralValue.Contains('.')) {
@ -478,6 +478,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -478,6 +478,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var contextList = new CompletionDataWrapper (this);
var identifierStart = GetExpressionAtCursor();
if (identifierStart != null && identifierStart.Node is TypeParameterDeclaration) {
return null;
}

69
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -421,7 +421,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -421,7 +421,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (mt == null) {
return null;
}
string memberText = mt.Item1;
var memberLocation = mt.Item2;
int closingBrackets = 1;
@ -429,18 +429,36 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -429,18 +429,36 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
var wrapper = new StringBuilder ();
bool wrapInClass = memberLocation != new TextLocation (1, 1);
if (wrapInClass) {
/* foreach (var child in Unit.Children) {
if (child is UsingDeclaration) {
var offset = document.GetOffset (child.StartLocation);
wrapper.Append (document.GetText (offset, document.GetOffset (child.EndLocation) - offset));
var nodeAtLocation = Unit.GetNodeAt(memberLocation, n => n is TypeDeclaration || n is NamespaceDeclaration);
foreach (var n in nodeAtLocation.AncestorsAndSelf) {
if (memberLocation == n.StartLocation) {
continue;
}
if (n is TypeDeclaration) {
var t = (TypeDeclaration)n;
switch (t.ClassType) {
case ClassType.Class:
wrapper.Append("class");
break;
case ClassType.Struct:
wrapper.Append("struct");
break;
case ClassType.Interface:
wrapper.Append("interface");
break;
case ClassType.Enum:
wrapper.Append("enum");
break;
}
wrapper.Append(" " + t.Name + " {");
wrapper.AppendLine();
closingBrackets++;
generatedLines++;
} else {
Console.WriteLine(n);
}
}*/
wrapper.Append("class Stub {");
wrapper.AppendLine();
closingBrackets++;
generatedLines = 1;
}
}
wrapper.Append(memberText);
wrapper.Append(continuation);
AppendMissingClosingBrackets(wrapper, memberText, appendSemicolon);
@ -486,7 +504,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -486,7 +504,6 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
--startOffset;
}
startOffset = 0;
if (cachedText == null)
cachedText = document.GetText (startOffset, offset - startOffset);
@ -552,10 +569,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -552,10 +569,11 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return ResolveExpression (tuple.Node, tuple.Unit);
}
protected Tuple<ResolveResult, CSharpResolver> ResolveExpression (AstNode expr, CompilationUnit unit)
protected Tuple<ResolveResult, CSharpResolver> ResolveExpression(AstNode expr, CompilationUnit unit)
{
if (expr == null)
if (expr == null) {
return null;
}
AstNode resolveNode;
if (expr is Expression || expr is AstType) {
resolveNode = expr;
@ -565,21 +583,21 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -565,21 +583,21 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
resolveNode = expr;
}
try {
var csResolver = new CSharpAstResolver (GetState (), unit, CSharpParsedFile);
var result = csResolver.Resolve (resolveNode);
var state = csResolver.GetResolverStateBefore (resolveNode);
return Tuple.Create (result, state);
} catch (Exception) {
var ctx = CSharpParsedFile.GetResolver(Compilation, location);
var root = expr.AncestorsAndSelf.FirstOrDefault(n => n is EntityDeclaration || n is CompilationUnit);
if (root == null) {
return null;
}
var csResolver = new CSharpAstResolver (ctx, root, CSharpParsedFile);
var result = csResolver.Resolve(resolveNode);
var state = csResolver.GetResolverStateBefore(resolveNode);
return Tuple.Create(result, state);
} catch (Exception e) {
Console.WriteLine(e);
return null;
}
}
protected static void Print (AstNode node)
{
var v = new CSharpOutputVisitor (Console.Out, new CSharpFormattingOptions ());
node.AcceptVisitor (v);
}
#endregion
class DefaultMemberProvider : IMemberProvider
@ -702,6 +720,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -702,6 +720,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
return bracketStack.Any (t => t == '{');
}
}
}
}

2
ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpParsedFile.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
return null;
}
public CSharpTypeResolveContext GetTypeResolveContext (ICompilation compilation, TextLocation loc)
public CSharpTypeResolveContext GetTypeResolveContext(ICompilation compilation, TextLocation loc)
{
var rctx = new CSharpTypeResolveContext (compilation.MainAssembly);
rctx = rctx.WithUsingScope (GetUsingScope (loc).Resolve (compilation));

Loading…
Cancel
Save