Browse Source

architectural changes in XamlBinding

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3950 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
a86a467ff3
  1. 51
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/Utils.cs
  2. 3
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlBinding.csproj
  3. 281
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCodeCompletionBinding.cs
  4. 5
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs
  5. 91
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs
  6. 54
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemProvider.cs
  7. 15
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs
  8. 155
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlResolver.cs

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

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.XmlEditor;
using System;
using System.IO;
using System.Xml;
namespace ICSharpCode.XamlBinding
{
/// <summary>
/// Description of Utils.
/// </summary>
public static class Utils
{
public static bool HasMatchingEndTag(string tagname, string text, int offset)
{
int index = XmlParser.GetActiveElementStartIndex(text, offset);
if (index == -1)
return false;
text = text.Substring(index);
XmlReader reader = XmlTextReader.Create(new StringReader(text));
int startTags = 0;
try {
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
startTags++;
break;
case XmlNodeType.EndElement:
startTags--;
if (startTags == 0 && tagname == reader.Name) {
return true;
}
break;
}
}
} catch (XmlException) {
return false;
}
return false;
}
}
}

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

@ -51,11 +51,12 @@ @@ -51,11 +51,12 @@
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Utils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XamlClassReturnType.cs" />
<Compile Include="XamlCodeCompletionBinding.cs" />
<Compile Include="XamlCompilationUnit.cs" />
<Compile Include="XamlCompletionItemProvider.cs" />
<Compile Include="XamlCompletionItemList.cs" />
<Compile Include="XamlExpressionContext.cs" />
<Compile Include="XamlExpressionFinder.cs" />
<Compile Include="XamlParser.cs" />

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

