Inheritance: ICSharpCode.NRefactory.Ast.Expression
		private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
		                                               ParenthesizedExpression parenthesizedlambdaExpression,
		                                               InvocationExpression invocationExpression)
		{
			INode node = lambdaExpression;
			var argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);
			switch (argPos)
			{
				case 0: // first one, select the collection
					// need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
					var selectManyExpression = new LambdaExpression
					{
						ExpressionBody =
							new CastExpression(new TypeReference("IEnumerable<dynamic>"),
							                   new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
						Parameters = lambdaExpression.Parameters,
					};
					node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
					                          new ParenthesizedExpression(selectManyExpression), CastType.Cast);
					break;
				case 1: // the transformation func
					node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
					                          CastType.Cast);
					break;
			}
			return node;
		}
        //, AstExpression expression)
        public static InvocationExpression add_Invocation(this BlockStatement blockStatement, string typeName, string methodName, params object[] parameters)
        {
            if (methodName.valid().isFalse())
                return null;

            Expression memberExpression = null;
            if (typeName.valid())
                memberExpression = new MemberReferenceExpression(new IdentifierExpression(typeName), methodName);
            else
                memberExpression = new IdentifierExpression(methodName);

            var memberReference = new InvocationExpression(memberExpression);
            if (parameters != null)
            {
                var arguments = new List<Expression>();
                foreach (var parameter in parameters)
                    if (parameter is Expression)
                        arguments.add(parameter as Expression);
                    else
                        arguments.add(new PrimitiveExpression(parameter, parameter.str()));

                memberReference.Arguments = arguments;
            }

            blockStatement.append(memberReference.expressionStatement());

            return memberReference;
        }
        public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
        {
            const string initializerBlock = "InitializerBlock";
            if (constructorDeclaration.Name == initializerBlock)
            {
                TypeDeclaration type = (TypeDeclaration) constructorDeclaration.Parent;
                string initName = "Init" + type.Name;
                MethodDeclaration initMethod = GetInitMethod(type);
                initMethod.Body.Children.AddRange(constructorDeclaration.Body.Children);
                Expression initInvocation = new InvocationExpression(new IdentifierExpression(initName));
                ExpressionStatement initInvocationStatement = new ExpressionStatement(initInvocation);

                IList constructors = AstUtil.GetChildrenWithType(type, typeof(ConstructorDeclaration));
                if (constructors.Count > 1)
                {
                    foreach (ConstructorDeclaration constructor in constructors)
                    {
                        if (constructor.Name != initializerBlock && !HasInitInvocation(constructor))
                            constructor.Body.Children.Insert(0, initInvocationStatement);
                    }
                }
                else if (((ConstructorDeclaration) constructors[0]).Name == initializerBlock)
                {
                    ConstructorDeclaration constructor = new ConstructorDeclaration(type.Name, Modifiers.Public, null, null);
                    constructor.Body = new BlockStatement();
                    constructor.Body.AddChild(initInvocationStatement);
                    type.AddChild(constructor);
                }
                RemoveCurrentNode();
            }
            return base.TrackedVisitConstructorDeclaration(constructorDeclaration, data);
        }
 public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     if (invocationExpression.TargetObject is FieldReferenceExpression)
     {
         FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
         string methodName = targetObject.FieldName;
         TypeDeclaration typeDeclaration = GetEnclosingTypeDeclaration(invocationExpression);
         TypeDeclaration thisTypeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
         if (typeDeclaration != null && IsTestFixture(thisTypeDeclaration))
         {
             IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
             IList specialMethods = GetMethods(methods, methodName);
             if (ContainsInternalMethod(specialMethods))
             {
                 Expression replacedExpression;
                 MethodDeclaration method = (MethodDeclaration) specialMethods[0];
                 bool staticMethod = AstUtil.ContainsModifier(method, Modifiers.Static);
                 replacedExpression = CreateReflectionInvocation(invocationExpression, staticMethod);
                 if (invocationExpression.Parent is Expression || invocationExpression.Parent is VariableDeclaration)
                 {
                     TypeReference returnType = GetInternalMethodReturnType(specialMethods);
                     CastExpression castExpression = new CastExpression(returnType, replacedExpression, CastType.Cast);
                     replacedExpression = castExpression;
                 }
                 ReplaceCurrentNode(replacedExpression);
             }
         }
     }
     return base.TrackedVisitInvocationExpression(invocationExpression, data);
 }
		public override void GenerateCode(List<AbstractNode> nodes, IList items)
		{
			TypeReference stringReference = new TypeReference("System.String");
			MethodDeclaration method = new MethodDeclaration("ToString",
			                                                 Modifiers.Public | Modifiers.Override,
			                                                 stringReference,
			                                                 null, null);
			method.Body = new BlockStatement();
			Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
			                                                 "Format");
			InvocationExpression methodCall = new InvocationExpression(target);
			StringBuilder formatString = new StringBuilder();
			formatString.Append('[');
			formatString.Append(currentClass.Name);
			for (int i = 0; i < items.Count; i++) {
				formatString.Append(' ');
				formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
				formatString.Append("={");
				formatString.Append(i);
				formatString.Append('}');
			}
			formatString.Append(']');
			methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
			foreach (FieldWrapper w in items) {
				methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
			}
			method.Body.AddChild(new ReturnStatement(methodCall));
			nodes.Add(method);
		}
        public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            if (invocationExpression.TargetObject is FieldReferenceExpression)
            {
                FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;

                if (targetObject.FieldName == "toArray" || targetObject.FieldName == "ToArray")
                {
                    Expression invoker = targetObject.TargetObject;
                    TypeReference invokerType = GetExpressionType(invoker);
                    if (invokerType != null && collectionTypes.Contains(invokerType.Type))
                    {
                        if (invocationExpression.Arguments.Count == 1)
                        {
                            Expression argExpression = (Expression) invocationExpression.Arguments[0];
                            if (argExpression is ArrayCreateExpression)
                            {
                                InvocationExpression newInvocation = invocationExpression;
                                TypeReference old = ((ArrayCreateExpression) argExpression).CreateType;
                                TypeReference tr = new TypeReference(old.Type);
                                TypeOfExpression tof = new TypeOfExpression(tr);
                                tr.Parent = tof;
                                tof.Parent = newInvocation;
                                newInvocation.Arguments.Clear();
                                newInvocation.Arguments.Add(tof);

                                ReplaceCurrentNode(newInvocation);
                            }
                        }
                    }
                }
            }
            return base.TrackedVisitInvocationExpression(invocationExpression, data);
        }
        public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;

            if (memberReferenceExpression == null)
                return base.VisitInvocationExpression(invocationExpression, data);

            LambdaExpression lambdaExpression;
            switch (memberReferenceExpression.MemberName)
            {
                case "Select":
                    if (invocationExpression.Arguments.Count != 1)
                        return base.VisitInvocationExpression(invocationExpression, data);
                    lambdaExpression = invocationExpression.Arguments[0] as LambdaExpression;
                    break;
                case "SelectMany":
                    if (invocationExpression.Arguments.Count != 2)
                        return base.VisitInvocationExpression(invocationExpression, data);
                    lambdaExpression = invocationExpression.Arguments[1] as LambdaExpression;
                    break;
                default:
                    return base.VisitInvocationExpression(invocationExpression, data);
            }

            if (lambdaExpression == null)
                return base.VisitInvocationExpression(invocationExpression, data);

            ProcessQuery(lambdaExpression.ExpressionBody);

            return base.VisitInvocationExpression(invocationExpression, data);
        }
