This interface represents a container which holds a text sequence and all necessary information about it. It is used as the base for a text editor.
        internal static IDocument MakeDocument(string message)
        {
            IDocument document = new DocumentFactory().CreateDocument();
            document.TextContent = message;

            return document;
        }
		public void TestDocumentRemoveStoreTest()
		{
			IDocument document = new DocumentFactory().CreateDocument();
			
			string top      = "1234567890\n";
			string testText =
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			document.TextContent = top + testText;
			document.Remove(0, top.Length);
			Assert.AreEqual(document.TextContent, testText);
			
			document.Remove(0, document.TextLength);
			LineSegment line = document.GetLineSegment(0);
			Assert.AreEqual(0, line.Offset);
			Assert.AreEqual(0, line.Length);
			Assert.AreEqual(0, document.TextLength);
			Assert.AreEqual(1, document.TotalNumberOfLines);
		}
示例#3
0
 public string GenerateHtml(string code, string highlighterName)
 {
     IDocument doc = new DocumentFactory().CreateDocument();
     doc.HighlightingStrategy = HighlightingManager.Manager.FindHighlighter(highlighterName);
     doc.TextContent = code;
     return GenerateHtml(doc);
 }
		/// <summary>
		/// Resolves a resource reference.
		/// Line and column are 0-based.
		/// </summary>
		protected ResourceResolveResult Resolve(string fileName, string code, int caretLine, int caretColumn, char? charTyped, bool parseFile)
		{
			this.EnlistTestFile(fileName, code, parseFile);
			IDocument doc = new DocumentFactory().CreateDocument();
			doc.TextContent = code;
			return ResourceResolverService.Resolve(fileName, doc, caretLine, caretColumn, charTyped);
		}
        internal static IDocument MakeDocument(string message, out int offset)
        {
            IDocument document = new DocumentFactory().CreateDocument();
            offset = message.IndexOf('|');
            document.TextContent = message.Remove(offset, 1);

            return document;
        }
		public void BeginLineOnSecondLine()
		{
			DomRegion region = new DomRegion(1, 0, 2, 0);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890\r\n1234567890\r\n1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(12, 13);
			
			Assert.AreEqual(expectedSegment, segment);
		}
		public void ThreeLinesWithoutCarriageReturn()
		{
			DomRegion region = new DomRegion(0, 2, 2, 1);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890\n1234567890\n1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22);
			
			Assert.AreEqual(expectedSegment, segment);
		}
		public void SingleLine()
		{
			DomRegion region = new DomRegion(0, 0, 0, 5);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(0, 6);
			
			Assert.AreEqual(expectedSegment, segment);
		}
示例#9
0
        public void TestDocumentBug2Test()
        {
            IDocument document = new DocumentFactory().CreateDocument();

            string top      = "123\n456\n789\n0";
            string testText = "Hello World!";

            document.TextContent = top;

            document.Insert(top.Length, testText);

            LineSegment line = document.GetLineSegment(document.TotalNumberOfLines - 1);

            Assert.AreEqual(top.Length - 1, line.Offset);
            Assert.AreEqual(testText.Length + 1, line.Length);
        }
