public override object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { TypeReference reference = typeReferenceExpression.TypeReference; ResolveResult rr = CreateTypeResolveResult(TypeVisitor.CreateReturnType(reference, resolver)); if (rr == null && reference.GenericTypes.Count == 0 && !reference.IsArrayType) { // reference to namespace is possible if (reference.IsGlobal) { if (resolver.ProjectContent.NamespaceExists(reference.Type)) { return(new NamespaceResolveResult(resolver.CallingClass, resolver.CallingMember, reference.Type)); } } else { string name = resolver.SearchNamespace(reference.Type, typeReferenceExpression.StartLocation); if (name != null) { return(new NamespaceResolveResult(resolver.CallingClass, resolver.CallingMember, name)); } } } if (rr != null) { return(rr); } else { return(new UnknownIdentifierResolveResult(resolver.CallingClass, resolver.CallingMember, reference.Type)); } }
IReturnType GetVariableType(LocalLookupVariable v) { if (v == null) { return(null); } return(TypeVisitor.CreateReturnType(v.TypeRef, this)); }
static IReturnType CreateReturnType(AST.TypeReference reference, IMethod method, IClass currentClass, ICompilationUnit cu, TypeVisitor.ReturnTypeOptions options) { if (currentClass == null) { return(TypeVisitor.CreateReturnType(reference, new DefaultClass(cu, "___DummyClass"), method, 1, 1, cu.ProjectContent, options | TypeVisitor.ReturnTypeOptions.Lazy)); } else { return(TypeVisitor.CreateReturnType(reference, currentClass, method, currentClass.Region.BeginLine + 1, 1, cu.ProjectContent, options | TypeVisitor.ReturnTypeOptions.Lazy)); } }
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { if (arrayCreateExpression.IsImplicitlyTyped) { return(CreateResolveResult(arrayCreateExpression.ArrayInitializer)); } else { return(CreateTypeResolveResult(TypeVisitor.CreateReturnType(arrayCreateExpression.CreateType, resolver))); } }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { IReturnType type; if (string.IsNullOrEmpty(memberReferenceExpression.MemberName)) { // NRefactory creates this "dummy" fieldReferenceExpression when it should // parse a primitive type name (int, short; Integer, Decimal) if (memberReferenceExpression.TargetObject is TypeReferenceExpression) { type = TypeVisitor.CreateReturnType(((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference, resolver); return(CreateTypeResolveResult(type)); } } ResolveResult targetRR = Resolve(memberReferenceExpression.TargetObject); if (targetRR == null) { return(null); } type = targetRR.ResolvedType; if (targetRR is NamespaceResolveResult) { return(ResolveMemberInNamespace(((NamespaceResolveResult)targetRR).Name, memberReferenceExpression)); } else if (type != null) { TypeResolveResult typeRR = targetRR as TypeResolveResult; if (typeRR != null && typeRR.ResolvedClass != null) { foreach (IClass c1 in typeRR.ResolvedClass.ClassInheritanceTree) { foreach (IClass c in c1.InnerClasses) { if (resolver.IsSameName(memberReferenceExpression.MemberName, c.Name) && c.TypeParameters.Count == memberReferenceExpression.TypeArguments.Count) { return(CreateTypeResolveResult(resolver.ConstructType(c.DefaultReturnType, memberReferenceExpression.TypeArguments))); } } } } return(resolver.ResolveMember(type, memberReferenceExpression.MemberName, memberReferenceExpression.TypeArguments, NRefactoryResolver.IsInvoked(memberReferenceExpression), typeRR == null, // allow extension methods only for non-static method calls targetRR is BaseResolveResult ? (bool?)true : null // allow calling protected members using "base." )); } return(null); }
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { if (objectCreateExpression.IsAnonymousType) { return(CreateResolveResult(CreateAnonymousTypeClass(objectCreateExpression.ObjectInitializer).DefaultReturnType)); } else { IReturnType rt = TypeVisitor.CreateReturnType(objectCreateExpression.CreateType, resolver); if (rt == null) { return(new UnknownConstructorCallResolveResult(resolver.CallingClass, resolver.CallingMember, objectCreateExpression.CreateType.ToString())); } return(ResolveConstructorOverload(rt, objectCreateExpression.Parameters) ?? CreateResolveResult(rt)); } }
public ResolveResult ResolveInternal(Expression expr, ExpressionContext context) { TypeVisitor typeVisitor = new TypeVisitor(this); IReturnType type; if (expr is PrimitiveExpression) { if (((PrimitiveExpression)expr).Value is int) { return(new IntegerLiteralResolveResult(callingClass, callingMember, projectContent.SystemTypes.Int32)); } } else if (expr is InvocationExpression) { IMethodOrProperty method = typeVisitor.GetMethod(expr as InvocationExpression); if (method != null) { return(CreateMemberResolveResult(method)); } else { // InvocationExpression can also be a delegate/event call ResolveResult invocationTarget = ResolveInternal((expr as InvocationExpression).TargetObject, ExpressionContext.Default); if (invocationTarget == null) { return(null); } type = invocationTarget.ResolvedType; if (type == null) { return(null); } IClass c = type.GetUnderlyingClass(); if (c == null || c.ClassType != ClassType.Delegate) { return(null); } // We don't want to show "System.EventHandler.Invoke" in the tooltip // of "EventCall(this, EventArgs.Empty)", we just show the event/delegate for now // but for DelegateCall(params).* completion, we use the delegate's // return type instead of the delegate type itself method = c.Methods.Find(delegate(IMethod innerMethod) { return(innerMethod.Name == "Invoke"); }); if (method != null) { invocationTarget.ResolvedType = method.ReturnType; } return(invocationTarget); } } else if (expr is IndexerExpression) { return(CreateMemberResolveResult(typeVisitor.GetIndexer(expr as IndexerExpression))); } else if (expr is FieldReferenceExpression) { FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)expr; if (fieldReferenceExpression.FieldName == null || fieldReferenceExpression.FieldName.Length == 0) { // NRefactory creates this "dummy" fieldReferenceExpression when it should // parse a primitive type name (int, short; Integer, Decimal) if (fieldReferenceExpression.TargetObject is TypeReferenceExpression) { type = TypeVisitor.CreateReturnType(((TypeReferenceExpression)fieldReferenceExpression.TargetObject).TypeReference, this); if (type != null) { return(new TypeResolveResult(callingClass, callingMember, type)); } } } type = fieldReferenceExpression.TargetObject.AcceptVisitor(typeVisitor, null) as IReturnType; if (type != null) { ResolveResult result = ResolveMemberReferenceExpression(type, fieldReferenceExpression); if (result != null) { return(result); } } } else if (expr is IdentifierExpression) { ResolveResult result = ResolveIdentifier(((IdentifierExpression)expr).Identifier, context); if (result != null) { return(result); } } else if (expr is TypeReferenceExpression) { type = TypeVisitor.CreateReturnType(((TypeReferenceExpression)expr).TypeReference, this); if (type != null) { if (type is TypeVisitor.NamespaceReturnType) { return(new NamespaceResolveResult(callingClass, callingMember, type.FullyQualifiedName)); } IClass c = type.GetUnderlyingClass(); if (c != null) { return(new TypeResolveResult(callingClass, callingMember, type, c)); } } return(null); } type = expr.AcceptVisitor(typeVisitor, null) as IReturnType; if (type == null || type.FullyQualifiedName == "") { return(null); } if (expr is ObjectCreateExpression) { List <IMethod> constructors = new List <IMethod>(); foreach (IMethod m in type.GetMethods()) { if (m.IsConstructor && !m.IsStatic) { constructors.Add(m); } } if (constructors.Count == 0) { // Class has no constructors -> create default constructor IClass c = type.GetUnderlyingClass(); if (c != null) { return(CreateMemberResolveResult(Constructor.CreateDefault(c))); } } IReturnType[] typeParameters = null; if (type.IsConstructedReturnType) { typeParameters = new IReturnType[type.CastToConstructedReturnType().TypeArguments.Count]; type.CastToConstructedReturnType().TypeArguments.CopyTo(typeParameters, 0); } ResolveResult rr = CreateMemberResolveResult(typeVisitor.FindOverload(constructors, typeParameters, ((ObjectCreateExpression)expr).Parameters, null)); if (rr != null) { rr.ResolvedType = type; } return(rr); } return(new ResolveResult(callingClass, callingMember, type)); }
IReturnType ResolveType(TypeReference typeRef) { return(TypeVisitor.CreateReturnType(typeRef, resolver)); }
ResolveResult CreateResolveResult(TypeReference reference) { return(CreateResolveResult(TypeVisitor.CreateReturnType(reference, resolver))); }