Esempio n. 8
0
        public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            Expression invocationTarget = invocationExpression.TargetObject;

            if (invocationTarget is FieldReferenceExpression)
            {
                FieldReferenceExpression methodTargetObject = (FieldReferenceExpression) invocationTarget;

                Expression invoker = methodTargetObject.TargetObject;
                TypeReference invokerType = GetExpressionType(invoker);

                if (invokerType != null)
                {
                    ReplaceMember(invocationExpression, data, invokerType);
                }
            }
            else if (invocationTarget is IdentifierExpression)
            {
                TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
                VerifyDerivedMethod(typeDeclaration, invocationExpression, data);
            }

            if (invocationExpression.TypeArguments.Count == 0)
                return base.TrackedVisitInvocationExpression(invocationExpression, data);
            else
            {
                invocationExpression.TypeArguments.Clear();
                return null;
            }
        }
		void CheckGenericInvoke(InvocationExpression expr)
		{
			Assert.AreEqual(1, expr.Arguments.Count);
			Assert.IsTrue(expr.TargetObject is IdentifierExpression);
			Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier);
			Assert.AreEqual(1, expr.TypeArguments.Count);
			Assert.AreEqual("System.Char", expr.TypeArguments[0].SystemType);
		}
Esempio n. 10
0
 public override object VisitInvocationExpression(InvocationExpression invocation, object data)
 {
     if (GetPrecedence(invocation.TargetObject) >= GetPrecedence(invocation)) {
         invocation.TargetObject = Deparenthesize(invocation.TargetObject);
     }
     for(int i = 0; i < invocation.Arguments.Count; i++) {
         invocation.Arguments[i] = Deparenthesize(invocation.Arguments[i]);
     }
     return base.VisitInvocationExpression(invocation, data);
 }
 public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     if (invocationExpression.TargetObject is IdentifierExpression)
     {
         IdentifierExpression identifierExpression = (IdentifierExpression) invocationExpression.TargetObject;
         if (Methods.Contains(identifierExpression.Identifier) && data is IList)
             ((IList) data).Add(invocationExpression);
     }
     return base.TrackedVisitInvocationExpression(invocationExpression, data);
 }
