I use compiler tree API to find start/end positions of the import constructs.
SourcePositions sourcePositions = Trees.instance(task).getSourcePositions();
long s = sourcePositions.getStartPosition(untiTree, impTree);
long e = sourcePositions.getEndPosition(untiTree, impTree);
It seems to me that under jdk6 the end position of the import constructs is not detected correctly. A small class demonstrating the problem (Javac.java) is attached. Being run under jdk6/jdk7 it reports different results:
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)
File: Javac.java
import: 0:0
import: 48:48
import: 87:87
import: 125:125
import: 169:169
import: 203:203
import: 224:224
import: 252:252
import: 280:280
import: 303:303
import: 336:336
import: 371:371
import: 415:415
-----
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)
File: Javac.java
import: 0:47
import: 48:86
import: 87:124
import: 125:168
import: 169:202
import: 203:223
import: 224:251
import: 252:279
import: 280:302
import: 303:335
import: 336:370
import: 371:414
import: 415:447
Trivial run.sh script is attached as well.
SourcePositions sourcePositions = Trees.instance(task).getSourcePositions();
long s = sourcePositions.getStartPosition(untiTree, impTree);
long e = sourcePositions.getEndPosition(untiTree, impTree);
It seems to me that under jdk6 the end position of the import constructs is not detected correctly. A small class demonstrating the problem (Javac.java) is attached. Being run under jdk6/jdk7 it reports different results:
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)
File: Javac.java
import: 0:0
import: 48:48
import: 87:87
import: 125:125
import: 169:169
import: 203:203
import: 224:224
import: 252:252
import: 280:280
import: 303:303
import: 336:336
import: 371:371
import: 415:415
-----
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)
File: Javac.java
import: 0:47
import: 48:86
import: 87:124
import: 125:168
import: 169:202
import: 203:223
import: 224:251
import: 252:279
import: 280:302
import: 303:335
import: 336:370
import: 371:414
import: 415:447
Trivial run.sh script is attached as well.
- duplicates
-
JDK-6402077 Start position is wrong for package private constructors
-
- Closed
-
- relates to
-
JDK-7158654 Compiler API returns a Diagnostic object which breaks invariant specified by doc
-
- Open
-