Skip to content

Commit 7b34fcb

Browse files
committed
Preference for "Rewrite Refactorings" in Eclipse. Default is 'true'
1 parent f36090d commit 7b34fcb

File tree

9 files changed

+160
-28
lines changed

9 files changed

+160
-28
lines changed

eclipse-language-servers/org.springframework.tooling.boot.ls/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Require-Bundle: org.eclipse.jdt.launching;bundle-version="3.9.0",
3333
org.eclipse.lsp4e.jdt;bundle-version="0.10.0",
3434
org.springsource.ide.eclipse.commons.boot.ls,
3535
org.springframework.ide.eclipse.editor.support,
36-
com.google.guava
36+
com.google.guava,
37+
org.eclipse.core.expressions
3738
Import-Package: com.google.common.base,
3839
com.google.common.collect,
3940
com.google.gson;version="2.7.0",

eclipse-language-servers/org.springframework.tooling.boot.ls/plugin.xml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@
137137
id="org.springframework.tooling.boot.ls.rewrite"
138138
name="Rewrite">
139139
</page>
140+
<page
141+
category="org.springframework.tooling.boot.ls.rewrite"
142+
class="org.springframework.tooling.boot.ls.RecipeFiltersPreferencePage"
143+
id="org.springframework.tooling.boot.ls.rewrite.filters"
144+
name="Filter Recipes">
145+
</page>
146+
<page
147+
category="org.springframework.tooling.boot.ls.rewrite"
148+
class="org.springframework.tooling.boot.ls.PlugRecipesPreferencePage"
149+
id="org.springframework.tooling.boot.ls.rewrite.load"
150+
name="Plug Recipes">
151+
</page>
140152

141153
</extension>
142154