Esempio n. 12
0
		public void MethodOnThisReferenceInvocation()
		{
			// InitializeComponents();
			MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
			InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
			object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
			Assert.IsTrue(output is CodeMethodInvokeExpression);
			CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
			Assert.AreEqual("InitializeComponents", mie.Method.MethodName);
			Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression);
		}
Esempio n. 13
0
		public void IdentifierOnlyInvocation()
		{
			// InitializeComponents();
			IdentifierExpression identifier = new IdentifierExpression("InitializeComponents");
			InvocationExpression invocation = new InvocationExpression(identifier, new List<Expression>());
			object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
			Assert.IsTrue(output is CodeMethodInvokeExpression);
			CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
			Assert.AreEqual("InitializeComponents", mie.Method.MethodName);
			Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression);
		}
Esempio n. 14
0
		void CheckGenericInvoke2(InvocationExpression expr)
		{
			Assert.AreEqual(0, expr.Arguments.Count);
			Assert.IsTrue(expr.TargetObject is IdentifierExpression);
			IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
			Assert.AreEqual("myMethod", ident.Identifier);
			Assert.AreEqual(2, ident.TypeArguments.Count);
			Assert.AreEqual("T", ident.TypeArguments[0].Type);
			Assert.IsFalse(ident.TypeArguments[0].IsKeyword);
			Assert.AreEqual("System.Boolean", ident.TypeArguments[1].Type);
			Assert.IsTrue(ident.TypeArguments[1].IsKeyword);
		}
 private InvocationExpression CreateGetClassMethodInvocation(TypeOfExpression typeOfExpression)
 {
     FieldReferenceExpression argument = new FieldReferenceExpression(typeOfExpression, "AssemblyQualifiedName");
     typeOfExpression.Parent = argument;
     List<Expression> arguments = new List<Expression>();
     arguments.Add(argument);
     IdentifierExpression methodIdentifier = new IdentifierExpression("java.lang.Class");
     FieldReferenceExpression methodReference = new FieldReferenceExpression(methodIdentifier, "forName");
     InvocationExpression invocationExpression = new InvocationExpression(methodReference, arguments);
     argument.Parent = invocationExpression;
     methodReference.Parent = invocationExpression;
     return invocationExpression;
 }
        public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            if (invocationExpression.TargetObject is IdentifierExpression)
            {
                TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
                IdentifierExpression methodIdentifier = (IdentifierExpression) invocationExpression.TargetObject;

                if (typeDeclaration.Parent is TypeDeclaration)
                {
                    List<ParameterDeclarationExpression> argList = new List<ParameterDeclarationExpression>();
                    int i = 0;
                    foreach (Expression argument in invocationExpression.Arguments)
                    {
                        TypeReference argumentType = GetExpressionType(argument);
                        if (argumentType != null)
                        {
                            string argType = argumentType.Type;

                            TypeReference typeReference = new TypeReference(argType);
                            ParameterDeclarationExpression parameterExpression = new ParameterDeclarationExpression(typeReference, "arg" + i);
                            parameterExpression.TypeReference.RankSpecifier = new int[0];
                            i++;
                            argList.Add(parameterExpression);
                        }
                    }
                    MethodDeclaration argMethod = new MethodDeclaration(methodIdentifier.Identifier, Modifiers.None, null, argList, null);

                    IList parentMethods = GetAccessibleMethods((TypeDeclaration) typeDeclaration.Parent);
                    if (Contains(parentMethods, argMethod))
                    {
                        int methodIndex = IndexOf(parentMethods, argMethod);
                        argMethod = (MethodDeclaration) parentMethods[methodIndex];
                        if (!AstUtil.ContainsModifier(argMethod, Modifiers.Static))
                        {
                            string parentTypeName = ((TypeDeclaration) typeDeclaration.Parent).Name;
                            AddInstanceField(typeDeclaration, parentTypeName);
                            AddProperConstructor(typeDeclaration, parentTypeName);

                            FieldReferenceExpression newReference = new FieldReferenceExpression(
                                new IdentifierExpression(parentTypeName),
                                ((IdentifierExpression) invocationExpression.TargetObject).Identifier);
                            InvocationExpression newInvication = new InvocationExpression(newReference, invocationExpression.Arguments);
                            newInvication.Parent = invocationExpression.Parent;

                            ReplaceCurrentNode(newInvication);
                        }
                    }
                }
            }
            return base.TrackedVisitInvocationExpression(invocationExpression, data);
        }
