示例#1
0
        public IStmt Translate(InvocationExpressionSyntax expression, SemanticModel semanticModel, CSharpSyntaxVisitor <IStmt> visitor)
        {
            var symbol = semanticModel.GetSymbolInfo(expression).Symbol;

            if (symbol == null || !SymbolHelper.IsAssignableFrom(symbol, "Stack"))
            {
                return(null);
            }
            var arguments       = expression.ArgumentList.Arguments;
            var exactSignatures = new Dictionary <string, string>
            {
                { "Push", "push" },
                { "Pop", "pop" },
            };

            if (exactSignatures.ContainsKey(symbol.Name))
            {
                var javaMethod = exactSignatures[symbol.Name];
                return(new CallExpr
                {
                    Expression = new MemberAccessExpr
                    {
                        ObjectExpr = visitor.Visit(ExtensionPointHelper.TryGetMemberOwner(expression.Expression)),
                        MemberExpr = new IdentifierExpr {
                            Identifier = javaMethod
                        }
                    },
                    Arguments = arguments.Select(visitor.Visit).ToArray()
                });
            }
            return(null);
        }
        public IStmt Translate(ObjectCreationExpressionSyntax node, SemanticModel semanticModel, CSharpSyntaxVisitor <IStmt> visitor)
        {
            var symbol = ModelExtensions.GetSymbolInfo(semanticModel, node).Symbol;

            if (symbol == null || !SymbolHelper.IsAssignableFrom(symbol, "IList"))
            {
                return(null);
            }
            return(new ObjectCreationExpr
            {
                TypeInformation = new TypeInformation
                {
                    TypeSymbol = symbol.ContainingType,
                    TypeName = "ArrayList"
                },
                Arguments = node.ArgumentList.Arguments.Select(visitor.Visit).ToArray()
            });
        }
        public IStmt Translate(ElementAccessExpressionSyntax node, SemanticModel semanticModel, CSharpSyntaxVisitor <IStmt> visitor)
        {
            var symbol = ModelExtensions.GetSymbolInfo(semanticModel, node).Symbol;

            if (symbol == null || !SymbolHelper.IsAssignableFrom(symbol, "IList"))
            {
                return(null);
            }
            return(new CallExpr
            {
                Expression = new MemberAccessExpr
                {
                    ObjectExpr = visitor.Visit(node.Expression),
                    MemberExpr = new IdentifierExpr {
                        Identifier = "get"
                    }
                },
                Arguments = new[] { visitor.Visit(node.ArgumentList.Arguments.First()) }
            });
        }
示例#4
0
        public IStmt Translate(InvocationExpressionSyntax node, SemanticModel semanticModel, CSharpSyntaxVisitor <IStmt> visitor)
        {
            var symbol = semanticModel.GetSymbolInfo(node).Symbol;

            if (symbol == null || !SymbolHelper.IsAssignableFrom(symbol, "Func"))
            {
                return(null);
            }
            var arguments = node.ArgumentList.Arguments;

            return(new CallExpr
            {
                Expression = new MemberAccessExpr
                {
                    ObjectExpr = visitor.Visit(node.Expression),
                    MemberExpr = new IdentifierExpr {
                        Identifier = "apply"
                    }
                },
                Arguments = arguments.Select(visitor.Visit).ToArray()
            });
        }
 public string Resolve(ITypeSymbol symbol)
 {
     return(SymbolHelper.IsAssignableFrom(symbol, "List")
         ? "ArrayList"
         : "");
 }