From 8ca86dc6c8b17b4a2af1ab509dcec9047c8bda25 Mon Sep 17 00:00:00 2001 From: isaki <10616227+isaki@users.noreply.github.com> Date: Mon, 24 Jun 2019 14:54:53 -0400 Subject: [PATCH 1/2] Build settings and rebuild to address 2019-06 --- META-INF/MANIFEST.MF | 6 +++--- README.md | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 1337213..899ff28 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -1,12 +1,12 @@ Manifest-Version: 1.0 Bundle-SymbolicName: OldJavaFormatter;singleton:=true Bundle-Name: OldJavaFormatter -Bundle-Version: 1.3.1 +Bundle-Version: 1.4.0 Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.17.0,4.0.0)", org.eclipse.jface.text;bundle-version="[3.15.0,4.0.0)", - org.eclipse.core.runtime + org.eclipse.core.runtime;bundle-version="[3.15.0,4.0.0)" Bundle-ManifestVersion: 2 Bundle-RequiredExecutionEnvironment: JavaSE-1.8, - JavaSE-9 + JavaSE-11 Automatic-Module-Name: OldJavaFormatter diff --git a/README.md b/README.md index aa081a9..eafa07b 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,10 @@ Original plugin can be found [here](http://eclipse-n-mati.blogspot.com.es/2015/0 * For Eclipse Mars (4.5) to 2018-09: Please use version 1.1.5 of this plugin. * For Eclipse 2018-12: Please use version 1.2.0 of this plugin. * For Eclipse 2019-03: Please use version 1.3.1 of this plugin. +* For Eclipse 2019-06: Please use version 1.4.0 of this plugin. + * The 1.4.0 version contains no code changes; it contains build setting changes and was built using Eclipse 2019-06. + * Before upgrading to this version, consider backing up your formatter settings (via Export). + * If, after upgrading eclipse to 2019-06 and this plugin to 1.4.0, the formatter does not work, there is a fix; there seems to be an occassional issue when upgrading that is fixed with the following steps: + 1. Change to the default Eclipse formatter. + 2. Change back to the `Old Luna Java Formatter`. + 3. Re-import your saved settings (select overwrite if prompted). From 85aa5cb6f4b641096d00746e16582352117e72f4 Mon Sep 17 00:00:00 2001 From: isaki <10616227+isaki@users.noreply.github.com> Date: Tue, 25 Jun 2019 13:02:26 -0400 Subject: [PATCH 2/2] Fixed formatter crash on switch statements. WARNING: This fix may not work with the new Java 12 switch syntax. BACKGROUND: The 2019-06 Eclipse changed the class heirarchy of SwitchStatement to inherit from Expression instead of directly from Statement; this caused the legacy Luna formatter to expect the switch block to end in a semicolon. By ensuring that Expressions are not SwitchStatements, the issue is mitigated. --- META-INF/MANIFEST.MF | 2 +- README.md | 9 ++------- .../eclipse/jdt/luna/formatter/CodeFormatterVisitor.java | 4 +++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 899ff28..7bb8280 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-SymbolicName: OldJavaFormatter;singleton:=true Bundle-Name: OldJavaFormatter -Bundle-Version: 1.4.0 +Bundle-Version: 1.4.1 Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.17.0,4.0.0)", org.eclipse.jface.text;bundle-version="[3.15.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.15.0,4.0.0)" diff --git a/README.md b/README.md index eafa07b..d60130c 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,5 @@ Original plugin can be found [here](http://eclipse-n-mati.blogspot.com.es/2015/0 * For Eclipse Mars (4.5) to 2018-09: Please use version 1.1.5 of this plugin. * For Eclipse 2018-12: Please use version 1.2.0 of this plugin. * For Eclipse 2019-03: Please use version 1.3.1 of this plugin. -* For Eclipse 2019-06: Please use version 1.4.0 of this plugin. - * The 1.4.0 version contains no code changes; it contains build setting changes and was built using Eclipse 2019-06. - * Before upgrading to this version, consider backing up your formatter settings (via Export). - * If, after upgrading eclipse to 2019-06 and this plugin to 1.4.0, the formatter does not work, there is a fix; there seems to be an occassional issue when upgrading that is fixed with the following steps: - 1. Change to the default Eclipse formatter. - 2. Change back to the `Old Luna Java Formatter`. - 3. Re-import your saved settings (select overwrite if prompted). +* For Eclipse 2019-06: Please use version 1.4.1 of this plugin. + * Please note that this may not work well with the new arrow based switch statements (if at all). diff --git a/src/org/eclipse/jdt/luna/formatter/CodeFormatterVisitor.java b/src/org/eclipse/jdt/luna/formatter/CodeFormatterVisitor.java index 6fc3d18..04d9c5b 100644 --- a/src/org/eclipse/jdt/luna/formatter/CodeFormatterVisitor.java +++ b/src/org/eclipse/jdt/luna/formatter/CodeFormatterVisitor.java @@ -914,6 +914,8 @@ public TextEdit format(String string, CompilationUnitDeclaration compilationUnit try { compilationUnitDeclaration.traverse(this, compilationUnitDeclaration.scope); } catch(AbortFormatting e){ + if (DEBUG) + e.printStackTrace(System.out); return failedToFormat(); } if (DEBUG){ @@ -2117,7 +2119,7 @@ private void formatStatements(BlockScope scope, final Statement[] statements, bo this.scribe.printNewLine(); } statement.traverse(this, scope); - if (statement instanceof Expression) { + if (statement instanceof Expression && !(statement instanceof SwitchStatement)) { this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); if (i != statementsLength - 1) {