Esempio n. 17
0
		public void InvocationOfStaticMethod()
		{
			// System.Drawing.Color.FromArgb();
			MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing");
			field = new MemberReferenceExpression(field, "Color");
			field = new MemberReferenceExpression(field, "FromArgb");
			InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
			object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
			Assert.IsTrue(output is CodeMethodInvokeExpression);
			CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
			Assert.AreEqual("FromArgb", mie.Method.MethodName);
			Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression);
			Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType);
		}
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			var expression = invocationExpression.TargetObject as IdentifierExpression;
			if(expression == null)
				return base.VisitInvocationExpression(invocationExpression, data);

			switch (expression.Identifier)
			{
				case "SpatialGenerate":
					throw new InvalidOperationException("SpatialIndex.Generate or SpatialGenerate cannot be used from transform results");
				case "CreateField":
					throw new InvalidOperationException("CreateField cannot be used from transform results");
			}
			return base.VisitInvocationExpression(invocationExpression, data);
		}
		public override object VisitInvocationExpression (InvocationExpression invocationExpression, object data)
		{
			string invocation = "";
			if (!invocationExpression.StartLocation.IsEmpty && !invocationExpression.EndLocation.IsEmpty) {
				invocation = this.data.Document.GetTextBetween (this.data.Document.LocationToOffset (invocationExpression.StartLocation.Line, invocationExpression.StartLocation.Column),
				                                                this.data.Document.LocationToOffset (invocationExpression.EndLocation.Line, invocationExpression.EndLocation.Column));
			}
			base.VisitInvocationExpression (invocationExpression, data);
			
			MethodResolveResult mrr = resolver.Resolve (new ExpressionResult (invocation), new DomLocation (invocationExpression.StartLocation.Line, invocationExpression.StartLocation.Column)) as MethodResolveResult;
			if (mrr != null && mrr.MostLikelyMethod != null && mrr.MostLikelyMethod is ExtensionMethod) {
				IMethod originalMethod = ((ExtensionMethod)mrr.MostLikelyMethod).OriginalMethod;
				possibleTypeReferences.Add (new TypeReference (originalMethod.DeclaringType.Name));
			}
			return null;
		}
