Пример #1
0
        ArrayList CtrlSpaceForAttributeName(string fileContent, XamlExpressionContext context)
        {
            if (context.ElementPath.Elements.Count == 0)
            {
                return(null);
            }
            QualifiedName       lastElement = context.ElementPath.Elements[context.ElementPath.Elements.Count - 1];
            XamlCompilationUnit cu          = parseInfo.BestCompilationUnit as XamlCompilationUnit;

            if (cu == null)
            {
                return(null);
            }
            IReturnType rt = cu.CreateType(lastElement.Namespace, lastElement.Name);

            if (rt == null)
            {
                return(null);
            }
            ArrayList list = new ArrayList();

            foreach (IProperty p in rt.GetProperties())
            {
                if (p.IsPublic && p.CanSet)
                {
                    list.Add(p);
                }
            }
            return(list);
        }
Пример #2
0
        MemberResolveResult ResolveProperty(string xmlNamespace, string className, string propertyName, bool allowAttached)
        {
            IProjectContent pc           = parseInfo.BestCompilationUnit.ProjectContent;
            IReturnType     resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className);

            if (resolvedType != null && resolvedType.GetUnderlyingClass() != null)
            {
                IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return(p.Name == propertyName); });
                if (member == null)
                {
                    member = resolvedType.GetEvents().Find(delegate(IEvent p) { return(p.Name == propertyName); });
                }
                if (member == null && allowAttached)
                {
                    member = resolvedType.GetMethods().Find(
                        delegate(IMethod p) {
                        return(p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName);
                    });
                }
                if (member != null)
                {
                    return(new MemberResolveResult(callingClass, null, member));
                }
            }
            return(null);
        }
