示例#1
0
        public void InterConvertCodeRangeAndIndicies(string code)
        {
            var ast = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(code);

            foreach (var elem in ast.DescendantsAndSelf("statement"))
            {
                int inclusiveStart, exclusiveEnd;
                var range = ConvertRangeToIndicies(code, elem, out inclusiveStart, out exclusiveEnd);
                ConvertIndiciesToRange(ast, code, inclusiveStart, exclusiveEnd, range);
            }
        }
示例#2
0
        public void FindElement()
        {
            var cst  = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(@"
public class Hello {
	public static void main(String[] args) {
		System.out.println(1);
	}
}");
            var stmt = cst.Descendants("statement").First();
            var pos  = CodeRange.Locate(stmt);

            Assert.That(pos.FindInnermostNode(cst), Is.EqualTo(stmt));
            Assert.That(pos.FindOutermostNode(cst), Is.EqualTo(stmt.Parent));
        }
示例#3
0
        public void Locate()
        {
            var code  = @"
public class Hello {
	public static void main(String[] args) {
	}
}";
            var xml   = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(code);
            var id    = xml.Descendants("IDENTIFIER").First();
            var range = CodeRange.Locate(id);

            Assert.That(range.GetCodeFragment(code), Is.EqualTo(id.TokenText));
            Assert.That(
                range.GetCodeFragment(new StructuredCode(code)),
                Is.EqualTo(id.TokenText));
        }
示例#4
0
        public void SerializeAndDeserialize() {
            var proc = new JavaCstGeneratorUsingAntlr3();
            var fileInfo = new FileInfo("temp.txt");
            var code = @"
class Main {
  void test() { obj.method().<Object>method2(); }
}
";
            var tree = proc.GenerateTreeFromCodeText(code);
            tree.Serialize(fileInfo);
            var tree2 = CstNode.Deserialize(fileInfo);

            Assert.That(tree.Code, Is.EqualTo(code));
            Assert.That(tree2.Code, Is.EqualTo(code));
            Assert.That(tree2.ToXml().ToCst().Code, Is.EqualTo(code));

            fileInfo.Delete();
        }
        public void SerializeAndDeserialize()
        {
            var proc     = new JavaCstGeneratorUsingAntlr3();
            var fileInfo = new FileInfo("temp.txt");
            var code     = @"
class Main {
  void test() { obj.method().<Object>method2(); }
}
";
            var tree     = proc.GenerateTreeFromCodeText(code);

            tree.Serialize(fileInfo);
            var tree2 = CstNode.Deserialize(fileInfo);

            Assert.That(tree.Code, Is.EqualTo(code));
            Assert.That(tree2.Code, Is.EqualTo(code));
            Assert.That(tree2.ToXml().ToCst().Code, Is.EqualTo(code));

            fileInfo.Delete();
        }
示例#6
0
        public void FindElement() {
            var cst = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(@"
public class Hello {
	public static void main(String[] args) {
		System.out.println(1);
	}
}");
            var stmt = cst.Descendants("statement").First();
            var pos = CodeRange.Locate(stmt);
            Assert.That(pos.FindInnermostNode(cst), Is.EqualTo(stmt));
            Assert.That(pos.FindOutermostNode(cst), Is.EqualTo(stmt.Parent));
        }
示例#7
0
 public void InterConvertCodeRangeAndIndicies(string code) {
     var ast = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(code);
     foreach (var elem in ast.DescendantsAndSelf("statement")) {
         int inclusiveStart, exclusiveEnd;
         var range = ConvertRangeToIndicies(code, elem, out inclusiveStart, out exclusiveEnd);
         ConvertIndiciesToRange(ast, code, inclusiveStart, exclusiveEnd, range);
     }
 }
示例#8
0
        public void Locate() {
            var code = @"
public class Hello {
	public static void main(String[] args) {
	}
}";
            var xml = new JavaCstGeneratorUsingAntlr3().GenerateTreeFromCodeText(code);
            var id = xml.Descendants("IDENTIFIER").First();
            var range = CodeRange.Locate(id);
            Assert.That(range.GetCodeFragment(code), Is.EqualTo(id.TokenText));
            Assert.That(
                    range.GetCodeFragment(new StructuredCode(code)),
                    Is.EqualTo(id.TokenText));
        }