Browse Source

Merge branch 'master' of github.com:icsharpcode/SharpDevelop

pull/503/head
Peter Forstmeier 11 years ago
parent
commit
2882c6a88d
  1. 35
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs
  2. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs
  3. 7
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs
  4. 28
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs
  5. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  6. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  7. 4
      src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs
  8. 1
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertMissingTokensDecorator.cs
  9. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  10. 49
      src/Main/Base/Project/Workbench/File/FileHelpers.cs
  11. 32
      src/Main/SharpDevelop/Workbench/FileService.cs

35
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

@ -58,6 +58,7 @@ namespace ICSharpCode.CodeCoverage @@ -58,6 +58,7 @@ namespace ICSharpCode.CodeCoverage
public string FileID { get; private set; }
public string FileName { get; private set; }
public string FileNameExt { get; private set; }
public bool IsVisited { get; private set; }
public int CyclomaticComplexity { get; private set; }
public decimal SequenceCoverage { get; private set; }
@ -86,9 +87,14 @@ namespace ICSharpCode.CodeCoverage @@ -86,9 +87,14 @@ namespace ICSharpCode.CodeCoverage
this.FileID = GetFileRef();
this.FileName = String.Empty;
this.FileNameExt = String.Empty;
if (!String.IsNullOrEmpty(this.FileID)) {
if (results != null) {
this.FileName = results.GetFileName(this.FileID);
try {
this.FileNameExt = Path.GetExtension(this.FileName).ToLowerInvariant();
}
catch {}
if (cacheFileName != this.FileName) {
cacheFileName = this.FileName;
cacheDocument = GetSource (cacheFileName);
@ -220,6 +226,7 @@ namespace ICSharpCode.CodeCoverage @@ -220,6 +226,7 @@ namespace ICSharpCode.CodeCoverage
// -> this method SP with lowest Line/Column
void getBodyStartSP() {
if (this.SequencePoints.Count != 0) {
if (this.FileNameExt == ".cs") {
foreach (CodeCoverageSequencePoint sp in this.SequencePoints) {
if (sp.FileID != this.FileID) continue;
if (this.BodyStartSP == null || (sp.Line < this.BodyStartSP.Line) ||
@ -229,6 +236,10 @@ namespace ICSharpCode.CodeCoverage @@ -229,6 +236,10 @@ namespace ICSharpCode.CodeCoverage
}
}
}
else {
this.BodyStartSP = this.SequencePoints.First();
}
}
}
// Find method-body last SequencePoint
@ -236,6 +247,7 @@ namespace ICSharpCode.CodeCoverage @@ -236,6 +247,7 @@ namespace ICSharpCode.CodeCoverage
// and lowest Offset (when duplicated bw ccrewrite)
void getBodyFinalSP() {
if (this.SequencePoints.Count != 0) {
if (this.FileNameExt == ".cs") {
for (int i = this.SequencePoints.Count-1; i > 0; i--) {
var sp = this.SequencePoints[i];
if (sp.FileID != this.FileID) continue;
@ -260,6 +272,10 @@ namespace ICSharpCode.CodeCoverage @@ -260,6 +272,10 @@ namespace ICSharpCode.CodeCoverage
}
}
}
else {
this.BodyFinalSP = this.SequencePoints.Last();
}
}
}
int GetSequencePointsCount() {
@ -273,6 +289,9 @@ namespace ICSharpCode.CodeCoverage @@ -273,6 +289,9 @@ namespace ICSharpCode.CodeCoverage
return 0;
}
const string @assert = "Assert";
const string @contract = "Contract";
void GetBranchRatio () {
this.BranchCoverageRatio = null;
@ -295,8 +314,11 @@ namespace ICSharpCode.CodeCoverage @@ -295,8 +314,11 @@ namespace ICSharpCode.CodeCoverage
// SequencePoint is visited and belongs to this method?
if (sp.VisitCount != 0 && sp.FileID == this.FileID) {
if (this.FileNameExt == ".cs") {
// Only for C#
// Don't want branch coverage of ccrewrite(n)
// SequencePoint's with offset before and after method body
// SequencePoint(s) with offset before and after method body
if (sp.Offset < BodyStartSP.Offset ||
sp.Offset > BodyFinalSP.Offset) {
sp.BranchCoverage = true;
@ -310,17 +332,16 @@ namespace ICSharpCode.CodeCoverage @@ -310,17 +332,16 @@ namespace ICSharpCode.CodeCoverage
// ie: static methods start sequence point "{" contains compiler generated branches
// 3) Exclude Contract class (EnsuresOnThrow/Assert/Assume is inside method body)
// 4) Exclude NUnit Assert(.Throws) class
const string assert = "Assert";
const string contract = "Contract";
if (sp.Content == "in" || sp.Content == "{" || sp.Content == "}" ||
sp.Content.StartsWith(assert + ".", StringComparison.Ordinal) ||
sp.Content.StartsWith(assert + " ", StringComparison.Ordinal) ||
sp.Content.StartsWith(contract + ".", StringComparison.Ordinal) ||
sp.Content.StartsWith(contract + " ", StringComparison.Ordinal)
sp.Content.StartsWith(@assert + ".", StringComparison.Ordinal) ||
sp.Content.StartsWith(@assert + " ", StringComparison.Ordinal) ||
sp.Content.StartsWith(@contract + ".", StringComparison.Ordinal) ||
sp.Content.StartsWith(@contract + " ", StringComparison.Ordinal)
) {
sp.BranchCoverage = true;
continue; // skip
}
}
totalBranchCount += sp.BranchExitsCount;
totalBranchVisit += sp.BranchExitsVisit;

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs

@ -50,7 +50,9 @@ namespace CSharpBinding.Completion @@ -50,7 +50,9 @@ namespace CSharpBinding.Completion
public void Show()
{
window = editor.ShowInsightWindow(items);
window.StartOffset = startOffset;
// Set startOffset so that window always appears below the caret line
var startLocation = editor.Document.GetLocation(startOffset);
window.StartOffset = editor.Document.GetOffset(editor.Caret.Line, startLocation.Column);
// closing the window at the end of the parameter list is handled by the CaretPositionChanged event
window.EndOffset = editor.Document.TextLength;
if (initiallySelectedItem != null)

7
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs

@ -86,7 +86,10 @@ namespace CSharpBinding.Refactoring @@ -86,7 +86,10 @@ namespace CSharpBinding.Refactoring
var node = context.RootNode.GetNodeAt<EntityDeclaration>(last.Region.Begin);
var resolver = context.GetResolverStateAfter(node);
var builder = new TypeSystemAstBuilder(resolver);
var delegateDecl = builder.ConvertEntity(eventDefinition.ReturnType.GetDefinition()) as DelegateDeclaration;
var invokeMethod = eventDefinition.ReturnType.GetDelegateInvokeMethod();
if (invokeMethod == null) return;
var importedMethod = resolver.Compilation.Import(invokeMethod);
var delegateDecl = builder.ConvertEntity(importedMethod) as MethodDeclaration;
if (delegateDecl == null) return;
var throwStmt = new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")));
var decl = new MethodDeclaration() {
@ -96,7 +99,7 @@ namespace CSharpBinding.Refactoring @@ -96,7 +99,7 @@ namespace CSharpBinding.Refactoring
throwStmt
}
};
var param = delegateDecl.Parameters.Select(p => p.Clone()).OfType<ParameterDeclaration>().ToArray();
var param = delegateDecl.Parameters.Select(p => p.Clone()).ToArray();
decl.Parameters.AddRange(param);
using (Script script = context.StartScript()) {

28
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using ICSharpCode.Core;
using ICSharpCode.NRefactory;
@ -82,7 +83,32 @@ namespace ICSharpCode.ILSpyAddIn @@ -82,7 +83,32 @@ namespace ICSharpCode.ILSpyAddIn
public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
{
return null;
var decompiledParseInfo = parseInfo as ILSpyFullParseInformation;
if (decompiledParseInfo == null)
throw new ArgumentException("ParseInfo does not have SyntaxTree");
CSharpAstResolver contextResolver = new CSharpAstResolver(compilation, decompiledParseInfo.SyntaxTree, null);
var node = decompiledParseInfo.SyntaxTree.GetNodeAt(location);
CSharpResolver context;
if (node != null)
context = contextResolver.GetResolverStateAfter(node, cancellationToken);
else
context = new CSharpResolver(compilation);
CSharpParser parser = new CSharpParser();
var expr = parser.ParseExpression(codeSnippet);
if (parser.HasErrors)
return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty);
CSharpAstResolver snippetResolver = new CSharpAstResolver(context, expr);
return snippetResolver.Resolve(expr, cancellationToken);
}
string PrintErrorsAsString(IEnumerable<Error> errors)
{
StringBuilder builder = new StringBuilder();
foreach (var error in errors)
builder.AppendLine(error.Message);
return builder.ToString();
}
public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action<SearchResultMatch> callback, CancellationToken cancellationToken)

26
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -668,6 +668,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -668,6 +668,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
}
public void AddNativeTypeAsResource(object component, string expectedXamlValue)
{
AddTypeAsResource(component, expectedXamlValue, "Controls0:", new string[] { "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\""} );
}
public void AddTypeAsResource(object component, string expectedXamlValue, string typePrefix, String[] additionalXmlns)
{
DesignItem textBlock = CreateCanvasContext("<TextBlock/>");
DesignItem canvas = textBlock.Parent;
@ -687,11 +692,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -687,11 +692,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
string typeName = component.GetType().Name;
string expectedXaml = "<Canvas.Resources>\n" +
" <Controls0:" + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</Controls0:" + typeName + ">\n" +
" <" + typePrefix + typeName + " x:Key=\"res1\">" + expectedXamlValue + "</" + typePrefix + typeName + ">\n" +
"</Canvas.Resources>\n" +
"<TextBlock Tag=\"{StaticResource ResourceKey=res1}\" />";
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, "xmlns:Controls0=\"clr-namespace:System;assembly=mscorlib\"");
AssertCanvasDesignerOutput(expectedXaml, textBlock.Context, additionalXmlns);
AssertLog("");
}
@ -736,6 +741,18 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -736,6 +741,18 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
const int i = 123;
AddNativeTypeAsResource(i, "123");
}
[Test]
public void AddWpfEnumAsResource()
{
AddTypeAsResource(VerticalAlignment.Center, "Center", "", new string[0]);
}
[Test]
public void AddCustomEnumAsResource()
{
AddTypeAsResource(MyEnum.One, "One", "t:", new string[0]);
}
}
public class MyMultiConverter : IMultiValueConverter
@ -760,4 +777,9 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -760,4 +777,9 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
set { stringProp = value; }
}
}
public enum MyEnum
{
One, Two
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -275,7 +275,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -275,7 +275,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
bool IsNativeType(object instance)
{
return instance.GetType().Assembly == typeof(String).Assembly;
return instance.GetType().Assembly == typeof(String).Assembly || instance.GetType().IsEnum;
}
}
}