Пример #3
0
        ArrayList CtrlSpaceForElement(string fileContent)
        {
            using (XmlTextReader r = new XmlTextReader(new StringReader(fileContent))) {
                try {
                    r.WhitespaceHandling = WhitespaceHandling.Significant;
                    // move reader to correct position
                    while (r.Read() && !IsReaderAtTarget(r))
                    {
                    }
                }
                catch (XmlException) {
                }
                ArrayList       result = new ArrayList();
                IProjectContent pc     = parseInfo.BestCompilationUnit.ProjectContent;

                resolveExpression = r.Name;
                TypeResolveResult rr = ResolveElementName(r) as TypeResolveResult;
                if (rr != null)
                {
                    AddPropertiesForType(result, r, rr);
                }

                foreach (var ns in r.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
                {
                    ArrayList list = XamlCompilationUnit.GetNamespaceMembers(pc, ns.Value);
                    if (list != null)
                    {
                        foreach (IClass c in list.OfType <IClass>())
                        {
                            if (c.ClassType != ClassType.Class)
                            {
                                continue;
                            }
                            if (c.IsAbstract && c.IsStatic)
                            {
                                continue;
                            }
                            if (c.ClassInheritanceTree.Any(b => b.FullyQualifiedName == "System.Attribute"))
                            {
                                continue;
                            }
                            if (!c.Methods.Any(m => m.IsConstructor && m.IsPublic))
                            {
                                continue;
                            }
                            if (string.IsNullOrEmpty(ns.Key))
                            {
                                result.Add(c);
                            }
                            else
                            {
                                result.Add(new XamlCompletionClass(c, ns.Key));
                            }
                        }
                    }
                }
                return(result);
            }
        }
		public XamlClassReturnType(XamlCompilationUnit compilationUnit, string xmlNamespace, string className)
		{
			if (compilationUnit == null)
				throw new ArgumentNullException("compilationUnit");

			this.compilationUnit = compilationUnit;
			this.xmlNamespace = xmlNamespace;
			this.className = className ?? "";
		}
Пример #5
0
        MemberResolveResult ResolveProperty(string xmlNamespace, string className, string propertyName, bool allowAttached)
        {
            IProjectContent pc           = context.ProjectContent;
            IReturnType     resolvedType = XamlCompilationUnit.FindType(pc, xmlNamespace, className);

            if (resolvedType != null && resolvedType.GetUnderlyingClass() != null)
            {
                return(ResolvePropertyName(resolvedType, propertyName, allowAttached));
            }
            return(null);
        }
Пример #6
0
        public XamlClassReturnType(XamlCompilationUnit compilationUnit, string xmlNamespace, string className)
        {
            if (compilationUnit == null)
            {
                throw new ArgumentNullException("compilationUnit");
            }

            this.compilationUnit = compilationUnit;
            this.xmlNamespace    = xmlNamespace;
            this.className       = className ?? "";
        }
		public CompilationUnitCreatorVisitor(IProjectContent projectContent, string fileContent, string fileName, string[] lexerTags)
		{
			this.CompilationUnit = new XamlCompilationUnit(projectContent);
			
			this.CompilationUnit.FileName = fileName;
			this.fileContent = fileContent;
			this.lexerTags = lexerTags;
			this.projectContent = projectContent;
			this.currentAmbience = projectContent.Language.GetAmbience();
			
			this.nodeStack = new Stack<NodeWrapper>();
		}
        public CompilationUnitCreatorVisitor(IProjectContent projectContent, string fileContent, string fileName, string[] lexerTags)
        {
            this.CompilationUnit = new XamlCompilationUnit(projectContent);

            this.CompilationUnit.FileName = fileName;
            this.fileContent     = fileContent;
            this.lexerTags       = lexerTags;
            this.projectContent  = projectContent;
            this.currentAmbience = projectContent.Language.GetAmbience();

            this.nodeStack = new Stack <NodeWrapper>();
        }
Пример #9
0
        public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent)
        {
            XamlCompilationUnit cu = new XamlCompilationUnit(projectContent);

            cu.FileName = fileName;
            try {
                using (XmlTextReader r = new XmlTextReader(new StringReader(fileContent))) {
                    r.WhitespaceHandling = WhitespaceHandling.Significant;
                    r.Read();
                    r.MoveToContent();
                    DomRegion classStart = new DomRegion(r.LineNumber, r.LinePosition - 1);
                    string    className  = r.GetAttribute("Class", XamlNamespace);
                    if (string.IsNullOrEmpty(className))
                    {
                        LoggingService.Debug("XamlParser: returning empty cu because root element has no Class attribute");
                    }
                    else
                    {
                        DefaultClass c = new DefaultClass(cu, className);
                        c.Modifiers = ModifierEnum.Partial;
                        c.Region    = classStart;
                        c.BaseTypes.Add(TypeFromXmlNode(cu, r));
                        cu.Classes.Add(c);

                        DefaultMethod initializeComponent = new DefaultMethod(
                            "InitializeComponent",
                            projectContent.SystemTypes.Void,
                            ModifierEnum.Public | ModifierEnum.Synthetic,
                            classStart, DomRegion.Empty,
                            c);
                        c.Methods.Add(initializeComponent);

                        ParseXamlElement(cu, c, r);
                        if (r.NodeType == XmlNodeType.EndElement)
                        {
                            c.Region = new DomRegion(classStart.BeginLine, classStart.BeginColumn, r.LineNumber, r.LinePosition + r.Name.Length);
                        }
                    }
                }
            }
            catch (XmlException ex) {
                LoggingService.Debug("XamlParser exception: " + ex.ToString());
                cu.ErrorsDuringCompile = true;
            }
            return(cu);
        }
