public Ust VisitClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            var typeTypeToken = new TypeTypeLiteral(TypeType.Class,
                                                    context.GetChild <ITerminalNode>(0).Symbol.GetTextSpan());

            var id = (IdToken)Visit(context.IDENTIFIER());

            EntityDeclaration[] typeMembers = context.classBody().classBodyDeclaration()
                                              .Select(dec => Visit(dec) as EntityDeclaration)
                                              .Where(dec => dec != null).ToArray();

            var baseTypes = new List <TypeToken>();

            if (context.typeType() != null)
            {
                baseTypes.Add((TypeToken)Visit(context.typeType()));
            }
            if (context.typeList() != null)
            {
                baseTypes.AddRange(context.typeList().typeType().Select(t => (TypeToken)Visit(t)));
            }

            var result = new TypeDeclaration(typeTypeToken, id, baseTypes, typeMembers, context.GetTextSpan());

            return(result);
        }
Exemplo n.º 2
0
        public override void EnterClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            string name = context.IDENTIFIER().GetText();

            string headerText = context.GetFullText();

            if (headerText.Contains("{"))
            {
                headerText = headerText.Substring(
                    0,
                    headerText.IndexOf("{", StringComparison.Ordinal));
            }

            ClassInfo newClassInfo;

            if (parentClass != null)
            {
                name = $"{parentClass.className.ShortName}${name}";

                ClassName className = new ClassName(
                    parentClass.className.ContainmentFile(),
                    parentClass.className.ContainmentPackage,
                    name);

                newClassInfo = new ClassInfo(
                    className,
                    new List <MethodInfo>(),
                    new List <FieldInfo>(),
                    AccessFlags.AccPrivate,
                    new List <ClassInfo>(),
                    new SourceCodeSnippet(headerText, SourceCodeLanguage.Java),
                    false);

                parentClass.Children.Add(newClassInfo);
            }
            else
            {
                // top level class
                ClassName className = new ClassName(
                    new FileName(parentFileName),
                    new PackageName(packageFqn),
                    name);

                newClassInfo = new ClassInfo(
                    className,
                    new List <MethodInfo>(),
                    new List <FieldInfo>(),
                    modifier,
                    new List <ClassInfo>(),
                    new SourceCodeSnippet(headerText, SourceCodeLanguage.Java),
                    false);

                OuterClass = newClassInfo;
            }

            ClassBodyListener classBodyListener = new ClassBodyListener(newClassInfo);

            context.classBody().EnterRule(classBodyListener);
        }
        public UstNode VisitClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            var typeTypeToken = new TypeTypeLiteral(TypeType.Class,
                                                    context.GetChild <ITerminalNode>(0).Symbol.GetTextSpan(), FileNode);

            var id = (IdToken)Visit(context.IDENTIFIER());

            EntityDeclaration[] typeMembers = context.classBody().classBodyDeclaration()
                                              .Select(dec => Visit(dec) as EntityDeclaration)
                                              .Where(dec => dec != null).ToArray();

            var result = new TypeDeclaration(typeTypeToken, id, typeMembers, context.GetTextSpan(), FileNode);

            return(result);
        }
Exemplo n.º 4
0
        public override void EnterClassDeclaration(JavaParser.ClassDeclarationContext context)
        {
            string name = context.IDENTIFIER().GetText();

            if (outerClass != null)
            {
                string history = outerClass
                                 .FullyQualified
                                 .Substring(outerClass.FullyQualified.LastIndexOf('/') + 1);
                name = $"{history}${name}";
            }

            string classPackageFqn = string.IsNullOrEmpty(packageFqn)
                ? name
                : $"{packageFqn}.{name}";

            ClassName className = new ClassName($"{parentFileName}|{classPackageFqn}");

            string headerText = context.GetFullText();

            if (headerText.Contains("{"))
            {
                headerText = headerText.Substring(
                    0,
                    headerText.IndexOf("{", StringComparison.Ordinal));
            }

            ClassBodyListener classBodyListener = new ClassBodyListener(className, parentFileName, packageFqn);

            context.classBody().EnterRule(classBodyListener);

            ClassInfo = new ClassInfo(
                className,
                classBodyListener.MethodInfos,
                classBodyListener.FieldInfos,
                modifier,
                classBodyListener.InnerClasses,
                new SourceCodeSnippet(headerText, SourceCodeLanguage.Java),
                false);
        }