[svn] r7417: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
N...
phantom
svnadmin at nemerle.org
Tue Feb 13 18:50:46 CET 2007
Log:
Refactoring.
Author: phantom
Date: Tue Feb 13 18:50:42 2007
New Revision: 7417
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Refactoring.n Tue Feb 13 18:50:42 2007
@@ -20,6 +20,19 @@
{
public partial class Project
{
+ public GetDefinition([NotNull] filePath : string, line : int, col : int) : array [GotoInfo]
+ {
+ def fileIndex = _compileUnits.GetFileIndex(filePath);
+ def declaration = GetActiveDecl(fileIndex, line, col);
+
+ match (declaration)
+ {
+ | Using as us => this.Engine.GetUsingGoto(us, fileIndex, line, col).ToArray();
+ | Type as tp => GetDefinitionInsideType(tp, fileIndex, line, col).ToArray();
+ | _ => null
+ }
+ }
+
public GetUsages([NotNull] filePath : string, line : int, col : int) : array [GotoInfo]
{
def fileIndex = _compileUnits.GetFileIndex(filePath);
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.Type.n Tue Feb 13 18:50:42 2007
@@ -285,7 +285,7 @@
}
}
- private GetTypeGoto(
+ private GetDefinitionInsideType(
typeDecl : Decl.Type,
fileIndex : int,
line : int,
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/Project.n Tue Feb 13 18:50:42 2007
@@ -218,19 +218,6 @@
}
}
- public GetGotoInfo([NotNull] filePath : string, line : int, col : int) : array [GotoInfo]
- {
- def fileIndex = _compileUnits.GetFileIndex(filePath);
- def decl = GetActiveDecl(fileIndex, line, col);
-
- match (decl)
- {
- | Using as us => this.Engine.GetUsingGoto(us, fileIndex, line, col).ToArray();
- | Type as tp => GetTypeGoto (tp, fileIndex, line, col).ToArray();
- | _ => null
- }
- }
-
public GetGotoInfo(member : SR.MemberInfo) : array [GotoInfo]
{
def isType = member is System.Type && Attribute.GetCustomAttribute(member, typeof(Nemerle.Internal.VariantOptionAttribute)) == null;
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/Tests/Heavy.Tests/Runner.n Tue Feb 13 18:50:42 2007
@@ -18,6 +18,22 @@
{
public class TestRunner
{
+ public stopAfterFirstFailedTest = false;
+
+ skipTestProjects : list[string] = []; // neglect some projects for a while
+
+ skipTestCases : list[int] = []; // neglect some tests for a while
+
+ // Run a particular broken test here
+ public static runSpecificTest : bool = true;
+
+ public static RunTheTest() : void
+ {
+ def suite = FindUsagesTestProjectTwo();
+ suite.SetUp();
+ suite.Test031();
+ }
+
public static Explode(this s : string, delimiter : string) : list[string]
{
s.Split(array[delimiter], StringSplitOptions.None).ToList()
@@ -196,6 +212,11 @@
GotoInfo(goto.Location, usageType)
}
+ public static FindDefinition(runner : TestRunner) : string * int * Location * string -> bool
+ {
+ runner.FindDefinition
+ }
+
public static FindUsages(runner : TestRunner) : string * int * Location * string -> bool
{
runner.FindUsages
@@ -251,10 +272,8 @@
found
}
- public FindUsages(line: string, testCase : int, declaration : Location, starter : string) : bool
+ public FindDefinition(line: string, testCase : int, declaration : Location, starter : string) : bool
{
- //when (skipTestCases.Contains(testCase)) // TODO: report about compiler bug here (no errors, just internal compiler error)
- //Nemerle.Imperative.Return;
if (skipTestCases.Contains(testCase))
true
else
@@ -305,64 +324,64 @@
}
}
- public static LoadProject(projectPath : string) : TestRunner
+ public FindUsages(line: string, testCase : int, declaration : Location, starter : string) : bool
{
- def findEntries(entryStart, lines)
+ //when (skipTestCases.Contains(testCase)) // TODO: report about compiler bug here (no errors, just internal compiler error)
+ //Nemerle.Imperative.Return;
+ if (skipTestCases.Contains(testCase))
+ true
+ else
{
- def lines = lines.Filter(_.Contains(entryStart));
- mutable entries = [];
- lines.Iter(line =>
+ def name = starter.Substring(starter.IndexOf('}') + 1).Trim();
+ def position = line.IndexOf(name);
+ def location = Location(declaration.File, declaration.Line, position, declaration.Line, position + name.Length);
+ WriteLine($"\nSearching for usages of '$name' (test case: $testCase, location: $location)... ");
+ // TODO: find multiple declarations (partial classes)
+ def shouldFindRing = MakeUsage(line, declaration, name, starter) ::
+ ScanSources(checkPhrase, testCase).Map((line, _, location, _) => MakeUsage(line, location, name, checkPhrase));
+ Write($"\n Should find $(shouldFindRing.Length) usages... ");
+ def foundMultiple =
+ shouldFindRing.Map(goto =>
{
- def position = line.IndexOf(entryStart) + entryStart.Length;
- def path = line.Substring(position + 1);
- def path = path.Substring(0, path.IndexOf('"'));
- entries ::= path;
+ def location = goto.Location;
+ def shift = if (name.Length > 1) 1 else 0;
+ TheEngine.Project.GetUsages(location.File, location.Line, location.Column + shift).ToList()
});
- entries.Reverse()
- }
-
- def lines = File.ReadAllLines(projectPath).ToList();
- def projectFolder = projectPath.Substring(0, projectPath.LastIndexOf('\\'));
- def sources = findEntries("<Compile Include=", lines).Map(source => $@"$projectFolder\$source");
- Write($"$projectPath : $(sources.Length) source files found, ");
- def references = findEntries("<Reference Include=", lines).Map(reference =>
+ Assert.IsFalse(foundMultiple.IsEmpty);
+ def found = foundMultiple.FoldLeft(foundMultiple.Head, (ring, ring') =>
{
- | "System" => "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
- | "System.Data" => "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
- | "System.Xml" => "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
- | _ => reference
- }) + [
- @"$(Nemerle)\Nemerle.Macros.dll",
- ];
- def references = references.Map(_.Replace("$(Nemerle)", @"C:\Program Files\Nemerle")).RemoveDuplicates();
- def references = references.Filter(reference => !reference.Contains("Nemerle"));
- WriteLine($"$(references.Length) reference files found");
-
- def runner = TestRunner();
- runner.InitializeEngine(sources, references);
- runner
+ def warning = "Find Usages should produce the same results, disregarding on which usage a user places a cursor";
+ def coincide =
+ try
+ {
+ FoldLeft2(ring, ring', true, (a, b, coincideToTheLeft) =>
+ if (coincideToTheLeft) a.Location.CompareLines(b.Location) == 0 else false)
}
-
- public stopAfterFirstFailedTest = false;
-
- skipTestProjects : list[string] = []; // neglect some projects for a while
-
- skipTestCases : list[int] = []; // neglect some tests for a while
-
- // Run a particular broken test here
- public static runSpecificTest : bool = true;
-
- public static RunTheTest() : void
+ catch
{
- def suite = FindUsagesTestProjectTwo();
- suite.SetUp();
- suite.Test030();
+ | _ => false
+ };
+ when (stopAfterFirstFailedTest)
+ Assert.IsTrue(coincide, warning);
+ ring
+ });
+ Write($"found $(found.Length) usages, checking for correspondance... ");
+ def success = FoundUsagesAreRight(testCase, shouldFindRing, found); // put breakpoint here to see what usages are actually found
+ def message = if (success) "ok" else "incorrect!.. saving changes...";
+ WriteLine(message);
+ unless (success)
+ {
+ Assert.IsFalse(stopAfterFirstFailedTest);
+ // TODO: save here instead of saving each time error happens
+ }
+ success
+ }
}
public static Main() : void
{
if (runSpecificTest)
- RunTheTest(); // comment if do not want to run the specific test
+ RunTheTest();
else
{
WriteLine("Running all tests...\n");
@@ -383,6 +402,7 @@
// this differs slightly from the NUnit-tests behaviour
// (they use different engines for every test) - this is intentional
def suites = [
+ (FindDefinition, UsageTypeToString(UsageType.Definition), UsageTypeToString(UsageType.Usage)),
(FindUsages, UsageTypeToString(UsageType.Definition), UsageTypeToString(UsageType.Usage))
];
suites.Iter(suite => projects.Iter(projectPath =>
@@ -406,6 +426,44 @@
_ = ReadLine();
}
+ public static LoadProject(projectPath : string) : TestRunner
+ {
+ def findEntries(entryStart, lines)
+ {
+ def lines = lines.Filter(_.Contains(entryStart));
+ mutable entries = [];
+ lines.Iter(line =>
+ {
+ def position = line.IndexOf(entryStart) + entryStart.Length;
+ def path = line.Substring(position + 1);
+ def path = path.Substring(0, path.IndexOf('"'));
+ entries ::= path;
+ });
+ entries.Reverse()
+ }
+
+ def lines = File.ReadAllLines(projectPath).ToList();
+ def projectFolder = projectPath.Substring(0, projectPath.LastIndexOf('\\'));
+ def sources = findEntries("<Compile Include=", lines).Map(source => $@"$projectFolder\$source");
+ Write($"$projectPath : $(sources.Length) source files found, ");
+ def references = findEntries("<Reference Include=", lines).Map(reference =>
+ {
+ | "System" => "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+ | "System.Data" => "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+ | "System.Xml" => "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
+ | _ => reference
+ }) + [
+ @"$(Nemerle)\Nemerle.Macros.dll",
+ ];
+ def references = references.Map(_.Replace("$(Nemerle)", @"C:\Program Files\Nemerle")).RemoveDuplicates();
+ def references = references.Filter(reference => !reference.Contains("Nemerle"));
+ WriteLine($"$(references.Length) reference files found");
+
+ def runner = TestRunner();
+ runner.InitializeEngine(sources, references);
+ runner
+ }
+
public InitializeEngine(sources : list[string], references : list[string]) : void
{
WriteLine($"Initializing engine with $(sources.Length) sources");
Modified: vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/Project/ProjectInfo.cs Tue Feb 13 18:50:42 2007
@@ -386,7 +386,7 @@
{
Trace.WriteLine(">>>> ##### GetGoto!");
ErrorHelper.ThrowIfPathNullOrEmpty(filePath, "filePath");
- GotoInfo[] result = Project.GetGotoInfo(filePath, line + 1, col + 1);
+ GotoInfo[] result = Project.GetDefinition(filePath, line + 1, col + 1);
Trace.WriteLine("<<<< ##### GetGoto!");
return result;
}
More information about the svn
mailing list