Пример #1
0
        /// <summary>
        /// Parses a Java package directive
        /// </summary>
        /// <param name="namespaceElement">A file unit</param>
        /// <param name="context">The parser context</param>
        public override void ParseNamespaceElement(XElement namespaceElement, ParserContext context) {
            var javaPackage = context.FileUnit.Elements(SRC.Package).FirstOrDefault();

            // Add a global namespace definition
            var globalNamespace = new NamespaceDefinition();
            context.Push(globalNamespace);

            if(null != javaPackage) {
                var namespaceElements = from name in javaPackage.Elements(SRC.Name)
                                        select name;
                foreach(var name in namespaceElements) {
                    var namespaceForName = new NamespaceDefinition() {
                        Name = name.Value,
                        ProgrammingLanguage = ParserLanguage,
                    };
                    namespaceForName.AddSourceLocation(context.CreateLocation(name));
                    context.Push(namespaceForName, globalNamespace);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a NamespaceDefinition object for the given namespace typeUseElement. This must be one of the typeUseElement types defined in NamespaceElementNames.
        /// </summary>
        /// <param name="namespaceElement">the namespace element</param>
        /// <param name="context">The parser context</param>
        /// <returns>a new NamespaceDefinition object</returns>
        public override void ParseNamespaceElement(XElement namespaceElement, ParserContext context) {
            if(namespaceElement == null)
                throw new ArgumentNullException("namespaceElement");
            if(!NamespaceElementNames.Contains(namespaceElement.Name))
                throw new ArgumentException(string.Format("Not a valid namespace typeUseElement: {0}", namespaceElement.Name), "namespaceElement");

            var nameElement = namespaceElement.Element(SRC.Name);
            var namespaceName = nameElement != null ? nameElement.Value : string.Empty;

            var namespaceDefinition = new NamespaceDefinition { Name = namespaceName };
            context.Push(namespaceDefinition);
        }
Пример #3
0
        /// <summary>
        /// Parses a C# namespace block
        /// </summary>
        /// <param name="namespaceElement">the namespace element to parse</param>
        /// <param name="context">the parser context</param>
        public override void ParseNamespaceElement(XElement namespaceElement, ParserContext context) {
            if(namespaceElement == null) throw new ArgumentNullException("namespaceElement");
            if(!NamespaceElementNames.Contains(namespaceElement.Name)) throw new ArgumentException(string.Format("Not a valid namespace element: {0}", namespaceElement.Name), "namespaceElement");

            var nameElement = namespaceElement.Element(SRC.Name);
            string namespaceName;
            if(nameElement == null) {
                namespaceName = string.Empty;
            } else {
                NamespaceDefinition root = null;
                foreach(var name in NameHelper.GetNameElementsFromName(nameElement)) {
                    var namespaceForName = new NamespaceDefinition() {
                        Name = name.Value,
                        ProgrammingLanguage = ParserLanguage,
                    };
                    if(root == null) {
                        root = namespaceForName;
                    } else {
                        namespaceForName.AddSourceLocation(context.CreateLocation(name));
                    }
                    context.Push(namespaceForName, root);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Creates a global <see cref="NamespaceDefinition"/> object for <paramref name="unitElement"/> and pushes it onto <paramref name="context"/>
        /// </summary>
        /// <param name="unitElement">The element to parse</param>
        /// <param name="context">The context to place the resulting namespace definition in</param>
        public virtual void ParseUnitElement(XElement unitElement, ParserContext context) {
            if(null == unitElement) throw new ArgumentNullException("unitElement");
            if(SRC.Unit != unitElement.Name) throw new ArgumentException("should be a SRC.Unit", "unitElement");
            context.FileUnit = unitElement;
            var aliases = from aliasStatement in GetAliasElementsForFile(unitElement)
                          select ParseAliasElement(aliasStatement, context);

            context.Aliases = new Collection<Alias>(aliases.ToList());

            var namespaceForUnit = new NamespaceDefinition();
            context.Push(namespaceForUnit);
        }
Пример #5
0
        /// <summary>
        /// Parses a type element and pushes a it onto the <paramref name="context"/>.
        /// </summary>
        /// <param name="typeElement">the type element to parse</param>
        /// <param name="context">The parser context</param>
        public virtual void ParseTypeElement(XElement typeElement, ParserContext context) {
            if(null == typeElement) throw new ArgumentNullException("typeElement");

            var typeDefinition = new TypeDefinition() {
                Accessibility = GetAccessModifierForType(typeElement),
                Kind = XNameMaps.GetKindForXElement(typeElement),
                Name = GetNameForType(typeElement),
            };
            foreach(var parentTypeElement in GetParentTypeUseElements(typeElement)) {
                var parentTypeUse = ParseTypeUseElement(parentTypeElement, context);
                typeDefinition.AddParentType(parentTypeUse);
            }
            context.Push(typeDefinition);
        }
Пример #6
0
        /// <summary>
        /// Creates a <see cref="MethodDefinition"/> object for <paramref name="methodElement"/> and pushes it onto <paramref name="context"/>
        /// </summary>
        /// <param name="methodElement">The element to parse</param>
        /// <param name="context">The context to place the resulting method definition in</param>
        public virtual void ParseMethodElement(XElement methodElement, ParserContext context) {
            if(null == methodElement) throw new ArgumentNullException("methodElement");
            if(!MethodElementNames.Contains(methodElement.Name)) throw new ArgumentException("must be a method typeUseElement", "fileUnit");

            var methodDefinition = new MethodDefinition() {
                Name = GetNameForMethod(methodElement),
                IsConstructor = (methodElement.Name == SRC.Constructor || methodElement.Name == SRC.ConstructorDeclaration),
                IsDestructor = (methodElement.Name == SRC.Destructor || methodElement.Name == SRC.DestructorDeclaration),
                Accessibility = GetAccessModifierForMethod(methodElement),
            };

            // get the return type for the method
            var returnTypeElement = methodElement.Element(SRC.Type);
            if(returnTypeElement != null) {
                // construct the return type
                // however, if the Name of the return type is "void", don't use it because it means the return type is void
                var returnTypeUse = ParseTypeUseElement(returnTypeElement, context);
                if(returnTypeUse.Name != "void") {
                    methodDefinition.ReturnType = ParseTypeUseElement(returnTypeElement, context);
                }
            }
            var parameters = from paramElement in GetParametersFromMethodElement(methodElement)
                             select ParseMethodParameterElement(paramElement, context);
            methodDefinition.AddMethodParameters(parameters);
            
            context.Push(methodDefinition);
        }
Пример #7
0
 /// <summary>
 /// Creates a <see cref="Scope"/> object for <paramref name="element"/> and pushes it onto <paramref name="context"/>
 /// </summary>
 /// <param name="element">The element to parse</param>
 /// <param name="context">the context to place the resulting scope on</param>
 public virtual void ParseContainerElement(XElement element, ParserContext context) {
     var scope = new Scope();
     context.Push(scope);
 }