public override void EnterTypeTypeOrVoid(JavaParser.TypeTypeOrVoidContext context) { if (context.typeType() == null) { TypeName = TypeName.For("void"); return; } TypeTypeListener typeTypeListener = new TypeTypeListener(); context.typeType().EnterRule(typeTypeListener); if (typeTypeListener.PrimitiveTypeName != null) { TypeName = typeTypeListener.PrimitiveTypeName; } else if (!string.IsNullOrEmpty(typeTypeListener.ID)) { TypeName = TypeName.For(typeTypeListener.ID); } else { TypeName = TypeName.For("void"); } }
public override void EnterFormalParameter(JavaParser.FormalParameterContext context) { // type of parameter TypeTypeListener typeTypeListener = new TypeTypeListener(); context.typeType().EnterRule(typeTypeListener); TypeName typeName = null; if (typeTypeListener.PrimitiveTypeName != null) { typeName = typeTypeListener.PrimitiveTypeName; } else if (!string.IsNullOrEmpty(typeTypeListener.ID)) { typeName = TypeName.For(typeTypeListener.ID); } else { typeName = PrimitiveTypeName.Void; } // name of parameter VariableDeclaratorIdListener variableDeclaratorIdListener = new VariableDeclaratorIdListener(); context.variableDeclaratorId().EnterRule(variableDeclaratorIdListener); Argument = new Argument(variableDeclaratorIdListener.ID, typeName); }
public override void EnterTyped_member_declaration(CSharpParser.Typed_member_declarationContext context) { var type = PrimitiveTypeName.Void; var className = string.Empty; if (context.type_() != null) { var typeListener = new TypeListener(); context.type_().EnterRule(typeListener); type = typeListener.Type; className = typeListener.ClassName; } var typeName = className != null ? TypeName.For(className) : type; if (context.field_declaration() != null) { var fieldDeclarationListener = new FieldDeclarationListener(_parentClassName, typeName.FullyQualified); context.field_declaration().EnterRule(fieldDeclarationListener); FieldInfo = fieldDeclarationListener.FieldInfo; } if (context.method_declaration() != null) { var methodDeclarationListener = new MethodDeclarationListener(_parentClassName, typeName); context.method_declaration().EnterRule(methodDeclarationListener); MethodInfo = methodDeclarationListener.MethodInfo; } }
public override void EnterTypeArgument(JavaParser.TypeArgumentContext context) { if (context.typeType() == null) { Type = TypeName.For("void").Signature; return; } TypeTypeListener typeTypeListener = new TypeTypeListener(); context.typeType().EnterRule(typeTypeListener); if (typeTypeListener.ID != null) { Type = typeTypeListener.ID; } else if (typeTypeListener.QualifiedName != null) { Type = typeTypeListener.QualifiedName; } else if (typeTypeListener.PrimitiveTypeName != null) { Type = TypeName.For("void").Signature; } }
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); }
public override void EnterFieldDeclaration(JavaParser.FieldDeclarationContext context) { PrimitiveTypeName primitiveTypeName = null; string qualifiedName = ""; if (context.typeType() != null) { TypeTypeListener typeTypeListener = new TypeTypeListener(); context.typeType().EnterRule(typeTypeListener); primitiveTypeName = typeTypeListener.PrimitiveTypeName; qualifiedName = typeTypeListener.QualifiedName; } List <string> IDs = new List <string>(); if (context.variableDeclarators() != null) { VariableDeclaratorsListener variableDeclaratorsListener = new VariableDeclaratorsListener(); context.variableDeclarators().EnterRule(variableDeclaratorsListener); IDs = variableDeclaratorsListener.IDs; } if (primitiveTypeName == null && string.IsNullOrEmpty(qualifiedName)) { primitiveTypeName = TypeName.For("void") as PrimitiveTypeName; } string fieldName = IDs.FirstOrDefault(); FieldName fieldFqn = new FieldName( parentClass.className, fieldName, primitiveTypeName != null ? primitiveTypeName.Signature : TypeName.For(qualifiedName).Signature); FieldInfo fieldInfo = new FieldInfo( fieldFqn, parentClass.className, AccessFlags.AccPublic, new SourceCodeSnippet(context.GetFullText(), SourceCodeLanguage.Java)); parentClass.Children.Add(fieldInfo); }
public override void EnterPrimitiveType(JavaParser.PrimitiveTypeContext context) { if (context.INT() != null) { PrimitiveTypeName = TypeName.For("int") as PrimitiveTypeName; } if (context.BYTE() != null) { PrimitiveTypeName = TypeName.For("byte") as PrimitiveTypeName; } if (context.CHAR() != null) { PrimitiveTypeName = TypeName.For("char") as PrimitiveTypeName; } if (context.LONG() != null) { PrimitiveTypeName = TypeName.For("long") as PrimitiveTypeName; } if (context.FLOAT() != null) { PrimitiveTypeName = TypeName.For("float") as PrimitiveTypeName; } if (context.SHORT() != null) { PrimitiveTypeName = TypeName.For("short") as PrimitiveTypeName; } if (context.DOUBLE() != null) { PrimitiveTypeName = TypeName.For("double") as PrimitiveTypeName; } if (context.BOOLEAN() != null) { PrimitiveTypeName = TypeName.For("bool") as PrimitiveTypeName; } }