示例#10
0
        public void TestDocumentBug1Test()
        {
            IDocument document = new DocumentFactory().CreateDocument();

            string top      = "1234567890";
            document.TextContent = top;

            Assert.AreEqual(document.GetLineSegment(0).Length, document.TextLength);

            document.Remove(0, document.TextLength);

            LineSegment line = document.GetLineSegment(0);
            Assert.AreEqual(0, line.Offset);
            Assert.AreEqual(0, line.Length);
            Assert.AreEqual(0, document.TextLength);
            Assert.AreEqual(1, document.TotalNumberOfLines);
        }
		public void TestDocumentInsertTest()
		{
			IDocument document = new DocumentFactory().CreateDocument();
			
			string top      = "1234567890\n";
			string testText =
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			
			document.TextContent = top;
			document.Insert(top.Length, testText);
			Assert.AreEqual(top + testText, document.TextContent);
		}
		public void TestDocumentStoreTest()
		{
			IDocument document = new DocumentFactory().CreateDocument();
			
			string testText = "1234567890\n" +
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			document.TextContent = testText;
			
			Assert.AreEqual(testText, document.TextContent);
			Assert.AreEqual(11, document.TotalNumberOfLines);
			Assert.AreEqual(testText.Length, document.TextLength);
		}
		public void SetUp()
		{
			IDocument doc = new DocumentFactory().CreateDocument();
			StringBuilder b = new StringBuilder();
			for (int i = 0; i < 50 ; i++) {
				b.AppendLine(new string('a', 50));
			}
			doc.TextContent = b.ToString();
			list = new List<FoldMarker>();
			list.Add(new FoldMarker(doc, 1, 6, 5, 2));
			list.Add(new FoldMarker(doc, 2, 1, 2, 3));
			list.Add(new FoldMarker(doc, 3, 7, 4, 1));
			list.Add(new FoldMarker(doc, 10, 1, 14, 1));
			list.Add(new FoldMarker(doc, 10, 3, 10, 3));
			list.Add(new FoldMarker(doc, 11, 1, 15, 1));
			list.Add(new FoldMarker(doc, 12, 1, 16, 1));
			foreach (FoldMarker fm in list) {
				fm.IsFolded = true;
			}
			doc.FoldingManager.UpdateFoldings(new List<FoldMarker>(list));
			manager = doc.FoldingManager;
		}
		public void TestDocumentGenerationTest()
		{
			IDocument document = new DocumentFactory().CreateDocument();
		}
		/// <summary>
		/// Gets the project resource from the specified expression.
		/// </summary>
		public ProjectResourceInfo GetProjectResource(CodePropertyReferenceExpression propRef)
		{
			CodeTypeReferenceExpression typeRef = propRef.TargetObject as CodeTypeReferenceExpression;
			if (typeRef == null) {
				LoggingService.Info("Target of possible project resources property reference is not a type reference, but " + propRef.TargetObject.ToString() + ".");
				return null;
			}
			
			// Get the (generated) class where the resource is defined.
			IClass resourceClass = this.projectContent.GetClassByReflectionName(typeRef.Type.BaseType, true);
			if (resourceClass == null) {
				throw new InvalidOperationException("Could not find class for project resources: '" + typeRef.Type.BaseType + "'.");
			}
			
			if (resourceClass.CompilationUnit == null || resourceClass.CompilationUnit.FileName == null) {
				return null;
			}
			
			// Make sure the class we have found is a generated resource class.
			if (!IsGeneratedResourceClass(resourceClass)) {
				return null;
			}
			
			// Get the name of the resource file based on the file that contains the generated class.
			string resourceFileName = Path.GetFileNameWithoutExtension(resourceClass.CompilationUnit.FileName);
			if (resourceFileName.EndsWith("Designer", StringComparison.OrdinalIgnoreCase)) {
				resourceFileName = Path.GetFileNameWithoutExtension(resourceFileName);
			}
			resourceFileName = Path.Combine(Path.GetDirectoryName(resourceClass.CompilationUnit.FileName), resourceFileName);
			if (File.Exists(resourceFileName + ".resources")) {
				resourceFileName = resourceFileName + ".resources";
			} else if (File.Exists(resourceFileName + ".resx")) {
				resourceFileName = resourceFileName + ".resx";
			} else {
				throw new FileNotFoundException("Could not find the resource file for type '" + resourceClass.FullyQualifiedName + "'. Tried these file names: '" + resourceFileName + ".(resources|resx)'.");
			}
			
			// Get the property for the resource.
			IProperty prop = resourceClass.Properties.SingleOrDefault(p => p.Name == propRef.PropertyName);
			if (prop == null) {
				throw new InvalidOperationException("Property '" + propRef.PropertyName + "' not found in type '" + resourceClass.FullyQualifiedName + "'.");
			}
			
			if (!prop.CanGet) {
				throw new InvalidOperationException("Property '" + propRef.PropertyName + "' in type '" + resourceClass.FullyQualifiedName + "' does not have a getter.");
			}
			
			// Get the code of the resource class and
			// extract the resource key from the property.
			// This is necessary because the key may differ from the property name
			// if special characters are used.
			// It would be better if we could use a real code parser for this, but
			// that is not possible without getting dependent on the programming language.
			
			IDocument doc = new DocumentFactory().CreateDocument();
			doc.TextContent = ParserService.GetParseableFileContent(resourceClass.CompilationUnit.FileName);
			
			int startOffset = doc.PositionToOffset(new TextLocation(prop.GetterRegion.BeginColumn - 1, prop.GetterRegion.BeginLine - 1));
			int endOffset   = doc.PositionToOffset(new TextLocation(prop.GetterRegion.EndColumn - 1, prop.GetterRegion.EndLine - 1));
			
			string code = doc.GetText(startOffset, endOffset - startOffset + 1);
			
			int index = code.IndexOf("ResourceManager", StringComparison.Ordinal);
			if (index == -1) {
				throw new InvalidOperationException("No reference to ResourceManager found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
			}
			
			index = code.IndexOf("Get", index, StringComparison.Ordinal);
			if (index == -1) {
				throw new InvalidOperationException("No call to Get... found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
			}
			
			index = code.IndexOf(this.StringLiteralDelimiter, index + 1, StringComparison.Ordinal);
			if (index == -1) {
				throw new InvalidOperationException("No string delimiter ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
			}
			index += this.StringLiteralDelimiter.Length;
			
			int endIndex = code.LastIndexOf(this.StringLiteralDelimiter, StringComparison.Ordinal);
			if (endIndex == -1) {
				throw new InvalidOperationException("No string terminator ('" + this.StringLiteralDelimiter + "') found in property getter of '" + prop.FullyQualifiedName + "'. Code: '" + code + "'");
			}
			
			string resourceKey = code.Substring(index, endIndex - index);
			LoggingService.Debug("-> Decoded resource: In: " + resourceFileName + ". Key: " + resourceKey);
			
			return new ProjectResourceInfo(resourceFileName, resourceKey);
		}