velo / maven-formatter-plugin

Maven2 Java Formatter Plugin - Exported from code.google.com/p/maven-java-formatter-plugin
Other
11 stars 7 forks source link

Java version mismatch between maven settings and formatting settings file may cause inconsistent results #24

Closed Legioth closed 7 years ago

Legioth commented 7 years ago

This issue occurs when using a legacy formatting settings file that defines an older Java version for org.eclipse.jdt.core.compiler.codegen.targetPlatform, org.eclipse.jdt.core.compiler.compliance or org.eclipse.jdt.core.compiler.source.

It seems like the Java version number configured through Maven will still be used for the main parsing of the java files since most new Java syntax features are processed and formatted without problems. One case where this causes issues is when using _ in numeric literals (introduced in Java 7). Any such occurrence will cause the entire method containing the numeric literal to become misformatted (see https://github.com/velo/maven-formatter-plugin/issues/20).

This appears to be different than how things work in Eclipse where the Java version configured for the project seems to override the version in the formatter settings. One indication of this behaviour is the Java version settings are updated when exporting settings that have been imported from a file with older versions.

I would suggest that the the plugin either automatically overrides those settings based on the Maven configuration, or alternatively outputs a warning if the settings are not in sync.

velo commented 7 years ago

You could use compilerSource, compilerCompliance and compilerTargetPlatform to override this settings.

The plugin takes the default from maven.compiler.source and maven.compiler.target, which may or may not be available.

Ideal it would read the compiler plugin section, that that ain't that easy.

velo commented 7 years ago

Please try it on 1.9.1.RC2

Legioth commented 7 years ago

Yes, now it works as expected even if using legacy formatting setting files. Thank you!