@ -1,40 +1,97 @@ @@ -1,40 +1,97 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision: 3494 $</version>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision: 3731 $</version>
// </file>
using ICSharpCode.SharpDevelop;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
public enum XamlContext {
/// <summary>
/// After '&lt;'
/// </summary>
AtTag,
/// <summary>
/// Inside '&lt;TagName &gt;'
/// </summary>
InTag,
/// <summary>
/// Inside '="Value"'
/// </summary>
InAttributeValue
}
public class XamlCodeCompletionBinding : ICodeCompletionBinding
{
public CodeCompletionKeyPressResult HandleKeyPress(ICSharpCode.SharpDevelop.ITextEditor editor, char ch)
public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
{
XamlCompletionItemProvider provider;
XamlResolver resolver = new XamlResolver();
int offset;
switch (ch) {
case '<':
provider = new XamlCompletionItemProvider(XamlExpressionContext.Empty);
provider.ShowCompletion(editor);
return CodeCompletionKeyPressResult.Completed;
int prevLTCharPos = GetPreviousLTCharPos(editor.Document.Text, editor.Caret.Offset) + 1;
XmlElementPath elPath = XmlParser.GetActiveElementStartPathAtIndex(editor.Document.Text, prevLTCharPos);
if (elPath != null && elPath.Elements.Count > 0) {
ICompletionItemList list = CreateListForContext(editor, XamlContext.AtTag, elPath, null);
editor.ShowCompletionWindow(list);
return CodeCompletionKeyPressResult.Completed;
}
break;
case '>': // XML tag completion
offset = editor.Caret.Offset;
if (offset > 0) {
int searchOffset = offset - 1;
char c = editor.Document.GetCharAt(searchOffset);
while (char.IsWhiteSpace(c)) {
searchOffset--;
c = editor.Document.GetCharAt(searchOffset);
}
if (c != '/') {
string document = editor.Document.Text.Insert(offset, ">");
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(document, offset);
if (path != null && path.Elements.Count > 0) {
QualifiedName last = path.Elements[path.Elements.Count - 1];
if (!Utils.HasMatchingEndTag(last.Name, document, offset)) {
editor.Document.Insert(offset, "></" + last.Name + ">");
editor.Caret.Offset = offset + 1;
return CodeCompletionKeyPressResult.EatKey;
}
}
}
}
break;
case ' ':
XmlElementPath ePath = XmlParser.GetActiveElementStartPathAtIndex(editor.Document.Text, editor.Caret.Offset);
if (ePath != null && ePath.Elements.Count > 0) {
ICompletionItemList list = CreateListForContext(editor, XamlContext.InTag, ePath, null);
editor.ShowCompletionWindow(list);
return CodeCompletionKeyPressResult.Completed;
}
break;
default:
if (char.IsLetter(ch)) {
int offset = editor.Caret.Offset;
offset = editor.Caret.Offset;
if (offset > 0) {
char c = editor.Document.GetCharAt(offset - 1);
if (c == ' ' || c == '\t') {
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(editor.Document.Text, offset);
if (path != null && path.Elements.Count > 0) {
provider = new XamlCompletionItemProvider(new XamlExpressionContext(path, "", false));
provider.ShowCompletion(editor);
ICompletionItemList list = CreateListForContext(editor, XamlContext.InTag, path, null);
editor.ShowCompletionWindow(list);
return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion;
}
}
@ -46,11 +103,205 @@ namespace ICSharpCode.XamlBinding @@ -46,11 +103,205 @@ namespace ICSharpCode.XamlBinding
return CodeCompletionKeyPressResult.None;
}
int GetPreviousLTCharPos(string text, int startIndex)
{
if (text == null)
throw new ArgumentNullException("text");
if (startIndex < 0)
return -1;
if (startIndex >= text.Length)
startIndex = text.Length - 1;
while (startIndex > -1 && text[startIndex] != '<')
startIndex--;
return startIndex;
}
static readonly List<ICompletionItem> standardItems = new List<ICompletionItem> {
new DefaultCompletionItem("!--"),
new DefaultCompletionItem("![CDATA["),
new DefaultCompletionItem("?")
};
public static ICompletionItemList CreateListForContext(ITextEditor editor, XamlContext context, XmlElementPath path, IEntity entity)
{
XamlCompletionItemList list = new XamlCompletionItemList();
ParseInformation info = ParserService.GetParseInformation(editor.FileName);
switch (context) {
case XamlContext.AtTag:
list.Items.AddRange(standardItems);
list.Items.AddRange(CtrlSpaceForElement(info, editor.Document.Text, editor.Caret.Line, editor.Caret.Column));
break;
case XamlContext.InTag:
list.Items.AddRange(CtrlSpaceForAttributeName(info, editor.Document.Text, new XamlExpressionContext(path, null, false)));
break;
case XamlContext.InAttributeValue:
if (entity is IProperty) {
IProperty prop = entity as IProperty;
IClass c = prop.ReturnType.GetUnderlyingClass();
if (c.ClassType == ClassType.Enum) {
foreach (IField f in c.Fields) {
list.Items.Add(new XamlCompletionItem(f));
}
}
} else if (entity is IEvent) {
}
break;
}
list.SortItems();
return list;
}
public bool CtrlSpace(ICSharpCode.SharpDevelop.ITextEditor editor)
{
XamlCompletionItemProvider provider = new XamlCompletionItemProvider(XamlExpressionContext.Empty);
provider.ShowCompletion(editor);
// XamlCompletionItemProvider provider = new XamlCompletionItemProvider(XamlExpressionContext.Empty);
// provider.ShowCompletion(editor);
return true;
}
// public ArrayList CtrlSpace(int caretLineNumber, int caretColumn, ParseInformation parseInfo, string fileContent, ExpressionContext expressionContext)
// {
// var callingClass = parseInfo.BestCompilationUnit.GetInnermostClass(caretLineNumber, caretColumn);
// var context = expressionContext as XamlExpressionContext;
// if (context == null) {
// return null;
// }
//
// if (context.AttributeName == null) {
// return CtrlSpaceForElement(fileContent);
// }
// else if (context.InAttributeValue) {
// return CtrlSpaceForAttributeValue(parseInfo, fileContent, context);
// }
// else {
// return CtrlSpaceForAttributeName(parseInfo, fileContent, context);
// }
// }
//
static List<ICompletionItem> CtrlSpaceForAttributeName(ParseInformation parseInfo, string fileContent, XamlExpressionContext context)
{
if (context.ElementPath.Elements.Count == 0)
return null;
QualifiedName lastElement = context.ElementPath.Elements[context.ElementPath.Elements.Count - 1];
XamlCompilationUnit cu = parseInfo.BestCompilationUnit as XamlCompilationUnit;
if (cu == null)
return null;
IReturnType rt = cu.CreateType(lastElement.Namespace, lastElement.Name);
if (rt == null)
return null;
var list = new List<ICompletionItem>();
foreach (IProperty p in rt.GetProperties()) {
if (p.IsPublic && p.CanSet) {
list.Add(new XamlCompletionItem(p));
}
}
foreach (IEvent e in rt.GetEvents()) {
if (e.IsPublic) {
list.Add(new XamlCompletionItem(e));
}
}
return list;
}
//
// ArrayList CtrlSpaceForAttributeValue(ParseInformation parseInfo, string fileContent, XamlExpressionContext context)
// {
// ArrayList attributes = CtrlSpaceForAttributeName(parseInfo, fileContent, context);
// if (attributes != null) {
// foreach (IProperty p in attributes.OfType<IProperty>()) {
// if (p.Name == context.AttributeName && p.ReturnType != null) {
// IClass c = p.ReturnType.GetUnderlyingClass();
// if (c != null && c.ClassType == ClassType.Enum) {
// return EnumCompletion(c);
// }
// }
// }
// }
// return null;
// }
//
// ArrayList EnumCompletion(IClass enumClass)
// {
// }
//
static bool IsReaderAtTarget(XmlTextReader r, int caretLine, int caretColumn)
{
if (r.LineNumber > caretLine)
return true;
else if (r.LineNumber == caretLine)
return r.LinePosition >= caretColumn;
else
return false;
}
static List<ICompletionItem> CtrlSpaceForElement(ParseInformation parseInfo, string fileContent, int caretLine, int caretColumn)
{
using (XmlTextReader r = new XmlTextReader(new StringReader(fileContent))) {
try {
r.WhitespaceHandling = WhitespaceHandling.Significant;
// move reader to correct position
while (r.Read() && !IsReaderAtTarget(r, caretLine, caretColumn)) { }
}
catch (XmlException) {
}
var result = new List<ICompletionItem>();
IProjectContent pc = parseInfo.BestCompilationUnit.ProjectContent;
TypeResolveResult rr = new XamlResolver().Resolve(new ExpressionResult(r.Name), parseInfo, fileContent) as TypeResolveResult;
// if (rr != null) {
// AddPropertiesForType(result, r, rr);
// AddEventsForType(result, r, rr);
// }
foreach (var ns in r.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)) {
var list = XamlCompilationUnit.GetNamespaceMembers(pc, ns.Value);
if (list != null) {
foreach (IClass c in list.OfType<IClass>()) {
if (c.ClassType != ClassType.Class)
continue;
if (c.IsAbstract && c.IsStatic)
continue;
if (c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute"))
continue;
if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic))
continue;
if (string.IsNullOrEmpty(ns.Key))
result.Add(new XamlCompletionItem(c));
else
result.Add(new XamlCompletionItem(c, ns.Key));
}
}
}
return result;
}
}
}
class XamlCompletionItem : DefaultCompletionItem
{
IEntity entity;
public IEntity Entity {
get { return entity; }
}
public XamlCompletionItem(IEntity entity, string prefix)
: base(prefix + ":" + entity.Name)
{
this.entity = entity;
}
public XamlCompletionItem(IEntity entity)
: base(entity.Name)
{
this.entity = entity;
}
}
}