Пример #10
0
        ResolveResult ResolveElementName(string exp)
        {
            string xmlNamespace;
            string name;

            this.resolveExpression = exp;
            if (resolveExpression.Contains(":"))
            {
                string prefix = resolveExpression.Substring(0, resolveExpression.IndexOf(':'));
                name = resolveExpression.Substring(resolveExpression.IndexOf(':') + 1);
                if (!context.XmlnsDefinitions.TryGetValue(prefix, out xmlNamespace))
                {
                    xmlNamespace = null;
                }
            }
            else
            {
                if (!context.XmlnsDefinitions.TryGetValue("", out xmlNamespace))
                {
                    xmlNamespace = null;
                }
                name = resolveExpression;
            }
            if (name.Contains("."))
            {
                string propertyName = name.Substring(name.IndexOf('.') + 1);
                name = name.Substring(0, name.IndexOf('.'));
                return(ResolveProperty(xmlNamespace, name, propertyName, true));
            }
            else
            {
                IProjectContent pc            = context.ProjectContent;
                IReturnType     resolvedType  = XamlCompilationUnit.FindType(pc, xmlNamespace, name);
                IClass          resolvedClass = resolvedType != null?resolvedType.GetUnderlyingClass() : null;

                if (resolvedClass != null)
                {
                    return(new TypeResolveResult(callingClass, null, resolvedClass));
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #11
0
        void ParseXamlElement(XamlCompilationUnit cu, DefaultClass c, XmlTextReader r)
        {
            Debug.Assert(r.NodeType == XmlNodeType.Element);
            string name           = r.GetAttribute("Name", XamlNamespace) ?? r.GetAttribute("Name");
            bool   isEmptyElement = r.IsEmptyElement;

            if (!string.IsNullOrEmpty(name))
            {
                IReturnType type = TypeFromXmlNode(cu, r);

                // Use position of Name attribute for field region
                //if (!r.MoveToAttribute("Name", XamlNamespace)) {
                //	r.MoveToAttribute("Name");
                //}
                DomRegion position = new DomRegion(r.LineNumber, r.LinePosition, r.LineNumber, r.LinePosition + name.Length);
                c.Fields.Add(new DefaultField(type, name, ModifierEnum.Internal, position, c));
            }

            if (isEmptyElement)
            {
                return;
            }
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    ParseXamlElement(cu, c, r);
                }
                else if (r.NodeType == XmlNodeType.Comment)
                {
                    foreach (string tag in lexerTags)
                    {
                        if (r.Value.Contains(tag))
                        {
                            cu.TagComments.Add(new TagComment(r.Value, new DomRegion(r.LineNumber, r.LinePosition, r.LineNumber, r.LinePosition + r.Value.Length)));
                            break;
                        }
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
            }
        }
Пример #12
0
        ResolveResult ResolveElementName(XmlReader r)
        {
            string xmlNamespace;
            string name;

            if (resolveExpression.Contains(":"))
            {
                string prefix = resolveExpression.Substring(0, resolveExpression.IndexOf(':'));
                name         = resolveExpression.Substring(resolveExpression.IndexOf(':') + 1);
                xmlNamespace = r.LookupNamespace(prefix);
            }
            else
            {
                xmlNamespace = r.LookupNamespace("");
                name         = resolveExpression;
            }
            if (name.Contains("."))
            {
                string propertyName = name.Substring(name.IndexOf('.') + 1);
                name = name.Substring(0, name.IndexOf('.'));
                return(ResolveProperty(xmlNamespace, name, propertyName, true));
            }
            else
            {
                IProjectContent pc            = parseInfo.BestCompilationUnit.ProjectContent;
                IReturnType     resolvedType  = XamlCompilationUnit.FindType(pc, xmlNamespace, name);
                IClass          resolvedClass = resolvedType != null?resolvedType.GetUnderlyingClass() : null;

                if (resolvedClass != null)
                {
                    return(new TypeResolveResult(callingClass, null, resolvedClass));
                }
                else
                {
                    return(null);
                }
            }
        }
		static IReturnType TypeFromXmlNode(XamlCompilationUnit cu, AXmlElement element)
		{
			return cu.CreateType(element.Namespace, element.LocalName);
		}
 static IReturnType TypeFromXmlNode(XamlCompilationUnit cu, AXmlElement element)
 {
     return(cu.CreateType(element.Namespace, element.LocalName));
 }
Пример #15
0
 IReturnType TypeFromXmlNode(XamlCompilationUnit cu, XmlReader r)
 {
     return(cu.CreateType(r.NamespaceURI, r.LocalName));
 }