Esempio n. 20
0
 public override object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data)
 {
     var expression = namedArgumentExpression.Expression as MemberReferenceExpression;
     if (expression == null)
         return base.VisitNamedArgumentExpression(namedArgumentExpression, data);
     var identifierExpression = expression.TargetObject as IdentifierExpression;
     if (identifierExpression == null || identifierExpression.Identifier != identifier)
         return base.VisitNamedArgumentExpression(namedArgumentExpression, data);
     var right = new InvocationExpression(new MemberReferenceExpression(namedArgumentExpression.Expression, "Unwrap"))
     {
         Parent = namedArgumentExpression.Expression.Parent
     };
     namedArgumentExpression.Expression.Parent = right;
     namedArgumentExpression.Expression = right;
     return base.VisitNamedArgumentExpression(namedArgumentExpression, data);
 }
		protected static Statement CreateCaller(AttributedNode parent, MethodDeclaration method, VariableDeclaration returnVariable)
		{
			Statement caller;
			InvocationExpression expr = new InvocationExpression(new IdentifierExpression(method.Name), CreateArgumentExpressions(method.Parameters));

			if (method.TypeReference.Type != "System.Void") {
				TypeReference parentType = GetParentReturnType(parent);
				if (method.TypeReference == parentType)
					caller = new ReturnStatement(expr);
				else {
					returnVariable.Initializer = expr;
					caller = new LocalVariableDeclaration(returnVariable);
				}
			} else {
				caller = new ExpressionStatement(expr);
			}
			return caller;
		}
        public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;

            if (memberReferenceExpression == null || memberReferenceExpression.MemberName != "Select")
                return base.VisitInvocationExpression(invocationExpression, data);

            if(invocationExpression.Arguments.Count != 1)
                return base.VisitInvocationExpression(invocationExpression, data);

            var lambdaExpression = invocationExpression.Arguments[0] as LambdaExpression;
            if(lambdaExpression == null)
                return base.VisitInvocationExpression(invocationExpression, data);

            ProcessQuery(lambdaExpression.ExpressionBody);

            return base.VisitInvocationExpression(invocationExpression, data);
        }
        private void CreateMethodImplementation(MethodDeclaration equalsMethod)
        {
            string fieldName = "instancehelper_" + equalsMethod.Name;
            IdentifierExpression targetObject = new IdentifierExpression("java.lang.Object");

            List<Expression> arguments = new List<Expression>();
            arguments.Add(new ThisReferenceExpression());
            string parameterName = ((ParameterDeclarationExpression) equalsMethod.Parameters[0]).ParameterName;
            IdentifierExpression identifier = new IdentifierExpression(parameterName);
            arguments.Add(identifier);

            FieldReferenceExpression fieldReferenceExpression = new FieldReferenceExpression(targetObject, fieldName);
            InvocationExpression invocationExpression = new InvocationExpression(fieldReferenceExpression, arguments);

            ReturnStatement returnStatement = new ReturnStatement(invocationExpression);
            BlockStatement block = new BlockStatement();
            block.Children.Add(returnStatement);
            equalsMethod.Body = block;
        }
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;
			if(memberReferenceExpression != null)
			{
				if(memberReferenceExpression.MemberName == "Generate")
				{
					var identifierExpression = memberReferenceExpression.TargetObject as IdentifierExpression;
					if (identifierExpression != null && identifierExpression.Identifier == "SpatialIndex")
						throw new InvalidOperationException("SpatialIndex.Generate cannot be used from transform results");
				}
			}
			var expression = invocationExpression.TargetObject as IdentifierExpression;
			if(expression != null && expression.Identifier == "CreateField")
			{
				throw new InvalidOperationException("CreateField cannot be used from transform results");
			}
			return base.VisitInvocationExpression(invocationExpression, data);
		}
        private bool ContainsMethod(TypeDeclaration typeDeclaration, InvocationExpression invocationExpression)
        {
            string identifier = null;
            if (invocationExpression.TargetObject is IdentifierExpression)
                identifier = ((IdentifierExpression) invocationExpression.TargetObject).Identifier;
            else if (invocationExpression.TargetObject is FieldReferenceExpression)
                identifier = ((FieldReferenceExpression) invocationExpression.TargetObject).FieldName;

            IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
            foreach (MethodDeclaration method in methods)
            {
                string pascalName = identifier[0].ToString().ToUpper() + identifier.Substring(1);
                if ((method.Name == identifier || method.Name == pascalName) && !IsMethodInExternalTypes(typeDeclaration, method))
                {
                    return true;
                }
            }
            return false;
        }
