Browse Source
Allow for code completion on ArrayReturnType and ConstructedReturnType even if they are encapsulated by an InferredReturnType. Fixed code completion on arrays created through array literals or the "array" builtin. Recognize variables created by "for" statements if their type is inferred from the element type of the enumerable object. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@610 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
22 changed files with 434 additions and 170 deletions
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Daniel Grunwald |
||||
* Date: 22.10.2005 |
||||
* Time: 19:19 |
||||
*/ |
||||
|
||||
using System; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace Grunwald.BooBinding.CodeCompletion |
||||
{ |
||||
/// <summary>
|
||||
/// The return type that is the element of an enumerable.
|
||||
/// Used to infer the type in "for x in enumerableVariable" loops.
|
||||
/// </summary>
|
||||
public class ElementReturnType : ProxyReturnType |
||||
{ |
||||
IReturnType listType; |
||||
|
||||
public ElementReturnType(IReturnType listType) |
||||
{ |
||||
// listType is probably an InferredReturnType
|
||||
this.listType = listType; |
||||
} |
||||
|
||||
public override IReturnType BaseType { |
||||
get { |
||||
// get element type from listType
|
||||
if (listType.ArrayDimensions > 0) |
||||
return listType.ArrayElementType; |
||||
|
||||
IClass c = listType.GetUnderlyingClass(); |
||||
if (c == null) |
||||
return null; |
||||
IClass genumerable = ProjectContentRegistry.Mscorlib.GetClass("System.Collections.Generic.IEnumerable", 1); |
||||
if (c.IsTypeInInheritanceTree(genumerable)) { |
||||
return MemberLookupHelper.GetTypeParameterPassedToBaseClass(listType, genumerable, 0); |
||||
} |
||||
IClass enumerable = ProjectContentRegistry.Mscorlib.GetClass("System.Collections.IEnumerable", 0); |
||||
if (c.IsTypeInInheritanceTree(enumerable)) { |
||||
// We can't use the EnumeratorItemType attribute because SharpDevelop
|
||||
// does not store attribute argument values in the cache.
|
||||
|
||||
// HACK: Hacked in support for range(), take out when RangeEnumerator implements IEnumerable<int>
|
||||
if (c.FullyQualifiedName == "Boo.Lang.Builtins.RangeEnumerator") { |
||||
return ReflectionReturnType.Int; |
||||
} |
||||
|
||||
return ReflectionReturnType.Object; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override bool IsDefaultReturnType { |
||||
get { |
||||
IReturnType baseType = BaseType; |
||||
return (baseType != null) ? baseType.IsDefaultReturnType : false; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
|
||||
// <license see="prj:///doc/license.txt">GNU General Public License</license>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class MemberLookupHelperTests |
||||
{ |
||||
IProjectContent msc = ProjectContentRegistry.Mscorlib; |
||||
|
||||
public IReturnType DictionaryRT { |
||||
get { |
||||
return new GetClassReturnType(msc, "System.Collections.Generic.Dictionary", 2); |
||||
} |
||||
} |
||||
|
||||
public IClass EnumerableClass { |
||||
get { |
||||
return msc.GetClass("System.Collections.Generic.IEnumerable", 1); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeParameterPassedToBaseClassTest() |
||||
{ |
||||
IReturnType[] stringInt = { ReflectionReturnType.String, ReflectionReturnType.Int }; |
||||
IReturnType rrt = new ConstructedReturnType(DictionaryRT, stringInt); |
||||
IReturnType res = MemberLookupHelper.GetTypeParameterPassedToBaseClass(rrt, EnumerableClass, 0); |
||||
Assert.AreEqual("System.Collections.Generic.KeyValuePair", res.FullyQualifiedName); |
||||
Assert.AreEqual("System.String", res.TypeArguments[0].FullyQualifiedName); |
||||
Assert.AreEqual("System.Int32", res.TypeArguments[1].FullyQualifiedName); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue