Skip to content

Commit fbc6662

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of bundles/org.eclipse.ltk.ui.refactoring
1 parent 23e8ab6 commit fbc6662

File tree

85 files changed

+914
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+914
-630
lines changed

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/AbstractChangeNode.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ boolean hasOneGroupCategory(List<GroupCategory> categories) {
130130

131131
@Override
132132
boolean hasDerived() {
133-
if (hasDerivedResourceChange(fChange))
133+
if (hasDerivedResourceChange(fChange)) {
134134
return true;
135+
}
135136
for (PreviewNode child : getChildren()) {
136137
if (child.hasDerived()) {
137138
return true;
@@ -145,8 +146,9 @@ int getDefaultChangeActive() {
145146
if (fChildren != null) {
146147
for (PreviewNode child : fChildren) {
147148
result= ACTIVATION_TABLE[child.getActive()][result];
148-
if (result == PARTLY_ACTIVE)
149+
if (result == PARTLY_ACTIVE) {
149150
break;
151+
}
150152
}
151153
}
152154
return result;
@@ -157,8 +159,9 @@ int getCompositeChangeActive() {
157159
int result= fChildren[0].getActive();
158160
for (int i= 1; i < fChildren.length; i++) {
159161
result= ACTIVATION_TABLE[fChildren[i].getActive()][result];
160-
if (result == PARTLY_ACTIVE)
162+
if (result == PARTLY_ACTIVE) {
161163
break;
164+
}
162165
}
163166
return result;
164167
} else {
@@ -177,8 +180,7 @@ static boolean hasDerivedResourceChange(Change change) {
177180
Object modifiedElement= change.getModifiedElement();
178181
if (modifiedElement instanceof IResource) {
179182
return ((IResource) modifiedElement).isDerived(IResource.CHECK_ANCESTORS);
180-
} else if (modifiedElement instanceof IAdaptable) {
181-
IAdaptable adaptable= (IAdaptable) modifiedElement;
183+
} else if (modifiedElement instanceof IAdaptable adaptable) {
182184
IResource resource= adaptable.getAdapter(IResource.class);
183185
if (resource != null) {
184186
return resource.isDerived(IResource.CHECK_ANCESTORS);

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/AbstractDescriptor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ public boolean matches(Object element, String variableName) throws CoreException
4646
Expression exp= getExpression();
4747
EvaluationContext evaluationContext= new EvaluationContext(null, element);
4848
evaluationContext.addVariable(variableName, element);
49-
if (exp.evaluate(evaluationContext) == EvaluationResult.FALSE)
49+
if (exp.evaluate(evaluationContext) == EvaluationResult.FALSE) {
5050
return false;
51+
}
5152
return true;
5253
}
5354

5455
public Expression getExpression() throws CoreException {
55-
if (fExpression == null)
56+
if (fExpression == null) {
5657
fExpression= createExpression(fConfigurationElement);
58+
}
5759
return fExpression;
5860
}
5961

@@ -63,8 +65,9 @@ public void clear() {
6365

6466
protected Expression createExpression(IConfigurationElement element) throws CoreException {
6567
IConfigurationElement[] children= element.getChildren(ExpressionTagNames.ENABLEMENT);
66-
if (children.length == 0)
68+
if (children.length == 0) {
6769
return Expression.FALSE;
70+
}
6871
// TODO we should add some sort of syntax check and throw an core exception in this case
6972
Assert.isTrue(children.length == 1);
7073
return ExpressionConverter.getDefault().perform(children[0]);

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/ChangeElementLabelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class ChangeElementLabelProvider extends LabelProvider implements IFontProvider {
2828

29-
private Map<ImageDescriptor, Image> fDescriptorImageMap= new HashMap<>();
29+
private final Map<ImageDescriptor, Image> fDescriptorImageMap= new HashMap<>();
3030

3131
public ChangeElementLabelProvider() {
3232
}

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/ChangeElementTreeViewer.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public void setGroupCategory(List<GroupCategory> groupCategories) {
4040
}
4141
@Override
4242
public boolean select(Viewer viewer, Object parentElement, Object element) {
43-
if (fGroupCategories == null)
43+
if (fGroupCategories == null) {
4444
return true;
45+
}
4546
return ((PreviewNode)element).hasOneGroupCategory(fGroupCategories);
4647
}
4748
}
@@ -161,8 +162,7 @@ protected void revealPrevious() {
161162

162163
private void setSubtreeGrayed(Object element, boolean grayed) {
163164
Widget widget= findItem(element);
164-
if (widget instanceof TreeItem) {
165-
TreeItem item= (TreeItem)widget;
165+
if (widget instanceof TreeItem item) {
166166
if (item.getGrayed() != grayed) {
167167
item.setGrayed(grayed);
168168
grayChildren(getChildren(item), grayed);
@@ -172,8 +172,7 @@ private void setSubtreeGrayed(Object element, boolean grayed) {
172172

173173
private void grayChildren(Item[] items, boolean grayed) {
174174
for (Item element : items) {
175-
if (element instanceof TreeItem) {
176-
TreeItem item= (TreeItem)element;
175+
if (element instanceof TreeItem item) {
177176
if (item.getGrayed() != grayed) {
178177
item.setGrayed(grayed);
179178
grayChildren(getChildren(item), grayed);
@@ -185,22 +184,25 @@ private void grayChildren(Item[] items, boolean grayed) {
185184
private void revealElement(boolean next) {
186185
PreviewNode current= (PreviewNode)getInput();
187186
IStructuredSelection selection= (IStructuredSelection)getSelection();
188-
if (!selection.isEmpty())
187+
if (!selection.isEmpty()) {
189188
current= (PreviewNode)selection.iterator().next();
189+
}
190190

191191
PreviewNode candidate= getLeaf(current, next);
192192
if (candidate == null) {
193193
candidate= getElement(current, next);
194194
if (candidate != null) {
195195
PreviewNode leaf= getLeaf(candidate, next);
196-
if (leaf != null)
196+
if (leaf != null) {
197197
candidate= leaf;
198+
}
198199
}
199200
}
200-
if (candidate != null)
201+
if (candidate != null) {
201202
setSelection(new StructuredSelection(candidate), true);
202-
else
203+
} else {
203204
getControl().getDisplay().beep();
205+
}
204206
}
205207

206208
private PreviewNode getLeaf(PreviewNode element, boolean first) {
@@ -216,30 +218,34 @@ private PreviewNode getLeaf(PreviewNode element, boolean first) {
216218
private PreviewNode getElement(PreviewNode element, boolean next) {
217219
while(true) {
218220
PreviewNode parent= element.getParent();
219-
if (parent == null)
221+
if (parent == null) {
220222
return null;
223+
}
221224
PreviewNode candidate= getSibling(
222225
getSortedChildrenAsPreviewNodes(parent),
223226
element, next);
224-
if (candidate != null)
227+
if (candidate != null) {
225228
return candidate;
229+
}
226230
element= parent;
227231
}
228232
}
229233

230234
private PreviewNode getSibling(PreviewNode[] children, PreviewNode element, boolean next) {
231235
for (int i= 0; i < children.length; i++) {
232236
if (children[i] == element) {
233-
if (next)
234-
if (i < children.length - 1)
235-
return children[i + 1];
236-
else
237-
return null;
238-
else
239-
if (i > 0)
240-
return children[i - 1];
241-
else
242-
return null;
237+
if (next) {
238+
if (i < children.length - 1) {
239+
return children[i + 1];
240+
} else {
241+
return null;
242+
}
243+
} else
244+
if (i > 0) {
245+
return children[i - 1];
246+
} else {
247+
return null;
248+
}
243249
}
244250
}
245251
return null;

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/ChangeExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
public class ChangeExceptionHandler {
4343

44-
private Shell fParent;
45-
private String fName;
44+
private final Shell fParent;
45+
private final String fName;
4646

4747
private static class RefactorErrorDialog extends ErrorDialog {
4848
public RefactorErrorDialog(Shell parentShell, String dialogTitle, String dialogMessage, IStatus status, int displayMask) {

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/DescriptorManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
public abstract class DescriptorManager {
2727

28-
private String fExtensionPoint;
29-
private String fVariableName;
28+
private final String fExtensionPoint;
29+
private final String fVariableName;
3030
private AbstractDescriptor[] fExtensions;
3131

3232
public DescriptorManager(String extensionPoint, String variableName) {
@@ -37,8 +37,9 @@ public DescriptorManager(String extensionPoint, String variableName) {
3737
}
3838

3939
public AbstractDescriptor getDescriptor(Object element) throws CoreException {
40-
if (fExtensions == null)
40+
if (fExtensions == null) {
4141
init();
42+
}
4243

4344
List<AbstractDescriptor> candidates= new ArrayList<>(1);
4445
for (AbstractDescriptor descriptor : fExtensions) {
@@ -47,8 +48,9 @@ public AbstractDescriptor getDescriptor(Object element) throws CoreException {
4748
}
4849
descriptor.clear();
4950
}
50-
if (candidates.isEmpty())
51+
if (candidates.isEmpty()) {
5152
return null;
53+
}
5254
// No support for conflicts yet.
5355
return candidates.get(0);
5456
}

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/ErrorWizardPage.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ public void setVisible(boolean visible) {
109109
// the page was not complete if we show a fatal error. In this
110110
// case we can finish anyway. To enable the OK and Preview button
111111
// on the user input page we have to mark the page as complete again.
112-
if (!isPageComplete() && fStatus.hasFatalError())
112+
if (!isPageComplete() && fStatus.hasFatalError()) {
113113
setPageComplete(true);
114+
}
114115
}
115116
super.setVisible(visible);
116117
}
@@ -131,8 +132,9 @@ public IWizardPage getNextPage() {
131132
change= wizard.internalCreateChange(InternalAPI.INSTANCE, new CreateChangeOperation(getRefactoring()), false);
132133
wizard.internalSetChange(InternalAPI.INSTANCE, change);
133134
}
134-
if (change == null)
135+
if (change == null) {
135136
return this;
137+
}
136138

137139
return super.getNextPage();
138140
}
@@ -149,10 +151,12 @@ protected boolean performFinish() {
149151
operation= new UIPerformChangeOperation(getShell().getDisplay(), ccop, getContainer());
150152
}
151153
FinishResult result= wizard.internalPerformFinish(InternalAPI.INSTANCE, operation);
152-
if (result.isException())
154+
if (result.isException()) {
153155
return true;
154-
if (result.isInterrupted())
156+
}
157+
if (result.isInterrupted()) {
155158
return false;
159+
}
156160
RefactoringStatus fValidationStatus= operation.getValidationStatus();
157161
if (fValidationStatus != null && fValidationStatus.hasFatalError()) {
158162
MessageDialog.openError(wizard.getShell(), wizard.getWindowTitle(),

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/ExceptionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ private void displayMessageDialog(String exceptionMessage, Shell shell, String t
108108
msg.write(message);
109109
msg.write("\n\n"); //$NON-NLS-1$
110110
}
111-
if (exceptionMessage == null || exceptionMessage.length() == 0)
111+
if (exceptionMessage == null || exceptionMessage.length() == 0) {
112112
msg.write(RefactoringUIMessages.ExceptionHandler_seeErrorLogMessage);
113-
else
113+
} else {
114114
msg.write(exceptionMessage);
115+
}
115116
MessageDialog.openError(shell, title, msg.toString());
116117
}
117118
}

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/FileStatusContextViewer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public void setInput(RefactoringStatusContext context) {
5454
updateTitle(file);
5555
IDocument document= getDocument(file);
5656
IRegion region= fc.getTextRegion();
57-
if (region != null && document.getLength() >= region.getOffset() + region.getLength())
57+
if (region != null && document.getLength() >= region.getOffset() + region.getLength()) {
5858
setInput(document, region);
59-
else {
59+
} else {
6060
setInput(document, new Region(0, 0));
6161
}
6262
}

bundles/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/FinishResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @since 3.0
2020
*/
2121
public class FinishResult {
22-
private int fValue;
22+
private final int fValue;
2323

2424
private FinishResult(int value) {
2525
fValue= value;

0 commit comments

Comments
 (0)