c2nes / javalang

Pure Python Java parser and tools
MIT License
736 stars 161 forks source link

Whithout package declaration, set the package name to 'default package'. #32

Closed roipoussiere closed 8 years ago

roipoussiere commented 8 years ago

If a file doesn't contain package declaration, a package is actually created, with the name default package.

The problem initially comes from here : I wanted to parse the test directory of a project but my test files didn't have package declaration, resulting a value Error.

I decided to PR on Javalang because in my opinion, set package to None is wrong, since every Java class have actually a package, although it can be unnamed.

Note: after merging this PR and release a new version, this test should be deleted on Javasphinx.

c2nes commented 8 years ago

I believe the current behavior is more correct in this case. The Java Language Specification states that classes without a package declaration are placed in an unnamed packaged, rather than a default package. Additionally, the current behavior mirrors Class#getPackage() which returns null for classes in an unnamed package.

Would you mind opening an issue against Javasphinx instead? I think it would be better to have it handle the unnamed packages explicitly.

roipoussiere commented 8 years ago

Ok.