Summary: | ImportDeclaration isStatic returning false for static import (obtained from ASTParser) | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Keith Power <keith.power> | ||||
Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||
Status: | VERIFIED INVALID | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | keith.power, Olivier_Thomann, satyam.kandula | ||||
Version: | 3.6.1 | ||||||
Target Milestone: | 3.7 M4 | ||||||
Hardware: | PC | ||||||
OS: | Windows 7 | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Keith Power
2010-12-01 10:47:33 EST
Created attachment 184271 [details]
Test Case
I'll take a look. Very prompt :-) Thanks. I meant also to say that the length of the ImportDeclaration node is correct (32) but the String being returned with toString is missing the static keyword also. I am investigating. It looks like the static modifier is lost after the import reference is created. Really weird. I checked the supplied test case in the ASTView plugin in Eclipse 3.5 installation and it correctly shows the import as static. Not sure if that's of any help to you. I know what is going on. Static imports are only valid in 1.5 and above. In your compiler options, you don't set the compliance, source or target platform and therefore you end up with the default (1.4). Change your getCompilerOptions() method for: private static Map getCompilerOptions() { Map defaultOptions = new HashMap(); defaultOptions.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE); defaultOptions.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE); defaultOptions.put(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_PB_POSSIBLE_ACCIDENTAL_BOOLEAN_ASSIGNMENT, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE); defaultOptions.put(JavaCore.COMPILER_PB_UNNECESSARY_ELSE, JavaCore.WARNING); defaultOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); defaultOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); defaultOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); return defaultOptions; } This is using JavaCore options and not the internal CompilerOptions class. Then it works fine. Closing as INVALID. If you would check the getProblems() of the compilation unit, you would have seen: Is java.lang.Math.PI import static ? false Number of problems : 1 Syntax error, static imports are only available if source level is 1.5 Many thanks for the quick solution, and apologies for not spotting that myself. Thanks for the pointer to getProblems() too, I'll check that in future. Verified for 3.7M4 |