Community
Participate
Working Groups
Build Identifier: 3.6.0_v48 ASTParser does not parse the following enum correctly when the source is set via setSource(char[] source), although JLS 3 is used: enum A { E1, E2; } When used with other setSource (e.g setSource(ITypeRoot source) ) methods it behaves correctly. This is due to the option org.eclipse.jdt.core.compiler.source which is then set correctly. Reproducible: Always Steps to Reproduce: 1. Run attached JUnit Test
Created attachment 170322 [details] JUnit test to reproduce the error.
It is clearly explained in the ASTParser documentation that compiler options are set to the JavaCore.getOptions() value if setSource(char[]) is used. Therefore you need to explicitly set the compiler options in order to parse the source. The default values are clearly explain in the JavaCore class. Closing as INVALID.
You are right. It is documented. What led me to the impression that it is a bug, was that I followed the code snippet in the Javadoc of the class. I thought that that this code is sufficient to parse Java Code that uses 1.5 features. In addition the constant JLS3 reinforced this impression. When I used the parser it even handled foreach loops correctly (producing error messages though as I found out later). When I stumbled across the enums, it took me quite some time to figure out the reason for the failure. To save others from this pitfall, maybe the code snippet could be updated, or it could be mentioned explicitly in the Javadocs of setSource(char[]) that the default source (1.3) will be used.
(In reply to comment #3) > To save others from this pitfall, maybe the code snippet could be updated, or > it could be mentioned explicitly in the Javadocs of setSource(char[]) that the > default source (1.3) will be used. Good suggestion. Will do. Thanks.
Created attachment 170559 [details] Proposed doc change Let me know if this clarifies the problem you had.
I also updated the documentation of the setSource(char[]) method.
Yes, this clarifies the problem. Thanks.
Verified for 3.6RC3
Created attachment 170625 [details] refer to JavaCore#setComplianceOptions(..) The advice in the Javadocs of ASTParser and setSource(char[]) is quite lengthy and only mentions some of the compliance options. It would be better to replace this with a reference to JavaCore#setComplianceOptions(String, Map). The patch also fixes two other typos.
.
Thanks Markus. Released for RC4.