简体   繁体   中英

Lines numbers inside the .class file differs from eclipse compilation and maven compilation

I am using Javassist to replace method calls inside a method based on the line number in the source file. The functionality works like a charm. The problem is line number of the method call differs from Eclipse compilation to Maven compilation.

Scenario:

Consider a statement or a condition is in two lines. By default Eclipse compiles the code and puts it in the output directory as specified but inside the compiled class file the condition is also in two lines. If the class is compiled by Maven build, the condition inside the class file is in a single line. Maven understands it as single statement and generate the class file accordingly.

Example :

32. public void verifyMock1(){
33. if(PaltformRuntime.getInstance().getElementRegistry().returnSuggestion()&&
34.     paltformRuntime.getInstance().getElementRegistry().returnSuggestion()){         
35.         System.out.println("entered into the castle");
36. }
37. }

Based on the above scenario if I want to replace returnSuggestion() method call inside the if condition. It is in two lines 34 and 35 but it is a single statement. If the class is compiled by Eclipse it says like 34 and 35 . If the same class is compiled by Maven build the whole if statement is in 34 (starting line). What is the cause of it and how to make Eclipse work like Maven compilation? (Note: both have Java 1.7 compiler.)

The reason behind ecj emitting more detailed line information is to enable a better debugging experience, where it's, eg, easier to step into a method call on the second line of the complex expression.

Ecj doesn't have an option to emit simpler line information nor does javac have the opposite option.

So, if you need to make Eclipse and Maven produce the exact same information, either of the two directions mentioned in comments will help you. See also the JDT FAQ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM