Example #1
0
        public override object VisitInterface_definition([NotNull] Interface_definitionContext context)
        {
            var identifier = context.identifier();

            IdentifierContext = identifier;
            return(null);
        }
        private void ParseTypeDeclaration(Type_declarationContext node)
        {
            Class_definitionContext     classContext     = node.class_definition();
            Interface_definitionContext interfaceContext = node.interface_definition();
            Delegate_definitionContext  delegateContext  = node.delegate_definition();
            Enum_definitionContext      enumContext      = node.enum_definition();

            bool isClass     = classContext != null;
            bool isInterface = interfaceContext != null;
            bool isDelegate  = delegateContext != null;
            bool isEnum      = enumContext != null;

            string type = "";
            string name = "";

            if (isClass)
            {
                type = "Class";
                name = this.GetNodeName(classContext.identifier());
            }
            else if (isInterface)
            {
                type = "Interface";
                name = this.GetNodeName(interfaceContext.identifier());
            }
            else if (isDelegate)
            {
                type = "Delegate";
                name = this.GetNodeName(delegateContext.identifier());
            }
            else if (isEnum)
            {
                type = "Enum";
                name = this.GetNodeName(enumContext.identifier());
            }

            if (!string.IsNullOrEmpty(name))
            {
                this.WriteLine();
                this.WriteKeyValue(type, name);
            }

            if (isClass)
            {
                this.WriteBeginBrace();
                this.ParseClassDeclaration(classContext);
                this.WriteEndBrace();
            }
            else if (isInterface)
            {
                this.WriteBeginBrace();
                this.ParseInterfaceDeclaration(interfaceContext);
                this.WriteEndBrace();
            }
        }
        /// <summary>
        /// Define interface class and symbol
        /// </summary>
        /// <param name="context"></param>
        public override void EnterInterface_definition([NotNull] Interface_definitionContext context)
        {
            var             identifierInterface = context.identifier();
            InterfaceSymbol symbol = new InterfaceSymbol(identifierInterface.GetText());

            symbol.SetEnclosingScope(currentScope);
            identifierInterface.Symbol = symbol;
            identifierInterface.Scope  = symbol;

            //get baseinterface
            var baseContext = context.interface_base();

            if (baseContext != null)
            {
                var baselist = baseContext.interface_type_list().namespace_or_type_name();
                foreach (var item in baselist)
                {
                    symbol.AddBaseName(item.GetText());
                }
            }
            Define(symbol);
            currentScope = symbol;
        }
        private void ParseInterfaceDeclaration(Interface_definitionContext node)
        {
            var members = node.interface_body().interface_member_declaration();

            foreach (var member in members)
            {
                if (member is Interface_member_declarationContext)
                {
                    Interface_member_declarationContext memberContext = member as Interface_member_declarationContext;
                    Type_Context typeContext = memberContext.type_();

                    bool isProperty = typeContext != null;

                    IdentifierContext identifierContext = memberContext.identifier();

                    if (identifierContext != null)
                    {
                        string name = this.GetNodeName(identifierContext);
                        this.WriteKeyValue((isProperty ? "Property" : "Method"), name);
                    }
                }
            }
        }
 public override void ExitInterface_definition([NotNull] Interface_definitionContext context)
 {
     currentScope = currentScope.GetEnclosingScope();
 }