*/
public static final String version = "3.29.2-GA";
+ private int linesCount = 0;
+
/**
* Prints the version number and the copyright notice.
*
new DelayedFileOutputStream(filename)));
}
+ public int getLinesCount() {
+ return linesCount;
+ }
+
+ void addLines(int count) {
+ this.linesCount += count;
+ }
+
/**
* Writes a class file as <code>writeFile()</code> does although this
* method does not prune or freeze the class after writing the class
Javac compiler = new Javac(declaring);
try {
CtMember obj = compiler.compile(src);
+ declaring.addLines(src.split("\n").length);
if (obj instanceof CtConstructor) {
// a stack map table has been already created.
return (CtConstructor)obj;
compiler.recordProceed(delegateObj, delegateMethod);
CtMember obj = compiler.compile(src);
+ declaring.addLines(src.split("\n").length);
if (obj instanceof CtMethod)
return (CtMethod)obj;
}
* @see #recordProceed(String,String)
*/
public CtMember compile(String src) throws CompileError {
- Parser p = new Parser(new Lex(src));
+ int startLine = gen.thisClass.getLinesCount();
+ Parser p = new Parser(new Lex(src, startLine));
ASTList mem = p.parseMember1(stable);
try {
if (mem instanceof FieldDecl)
* Constructs a lexical analyzer.
*/
public Lex(String s) {
+ this(s, 0);
+ }
+
+ Lex(String s, int startLineNumber) {
lastChar = -1;
textBuffer = new StringBuilder();
currentToken = new Token();
input = s;
position = 0;
maxlen = s.length();
- lineNumber = 0;
+ lineNumber = startLineNumber;
}
public int get() {
fail("should not happen");
}
+ public void testLineNumberCompiler2() {
+ CtClass testClass = loader.makeClass("javassist.bytecode.LineNumberCompilerClass2");
+ String ctor = String.join("\n",
+ "public LineNumberCompilerClass2() {",
+ " super();",
+ "}");
+ String run = String.join("\n",
+ "public void run() {",
+ " return;",
+ "}");
+ String run2 = String.join("\n",
+ "public void run2() {",
+ " run()",
+ "}");
+ try {
+ testClass.addConstructor(CtNewConstructor.make(ctor, testClass));
+ testClass.addMethod(CtMethod.make(run, testClass));
+ testClass.addMethod(CtMethod.make(run2, testClass));
+ } catch (CannotCompileException e) {
+ assertEquals("line 9: ; is missing", e.getCause().getMessage());
+ return;
+ }
+ fail("should not happen");
+ }
+
public void testLineNumberException() {
CtClass testClass = loader.makeClass("javassist.bytecode.LineNumberExceptionClass");
String run = String.join("\n",