Skip to content
Browse files

[NRefactory] Fixed unit tests.

  • Loading branch information...
1 parent b582472 commit 8ec3728f92073ffa7c8bedf851a38f448b81d47a @mkrueger mkrueger committed Apr 18, 2012
Showing with 63 additions and 59 deletions.
  1. +63 −59 main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
View
122 main/contrib/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs
@@ -1130,31 +1130,33 @@ static bool IsInSwitchContext(AstNode node)
return false;
}
- void AddTypesAndNamespaces (CompletionDataWrapper wrapper, CSharpResolver state, AstNode node, Func<IType, IType> typePred = null, Predicate<IMember> memberPred = null, Action<ICompletionData, IType> callback = null)
+ void AddTypesAndNamespaces(CompletionDataWrapper wrapper, CSharpResolver state, AstNode node, Func<IType, IType> typePred = null, Predicate<IMember> memberPred = null, Action<ICompletionData, IType> callback = null)
{
if (currentType != null) {
for (var ct = currentType; ct != null; ct = ct.DeclaringTypeDefinition) {
foreach (var nestedType in ct.NestedTypes) {
string name = nestedType.Name;
- if (IsAttributeContext (node) && name.EndsWith ("Attribute") && name.Length > "Attribute".Length)
- name = name.Substring (0, name.Length - "Attribute".Length);
+ if (IsAttributeContext(node) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
+ name = name.Substring(0, name.Length - "Attribute".Length);
+ }
if (typePred == null) {
- wrapper.AddType (nestedType, name);
+ wrapper.AddType(nestedType, name);
continue;
}
- var type = typePred (nestedType.Resolve (ctx));
+ var type = typePred(nestedType.Resolve(ctx));
if (type != null) {
- var a2 = wrapper.AddType (type, name);
- if (a2 != null && callback != null)
- callback (a2, type);
+ var a2 = wrapper.AddType(type, name);
+ if (a2 != null && callback != null) {
+ callback(a2, type);
+ }
}
continue;
}
}
if (this.currentMember != null && !(node is AstType)) {
- var def = ctx.CurrentTypeDefinition ?? Compilation.MainAssembly.GetTypeDefinition (currentType);
+ var def = ctx.CurrentTypeDefinition ?? Compilation.MainAssembly.GetTypeDefinition(currentType);
if (def != null) {
foreach (var member in def.GetMembers ()) {
if (member is IMethod && ((IMethod)member).FullName == "System.Object.Finalize") {
@@ -1166,52 +1168,54 @@ void AddTypesAndNamespaces (CompletionDataWrapper wrapper, CSharpResolver state,
if (member.IsExplicitInterfaceImplementation) {
continue;
}
- if (memberPred == null || memberPred (member)) {
- wrapper.AddMember (member);
+ if (memberPred == null || memberPred(member)) {
+ wrapper.AddMember(member);
}
}
var declaring = def.DeclaringTypeDefinition;
while (declaring != null) {
foreach (var member in declaring.GetMembers (m => m.IsStatic)) {
- if (memberPred == null || memberPred (member)) {
- wrapper.AddMember (member);
+ if (memberPred == null || memberPred(member)) {
+ wrapper.AddMember(member);
}
}
declaring = declaring.DeclaringTypeDefinition;
}
}
}
foreach (var p in currentType.TypeParameters) {
- wrapper.AddTypeParameter (p);
+ wrapper.AddTypeParameter(p);
}
}
- var scope = CSharpParsedFile.GetUsingScope (location).Resolve (Compilation);
+ var scope = CSharpParsedFile.GetUsingScope(location).Resolve(Compilation);
for (var n = scope; n != null; n = n.Parent) {
foreach (var pair in n.UsingAliases) {
- wrapper.AddNamespace (pair.Key);
+ wrapper.AddNamespace(pair.Key);
}
foreach (var u in n.Usings) {
foreach (var type in u.Types) {
- IType addType = typePred != null ? typePred (type) : type;
+ IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
string name = type.Name;
- if (IsAttributeContext (node) && name.EndsWith ("Attribute") && name.Length > "Attribute".Length) {
- name = name.Substring (0, name.Length - "Attribute".Length);
+ if (IsAttributeContext(node) && name.EndsWith("Attribute") && name.Length > "Attribute".Length) {
+ name = name.Substring(0, name.Length - "Attribute".Length);
+ }
+ var a = wrapper.AddType(addType, name);
+ if (a != null && callback != null) {
+ callback(a, type);
}
- var a = wrapper.AddType (addType, name);
- if (a != null && callback != null)
- callback (a, type);
}
}
}
foreach (var type in n.Namespace.Types) {
- IType addType = typePred != null ? typePred (type) : type;
+ IType addType = typePred != null ? typePred(type) : type;
if (addType != null) {
- var a2 = wrapper.AddType (addType, addType.Name);
- if (a2 != null && callback != null)
- callback (a2, type);
+ var a2 = wrapper.AddType(addType, addType.Name);
+ if (a2 != null && callback != null) {
+ callback(a2, type);
+ }
}
}
@@ -1585,76 +1589,76 @@ public override int CompareTo (CompletionCategory other)
}
}
- IEnumerable<ICompletionData> CreateTypeCompletionData (IType hintType, AstType hintTypeAst)
+ IEnumerable<ICompletionData> CreateTypeCompletionData(IType hintType, AstType hintTypeAst)
{
- var wrapper = new CompletionDataWrapper (this);
- var state = GetState ();
+ var wrapper = new CompletionDataWrapper(this);
+ var state = GetState();
Func<IType, IType> pred = null;
Action<ICompletionData, IType> typeCallback = null;
- var inferredTypesCategory = new Category ("Inferred Types", null);
- var derivedTypesCategory = new Category ("Derived Types", null);
+ var inferredTypesCategory = new Category("Inferred Types", null);
+ var derivedTypesCategory = new Category("Derived Types", null);
if (hintType != null) {
if (hintType.Kind != TypeKind.Unknown) {
- var lookup = new MemberLookup (ctx.CurrentTypeDefinition, Compilation.MainAssembly);
+ var lookup = new MemberLookup(ctx.CurrentTypeDefinition, Compilation.MainAssembly);
typeCallback = (data, t) => {
//check if type is in inheritance tree.
- if (hintType.GetDefinition () != null &&
- t.GetDefinition () != null &&
- t.GetDefinition ().IsDerivedFrom (hintType.GetDefinition ())) {
+ if (hintType.GetDefinition() != null &&
+ t.GetDefinition() != null &&
+ t.GetDefinition().IsDerivedFrom(hintType.GetDefinition())) {
data.CompletionCategory = derivedTypesCategory;
}
};
pred = t => {
- if (hintType.GetDefinition () != null &&
- t.GetDefinition () != null &&
- t.GetDefinition ().IsDerivedFrom (hintType.GetDefinition ())) {
- return t;
- }
if (t.Kind == TypeKind.Interface && hintType.Kind != TypeKind.Array) {
return null;
}
// check for valid constructors
- if (t.GetConstructors ().Count () > 0) {
+ if (t.GetConstructors().Count() > 0) {
bool isProtectedAllowed = currentType != null ?
- currentType.Resolve (ctx).GetDefinition ().IsDerivedFrom (t.GetDefinition ()) :
+ currentType.Resolve(ctx).GetDefinition().IsDerivedFrom(t.GetDefinition()) :
false;
- if (!t.GetConstructors ().Any (m => lookup.IsAccessible (m, isProtectedAllowed))) {
+ if (!t.GetConstructors().Any(m => lookup.IsAccessible(m, isProtectedAllowed))) {
return null;
}
}
- var typeInference = new TypeInference (Compilation);
+ var typeInference = new TypeInference(Compilation);
typeInference.Algorithm = TypeInferenceAlgorithm.ImprovedReturnAllResults;
- var inferedType = typeInference.FindTypeInBounds (new [] { t }, new [] { hintType });
+ var inferedType = typeInference.FindTypeInBounds(new [] { t }, new [] { hintType });
if (inferedType != SpecialType.UnknownType) {
- var newType = wrapper.AddType (inferedType, amb.ConvertType (inferedType));
- if (newType != null)
+ var newType = wrapper.AddType(inferedType, amb.ConvertType(inferedType));
+ if (newType != null) {
newType.CompletionCategory = inferredTypesCategory;
+ }
+ return null;
}
return t;
};
if (!(hintType.Kind == TypeKind.Interface && hintType.Kind != TypeKind.Array)) {
- DefaultCompletionString = GetShortType (hintType, GetState ());
- var hint = wrapper.AddType (hintType, DefaultCompletionString);
- if (hint != null)
+ DefaultCompletionString = GetShortType(hintType, GetState());
+ var hint = wrapper.AddType(hintType, DefaultCompletionString);
+ if (hint != null) {
hint.CompletionCategory = derivedTypesCategory;
+ }
}
if (hintType is ParameterizedType && hintType.TypeParameterCount == 1 && hintType.FullName == "System.Collections.Generic.IEnumerable") {
- var arg = ((ParameterizedType)hintType).TypeArguments.FirstOrDefault ();
- var array = new ArrayTypeReference (arg.ToTypeReference (), 1).Resolve (ctx);
- wrapper.AddType (array, amb.ConvertType (array));
+ var arg = ((ParameterizedType)hintType).TypeArguments.FirstOrDefault();
+ var array = new ArrayTypeReference(arg.ToTypeReference(), 1).Resolve(ctx);
+ wrapper.AddType(array, amb.ConvertType(array));
}
} else {
- DefaultCompletionString = hintTypeAst.ToString ();
- var hint = wrapper.AddType (hintType, DefaultCompletionString);
- if (hint != null)
+ DefaultCompletionString = hintTypeAst.ToString();
+ var hint = wrapper.AddType(hintType, DefaultCompletionString);
+ if (hint != null) {
hint.CompletionCategory = derivedTypesCategory;
+ }
}
}
- AddTypesAndNamespaces (wrapper, state, null, pred, m => false, typeCallback);
- if (hintType == null || hintType == SpecialType.UnknownType)
- AddKeywords (wrapper, primitiveTypesKeywords.Where (k => k != "void"));
+ AddTypesAndNamespaces(wrapper, state, null, pred, m => false, typeCallback);
+ if (hintType == null || hintType == SpecialType.UnknownType) {
+ AddKeywords(wrapper, primitiveTypesKeywords.Where(k => k != "void"));
+ }
CloseOnSquareBrackets = true;
AutoCompleteEmptyMatch = true;

0 comments on commit 8ec3728

Please sign in to comment.
Something went wrong with that request. Please try again.