4
src/AddIns/VersionControl/SubversionAddIn/Src/Commands/AutostartCommands.cs

@ -389,6 +389,10 @@ namespace ICSharpCode.Svn.Commands @@ -389,6 +389,10 @@ namespace ICSharpCode.Svn.Commands
if (!AddInOptions.AutomaticallyRenameFiles) return;
string fullSource = Path.GetFullPath(e.SourceFile);
if (!CanBeVersionControlledFile(fullSource)) return;
if (!FileHelpers.CheckRenameOrReplacePossible(e)) {
e.Cancel = true;
return;
}
try {
using (SvnClientWrapper client = new SvnClientWrapper()) {
SvnMessageView.HandleNotifications(client);

1
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertMissingTokensDecorator.cs

@ -61,6 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -61,6 +61,7 @@ namespace ICSharpCode.NRefactory.CSharp
public override void WriteToken(Role role, string token)
{
CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
t.Role = role;
EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement;
if (node == null)
currentList.Add(t);

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -366,6 +366,7 @@ @@ -366,6 +366,7 @@
<Compile Include="Workbench\DisplayBinding\ISecondaryDisplayBinding.cs" />
<Compile Include="Workbench\FakeXmlViewContent.cs" />
<Compile Include="Workbench\FileChangeWatcher.cs" />
<Compile Include="Workbench\File\FileHelpers.cs" />
<Compile Include="Workbench\File\FileService.cs" />
<Compile Include="Workbench\File\IRecentOpen.cs" />
<Compile Include="Workbench\ICustomizedCommands.cs" />

49
src/Main/Base/Project/Workbench/File/FileHelpers.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Workbench
{
/// <summary>
/// Utility/helper methods for IFileService to avoid changing the IFileService interface.
/// </summary>
public static class FileHelpers
{
/// <summary>
/// Checks that the rename/overwrite operation is possible.
/// </summary>
public static bool CheckRenameOrReplacePossible(FileRenameEventArgs e, bool replaceAllowed = false)
{
if (e.IsDirectory && Directory.Exists(e.SourceFile)) {
if (!replaceAllowed && Directory.Exists(e.TargetFile)) {
SD.MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
} else if (File.Exists(e.SourceFile)) {
if (!replaceAllowed && File.Exists(e.TargetFile)) {
SD.MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
}
return true;
}
}
}

32
src/Main/SharpDevelop/Workbench/FileService.cs

@ -580,21 +580,13 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -580,21 +580,13 @@ namespace ICSharpCode.SharpDevelop.Workbench
return false;
if (!eargs.OperationAlreadyDone) {
try {
if (isDirectory && Directory.Exists(oldName)) {
if (Directory.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
if (FileHelpers.CheckRenameOrReplacePossible(eargs)) {
if (isDirectory) {
Directory.Move(oldName, newName);
} else if (File.Exists(oldName)) {
if (File.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
} else {
File.Move(oldName, newName);
}
}
} catch (Exception e) {
if (isDirectory) {
MessageService.ShowHandledException(e, "Can't rename directory " + oldName);
@ -624,21 +616,13 @@ namespace ICSharpCode.SharpDevelop.Workbench @@ -624,21 +616,13 @@ namespace ICSharpCode.SharpDevelop.Workbench
return false;
if (!eargs.OperationAlreadyDone) {
try {
if (isDirectory && Directory.Exists(oldName)) {
if (!overwrite && Directory.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
if (FileHelpers.CheckRenameOrReplacePossible(eargs, overwrite)) {
if (isDirectory) {
FileUtility.DeepCopy(oldName, newName, overwrite);
} else if (File.Exists(oldName)) {
if (!overwrite && File.Exists(newName)) {
MessageService.ShowMessage(StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}"));
return false;
}
} else {
File.Copy(oldName, newName, overwrite);
}
}
} catch (Exception e) {
if (isDirectory) {
MessageService.ShowHandledException(e, "Can't copy directory " + oldName);

Loading…
Cancel
Save