Browse Source

Remove constructors from CSharpUnresolvedFile - they could be mistaken to load the specified file name.

pull/45/merge
Daniel Grunwald 13 years ago
parent
commit
5f67bc0933
  1. 4
      ICSharpCode.NRefactory.CSharp/Ast/SyntaxTree.cs
  2. 2
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs
  3. 26
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpUnresolvedFile.cs
  4. 3
      ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs
  5. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/GetCurrentParameterIndexTests.cs
  6. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeDomConvertVisitorTests.cs
  7. 16
      ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs
  8. 2
      ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemHelper.cs

4
ICSharpCode.NRefactory.CSharp/Ast/SyntaxTree.cs

@ -164,24 +164,28 @@ namespace ICSharpCode.NRefactory.CSharp @@ -164,24 +164,28 @@ namespace ICSharpCode.NRefactory.CSharp
public static SyntaxTree Parse (string program, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
var parser = new CSharpParser (settings);
return parser.Parse (program, fileName);
}
public static SyntaxTree Parse (TextReader reader, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
var parser = new CSharpParser (settings);
return parser.Parse (reader, fileName);
}
public static SyntaxTree Parse (Stream stream, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
var parser = new CSharpParser (settings);
return parser.Parse (stream, fileName);
}
public static SyntaxTree Parse (ITextSource textSource, string fileName = "", CompilerSettings settings = null, CancellationToken cancellationToken = default (CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
var parser = new CSharpParser (settings);
return parser.Parse (textSource, fileName);
}

2
ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

@ -589,7 +589,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -589,7 +589,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
// Last using scope:
usingScope = new UsingScope(resolver.CurrentUsingScope.UnresolvedUsingScope, identifiers.Last().Name);
usingScope.Region = region;
var cv = new TypeSystemConvertVisitor(new CSharpUnresolvedFile(region.FileName ?? string.Empty), usingScope);
var cv = new TypeSystemConvertVisitor(new CSharpUnresolvedFile(), usingScope);
ApplyVisitorToUsings(cv, namespaceDeclaration.Children);
PushUsingScope(usingScope);
}

26
ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpUnresolvedFile.cs

@ -36,8 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -36,8 +36,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
// The 'FastSerializerVersion' attribute on CSharpUnresolvedFile must be incremented when fixing
// bugs in the TypeSystemConvertVisitor
readonly string fileName;
readonly UsingScope rootUsingScope;
string fileName = string.Empty;
readonly UsingScope rootUsingScope = new UsingScope();
IList<IUnresolvedTypeDefinition> topLevelTypeDefinitions = new List<IUnresolvedTypeDefinition>();
IList<IUnresolvedAttribute> assemblyAttributes = new List<IUnresolvedAttribute>();
IList<IUnresolvedAttribute> moduleAttributes = new List<IUnresolvedAttribute>();
@ -55,26 +55,12 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -55,26 +55,12 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
usingScopes = FreezableHelper.FreezeListAndElements(usingScopes);
}
public CSharpUnresolvedFile(string fileName)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
this.fileName = fileName;
this.rootUsingScope = new UsingScope();
}
public CSharpUnresolvedFile(string fileName, UsingScope rootUsingScope)
{
if (fileName == null)
throw new ArgumentNullException("fileName");
if (rootUsingScope == null)
throw new ArgumentNullException("rootUsingScope");
this.fileName = fileName;
this.rootUsingScope = rootUsingScope;
}
public string FileName {
get { return fileName; }
set {
FreezableHelper.ThrowIfFrozen(this);
fileName = value ?? string.Empty;
}
}
DateTime? lastWriteTime;

3
ICSharpCode.NRefactory.CSharp/TypeSystem/TypeSystemConvertVisitor.cs

@ -75,7 +75,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -75,7 +75,8 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
{
if (fileName == null)
throw new ArgumentNullException("fileName");
this.unresolvedFile = new CSharpUnresolvedFile(fileName);
this.unresolvedFile = new CSharpUnresolvedFile();
this.unresolvedFile.FileName = fileName;
this.usingScope = unresolvedFile.RootUsingScope;
}

2
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/GetCurrentParameterIndexTests.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion @@ -54,7 +54,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
var doc = new ReadOnlyDocument(editorText.ToString ());
var pctx = new CSharpProjectContent();
var rctx = new CSharpTypeResolveContext(pctx.CreateCompilation().MainAssembly);
var ctxProvider = new DefaultCompletionContextProvider(doc, new CSharpUnresolvedFile("a.cs"));
var ctxProvider = new DefaultCompletionContextProvider(doc, new CSharpUnresolvedFile());
var engine = new CSharpParameterCompletionEngine(doc, ctxProvider, new ParameterCompletionTests.TestFactory(pctx), pctx, rctx);
return engine.GetCurrentParameterIndex(trigger, end);

2
ICSharpCode.NRefactory.Tests/CSharp/CodeDomConvertVisitorTests.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -39,7 +39,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override void SetUp()
{
base.SetUp();
unresolvedFile = new CSharpUnresolvedFile("test.cs");
unresolvedFile = new CSharpUnresolvedFile();
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System"));
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System.Collections.Generic"));
unresolvedFile.RootUsingScope.Usings.Add(MakeReference("System.Linq"));

16
ICSharpCode.NRefactory.Tests/CSharp/Parser/Expression/QueryExpressionTests.cs

@ -302,6 +302,22 @@ select new { c.Name, o.OrderID, o.Total }", @@ -302,6 +302,22 @@ select new { c.Name, o.OrderID, o.Total }",
}});
}
[Test]
public void LocationOfWhere()
{
var expr = ParseUtilCSharp.ParseExpression<QueryExpression>("from c in customers where c.City == \"London\" select c");
var where = expr.Clauses.ElementAt(1);
Assert.That(where.StartLocation, Is.EqualTo(new TextLocation(1, 21)));
}
[Test]
public void LocationOfOrderBy()
{
var expr = ParseUtilCSharp.ParseExpression<QueryExpression>("from c in customers orderby c.City select c");
var where = expr.Clauses.ElementAt(1);
Assert.That(where.StartLocation, Is.EqualTo(new TextLocation(1, 21)));
}
[Test]
public void ExpressionWithOrderByAndLet()
{

2
ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemHelper.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -32,7 +32,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
public static ICompilation CreateCompilation(params IUnresolvedTypeDefinition[] unresolvedTypeDefinitions)
{
var unresolvedFile = new CSharpUnresolvedFile("dummy.cs");
var unresolvedFile = new CSharpUnresolvedFile();
foreach (var typeDef in unresolvedTypeDefinitions)
unresolvedFile.TopLevelTypeDefinitions.Add(typeDef);
return CreateCompilation(unresolvedFile);

Loading…
Cancel
Save