Esempio n. 26
0
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			IMethodOrProperty m = GetMethod(invocationExpression);
			if (m == null) {
				// This might also be a delegate invocation:
				// get the delegate's Invoke method
				IReturnType targetType = invocationExpression.TargetObject.AcceptVisitor(this, data) as IReturnType;
				if (targetType != null) {
					IClass c = targetType.GetUnderlyingClass();
					if (c != null && c.ClassType == ClassType.Delegate) {
						// find the delegate's return type
						m = c.Methods.Find(delegate(IMethod innerMethod) { return innerMethod.Name == "Invoke"; });
					}
				}
			}
			if (m != null)
				return m.ReturnType;
			else
				return null;
		}
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;
			if(memberReferenceExpression == null)
				return base.VisitInvocationExpression(invocationExpression, data);
			if(methodNames.Contains(memberReferenceExpression.MemberName) == false)
				return base.VisitInvocationExpression(invocationExpression, data);

			invocationExpression.Arguments.Insert(0, memberReferenceExpression.TargetObject);
			var newInvocation = new InvocationExpression(
				new MemberReferenceExpression(
					new TypeReferenceExpression(new TypeReference(typeof (DynamicExtensionMethods).FullName)),
					memberReferenceExpression.MemberName),
				invocationExpression.Arguments
				);
			ReplaceCurrentNode(newInvocation);


			return base.VisitInvocationExpression(invocationExpression, data);
		}
