public override void EnterFormalParameters(JavaParser.FormalParametersContext context) { if (context.formalParameterList() != null) { FormalParameterListListener formalParameterListListener = new FormalParameterListListener(); context.formalParameterList().EnterRule(formalParameterListListener); Arguments = formalParameterListListener.Arguments; } }
public UstNode VisitMethodDeclaration(JavaParser.MethodDeclarationContext context) { JavaParser.TypeTypeOrVoidContext type = context.typeTypeOrVoid(); ITerminalNode child0Terminal = context.GetChild <ITerminalNode>(0); ITerminalNode identifier = context.IDENTIFIER(); JavaParser.FormalParametersContext formalParameters = context.formalParameters(); JavaParser.BlockContext methodBody = context.methodBody().block(); MethodDeclaration result = ConvertMethodDeclaration(type, child0Terminal, identifier, formalParameters, methodBody, context.GetTextSpan()); return(result); }
protected void ParseMethodFromContext( JavaParser.FormalParametersContext formalParametersContext, JavaParser.TypeTypeOrVoidContext typeTypeOrVoidContext, JavaParser.QualifiedNameListContext qualifiedNameListContext, string methodNameText, string methodBody) { FormalParametersListener formalParametersListener = new FormalParametersListener(); formalParametersContext.EnterRule(formalParametersListener); TypeName returnType = TypeName.For("void"); if (typeTypeOrVoidContext != null) { TypeTypeOrVoidListener typeOrVoidListener = new TypeTypeOrVoidListener(); typeTypeOrVoidContext.EnterRule(typeOrVoidListener); returnType = typeOrVoidListener.TypeName; } QualifiedNameListListener qualifiedNameListListener = new QualifiedNameListListener(); if (qualifiedNameListContext != null) { // Exceptions qualifiedNameListContext.EnterRule(qualifiedNameListListener); List <string> qualifiedNames = qualifiedNameListListener.QualifiedNames; } MethodName methodName = new MethodName( parentClass.className, methodNameText, returnType.Signature, formalParametersListener .Arguments .Select(arg => new Argument( arg.Type.Signature, TypeName.For(arg.Type.Signature))).ToList()); MethodInfo newMethodInfo = new MethodInfo( methodName, AccessFlags.AccPublic, // TODO parentClass.className, formalParametersListener.Arguments, returnType, new SourceCodeSnippet(methodBody, SourceCodeLanguage.Java)); parentClass.Children.Add(newMethodInfo); }
private MethodDeclaration ConvertMethodDeclaration(JavaParser.TypeTypeOrVoidContext type, ITerminalNode child0Terminal, ITerminalNode identifier, JavaParser.FormalParametersContext formalParameters, JavaParser.BlockContext methodBody, TextSpan textSpan) { TypeToken typeToken; if (type != null) { typeToken = (TypeToken)Visit(type); } else { var voidTerminal = child0Terminal; typeToken = new TypeToken(voidTerminal.GetText(), voidTerminal.GetTextSpan()); } var id = (IdToken)Visit(identifier); // TODO: Fix with ParamsNode IEnumerable <ParameterDeclaration> parameters; JavaParser.FormalParameterListContext formalParameterList = formalParameters.formalParameterList(); if (formalParameterList == null) { parameters = Enumerable.Empty <ParameterDeclaration>(); } else { parameters = formalParameterList.formalParameter() .Select(param => (ParameterDeclaration)Visit(param)) .Where(p => p != null).ToArray(); } BlockStatement body = methodBody != null ? (BlockStatement)Visit(methodBody) /*: new BlockStatement(Enumerable.Empty<Statement>(), * GetAndConvertTextSpan((ITerminalNode)context.GetChild(context.ChildCount - 1)), FileNode);*/ : null; var result = new MethodDeclaration(id, parameters, body, textSpan); return(result); }
public UstNode VisitFormalParameters(JavaParser.FormalParametersContext context) { return(VisitChildren(context)); }