Example #1
0
 /// <summary> Is call to UpdateDataFrom is allowed? </summary>
 internal bool CanUpdateDataFrom(AXmlObject source)
 {
     return
         (this.GetType() == source.GetType() &&
          this.StartOffset == source.StartOffset &&
          (this.LastUpdatedFrom == source || !this.IsCached));
 }
Example #2
0
        /// <summary> Copy all data from the 'source' to this object </summary>
        /// <remarks> Returns true if any updates were done </remarks>
        internal virtual bool UpdateDataFrom(AXmlObject source)
        {
            Assert(this.GetType() == source.GetType(), "Source has different type");
            DebugAssert(this.StartOffset == source.StartOffset, "Source has different StartOffset");

            if (this.LastUpdatedFrom == source)
            {
                DebugAssert(this.EndOffset == source.EndOffset, "Source has different EndOffset");
                return(false);
            }

            Assert(!this.IsCached, "Can not update cached item");
            Assert(source.IsCached, "Must update from cache");

            this.LastUpdatedFrom = source;
            this.StartOffset     = source.StartOffset;
            // In some cases we are just updating objects of that same
            // type and position and hoping to be luckily right
            this.EndOffset = source.EndOffset;

            // Do not bother comparing - assume changed if non-null
            if (this.syntaxErrors != null || source.syntaxErrors != null)
            {
                // May be called again in derived class - oh, well, does not matter
                OnChanging();
                this.Document.Parser.TrackedSegments.RemoveSyntaxErrorsOf(this);
                if (source.syntaxErrors == null)
                {
                    this.syntaxErrors = null;
                }
                else
                {
                    this.syntaxErrors = new List <SyntaxError>();
                    foreach (var error in source.MySyntaxErrors)
                    {
                        // The object differs, so create our own copy
                        // The source still might need it in the future and we do not want to break it
                        this.AddSyntaxError(error.Clone(this));
                    }
                }
                this.Document.Parser.TrackedSegments.AddSyntaxErrorsOf(this);
                OnChanged();
            }

            return(true);
        }
Example #3
0
		/// <summary> Copy all data from the 'source' to this object </summary>
		/// <remarks> Returns true if any updates were done </remarks>
		internal virtual bool UpdateDataFrom(AXmlObject source)
		{
			Assert(this.GetType() == source.GetType(), "Source has different type");
			DebugAssert(this.StartOffset == source.StartOffset, "Source has different StartOffset");
			
			if (this.LastUpdatedFrom == source) {
				DebugAssert(this.EndOffset == source.EndOffset, "Source has different EndOffset");
				return false;
			}
			
			Assert(!this.IsCached, "Can not update cached item");
			Assert(source.IsCached, "Must update from cache");
			
			this.LastUpdatedFrom = source;
			this.StartOffset = source.StartOffset;
			// In some cases we are just updating objects of that same
			// type and position and hoping to be luckily right
			this.EndOffset = source.EndOffset;
			
			// Do not bother comparing - assume changed if non-null
			if (this.syntaxErrors != null || source.syntaxErrors != null) {
				// May be called again in derived class - oh, well, does not matter
				OnChanging();
				this.Document.Parser.TrackedSegments.RemoveSyntaxErrorsOf(this);
				if (source.syntaxErrors == null) {
					this.syntaxErrors = null;
				} else {
					this.syntaxErrors = new List<SyntaxError>();
					foreach(var error in source.MySyntaxErrors) {
						// The object differs, so create our own copy
						// The source still might need it in the future and we do not want to break it
						this.AddSyntaxError(error.Clone(this));
					}
				}
				this.Document.Parser.TrackedSegments.AddSyntaxErrorsOf(this);
				OnChanged();
			}
			
			return true;
		}
Example #4
0
		/// <summary> Is call to UpdateDataFrom is allowed? </summary>
		internal bool CanUpdateDataFrom(AXmlObject source)
		{
			return
				this.GetType() == source.GetType() &&
				this.StartOffset == source.StartOffset &&
				(this.LastUpdatedFrom == source || !this.IsCached);
		}
Example #5
0
        /// <summary> Get posible configurations after considering fiven object </summary>
        Configurations ProcessObject(Configurations oldConfigs, AXmlObject obj)
        {
            AXmlParser.Log("Processing {0}", obj);

            AXmlTag tag = obj as AXmlTag;

            AXmlParser.Assert(obj is AXmlTag || obj is AXmlText || obj is AXmlElement, obj.GetType().Name + " not expected");
            if (obj is AXmlElement)
            {
                AXmlParser.Assert(((AXmlElement)obj).IsProperlyNested, "Element not proprly nested");
            }

            Configurations newConfigs = new Configurations();

            foreach (var kvp in oldConfigs)
            {
                Configuration oldConfig    = kvp.Value;
                var           oldStartTags = oldConfig.StartTags;
                var           oldDocument  = oldConfig.Document;
                int           oldCost      = oldConfig.Cost;

                if (tag != null && tag.IsStartTag)
                {
                    newConfigs.Add(new Configuration {                                        // Push start-tag (cost 0)
                        StartTags = oldStartTags.Push(tag),
                        Document  = oldDocument.Push(tag),
                        Cost      = oldCost,
                    });
                }
                else if (tag != null && tag.IsEndTag)
                {
                    newConfigs.Add(new Configuration {                                        // Ignore (cost 1)
                        StartTags = oldStartTags,
                        Document  = oldDocument.Push(StartTagPlaceholder).Push(tag),
                        Cost      = oldCost + 1,
                    });
                    if (!oldStartTags.IsEmpty && oldStartTags.Peek().Name != tag.Name)
                    {
                        newConfigs.Add(new Configuration {                                        // Pop 1 item (cost 1) - not mathcing
                            StartTags = oldStartTags.Pop(),
                            Document  = oldDocument.Push(tag),
                            Cost      = oldCost + 1,
                        });
                    }
                    int popedCount = 0;
                    var startTags  = oldStartTags;
                    var doc        = oldDocument;
                    foreach (AXmlTag poped in oldStartTags)
                    {
                        popedCount++;
                        if (poped.Name == tag.Name)
                        {
                            newConfigs.Add(new Configuration {                                         // Pop 'x' items (cost x-1) - last one is matching
                                StartTags = startTags.Pop(),
                                Document  = doc.Push(tag),
                                Cost      = oldCost + popedCount - 1,
                            });
                        }
                        startTags = startTags.Pop();
                        doc       = doc.Push(EndTagPlaceholder);
                    }
                }
                else
                {
                    // Empty tag  or  other tag type  or  text  or  properly nested element
                    newConfigs.Add(new Configuration {                                        // Ignore (cost 0)
                        StartTags = oldStartTags,
                        Document  = oldDocument.Push(obj),
                        Cost      = oldCost,
                    });
                }
            }

            // Log("New configurations:" + newConfigs.ToString());

            Configurations bestNewConfigurations = new Configurations(
                newConfigs.Values.OrderBy(v => v.Cost).Take(maxConfigurationCount)
                );

            // AXmlParser.Log("Best new configurations:" + bestNewConfigurations.ToString());

            return(bestNewConfigurations);
        }