20
20
import org .eclipse .ltk .ui .refactoring .RefactoringWizard ;
21
21
import org .eclipse .ltk .ui .refactoring .UserInputWizardPage ;
22
22
import org .eclipse .swt .SWT ;
23
- import org .eclipse .swt .events .ModifyEvent ;
24
- import org .eclipse .swt .events .ModifyListener ;
25
23
import org .eclipse .swt .events .SelectionAdapter ;
26
24
import org .eclipse .swt .events .SelectionEvent ;
27
25
import org .eclipse .swt .layout .GridData ;
@@ -45,40 +43,76 @@ public class OptimizeStreamRefactoringWizard extends RefactoringWizard {
45
43
46
44
private static class OptimizeStreamsInputPage extends UserInputWizardPage {
47
45
48
- public static final String PAGE_NAME = "OptimizeStreamsInputPage" ; //$NON-NLS-1$
49
-
50
46
private static final String DESCRIPTION = Messages .Name ;
51
47
52
48
private static final String DIALOG_SETTING_SECTION = "OptimizeStreams" ; //$NON-NLS-1$
53
49
54
- private static final String USE_IMPLICIT_ENTRY_POINTS = "useImplicitEntryPoints " ; //$NON-NLS-1$
50
+ private static final String K_FOR_STREAMS = "kForStreams " ; //$NON-NLS-1$
55
51
56
- private static final String USE_IMPLICIT_TEST_ENTRY_POINTS = "useImplicitTestEntryPoints " ; //$NON-NLS-1$
52
+ public static final String PAGE_NAME = "OptimizeStreamsInputPage " ; //$NON-NLS-1$
57
53
58
- private static final String USE_IMPLICIT_JMH_ENTRY_POINTS = "useImplicitJMHEntryPoints " ; //$NON-NLS-1$
54
+ private static final String USE_IMPLICIT_ENTRY_POINTS = "useImplicitEntryPoints " ; //$NON-NLS-1$
59
55
60
56
private static final String USE_IMPLICIT_JAVAFX_ENTRY_POINTS = "useImplicitJavaFXEntryPoints" ; //$NON-NLS-1$
61
57
62
- private static final String K_FOR_STREAMS = "kForStreams " ; //$NON-NLS-1$
58
+ private static final String USE_IMPLICIT_JMH_ENTRY_POINTS = "useImplicitJMHEntryPoints " ; //$NON-NLS-1$
63
59
64
- IDialogSettings settings ;
60
+ private static final String USE_IMPLICIT_TEST_ENTRY_POINTS = "useImplicitTestEntryPoints" ; //$NON-NLS-1$
65
61
66
62
private OptimizeStreamsRefactoringProcessor processor ;
67
63
64
+ IDialogSettings settings ;
65
+
68
66
public OptimizeStreamsInputPage () {
69
67
super (PAGE_NAME );
70
- setDescription (DESCRIPTION );
68
+ this .setDescription (DESCRIPTION );
69
+ }
70
+
71
+ private void addBooleanButton (String text , String key , Consumer <Boolean > valueConsumer , Composite result ) {
72
+ Button button = new Button (result , SWT .CHECK );
73
+ button .setText (text );
74
+ boolean value = this .settings .getBoolean (key );
75
+ valueConsumer .accept (value );
76
+ button .setSelection (value );
77
+ button .addSelectionListener (new SelectionAdapter () {
78
+ @ Override
79
+ public void widgetSelected (SelectionEvent e ) {
80
+ boolean selection = ((Button ) e .widget ).getSelection ();
81
+ OptimizeStreamsInputPage .this .settings .put (key , selection );
82
+ valueConsumer .accept (selection );
83
+ }
84
+ });
85
+ }
86
+
87
+ private void addIntegerButton (String text , String key , Consumer <Integer > valueConsumer , Composite result ) {
88
+ Label label = new Label (result , SWT .HORIZONTAL );
89
+ label .setText (text );
90
+
91
+ Text textBox = new Text (result , SWT .SINGLE );
92
+ int value = this .settings .getInt (key );
93
+ valueConsumer .accept (value );
94
+ textBox .setText (String .valueOf (value ));
95
+ textBox .addModifyListener (event -> {
96
+ int selection ;
97
+ try {
98
+ selection = Integer .parseInt (((Text ) event .widget ).getText ());
99
+ } catch (NumberFormatException e ) {
100
+ return ;
101
+ }
102
+ OptimizeStreamsInputPage .this .settings .put (key , selection );
103
+ valueConsumer .accept (selection );
104
+ });
71
105
}
72
106
73
107
@ Override
74
108
public void createControl (Composite parent ) {
75
- ProcessorBasedRefactoring processorBasedRefactoring = (ProcessorBasedRefactoring ) getRefactoring ();
109
+ ProcessorBasedRefactoring processorBasedRefactoring = (ProcessorBasedRefactoring ) this . getRefactoring ();
76
110
RefactoringProcessor refactoringProcessor = processorBasedRefactoring .getProcessor ();
77
111
this .setProcessor ((OptimizeStreamsRefactoringProcessor ) refactoringProcessor );
78
112
this .loadSettings ();
79
113
80
114
Composite result = new Composite (parent , SWT .NONE );
81
- setControl (result );
115
+ this . setControl (result );
82
116
GridLayout layout = new GridLayout ();
83
117
layout .numColumns = 1 ;
84
118
result .setLayout (layout );
@@ -91,105 +125,67 @@ public void createControl(Composite parent) {
91
125
separator .setLayoutData (new GridData (SWT .FILL , SWT .BEGINNING , true , false ));
92
126
93
127
// set up buttons.
94
- addBooleanButton ("Automatically discover standard entry points (main methods)." , USE_IMPLICIT_ENTRY_POINTS ,
95
- this .getProcessor ()::setUseImplicitEntrypoints , result );
96
- addBooleanButton ("Automatically discover test-based entry points (JUnit)." , USE_IMPLICIT_TEST_ENTRY_POINTS ,
97
- this .getProcessor ()::setUseImplicitTestEntrypoints , result );
98
- addBooleanButton ("Automatically discover benchmark entry points (JMH)." , USE_IMPLICIT_JMH_ENTRY_POINTS ,
128
+ this . addBooleanButton ("Automatically discover standard entry points (main methods)." ,
129
+ USE_IMPLICIT_ENTRY_POINTS , this .getProcessor ()::setUseImplicitEntrypoints , result );
130
+ this . addBooleanButton ("Automatically discover test-based entry points (JUnit)." ,
131
+ USE_IMPLICIT_TEST_ENTRY_POINTS , this .getProcessor ()::setUseImplicitTestEntrypoints , result );
132
+ this . addBooleanButton ("Automatically discover benchmark entry points (JMH)." , USE_IMPLICIT_JMH_ENTRY_POINTS ,
99
133
this .getProcessor ()::setUseImplicitBenchmarkEntrypoints , result );
100
- addBooleanButton ("Automatically discover GUI entry points (JavaFX)." , USE_IMPLICIT_JAVAFX_ENTRY_POINTS ,
134
+ this . addBooleanButton ("Automatically discover GUI entry points (JavaFX)." , USE_IMPLICIT_JAVAFX_ENTRY_POINTS ,
101
135
this .getProcessor ()::setUseImplicitJavaFXEntrypoints , result );
102
136
103
137
Composite compositeForIntegerButton = new Composite (result , SWT .NONE );
104
138
GridLayout layoutForIntegerButton = new GridLayout (2 , false );
105
139
106
140
compositeForIntegerButton .setLayout (layoutForIntegerButton );
107
141
108
- addIntegerButton ("k value to use for streams for kCFA: " , K_FOR_STREAMS ,
142
+ this . addIntegerButton ("k value to use for streams for kCFA: " , K_FOR_STREAMS ,
109
143
this .getProcessor ()::setNForStreams , compositeForIntegerButton );
110
144
111
- updateStatus ();
145
+ this . updateStatus ();
112
146
Dialog .applyDialogFont (result );
113
- PlatformUI .getWorkbench ().getHelpSystem ().setHelp (getControl (), "optimize_streams_wizard_page_context" );
147
+ PlatformUI .getWorkbench ().getHelpSystem ().setHelp (this .getControl (),
148
+ "optimize_streams_wizard_page_context" );
114
149
}
115
150
116
- private void addBooleanButton (String text , String key , Consumer <Boolean > valueConsumer , Composite result ) {
117
- Button button = new Button (result , SWT .CHECK );
118
- button .setText (text );
119
- boolean value = settings .getBoolean (key );
120
- valueConsumer .accept (value );
121
- button .setSelection (value );
122
- button .addSelectionListener (new SelectionAdapter () {
123
- @ Override
124
- public void widgetSelected (SelectionEvent e ) {
125
- boolean selection = ((Button ) e .widget ).getSelection ();
126
- settings .put (key , selection );
127
- valueConsumer .accept (selection );
128
- }
129
- });
130
- }
131
-
132
- private void addIntegerButton (String text , String key , Consumer <Integer > valueConsumer , Composite result ) {
133
- Label label = new Label (result , SWT .HORIZONTAL );
134
- label .setText (text );
135
-
136
- Text textBox = new Text (result , SWT .SINGLE );
137
- int value = settings .getInt (key );
138
- valueConsumer .accept (value );
139
- textBox .setText (String .valueOf (value ));
140
- textBox .addModifyListener (new ModifyListener () {
141
-
142
- @ Override
143
- public void modifyText (ModifyEvent event ) {
144
- int selection ;
145
- try {
146
- selection = Integer .parseInt (((Text ) event .widget ).getText ());
147
- } catch (NumberFormatException e ) {
148
- return ;
149
- }
150
- settings .put (key , selection );
151
- valueConsumer .accept (selection );
152
- }
153
- });
151
+ private OptimizeStreamsRefactoringProcessor getProcessor () {
152
+ return this .processor ;
154
153
}
155
154
156
155
private void loadSettings () {
157
- settings = getDialogSettings ().getSection (DIALOG_SETTING_SECTION );
158
- if (settings == null ) {
159
- settings = getDialogSettings ().addNewSection (DIALOG_SETTING_SECTION );
160
- settings .put (USE_IMPLICIT_ENTRY_POINTS , this .getProcessor ().getUseImplicitEntrypoints ());
161
- settings .put (USE_IMPLICIT_TEST_ENTRY_POINTS , this .getProcessor ().getUseImplicitTestEntrypoints ());
162
- settings .put (USE_IMPLICIT_JMH_ENTRY_POINTS , this .getProcessor ().getUseImplicitBenchmarkEntrypoints ());
163
- settings .put (USE_IMPLICIT_JAVAFX_ENTRY_POINTS ,
156
+ this .settings = this .getDialogSettings ().getSection (DIALOG_SETTING_SECTION );
157
+ if (this .settings == null ) {
158
+ this .settings = this .getDialogSettings ().addNewSection (DIALOG_SETTING_SECTION );
159
+ this .settings .put (USE_IMPLICIT_ENTRY_POINTS , this .getProcessor ().getUseImplicitEntrypoints ());
160
+ this .settings .put (USE_IMPLICIT_TEST_ENTRY_POINTS , this .getProcessor ().getUseImplicitTestEntrypoints ());
161
+ this .settings .put (USE_IMPLICIT_JMH_ENTRY_POINTS ,
162
+ this .getProcessor ().getUseImplicitBenchmarkEntrypoints ());
163
+ this .settings .put (USE_IMPLICIT_JAVAFX_ENTRY_POINTS ,
164
164
this .getProcessor ().getUseImplicitBenchmarkEntrypoints ());
165
- settings .put (K_FOR_STREAMS , this .getProcessor ().getNForStreams ());
165
+ this . settings .put (K_FOR_STREAMS , this .getProcessor ().getNForStreams ());
166
166
}
167
- processor .setUseImplicitEntrypoints (settings .getBoolean (USE_IMPLICIT_ENTRY_POINTS ));
168
- processor .setUseImplicitTestEntrypoints (settings .getBoolean (USE_IMPLICIT_TEST_ENTRY_POINTS ));
169
- processor .setUseImplicitBenchmarkEntrypoints (settings .getBoolean (USE_IMPLICIT_JMH_ENTRY_POINTS ));
170
- processor .setUseImplicitJavaFXEntrypoints (settings .getBoolean (USE_IMPLICIT_JAVAFX_ENTRY_POINTS ));
167
+ this . processor .setUseImplicitEntrypoints (this . settings .getBoolean (USE_IMPLICIT_ENTRY_POINTS ));
168
+ this . processor .setUseImplicitTestEntrypoints (this . settings .getBoolean (USE_IMPLICIT_TEST_ENTRY_POINTS ));
169
+ this . processor .setUseImplicitBenchmarkEntrypoints (this . settings .getBoolean (USE_IMPLICIT_JMH_ENTRY_POINTS ));
170
+ this . processor .setUseImplicitJavaFXEntrypoints (this . settings .getBoolean (USE_IMPLICIT_JAVAFX_ENTRY_POINTS ));
171
171
172
172
int value ;
173
173
try {
174
- value = settings .getInt (K_FOR_STREAMS );
174
+ value = this . settings .getInt (K_FOR_STREAMS );
175
175
} catch (NumberFormatException e ) {
176
- settings .put (K_FOR_STREAMS , this .getProcessor ().getNForStreams ());
177
- value = settings .getInt (K_FOR_STREAMS );
176
+ this . settings .put (K_FOR_STREAMS , this .getProcessor ().getNForStreams ());
177
+ value = this . settings .getInt (K_FOR_STREAMS );
178
178
}
179
- processor .setNForStreams (value );
180
- }
181
-
182
- private void updateStatus () {
183
- setPageComplete (true );
184
- }
185
-
186
- private OptimizeStreamsRefactoringProcessor getProcessor () {
187
- return processor ;
179
+ this .processor .setNForStreams (value );
188
180
}
189
181
190
182
private void setProcessor (OptimizeStreamsRefactoringProcessor processor ) {
191
183
this .processor = processor ;
192
184
}
185
+
186
+ private void updateStatus () {
187
+ this .setPageComplete (true );
188
+ }
193
189
}
194
190
195
191
public static void startRefactoring (IJavaProject [] javaProjects , Shell shell , Optional <IProgressMonitor > monitor )
0 commit comments