Browse Source

add tag comment tracking

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
4446aac04b
  1. 1
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  2. 58
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  3. 11
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/CSharpProject.cs
  4. 123
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/SDRefactoringContext.cs
  5. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs
  6. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/RefactoringContext.cs
  7. 2
      src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs
  8. 10
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

1
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

@ -77,6 +77,7 @@
<Compile Include="Src\CSharpContextActionDoozer.cs" /> <Compile Include="Src\CSharpContextActionDoozer.cs" />
<Compile Include="Src\CSharpLanguageBinding.cs" /> <Compile Include="Src\CSharpLanguageBinding.cs" />
<Compile Include="Src\CSharpProjectBinding.cs" /> <Compile Include="Src\CSharpProjectBinding.cs" />
<Compile Include="Src\SDRefactoringContext.cs" />
<Compile Include="Src\CSharpSemanticHighlighter.cs" /> <Compile Include="Src\CSharpSemanticHighlighter.cs" />
<Compile Include="Src\ExtensionMethods.cs" /> <Compile Include="Src\ExtensionMethods.cs" />
<Compile Include="Src\FormattingStrategy\CSharpFormattingStrategy.cs" /> <Compile Include="Src\FormattingStrategy\CSharpFormattingStrategy.cs" />

58
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -2,9 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp;
@ -13,6 +14,8 @@ using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Parser; using ICSharpCode.SharpDevelop.Parser;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Refactoring; using ICSharpCode.SharpDevelop.Refactoring;
@ -83,22 +86,59 @@ namespace CSharpBinding.Parser
} }
CSharpParsedFile file = cu.ToTypeSystem(); CSharpParsedFile file = cu.ToTypeSystem();
ParseInformation parseInfo;
if (fullParseInformationRequested) if (fullParseInformationRequested)
return new CSharpFullParseInformation(file, cu); parseInfo = new CSharpFullParseInformation(file, cu);
else else
return new ParseInformation(file, fullParseInformationRequested); parseInfo = new ParseInformation(file, fullParseInformationRequested);
AddCommentTags(cu, parseInfo.TagComments, fileContent);
return parseInfo;
} }
/*void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.TagComment> tagComments) void AddCommentTags(CompilationUnit cu, IList<TagComment> tagComments, ITextSource fileContent)
{ {
foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) { ReadOnlyDocument document = null;
DomRegion tagRegion = new DomRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X); foreach (var comment in cu.Descendants.OfType<Comment>().Where(c => c.CommentType != CommentType.InactiveCode)) {
var tag = new ICSharpCode.SharpDevelop.Dom.TagComment(tagComment.Tag, tagRegion, tagComment.CommentText); int matchLength;
cu.TagComments.Add(tag); int index = IndexOfAny(comment.Content, lexerTags, 0, out matchLength);
if (index > -1) {
if (document == null)
document = new ReadOnlyDocument(fileContent);
int startOffset = document.GetOffset(comment.StartLocation);
int commentSignLength = comment.CommentType == CommentType.Documentation || comment.CommentType == CommentType.MultiLineDocumentation ? 3 : 2;
int commentEndSignLength = comment.CommentType == CommentType.MultiLine || comment.CommentType == CommentType.MultiLineDocumentation ? 2 : 0;
do {
int absoluteOffset = startOffset + index + commentSignLength;
var startLocation = document.GetLocation(absoluteOffset);
int endOffset = Math.Min(document.GetLineByNumber(startLocation.Line).EndOffset, document.GetOffset(comment.EndLocation) - commentEndSignLength);
string content = document.GetText(absoluteOffset, endOffset - absoluteOffset);
tagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(cu.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength)));
index = IndexOfAny(comment.Content, lexerTags, endOffset - startOffset - commentSignLength, out matchLength);
} while (index > -1);
} }
} }
*/ }
static int IndexOfAny(string haystack, string[] needles, int startIndex, out int matchLength)
{
if (haystack == null)
throw new ArgumentNullException("haystack");
if (needles == null)
throw new ArgumentNullException("needles");
int index = -1;
matchLength = 0;
foreach (var needle in needles) {
int i = haystack.IndexOf(needle, startIndex, StringComparison.Ordinal);
if (i != -1 && (index == -1 || index > i)) {
index = i;
matchLength = needle.Length;
}
}
return index;
}
public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken) public ResolveResult Resolve(ParseInformation parseInfo, TextLocation location, ICompilation compilation, CancellationToken cancellationToken)
{ {

11
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/CSharpProject.cs

@ -30,6 +30,17 @@ namespace CSharpBinding
get { return CSharpProjectBinding.LanguageName; } get { return CSharpProjectBinding.LanguageName; }
} }
public Version LanguageVersion {
get {
string toolsVersion;
lock (SyncRoot) toolsVersion = this.ToolsVersion;
Version version = new Version(toolsVersion);
if (version == new Version(4, 0) && DotnetDetection.IsDotnet45Installed())
return new Version(5, 0);
return version;
}
}
void Init() void Init()
{ {
reparseReferencesSensitiveProperties.Add("TargetFrameworkVersion"); reparseReferencesSensitiveProperties.Add("TargetFrameworkVersion");

123
src/AddIns/BackendBindings/CSharpBinding/Project/Src/SDRefactoringContext.cs

@ -0,0 +1,123 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Threading;
using CSharpBinding.Parser;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Parser;
namespace CSharpBinding
{
public class SDRefactoringContext : RefactoringContext
{
ITextEditor editor;
ICompilation compilation;
CancellationToken cancellationToken;
public SDRefactoringContext(ITextEditor editor, CancellationToken cancellationToken)
{
this.editor = editor;
this.cancellationToken = cancellationToken;
this.compilation = ParserService.GetCompilationForFile(editor.FileName);
}
public override bool Supports(Version version)
{
CSharpProject project = compilation.GetProject() as CSharpProject;
if (project == null)
return false;
return project.LanguageVersion >= version;
}
public override Script StartScript()
{
throw new NotImplementedException();
}
public override int SelectionStart {
get {
return editor.SelectionStart;
}
}
public override int SelectionLength {
get {
return editor.SelectionLength;
}
}
public override int SelectionEnd {
get {
return editor.SelectionStart + editor.SelectionLength;
}
}
public override string SelectedText {
get {
return editor.SelectedText;
}
}
public override ResolveResult Resolve(AstNode expression)
{
var parseInfo = ParserService.Parse(editor.FileName, editor.Document) as CSharpFullParseInformation;
var resolver = new CSharpAstResolver(compilation, parseInfo.CompilationUnit, parseInfo.ParsedFile);
return resolver.Resolve(expression, cancellationToken);
}
public override void ReplaceReferences(IMember member, MemberDeclaration replaceWidth)
{
throw new NotImplementedException();
}
public override bool IsSomethingSelected {
get {
return editor.SelectionLength > 0;
}
}
public override string GetText(int offset, int length)
{
return editor.Document.GetText(offset, length);
}
public override int GetOffset(TextLocation location)
{
return editor.Document.GetOffset(location);
}
public override TextLocation GetLocation(int offset)
{
return editor.Document.GetLocation(offset);
}
public override CSharpFormattingOptions FormattingOptions {
get {
return new CSharpFormattingOptions();
}
}
public override string EolMarker {
get {
return DocumentUtilitites.GetLineTerminator(editor.Document, 1);
}
}
public override AstType CreateShortType(IType fullType)
{
var parseInfo = ParserService.Parse(editor.FileName, editor.Document) as CSharpFullParseInformation;
var parsedFile = parseInfo.ParsedFile;
var csResolver = parsedFile.GetResolver(compilation, editor.Caret.Location);
var builder = new TypeSystemAstBuilder(csResolver);
return builder.ConvertType(fullType);
}
}
}

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs

@ -75,13 +75,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// } // }
// } // }
// //
static readonly Version csharp3 = new Version(3, 0);
static IField GetBackingField (RefactoringContext context) static IField GetBackingField (RefactoringContext context)
{ {
var propertyDeclaration = context.GetNode<PropertyDeclaration> (); var propertyDeclaration = context.GetNode<PropertyDeclaration> ();
// automatic properties always need getter & setter // automatic properties always need getter & setter
if (propertyDeclaration == null || propertyDeclaration.Getter.IsNull || propertyDeclaration.Setter.IsNull || propertyDeclaration.Getter.Body.IsNull || propertyDeclaration.Setter.Body.IsNull) if (propertyDeclaration == null || propertyDeclaration.Getter.IsNull || propertyDeclaration.Setter.IsNull || propertyDeclaration.Getter.Body.IsNull || propertyDeclaration.Setter.Body.IsNull)
return null; return null;
if (!context.HasCSharp3Support || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface) if (!context.Supports(csharp3) || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface)
return null; return null;
var getterField = ScanGetter (context, propertyDeclaration); var getterField = ScanGetter (context, propertyDeclaration);
if (getterField == null) if (getterField == null)

4
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/RefactoringContext.cs

@ -44,9 +44,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
protected set; protected set;
} }
public abstract bool HasCSharp3Support { public abstract bool Supports(Version version);
get;
}
public ICompilation Compilation { public ICompilation Compilation {
get; get;

2
src/Main/Base/Project/Src/Project/Behaviors/DotNetStartBehavior.cs

@ -141,7 +141,7 @@ namespace ICSharpCode.SharpDevelop.Project
lock (Project.SyncRoot) { lock (Project.SyncRoot) {
TargetFramework oldFramework = ((CompilableProject)Project).CurrentTargetFramework; TargetFramework oldFramework = ((CompilableProject)Project).CurrentTargetFramework;
if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) { if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
((CompilableProject)Project).SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor); ((CompilableProject)Project).ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
} }
if (newFramework != null) { if (newFramework != null) {
UpdateAppConfig(newFramework); UpdateAppConfig(newFramework);

10
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -118,17 +118,19 @@ namespace ICSharpCode.SharpDevelop.Project
public event EventHandler MinimumSolutionVersionChanged; public event EventHandler MinimumSolutionVersionChanged;
protected internal void SetToolsVersion(string newToolsVersion) public string ToolsVersion {
{ get { return projectFile.ToolsVersion; }
protected internal set {
PerformUpdateOnProjectFile( PerformUpdateOnProjectFile(
delegate { delegate {
projectFile.ToolsVersion = newToolsVersion; projectFile.ToolsVersion = value;
userProjectFile.ToolsVersion = newToolsVersion; userProjectFile.ToolsVersion = value;
}); });
if (MinimumSolutionVersionChanged != null) if (MinimumSolutionVersionChanged != null)
MinimumSolutionVersionChanged(this, EventArgs.Empty); MinimumSolutionVersionChanged(this, EventArgs.Empty);
} }
}
public void PerformUpdateOnProjectFile(Action action) public void PerformUpdateOnProjectFile(Action action)
{ {

Loading…
Cancel
Save