5
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompilationUnit.cs

@ -26,8 +26,7 @@ namespace ICSharpCode.XamlBinding @@ -26,8 +26,7 @@ namespace ICSharpCode.XamlBinding
{
if (xmlNamespace.StartsWith("clr-namespace:")) {
return CreateClrNamespaceType(this.ProjectContent, xmlNamespace, className);
}
else {
} else {
return new XamlClassReturnType(this, xmlNamespace, className);
}
}
@ -97,7 +96,7 @@ namespace ICSharpCode.XamlBinding @@ -97,7 +96,7 @@ namespace ICSharpCode.XamlBinding
{
if (pc == null)
throw new ArgumentNullException("pc");
if (xmlNamespace == null)
if (string.IsNullOrEmpty(xmlNamespace))
return null;
if (xmlNamespace.StartsWith("clr-namespace:")) {
return pc.GetNamespaceContents(GetNamespaceNameFromClrNamespace(xmlNamespace));

91
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemList.cs

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="sie_pam@gmx.at"/>
// <version>$Revision: 3731 $</version>
// </file>
using ICSharpCode.SharpDevelop.Dom.Refactoring;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.XmlEditor;
namespace ICSharpCode.XamlBinding
{
sealed class XamlCompletionItemList : DefaultCompletionItemList
{
public XamlCompletionItemList()
{
}
public override CompletionItemListKeyResult ProcessInput(char key)
{
return base.ProcessInput(key);
}
public override void Complete(CompletionContext context, ICompletionItem item)
{
if (item is XamlCompletionItem) {
XamlCompletionItem cItem = item as XamlCompletionItem;
if (cItem.Entity is IProperty) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.Editor.Caret.Offset--;
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(context.Editor.Document.Text, context.Editor.Caret.Offset);
if (path != null && path.Elements.Count > 0) {
ICompletionItemList list = XamlCodeCompletionBinding.CreateListForContext(context.Editor, XamlContext.InAttributeValue, path, cItem.Entity);
context.Editor.ShowCompletionWindow(list);
}
}
if (cItem.Entity is IEvent) {
context.Editor.Document.Insert(context.EndOffset, "=\"\"");
context.Editor.Caret.Offset--;
XmlElementPath path = XmlParser.GetActiveElementStartPathAtIndex(context.Editor.Document.Text, context.Editor.Caret.Offset);
if (path != null && path.Elements.Count > 0) {
ICompletionItemList list = XamlCodeCompletionBinding.CreateListForContext(context.Editor, XamlContext.InAttributeValue, path, cItem.Entity);
context.Editor.ShowCompletionWindow(list);
}
}
} else {
if (item is DefaultCompletionItem) {
if (item.Text == "<new event handler>") { // TODO : replace with translation string
}
}
}
base.Complete(context, item);
}
string CreateEventHandlerCode(CompletionContext context, out IMember lastMember)
{
ParseInformation p = ParserService.GetParseInformation(context.Editor.FileName);
var unit = p.MostRecentCompilationUnit;
var loc = context.Editor.Document.OffsetToPosition(context.StartOffset);
IClass c = unit.GetInnermostClass(loc.Line, loc.Column);
CompoundClass compound = c.GetCompoundClass() as CompoundClass;
if (compound != null) {
foreach (IClass part in compound.Parts) {
RefactoringProvider provider = part.ProjectContent.Language.RefactoringProvider;
if (provider.SupportsCreateEventHandler) {
lastMember = part.Methods.Last();
//return provider.CreateEventHandler(;
}
}
}
lastMember = null;
return string.Empty;
}
}
}

54
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlCompletionItemProvider.cs

@ -1,54 +0,0 @@ @@ -1,54 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision: 3494 $</version>
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
namespace ICSharpCode.XamlBinding
{
sealed class XamlCompletionItemProvider : CtrlSpaceCompletionItemProvider
{
public XamlCompletionItemProvider()
{
}
public XamlCompletionItemProvider(XamlExpressionContext context)
: base(context)
{
}
public override ICompletionItemList GenerateCompletionListForCompletionData(ArrayList arr, ExpressionContext context)
{
DefaultCompletionItemList list = new DefaultCompletionItemList();
list.Items.AddRange(base.GenerateCompletionListForCompletionData(arr, context).Items);
if (context is XamlExpressionContext) {
XamlExpressionContext xContext = context as XamlExpressionContext;
if (string.IsNullOrEmpty(xContext.AttributeName) && !xContext.InAttributeValue) {
list.Items.Add(new DefaultCompletionItem("!--"));
list.Items.Add(new DefaultCompletionItem("![CDATA["));
list.Items.Add(new DefaultCompletionItem("?"));
}
}
list.SortItems();
return list;
}
}
}

15
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParser.cs

@ -23,22 +23,13 @@ namespace ICSharpCode.XamlBinding @@ -23,22 +23,13 @@ namespace ICSharpCode.XamlBinding
public string[] LexerTags
{
get
{
return lexerTags;
}
set
{
lexerTags = value;
}
get { return lexerTags; }
set { lexerTags = value; }
}
public LanguageProperties Language
{
get
{
return LanguageProperties.CSharp;
}
get { return LanguageProperties.CSharp; }
}
public bool CanParse(string fileName)

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

@ -28,7 +28,7 @@ namespace ICSharpCode.XamlBinding @@ -28,7 +28,7 @@ namespace ICSharpCode.XamlBinding
ParseInformation parseInfo;
int caretLineNumber, caretColumn;
bool IsReaderAtTarget(XmlTextReader r)
internal bool IsReaderAtTarget(XmlTextReader r)
{
if (r.LineNumber > caretLineNumber)
return true;
@ -55,7 +55,7 @@ namespace ICSharpCode.XamlBinding @@ -55,7 +55,7 @@ namespace ICSharpCode.XamlBinding
while (r.Read() && !IsReaderAtTarget(r)) { }
if (string.IsNullOrEmpty(context.AttributeName)) {
return ResolveElementName(r);
return ResolveElementName(r, expressionResult.Expression);
}
else if (context.InAttributeValue) {
MemberResolveResult mrr = ResolveAttribute(r, context.AttributeName);
@ -75,10 +75,11 @@ namespace ICSharpCode.XamlBinding @@ -75,10 +75,11 @@ namespace ICSharpCode.XamlBinding
}
}
ResolveResult ResolveElementName(XmlReader r)
ResolveResult ResolveElementName(XmlReader r, string exp)
{
string xmlNamespace;
string name;
this.resolveExpression = exp;
if (resolveExpression.Contains(":")) {
string prefix = resolveExpression.Substring(0, resolveExpression.IndexOf(':'));
name = resolveExpression.Substring(resolveExpression.IndexOf(':') + 1);
@ -179,114 +180,19 @@ namespace ICSharpCode.XamlBinding @@ -179,114 +180,19 @@ namespace ICSharpCode.XamlBinding
}
return null;
}
public ArrayList CtrlSpace(int caretLineNumber, int caretColumn, ParseInformation parseInfo, string fileContent, ExpressionContext expressionContext)
{
this.parseInfo = parseInfo;
this.caretLineNumber = caretLineNumber;
this.caretColumn = caretColumn;
this.callingClass = parseInfo.BestCompilationUnit.GetInnermostClass(caretLineNumber, caretColumn);
this.context = expressionContext as XamlExpressionContext;
if (context == null) {
return null;
}
if (context.AttributeName == null) {
return CtrlSpaceForElement(fileContent);
}
else if (context.InAttributeValue) {
return CtrlSpaceForAttributeValue(fileContent, context);
}
else {
return CtrlSpaceForAttributeName(fileContent, context);
}
}
ArrayList CtrlSpaceForAttributeName(string fileContent, XamlExpressionContext context)
{
if (context.ElementPath.Elements.Count == 0)
return null;
QualifiedName lastElement = context.ElementPath.Elements[context.ElementPath.Elements.Count - 1];
XamlCompilationUnit cu = parseInfo.BestCompilationUnit as XamlCompilationUnit;
if (cu == null)
return null;
IReturnType rt = cu.CreateType(lastElement.Namespace, lastElement.Name);
if (rt == null)
return null;
ArrayList list = new ArrayList();
foreach (IProperty p in rt.GetProperties()) {
if (p.IsPublic && p.CanSet) {
list.Add(p);
}
}
return list;
}
ArrayList CtrlSpaceForAttributeValue(string fileContent, XamlExpressionContext context)
{
ArrayList attributes = CtrlSpaceForAttributeName(fileContent, context);
if (attributes != null) {
foreach (IProperty p in attributes.OfType<IProperty>()) {
if (p.Name == context.AttributeName && p.ReturnType != null) {
IClass c = p.ReturnType.GetUnderlyingClass();
if (c != null && c.ClassType == ClassType.Enum) {
return EnumCompletion(c);
}
}
}
}
return null;
}
ArrayList EnumCompletion(IClass enumClass)
{
ArrayList arr = new ArrayList();
foreach (IField f in enumClass.Fields) {
arr.Add(f);
}
return arr;
}
ArrayList CtrlSpaceForElement(string fileContent)
void AddEventsForType(ArrayList result, XmlTextReader r, TypeResolveResult rr)
{
using (XmlTextReader r = new XmlTextReader(new StringReader(fileContent))) {
try {
r.WhitespaceHandling = WhitespaceHandling.Significant;
// move reader to correct position
while (r.Read() && !IsReaderAtTarget(r)) { }
}
catch (XmlException) {
}
ArrayList result = new ArrayList();
IProjectContent pc = parseInfo.BestCompilationUnit.ProjectContent;
resolveExpression = r.Name;
TypeResolveResult rr = ResolveElementName(r) as TypeResolveResult;
if (rr != null) {
AddPropertiesForType(result, r, rr);
}
foreach (var ns in r.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)) {
ArrayList list = XamlCompilationUnit.GetNamespaceMembers(pc, ns.Value);
if (list != null) {
foreach (IClass c in list.OfType<IClass>()) {
if (c.ClassType != ClassType.Class)
continue;
if (c.IsAbstract && c.IsStatic)
continue;
if (c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute"))
continue;
if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic))
continue;
if (string.IsNullOrEmpty(ns.Key))
result.Add(c);
else
result.Add(new XamlCompletionClass(c, ns.Key));
}
}
if (rr.ResolvedType != null) {
foreach (IEvent e in rr.ResolvedType.GetEvents()) {
if (!e.IsPublic)
continue;
string propPrefix = e.DeclaringType.Name;
if (!string.IsNullOrEmpty(r.Prefix))
propPrefix = r.Prefix + ":" + propPrefix;
result.Add(new XamlCompletionEvent(e, propPrefix));
}
return result;
}
}
@ -313,15 +219,18 @@ namespace ICSharpCode.XamlBinding @@ -313,15 +219,18 @@ namespace ICSharpCode.XamlBinding
return rt.GetMethods().Any(m => m.Name == "Add" && m.IsPublic);
}
class XamlCompletionClass : DefaultClass, IEntity
class XamlCompletionProperty : DefaultProperty, IEntity
{
string newName;
public XamlCompletionClass(IClass baseClass, string prefix)
: base(baseClass.CompilationUnit, baseClass.FullyQualifiedName)
public XamlCompletionProperty(IProperty baseProperty, string prefix)
: base(baseProperty.DeclaringType, baseProperty.Name)
{
this.Modifiers = baseClass.Modifiers;
newName = prefix + ":" + baseClass.Name;
this.Modifiers = baseProperty.Modifiers;
this.CopyDocumentationFrom(baseProperty);
newName = prefix + "." + baseProperty.Name;
}
string IEntity.Name
@ -329,16 +238,17 @@ namespace ICSharpCode.XamlBinding @@ -329,16 +238,17 @@ namespace ICSharpCode.XamlBinding
get { return newName; }
}
}
class XamlCompletionProperty : DefaultProperty, IEntity
class XamlCompletionEvent : DefaultEvent, IEntity
{
string newName;
public XamlCompletionProperty(IProperty baseProperty, string prefix)
: base(baseProperty.DeclaringType, baseProperty.Name)
public XamlCompletionEvent(IEvent baseEvent, string prefix)
: base(baseEvent.DeclaringType, baseEvent.Name)
{
this.Modifiers = baseProperty.Modifiers;
newName = prefix + "." + baseProperty.Name;
this.Modifiers = baseEvent.Modifiers;
this.CopyDocumentationFrom(baseEvent);
newName = prefix + "." + baseEvent.Name;
}
string IEntity.Name
@ -346,5 +256,10 @@ namespace ICSharpCode.XamlBinding @@ -346,5 +256,10 @@ namespace ICSharpCode.XamlBinding
get { return newName; }
}
}
public ArrayList CtrlSpace(int caretLine, int caretColumn, ParseInformation parseInfo, string fileContent, ExpressionContext context)
{
return new ArrayList();
}
}
}

Loading…
Cancel
Save