public Ust VisitLocalVariableDeclaration(JavaParser.LocalVariableDeclarationContext context) { var type = (TypeToken)Visit(context.typeType()); AssignmentExpression[] initializers = context.variableDeclarators().variableDeclarator() .Select(varDec => (AssignmentExpression)Visit(varDec)) .Where(initializer => initializer != null).ToArray(); if (initializers.Count() == 1 && initializers.First().Right is MultichildExpression multichildExpression) { var expressions = multichildExpression.Expressions; // is array? if (CommonUtils.TryCheckIdTokenValue(expressions.FirstOrDefault(), "{") && CommonUtils.TryCheckIdTokenValue(expressions.LastOrDefault(), "}")) { int dimensions = multichildExpression.GetDepth(1); var sizes = Enumerable.Range(0, dimensions).Select( _ => new IntLiteral(0, type.TextSpan)).ToList <Expression>(); var array_initializers = expressions.Where(el => !(el is IdToken)); initializers.First().Right = new ArrayCreationExpression( new TypeToken(type.TypeText, type.TextSpan), sizes, array_initializers, multichildExpression.TextSpan); } } var result = new VariableDeclarationExpression(type, initializers, context.GetTextSpan()); return(result); }
public UstNode VisitLocalVariableDeclaration(JavaParser.LocalVariableDeclarationContext context) { var type = (TypeToken)Visit(context.typeType()); AssignmentExpression[] initializers = context.variableDeclarators().variableDeclarator() .Select(varDec => (AssignmentExpression)Visit(varDec)) .Where(initializer => initializer != null).ToArray(); var result = new VariableDeclarationExpression(type, initializers, context.GetTextSpan(), FileNode); return(result); }