@@ -413,15 +425,24 @@
413425
</and>
414426
</or>
415427
</iterate>
416-
<systemTest
417-
property="sts.rewrite.recipes"
418-
value="true">
419-
</systemTest>
428+
<test
429+
property="org.springframework.tooling.boot.ls.areRewriteProjectRefactoringsOn">
430+
</test>
420431
</and>
421432
</visibleWhen>
422433
</command>
423434
</menuContribution>
424435
</extension>
436+
<extension
437+
point="org.eclipse.core.expressions.propertyTesters">
438+
<propertyTester
439+
class="org.springframework.tooling.boot.ls.prefs.PrefsPropertyTester"
440+
id="org.springframework.tooling.boot.ls"
441+
namespace="org.springframework.tooling.boot.ls"
442+
properties="areRewriteProjectRefactoringsOn"
443+
type="java.lang.Object">
444+
</propertyTester>
445+
</extension>
425446
<!--
426447
<extension
427448
point="org.eclipse.wildwebdeveloper.xml.lemminxExtension">

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public class Constants {
3838
public static final String PREF_REWRITE_RECIPES_SCAN_FILES = "boot-java.rewrite.scan-files";
3939

4040
public static final String PREF_REWRITE_RECIPES_SCAN_DIRS = "boot-java.rewrite.scan-directories";
41+
42+
public static final String PREF_REWRITE_PROJECT_REFACTORINGS = "boot-java.rewrite.project-refactorings";
4143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 VMware, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* VMware, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.tooling.boot.ls;
12+
13+
import java.util.List;
14+
15+
import org.eclipse.jface.preference.FieldEditorPreferencePage;
16+
import org.eclipse.jface.preference.PathEditor;
17+
import org.eclipse.swt.widgets.Composite;
18+
import org.eclipse.ui.IWorkbench;
19+
import org.eclipse.ui.IWorkbenchPreferencePage;
20+
import org.springframework.tooling.boot.ls.prefs.FileListEditor;
21+
22+
public class PlugRecipesPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
23+
24+
@Override
25+
public void init(IWorkbench workbench) {
26+
setPreferenceStore(BootLanguageServerPlugin.getDefault().getPreferenceStore());
27+
}
28+
29+
@Override
30+
protected void createFieldEditors() {
31+
Composite fieldEditorParent = getFieldEditorParent();
32+
33+
addField(new FileListEditor(Constants.PREF_REWRITE_RECIPES_SCAN_FILES, "JAR and YAML files to scan for Recipes",
34+
"Select JARs and YAML files:", fieldEditorParent, List.of("jar", "yml", "yaml")));
35+
36+
addField(new PathEditor(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS, "Directories to scan for Recipes",
37+
"Select directory to scan for Recipes", fieldEditorParent));
38+
39+
40+
}
41+
42+
}

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void initializeDefaultPreferences() {
4343
preferenceStore.setDefault(Constants.PREF_SCAN_JAVA_TEST_SOURCES, false);
4444

4545
preferenceStore.setDefault(Constants.PREF_REWRITE_RECONCILE, false);
46+
preferenceStore.setDefault(Constants.PREF_REWRITE_PROJECT_REFACTORINGS, true);
4647

4748
preferenceStore.setDefault(Constants.PREF_REWRITE_RECIPE_FILTERS, StringListEditor.encode(new String[] {
4849
"org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 VMware, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* VMware, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.tooling.boot.ls;
12+
13+
import org.eclipse.jface.preference.FieldEditorPreferencePage;
14+
import org.eclipse.swt.widgets.Composite;
15+
import org.eclipse.ui.IWorkbench;
16+
import org.eclipse.ui.IWorkbenchPreferencePage;
17+
import org.springframework.tooling.boot.ls.prefs.StringListEditor;
18+
19+
public class RecipeFiltersPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
20+
21+
@Override
22+
public void init(IWorkbench workbench) {
23+
setPreferenceStore(BootLanguageServerPlugin.getDefault().getPreferenceStore());
24+
}
25+
26+
@Override
27+
protected void createFieldEditors() {
28+
Composite fieldEditorParent = getFieldEditorParent();
29+
30+
addField(new StringListEditor(fieldEditorParent, Constants.PREF_REWRITE_RECIPE_FILTERS,
31+
"Recipe filter IDs and patterns", "Filter Value",
32+
"Either exact ID or pattern with '*' as the wild-card:", text -> text.isBlank() ? "Cannot be blank" : null));
33+
}
34+
35+
}

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/RewritePreferencePage.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 VMware, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* VMware, Inc. - initial API and implementation
10+
*******************************************************************************/
111
package org.springframework.tooling.boot.ls;
212

3-
import java.util.List;
4-
513
import org.eclipse.jface.preference.BooleanFieldEditor;
614
import org.eclipse.jface.preference.FieldEditorPreferencePage;
7-
import org.eclipse.jface.preference.PathEditor;
815
import org.eclipse.swt.widgets.Composite;
916
import org.eclipse.ui.IWorkbench;
1017
import org.eclipse.ui.IWorkbenchPreferencePage;
11-
import org.springframework.tooling.boot.ls.prefs.FileListEditor;
12-
import org.springframework.tooling.boot.ls.prefs.StringListEditor;
1318

1419
public class RewritePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
1520

@@ -22,19 +27,12 @@ public void init(IWorkbench workbench) {
2227
protected void createFieldEditors() {
2328
Composite fieldEditorParent = getFieldEditorParent();
2429

30+
addField(new BooleanFieldEditor(Constants.PREF_REWRITE_PROJECT_REFACTORINGS,
31+
"Project refactoring actions", fieldEditorParent));
32+
2533
addField(new BooleanFieldEditor(Constants.PREF_REWRITE_RECONCILE,
2634
"Experimental reconciling for Java source based on Rewrite project", fieldEditorParent));
27-
28-
addField(new StringListEditor(fieldEditorParent, Constants.PREF_REWRITE_RECIPE_FILTERS,
29-
"Recipe filter IDs and patterns", "Filter Value",
30-
"Either exact ID or pattern with '*' as the wild-card:", text -> text.isBlank() ? "Cannot be blank" : null));
31-
32-
addField(new FileListEditor(Constants.PREF_REWRITE_RECIPES_SCAN_FILES, "JAR and YAML files to scan for Recipes",
33-
"Select JARs and YAML files:", fieldEditorParent, List.of("jar", "yml", "yaml")));
34-
35-
addField(new PathEditor(Constants.PREF_REWRITE_RECIPES_SCAN_DIRS, "Directories to scan for Recipes",
36-
"Select directory to scan for Recipes", fieldEditorParent));
37-
35+
3836
}
3937

4038

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 VMware, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* VMware, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.tooling.boot.ls.prefs;
12+
13+
import org.eclipse.core.expressions.PropertyTester;
14+
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
15+
import org.springframework.tooling.boot.ls.Constants;
16+
17+
public class PrefsPropertyTester extends PropertyTester {
18+
19+
public PrefsPropertyTester() {
20+
// TODO Auto-generated constructor stub
21+
}
22+
23+
@Override
24+
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
25+
switch (property) {
26+
case "areRewriteProjectRefactoringsOn":
27+
return BootLanguageServerPlugin.getDefault().getPreferenceStore().getBoolean(Constants.PREF_REWRITE_PROJECT_REFACTORINGS);
28+
}
29+
return false;
30+
}
31+
32+
}

vscode-extensions/vscode-spring-boot/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
],
7777
"explorer/context": [
7878
{
79-
"when": "resourceFilename == pom.xml && config.boot-java.rewrite.globa-commands.on == true",
79+
"when": "resourceFilename == pom.xml && config.boot-java.rewrite.refactorings.on == true",
8080
"command": "vscode-spring-boot.rewrite.list",
8181
"group": "SpringBoot"
8282
}
@@ -89,7 +89,7 @@
8989
"category": "Spring Boot"
9090
},
9191
{
92-
"enablement": "config.boot-java.rewrite.globa-commands.on == true",
92+
"enablement": "config.boot-java.rewrite.refactorings.on == true",
9393
"command": "vscode-spring-boot.rewrite.list",
9494
"category": "Spring Boot",
9595
"title": "Rewrite Refactorings..."
@@ -106,11 +106,6 @@
106106
"title": "Features",
107107
"order": 100,
108108
"properties": {
109-
"boot-java.rewrite.globa-commands.on": {
110-
"type": "boolean",
111-
"default": false,
112-
"description": "Experimental support for Rewrite recipes refactoring the whole maven projects via commands"
113-
},
114109
"boot-java.live-information.automatic-connection.on": {
115110
"type": "boolean",
116111
"default": true,
@@ -193,6 +188,11 @@
193188
"title": "Rewrite",
194189
"order": 400,
195190
"properties": {
191+
"boot-java.rewrite.refactorings.on": {
192+
"type": "boolean",
193+
"default": true,
194+
"description": "Recipes refactoring entire Maven project via commands"
195+
},
196196
"boot-java.rewrite.reconcile": {
197197
"type": "boolean",
198198
"default": false,

0 commit comments

Comments
 (0)