Browse Source

fixed Unit Tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4283 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 16 years ago
parent
commit
3754225517
  1. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XamlBinding.Tests.csproj
  2. 23
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs
  3. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionInfo.cs
  4. 7
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  5. 43
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  6. 2
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs
  7. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

3
src/AddIns/BackendBindings/XamlBinding/XamlBinding.Tests/XamlBinding.Tests.csproj

@ -39,8 +39,7 @@ @@ -39,8 +39,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\bin\Tools\NUnit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">

23
src/AddIns/BackendBindings/XamlBinding/XamlBinding/CompletionDataHelper.cs

@ -90,6 +90,12 @@ namespace ICSharpCode.XamlBinding @@ -90,6 +90,12 @@ namespace ICSharpCode.XamlBinding
if (Utils.IsInsideXmlComment(text, offset))
description = XamlContextDescription.InComment;
Dictionary<string, string> xmlnsDefs = new Dictionary<string, string>();
using (XmlTextReader reader = CreateReaderAtTarget(editor.Document.Text, editor.Caret.Line, editor.Caret.Column)) {
}
var context = new XamlContext() {
PressedKey = typedValue,
Description = description,
@ -98,7 +104,8 @@ namespace ICSharpCode.XamlBinding @@ -98,7 +104,8 @@ namespace ICSharpCode.XamlBinding
AttributeValue = value,
RawAttributeValue = attributeValue,
ValueStartOffset = offsetFromValueStart,
Path = (path == null || path.Elements.Count == 0) ? null : path
Path = (path == null || path.Elements.Count == 0) ? null : path,
XmlnsDefinitions = xmlnsDefs
};
LoggingService.Debug(context);
@ -355,7 +362,7 @@ namespace ICSharpCode.XamlBinding @@ -355,7 +362,7 @@ namespace ICSharpCode.XamlBinding
{
var ctors = trr.ResolvedType.GetMethods().Where(m => m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count);
if (ctors.Any(ctor => ctor.Parameters.Count >= markup.PositionalArguments.Count)) {
list.Items.AddRange(trr.ResolvedType.GetProperties().Select(p => new XamlCodeCompletionItem(p, p.Name + "=")).Cast<ICompletionItem>());
list.Items.AddRange(trr.ResolvedType.GetProperties().Where(p => p.CanSet && p.IsPublic).Select(p => new XamlCodeCompletionItem(p, p.Name + "=")).Cast<ICompletionItem>());
}
}
@ -542,11 +549,10 @@ namespace ICSharpCode.XamlBinding @@ -542,11 +549,10 @@ namespace ICSharpCode.XamlBinding
public static MarkupExtensionInfo GetInnermostMarkup(MarkupExtensionInfo markup)
{
var lastPair = markup.NamedArguments.LastOrDefault();
var last = markup.PositionalArguments.LastOrDefault();
if (markup.NamedArguments.Count > 0)
last = lastPair.Value;
last = markup.NamedArguments.LastOrDefault().Value;
if (last != null) {
if (!last.IsString) {
@ -557,7 +563,7 @@ namespace ICSharpCode.XamlBinding @@ -557,7 +563,7 @@ namespace ICSharpCode.XamlBinding
return markup;
}
static TypeResolveResult ResolveMarkupExtensionType(MarkupExtensionInfo markup, ParseInformation info, ITextEditor editor, XmlElementPath path)
public static TypeResolveResult ResolveMarkupExtensionType(MarkupExtensionInfo markup, ParseInformation info, ITextEditor editor, XmlElementPath path)
{
XamlResolver resolver = new XamlResolver();
TypeResolveResult trr = resolver.Resolve(new ExpressionResult(markup.ExtensionType, new XamlExpressionContext(path, null, false)), info, editor.Document.Text) as TypeResolveResult;
@ -566,6 +572,13 @@ namespace ICSharpCode.XamlBinding @@ -566,6 +572,13 @@ namespace ICSharpCode.XamlBinding
return trr;
}
public static TypeResolveResult ResolveType(string name, XamlContext context, ITextEditor editor)
{
return new XamlResolver()
.Resolve(new ExpressionResult(name, new XamlExpressionContext(context.Path, null, false)),
ParserService.GetParseInformation(editor.FileName), editor.Document.Text) as TypeResolveResult;
}
public static IEnumerable<ICompletionItem> AddMatchingEventHandlers(ITextEditor editor, IMethod delegateInvoker)
{
ParseInformation p = ParserService.GetParseInformation(editor.FileName);

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/MarkupExtensionInfo.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.XamlBinding @@ -22,7 +22,7 @@ namespace ICSharpCode.XamlBinding
public IDictionary<string, AttributeValue> NamedArguments { get; private set; }
public MarkupExtensionInfo()
: this(string.Empty, new List<AttributeValue>(), new Dictionary<string, AttributeValue>())
: this(string.Empty, new List<AttributeValue>(), new Dictionary<string, AttributeValue>(StringComparer.OrdinalIgnoreCase))
{
}

7
src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs

@ -5,14 +5,16 @@ @@ -5,14 +5,16 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Editor;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
@ -234,7 +236,8 @@ namespace ICSharpCode.XamlBinding @@ -234,7 +236,8 @@ namespace ICSharpCode.XamlBinding
var list = Utils.GetXmlNamespacesForOffset(text, offset);
foreach (var item in list) {
namespaceDecls += item.Key + "=\"" + item.Value + "\" ";
if (!Regex.IsMatch(text, item.Key + "\\s*=\\s*\""))
namespaceDecls += item.Key + "=\"" + item.Value + "\" ";
}
text = "<" + name + " " + newText + " " + namespaceDecls + " />";

43
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs

@ -5,13 +5,15 @@ @@ -5,13 +5,15 @@
// <version>$Revision: 3731 $</version>
// </file>
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
@ -189,6 +191,30 @@ namespace ICSharpCode.XamlBinding @@ -189,6 +191,30 @@ namespace ICSharpCode.XamlBinding
editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr));
}
if (context.AttributeName == "Property" && context.Path.Elements.LastOrDefault().Name == "Setter") {
int offset = Utils.GetParentElementStart(editor);
string[] attributes = Utils.GetListOfExistingAttributeNames(editor.Document.Text, offset);
if (attributes.Contains("TargetType")) {
AttributeValue value = MarkupExtensionParser.ParseValue(Utils.GetAttributeValue(editor.Document.Text, offset, "TargetType"));
if (!value.IsString) {
TypeResolveResult trr = CompletionDataHelper.ResolveMarkupExtensionType(value.ExtensionValue, info, editor, context.Path);
var typeName = CompletionDataHelper.ResolveType(GetTypeNameFromTypeExtension(value.ExtensionValue), context, editor);
if (trr != null && trr.ResolvedClass != null && trr.ResolvedClass.FullyQualifiedName == "System.Windows.Markup.TypeExtension"
&& typeName != null && typeName != null) {
/* completionList.Items.AddRange(
typeName.ResolvedClass.Properties
.Where(p => p.IsPublic && p.CanSet)
.Select(prop => new DefaultCompletionItem(prop.Name))
.Cast<ICompletionItem>()
);*/
}
}
}
}
if (context.AttributeName.StartsWith("xmlns"))
completionList.Items.AddRange(CompletionDataHelper.CreateListForXmlnsCompletion(info.BestCompilationUnit.ProjectContent));
@ -205,6 +231,21 @@ namespace ICSharpCode.XamlBinding @@ -205,6 +231,21 @@ namespace ICSharpCode.XamlBinding
return false;
}
static string GetTypeNameFromTypeExtension(MarkupExtensionInfo info)
{
var item = info.PositionalArguments.FirstOrDefault();
if (item != null && item.IsString) {
return item.StringValue;
} else {
if (info.NamedArguments.TryGetValue("typename", out item)) {
if (item.IsString)
return item.StringValue;
}
}
return string.Empty;
}
static bool DoMarkupExtensionCompletion(ITextEditor editor, ParseInformation info, XamlContext context)
{
if (context.AttributeValue != null && !context.AttributeValue.IsString) {

2
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlContext.cs

@ -28,6 +28,7 @@ namespace ICSharpCode.XamlBinding @@ -28,6 +28,7 @@ namespace ICSharpCode.XamlBinding
public int ValueStartOffset { get; set; }
public XamlContextDescription Description { get; set; }
public bool Forced { get; set; }
public Dictionary<string, string> XmlnsDefinitions { get; set; }
public XamlContext() {}
@ -40,7 +41,6 @@ namespace ICSharpCode.XamlBinding @@ -40,7 +41,6 @@ namespace ICSharpCode.XamlBinding
" ValueStartOffset: " + ValueStartOffset +
" ]";
}
}
public enum XamlContextDescription {

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

@ -77,6 +77,7 @@ namespace ICSharpCode.XamlBinding @@ -77,6 +77,7 @@ namespace ICSharpCode.XamlBinding
ResolveResult ResolveElementName(XmlReader r, string exp)
{
//Utils.GetXmlNamespacesForOffset(
string xmlNamespace;
string name;
this.resolveExpression = exp;

Loading…
Cancel
Save