Esempio n. 28
0
        public override object VisitInvocationExpression(ICSharpCode.NRefactory.Ast.InvocationExpression invocationExpression, object data)
        {
            var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;

            if (memberReferenceExpression == null || memberReferenceExpression.MemberName != "Generate")
            {
                return(base.VisitInvocationExpression(invocationExpression, data));
            }

            var identifierExpression = memberReferenceExpression.TargetObject as IdentifierExpression;

            if (identifierExpression == null || identifierExpression.Identifier != "SpatialIndex")
            {
                return(base.VisitInvocationExpression(invocationExpression, data));
            }

            ReplaceCurrentNode(new InvocationExpression(new IdentifierExpression("SpatialGenerate"), invocationExpression.Arguments));

            return(base.VisitInvocationExpression(invocationExpression, data));
        }
			public static string EvaluateMethodCoupling(InvocationExpression expression, MethodProperties meth)
			{
				Console.WriteLine(expression.ToString());
				
				meth.EfferentCoupling++;
				
				StringBuilder calleeName = new StringBuilder();
				List<string> paramList = new List<string>();
				MethodProperties methCallee = null;
				lock(coupleLock)
				{
					if(expression.TargetObject is MemberReferenceExpression) {
					
			   			calleeName.Append(ExtractCalleeFullName((MemberReferenceExpression)(expression.TargetObject), meth));
						paramList = ExtractParamList(expression, meth);
					
						try {
							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					
					} else if (expression.TargetObject is IdentifierExpression) {
					
						calleeName.Append(((IdentifierExpression)expression.TargetObject).Identifier);
						paramList = ExtractParamList(expression, meth);
					
						try {
							Console.WriteLine(calleeName.ToString());
							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					} 
				}
				return methCallee.Method.ReturnType.FullName;
			}
Esempio n. 30
0
        public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
        {
            base.VisitInvocationExpression(invocationExpression, data);

            // Reduce "String.Concat(a, b)" to "a + b"
            MemberReferenceExpression target = invocationExpression.TargetObject as MemberReferenceExpression;
            if (target != null &&
                target.MemberName == "Concat" &&
                invocationExpression.Arguments.Count == 2 &&
                target.TargetObject is IdentifierExpression &&
                (target.TargetObject as IdentifierExpression).Identifier == "String")
            {
                ReplaceCurrentNode(
                    new BinaryOperatorExpression(
                        invocationExpression.Arguments[0],
                        BinaryOperatorType.Add,
                        invocationExpression.Arguments[1]
                    )
                );
            }

            return null;
        }
Esempio n. 31
0
	void ReDimClauseInternal(
//#line  3486 "VBNET.ATG" 
ref Expression expr) {

//#line  3487 "VBNET.ATG" 
		List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; Location startLocation = la.Location; 
		while (la.kind == 26 || 
//#line  3490 "VBNET.ATG" 
la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) {
			if (la.kind == 26) {
				lexer.NextToken();
				IdentifierOrKeyword(
//#line  3489 "VBNET.ATG" 
out name);

//#line  3489 "VBNET.ATG" 
				expr = new MemberReferenceExpression(expr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; 
			} else {
				InvocationExpression(
//#line  3491 "VBNET.ATG" 
ref expr);

//#line  3493 "VBNET.ATG" 
				expr.StartLocation = startLocation;
				expr.EndLocation = t.EndLocation;
				
			}
		}
		Expect(37);
		NormalOrReDimArgumentList(
//#line  3498 "VBNET.ATG" 
out arguments, out canBeNormal, out canBeRedim);
		Expect(38);

//#line  3500 "VBNET.ATG" 
		expr = new InvocationExpression(expr, arguments);
		if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) {
			if (this.Errors.Count == 0) {
				// don't recurse on parse errors - could result in endless recursion
				ReDimClauseInternal(ref expr);
			}
		}
		
	}
Esempio n. 32
0
        IEnumerable <Ast.ParameterDeclarationExpression> CreateParameters(UnknownMethodResolveResult rr, ClassFinder context, Ast.InvocationExpression invocation)
        {
            List <string> usedNames = new List <string>();

            for (int i = 0; i < rr.Arguments.Count; i++)
            {
                IReturnType type = rr.Arguments[i];

                if (type is LambdaReturnType)
                {
                    type = (type as LambdaReturnType).ToDefaultDelegate();
                }

                Ast.TypeReference typeRef = CodeGenerator.ConvertType(type, context);
                typeRef = typeRef.IsNull ? new Ast.TypeReference("object", true) : typeRef;

                Ast.Expression ex        = invocation.Arguments[i];
                string         paramName = IsNumericType(type) ? "num" + i : type.Name + i.ToString();

                if (ex is Ast.IdentifierExpression)
                {
                    paramName = (ex as Ast.IdentifierExpression).Identifier;
                }

                if (ex is Ast.MemberReferenceExpression)
                {
                    paramName = (ex as Ast.MemberReferenceExpression).MemberName;
                }

                Ast.ParameterModifiers mod = Ast.ParameterModifiers.None;

                if (ex is Ast.DirectionExpression)
                {
                    var dex = ex as Ast.DirectionExpression;

                    if (dex.Expression is Ast.IdentifierExpression)
                    {
                        paramName = (dex.Expression as Ast.IdentifierExpression).Identifier;
                    }

                    if (dex.Expression is Ast.MemberReferenceExpression)
                    {
                        paramName = (dex.Expression as Ast.MemberReferenceExpression).MemberName;
                    }

                    mod = dex.FieldDirection == Ast.FieldDirection.Out ? Ast.ParameterModifiers.Out : (dex.FieldDirection == Ast.FieldDirection.Ref ? Ast.ParameterModifiers.Ref : Ast.ParameterModifiers.None);
                }

                paramName = rr.CallingClass.ProjectContent.Language.CodeGenerator.GetParameterName(paramName);

                if (usedNames.Contains(paramName))
                {
                    paramName += i.ToString();
                }

                usedNames.Add(paramName);

                yield return(new Ast.ParameterDeclarationExpression(typeRef, paramName)
                {
                    ParamModifier = mod
                });
            }
        }