Community
Participate
Working Groups
Build Identifier: 3.6.1 I'm parsing a file using the ASTParser, then checking the imports. An import that is declared as static in the source is represented by an ImportDeclaration that returns false for isStatic. Also tested on 3.5 with the same results. Source uses ASTParser.createAST, but I also tested with createASTs on 3.6.1. Reproducible: Always Steps to Reproduce: 1. Download the source file, perhaps modifying package (will attach once submitted) 2. Run the program providing the path to the Java file as an argument 3. Note output is "Is java.lang.Math.PI import static ? false"
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