Browse Source

Fixed SD2-635: Code completion does not work for VB array access.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@965 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e0d0b12338
  1. 11
      src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/IndexerExpression.cs
  2. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  3. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  4. 4
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs
  5. 31
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

11
src/Libraries/NRefactory/Project/Src/Parser/AST/CSharp/Expressions/IndexerExpression.cs

@ -7,15 +7,14 @@ @@ -7,15 +7,14 @@
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser.AST
{
public class IndexerExpression : Expression
{
Expression targetObject;
// List<Expression> indices;
ArrayList indices;
List<Expression> indices;
public Expression TargetObject {
get {
@ -26,16 +25,16 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -26,16 +25,16 @@ namespace ICSharpCode.NRefactory.Parser.AST
}
}
public ArrayList Indices {
public List<Expression> Indices {
get {
return indices;
}
set {
indices = value == null ? new ArrayList(1) : value;
indices = value ?? new List<Expression>(1);
}
}
public IndexerExpression(Expression targetObject, ArrayList indices)
public IndexerExpression(Expression targetObject, List<Expression> indices)
{
this.TargetObject = targetObject;
this.Indices = indices;

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -4771,7 +4771,7 @@ out expr); @@ -4771,7 +4771,7 @@ out expr);
out expr);
#line 2167 "cs.ATG"
ArrayList indices = new ArrayList(); if (expr != null) { indices.Add(expr); }
List<Expression> indices = new List<Expression>(); if (expr != null) { indices.Add(expr); }
while (la.kind == 14) {
lexer.NextToken();
Expr(
@ -5084,7 +5084,7 @@ out expr); @@ -5084,7 +5084,7 @@ out expr);
#line 2239 "cs.ATG"
if (isArrayCreation) Error("element access not allow on array creation");
ArrayList indices = new ArrayList();
List<Expression> indices = new List<Expression>();
lexer.NextToken();
Expr(

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -2164,7 +2164,7 @@ PrimaryExpr<out Expression pexpr> @@ -2164,7 +2164,7 @@ PrimaryExpr<out Expression pexpr>
| "base" (. Expression retExpr = new BaseReferenceExpression(); .)
(
"." ident (. retExpr = new FieldReferenceExpression(retExpr, t.val); .)
| "[" Expr<out expr> (. ArrayList indices = new ArrayList(); if (expr != null) { indices.Add(expr); } .)
| "[" Expr<out expr> (. List<Expression> indices = new List<Expression>(); if (expr != null) { indices.Add(expr); } .)
{ "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .) }
"]" (. retExpr = new IndexerExpression(retExpr, indices); .)
) (. pexpr = retExpr; .)
@ -2237,7 +2237,7 @@ PrimaryExpr<out Expression pexpr> @@ -2237,7 +2237,7 @@ PrimaryExpr<out Expression pexpr>
} ] ")" (. pexpr = new InvocationExpression(pexpr, parameters, typeList); .)
/*--- element access */
| (. if (isArrayCreation) Error("element access not allow on array creation");
ArrayList indices = new ArrayList();
List<Expression> indices = new List<Expression>();
.)
"[" Expr<out expr> (. if (expr != null) { indices.Add(expr); } .)
{ "," Expr<out expr> (. if (expr != null) { indices.Add(expr); } .)

4
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryResolver.cs

@ -296,7 +296,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -296,7 +296,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
if (((PrimitiveExpression)expr).Value is int)
return new IntegerLiteralResolveResult(callingClass, callingMember);
} else if (expr is InvocationExpression) {
IMethod method = typeVisitor.GetMethod(expr as InvocationExpression, null);
IMethodOrProperty method = typeVisitor.GetMethod(expr as InvocationExpression);
if (method != null) {
return CreateMemberResolveResult(method);
} else {
@ -322,7 +322,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -322,7 +322,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
return invocationTarget;
}
} else if (expr is IndexerExpression) {
return CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression, null));
return CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression));
} else if (expr is FieldReferenceExpression) {
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr;
if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName.Length == 0) {

31
src/Main/Base/Project/Src/Dom/NRefactoryResolver/TypeVisitor.cs

@ -70,7 +70,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -70,7 +70,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object Visit(InvocationExpression invocationExpression, object data)
{
IMethod m = GetMethod(invocationExpression, data);
IMethodOrProperty m = GetMethod(invocationExpression);
if (m == null) {
// This might also be a delegate invocation:
// get the delegate's Invoke method
@ -91,7 +91,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -91,7 +91,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
public override object Visit(IndexerExpression indexerExpression, object data)
{
IProperty i = GetIndexer(indexerExpression, data);
IProperty i = GetIndexer(indexerExpression);
if (i != null)
return i.ReturnType;
else
@ -196,28 +196,41 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -196,28 +196,41 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
}
*/
public IMethod GetMethod(InvocationExpression invocationExpression, object data)
/// <summary>
/// Gets the method called by the InvocationExpression. In Visual Basic, the result
/// can also be an Indexer.
/// </summary>
public IMethodOrProperty GetMethod(InvocationExpression invocationExpression)
{
IReturnType[] typeParameters = CreateReturnTypes(invocationExpression.TypeArguments);
if (invocationExpression.TargetObject is FieldReferenceExpression) {
FieldReferenceExpression field = (FieldReferenceExpression)invocationExpression.TargetObject;
IReturnType type = field.TargetObject.AcceptVisitor(this, data) as IReturnType;
IReturnType type = field.TargetObject.AcceptVisitor(this, null) as IReturnType;
List<IMethod> methods = resolver.SearchMethod(type, field.FieldName);
return FindOverload(methods, typeParameters, invocationExpression.Arguments, data);
if (methods.Count == 0 && resolver.Language == SupportedLanguage.VBNet)
return GetVisualBasicIndexer(invocationExpression);
return FindOverload(methods, typeParameters, invocationExpression.Arguments, null);
} else if (invocationExpression.TargetObject is IdentifierExpression) {
string id = ((IdentifierExpression)invocationExpression.TargetObject).Identifier;
if (resolver.CallingClass == null) {
return null;
}
List<IMethod> methods = resolver.SearchMethod(id);
return FindOverload(methods, typeParameters, invocationExpression.Arguments, data);
if (methods.Count == 0 && resolver.Language == SupportedLanguage.VBNet)
return GetVisualBasicIndexer(invocationExpression);
return FindOverload(methods, typeParameters, invocationExpression.Arguments, null);
}
return null;
}
public IProperty GetIndexer(IndexerExpression indexerExpression, object data)
IProperty GetVisualBasicIndexer(InvocationExpression invocationExpression)
{
return GetIndexer(new IndexerExpression(invocationExpression.TargetObject, invocationExpression.Arguments));
}
public IProperty GetIndexer(IndexerExpression indexerExpression)
{
IReturnType type = (IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, data);
IReturnType type = (IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, null);
if (type == null) {
return null;
}
@ -231,7 +244,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -231,7 +244,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
for (int i = 0; i < parameters.Length; i++) {
Expression expr = indexerExpression.Indices[i] as Expression;
if (expr != null)
parameters[i] = (IReturnType)expr.AcceptVisitor(this, data);
parameters[i] = (IReturnType)expr.AcceptVisitor(this, null);
}
return MemberLookupHelper.FindOverload(indexers.ToArray(), parameters);
}

Loading…
Cancel
Save