Browse Source

Fixed assertion when parsing method declaration with an unnamed parameter (when the user is still typing): use name '?' instead.

Double-Clicking on the definition view pad now jumps to the location clicked on in the main view.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@137 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
da478ba25f
  1. 4
      src/Libraries/NRefactory/NRefactory.sln
  2. 5
      src/Libraries/NRefactory/Project/NRefactory.csproj
  3. 17
      src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs
  4. 11
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/ParameterDeclarationExpression.cs
  5. 5
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj
  6. 2
      src/Libraries/NRefactory/Test/NRefactoryTests.csproj.user
  7. 17
      src/Libraries/NRefactory/Test/Parser/ParseUtilCSharp.cs
  8. 15
      src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs
  9. 26
      src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs

4
src/Libraries/NRefactory/NRefactory.sln

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Tests", "Test\NRefactoryTests.csproj", "{870115dd-960a-4406-a6b9-600bcdc36a03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "Project\NRefactory.csproj", "{3a9ae6aa-bc07-4a2f-972c-581e3ae2f195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Tests", "Test\NRefactoryTests.csproj", "{870115dd-960a-4406-a6b9-600bcdc36a03}"
EndProject
Global
EndGlobal

5
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.41115</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</ProjectGuid>
<ProjectGuid>{3a9ae6aa-bc07-4a2f-972c-581e3ae2f195}</ProjectGuid>
<RootNamespace>ICSharpCode.NRefactory</RootNamespace>
<AssemblyName>ICSharpCode.NRefactory</AssemblyName>
<OutputTarget>Library</OutputTarget>
@ -37,7 +37,6 @@ @@ -37,7 +37,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ICSharpCode.NRefactory.snk" />
@ -198,4 +197,4 @@ @@ -198,4 +197,4 @@
<Folder Include="Src\Parser\AST\VBNet\Tests\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
</Project>

17
src/Libraries/NRefactory/Project/Src/Output/CodeDOM/CodeDOMOutputVisitor.cs

@ -817,23 +817,8 @@ namespace ICSharpCode.NRefactory.Parser @@ -817,23 +817,8 @@ namespace ICSharpCode.NRefactory.Parser
bool IsField(string type, string fieldName)
{
Type t = null;
Assembly asm = null;
t = this.GetType(type);
if (t == null) {
asm = typeof(System.Drawing.Point).Assembly;
t = asm.GetType(type);
}
if (t == null) {
asm = typeof(System.Windows.Forms.Control).Assembly;
t = asm.GetType(type);
}
if (t == null) {
asm = typeof(System.String).Assembly;
t = asm.GetType(type);
}
t = this.GetType(type); // search in all currently loaded assemblies
bool isField = t != null && (t.IsEnum || t.GetField(fieldName) != null);
if (!isField) {

11
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeLevel/ParameterDeclarationExpression.cs

@ -5,7 +5,7 @@ using System.Diagnostics; @@ -5,7 +5,7 @@ using System.Diagnostics;
using System.Collections;
namespace ICSharpCode.NRefactory.Parser.AST
{
{
public class ParameterDeclarationExpression : Expression
{
TypeReference typeReference = TypeReference.Null;
@ -64,7 +64,8 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -64,7 +64,8 @@ namespace ICSharpCode.NRefactory.Parser.AST
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName)
{
this.typeReference = typeReference;
Debug.Assert(parameterName != null);
if (parameterName == null || parameterName.Length == 0)
parameterName = "?";
this.parameterName = parameterName;
this.paramModifier = ParamModifier.In;
}
@ -72,7 +73,8 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -72,7 +73,8 @@ namespace ICSharpCode.NRefactory.Parser.AST
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParamModifier paramModifier)
{
this.typeReference = typeReference;
Debug.Assert(parameterName != null);
if (parameterName == null || parameterName.Length == 0)
parameterName = "?";
this.parameterName = parameterName;
this.paramModifier = paramModifier;
}
@ -80,7 +82,8 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -80,7 +82,8 @@ namespace ICSharpCode.NRefactory.Parser.AST
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParamModifier paramModifier, Expression defaultValue)
{
this.typeReference = typeReference;
Debug.Assert(parameterName != null);
if (parameterName == null || parameterName.Length == 0)
parameterName = "?";
this.parameterName = parameterName;
this.paramModifier = paramModifier;
this.DefaultValue = defaultValue;

5
src/Libraries/NRefactory/Test/NRefactoryTests.csproj

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -32,10 +32,7 @@ @@ -32,10 +32,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=2.2.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
</ItemGroup>
<ItemGroup>

2
src/Libraries/NRefactory/Test/NRefactoryTests.csproj.user

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
</Project>

17
src/Libraries/NRefactory/Test/Parser/ParseUtilCSharp.cs

@ -21,11 +21,19 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -21,11 +21,19 @@ namespace ICSharpCode.NRefactory.Tests.AST
public class ParseUtilCSharp
{
public static object ParseGlobal(string program, Type type)
{
return ParseGlobal(program, type, false);
}
public static object ParseGlobal(string program, Type type, bool expectError)
{
IParser parser = ParserFactory.CreateParser(SupportedLanguages.CSharp, new StringReader(program));
parser.Parse();
Assert.IsNotNull(parser.Errors);
Assert.AreEqual("", parser.Errors.ErrorOutput);
if (expectError)
Assert.IsTrue(parser.Errors.ErrorOutput.Length > 0, "There were errors expected, but parser finished without errors.");
else
Assert.AreEqual("", parser.Errors.ErrorOutput);
Assert.IsNotNull(parser.CompilationUnit);
Assert.IsNotNull(parser.CompilationUnit.Children);
Assert.IsNotNull(parser.CompilationUnit.Children[0]);
@ -36,7 +44,12 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -36,7 +44,12 @@ namespace ICSharpCode.NRefactory.Tests.AST
public static object ParseTypeMember(string typeMember, Type type)
{
TypeDeclaration td = (TypeDeclaration)ParseGlobal("class MyClass {" + typeMember + "}", typeof(TypeDeclaration));
return ParseTypeMember(typeMember, type, false);
}
public static object ParseTypeMember(string typeMember, Type type, bool expectError)
{
TypeDeclaration td = (TypeDeclaration)ParseGlobal("class MyClass {" + typeMember + "}", typeof(TypeDeclaration), expectError);
Assert.IsTrue(td.Children.Count > 0);
Assert.IsTrue(type.IsAssignableFrom(td.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", td.GetType(), type, td));
return td.Children[0];

15
src/Libraries/NRefactory/Test/Parser/TypeLevel/MethodDeclarationTests.cs

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* User: Omnibrain
* Date: 13.09.2004
* Time: 19:54
*
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
@ -28,10 +28,19 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -28,10 +28,19 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("void", md.TypeReference.Type);
Assert.AreEqual(0, md.Parameters.Count);
}
[Test]
public void CSharpMethodWithUnnamedParameterDeclarationTest()
{
MethodDeclaration md = (MethodDeclaration)ParseUtilCSharp.ParseTypeMember("void MyMethod(int) {} ", typeof(MethodDeclaration), true);
Assert.AreEqual("void", md.TypeReference.Type);
Assert.AreEqual(1, md.Parameters.Count);
Assert.AreEqual("?", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);
}
#endregion
#region VB.NET
// TODO
#endregion
// TODO
#endregion
}
}

26
src/Main/Base/Project/Src/Gui/Pads/DefinitionViewPad.cs

@ -38,9 +38,22 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -38,9 +38,22 @@ namespace ICSharpCode.SharpDevelop.Gui
ctl = new TextEditorControl();
ctl.Document.ReadOnly = true;
ctl.TextEditorProperties = new SharpDevelopTextEditorProperties();
ctl.ActiveTextAreaControl.TextArea.DoubleClick += OnDoubleClick;
ParserService.ParserUpdateStepFinished += UpdateTick;
}
void OnDoubleClick(object sender, EventArgs e)
{
string fileName = ctl.FileName;
if (fileName != null) {
Caret caret = ctl.ActiveTextAreaControl.Caret;
FileService.JumpToFilePosition(fileName, caret.Line, caret.Column);
// refresh DefinitionView to show the definition of the expression that was double-clicked
UpdateTick(null, null);
}
}
void UpdateTick(object sender, ParserUpdateStepEventArgs e)
{
if (!this.IsVisible) return;
@ -58,13 +71,17 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -58,13 +71,17 @@ namespace ICSharpCode.SharpDevelop.Gui
ITextEditorControlProvider provider = window.ActiveViewContent as ITextEditorControlProvider;
if (provider == null) return null;
TextEditorControl ctl = provider.TextEditorControl;
if (ctl.FileName != e.FileName) return null;
IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(e.FileName);
// e might be null when this is a manually triggered update
string fileName = (e == null) ? ctl.FileName : e.FileName;
if (ctl.FileName != fileName) return null;
IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName);
if (expressionFinder == null) return null;
Caret caret = ctl.ActiveTextAreaControl.Caret;
string expr = expressionFinder.FindFullExpression(e.Content, caret.Offset);
string content = (e == null) ? ctl.Text : e.Content;
string expr = expressionFinder.FindFullExpression(content, caret.Offset);
if (expr == null) return null;
return ParserService.Resolve(expr, caret.Line, caret.Column, e.FileName, e.Content);
return ParserService.Resolve(expr, caret.Line, caret.Column, fileName, content);
}
delegate void OpenFileDelegate(FilePosition pos);
@ -97,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -97,6 +114,7 @@ namespace ICSharpCode.SharpDevelop.Gui
{
ParserService.ParserUpdateStepFinished -= UpdateTick;
ctl.Dispose();
base.Dispose();
}
}
}

Loading…
Cancel
Save