Skip to content

Commit a373317

Browse files
eclipse-pde-botlaeubi
authored andcommitted
Perform clean code of ds/org.eclipse.pde.ds.annotations
1 parent 2963154 commit a373317

File tree

7 files changed

+100
-51
lines changed

7 files changed

+100
-51
lines changed

ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/AnnotationVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ public String getReadableName(TextEdit edit) {
467467
try {
468468
latch.await();
469469
} catch (InterruptedException e) {
470-
if (debug.isDebugging())
470+
if (debug.isDebugging()) {
471471
debug.trace("Interrupted while waiting for edits to complete on display thread.", e); //$NON-NLS-1$
472+
}
472473
}
473474

474475
if (ex[0] != null) {

ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/ComponentPropertyTester.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,58 @@ public class ComponentPropertyTester extends PropertyTester {
4848

4949
@Override
5050
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
51-
if (!"containsComponentWithImplicitName".equals(property)) //$NON-NLS-1$
51+
if (!"containsComponentWithImplicitName".equals(property)) { //$NON-NLS-1$
5252
return false;
53+
}
5354

54-
if (!(receiver instanceof IType) && !(receiver instanceof IPackageFragment))
55+
if (!(receiver instanceof IType) && !(receiver instanceof IPackageFragment)) {
5556
return false;
57+
}
5658

5759
IJavaElement element = (IJavaElement) receiver;
5860
IJavaProject javaProject = element.getJavaProject();
5961

6062
boolean enabled = Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, Activator.PREF_ENABLED, false, new IScopeContext[] { new ProjectScope(javaProject.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE });
61-
if (!enabled)
63+
if (!enabled) {
6264
return false;
65+
}
6366

6467
try {
6568
return element.getElementType() == IJavaElement.TYPE ? containsImplicitName((IType) receiver) : containsImplicitName((IPackageFragment) receiver);
6669
} catch (JavaModelException e) {
67-
if (debug.isDebugging())
70+
if (debug.isDebugging()) {
6871
debug.trace(String.format("Error searching for components with implicit names in element: %s", element), e); //$NON-NLS-1$
72+
}
6973
}
7074

7175
return false;
7276
}
7377

7478
private boolean containsImplicitName(IPackageFragment fragment) throws JavaModelException {
75-
if (!fragment.containsJavaResources())
79+
if (!fragment.containsJavaResources()) {
7680
return false;
81+
}
7782

7883
for (ICompilationUnit cu : fragment.getCompilationUnits()) {
7984
for (IType type : cu.getAllTypes()) {
80-
if (hasImplicitName(type))
85+
if (hasImplicitName(type)) {
8186
return true;
87+
}
8288
}
8389
}
8490

8591
return false;
8692
}
8793

8894
private boolean containsImplicitName(IType type) throws JavaModelException {
89-
if (hasImplicitName(type))
95+
if (hasImplicitName(type)) {
9096
return true;
97+
}
9198

9299
for (IType child : type.getTypes()) {
93-
if (hasImplicitName(child))
100+
if (hasImplicitName(child)) {
94101
return true;
102+
}
95103
}
96104

97105
return false;

ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/ComponentRefactoringHelper.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ public boolean initialize(Object element) {
8585
}
8686

8787
private RefactoringArguments getArguments() {
88-
if (participant instanceof RenameParticipant)
88+
if (participant instanceof RenameParticipant) {
8989
return ((RenameParticipant) participant).getArguments();
90+
}
9091

91-
if (participant instanceof MoveParticipant)
92+
if (participant instanceof MoveParticipant) {
9293
return ((MoveParticipant) participant).getArguments();
94+
}
9395

9496
return null;
9597
}
@@ -110,19 +112,22 @@ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditio
110112
ResourceChangeChecker checker = context.getChecker(ResourceChangeChecker.class);
111113
IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
112114
for (Map.Entry<Object, RefactoringArguments> entry : elements.entrySet()) {
113-
if (progress.isCanceled())
115+
if (progress.isCanceled()) {
114116
throw new OperationCanceledException();
117+
}
115118

116119
progress.worked(1);
117120

118121
RefactoringArguments args = entry.getValue();
119-
if (!getUpdateReferences(args))
122+
if (!getUpdateReferences(args)) {
120123
continue;
124+
}
121125

122126
IJavaElement element = (IJavaElement) entry.getKey();
123127
IJavaProject javaProject = element.getJavaProject();
124-
if (unmanaged.contains(javaProject))
128+
if (unmanaged.contains(javaProject)) {
125129
continue;
130+
}
126131

127132
ProjectState state = states.get(javaProject);
128133
if (state == null) {
@@ -136,10 +141,11 @@ public RefactoringStatus checkConditions(IProgressMonitor monitor, CheckConditio
136141

137142
states.put(javaProject, state);
138143

139-
if (element.getElementType() == IJavaElement.TYPE)
144+
if (element.getElementType() == IJavaElement.TYPE) {
140145
createRenames((IType) element, args, state, deltaFactory);
141-
else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
146+
} else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
142147
createRenames((IPackageFragment) element, args, state, deltaFactory);
148+
}
143149
}
144150

145151
return new RefactoringStatus();
@@ -150,11 +156,13 @@ else if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
150156
}
151157

152158
private boolean getUpdateReferences(RefactoringArguments args) {
153-
if (args instanceof RenameArguments)
159+
if (args instanceof RenameArguments) {
154160
return ((RenameArguments) args).getUpdateReferences();
161+
}
155162

156-
if (args instanceof MoveArguments)
163+
if (args instanceof MoveArguments) {
157164
return ((MoveArguments) args).getUpdateReferences();
165+
}
158166

159167
return false;
160168
}
@@ -228,20 +236,23 @@ public Change createChange(IProgressMonitor monitor) throws CoreException, Opera
228236
CompositeChange compositeChange = new CompositeChange(Messages.ComponentRefactoringHelper_topLevelChangeLabel);
229237

230238
for (Map.Entry<Object, RefactoringArguments> entry : elements.entrySet()) {
231-
if (progress.isCanceled())
239+
if (progress.isCanceled()) {
232240
throw new OperationCanceledException();
241+
}
233242

234243
progress.worked(1);
235244

236245
RefactoringArguments args = entry.getValue();
237-
if (!getUpdateReferences(args))
246+
if (!getUpdateReferences(args)) {
238247
continue;
248+
}
239249

240250
IJavaElement element = (IJavaElement) entry.getKey();
241-
if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT)
251+
if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
242252
collectChanges((IPackageFragment) element, compositeChange);
243-
else if (element.getElementType() == IJavaElement.TYPE)
253+
} else if (element.getElementType() == IJavaElement.TYPE) {
244254
collectChanges((IType) element, compositeChange);
255+
}
245256
}
246257

247258
return compositeChange;
@@ -257,8 +268,9 @@ private void collectChanges(IPackageFragment fragment, CompositeChange composite
257268

258269
private void collectChanges(IType type, CompositeChange compositeChange) throws CoreException {
259270
Change change = createChange(type);
260-
if (change != null)
271+
if (change != null) {
261272
compositeChange.add(change);
273+
}
262274

263275
for (IType child : type.getTypes()) {
264276
collectChanges(child, compositeChange);
@@ -267,28 +279,33 @@ private void collectChanges(IType type, CompositeChange compositeChange) throws
267279

268280
private Change createChange(IType type) throws CoreException {
269281
IFile modelFile = modelFiles.get(type);
270-
if (modelFile == null)
282+
if (modelFile == null) {
271283
return null;
284+
}
272285

273286
String componentName = componentNames.get(modelFile);
274-
if (componentName == null)
287+
if (componentName == null) {
275288
return null;
289+
}
276290

277291
IFile newModelFile = renames.get(modelFile);
278-
if (newModelFile == null)
292+
if (newModelFile == null) {
279293
return null;
294+
}
280295

281-
if (debug.isDebugging())
296+
if (debug.isDebugging()) {
282297
debug.trace(String.format("Changing %s from %s to %s.", type.getFullyQualifiedName(), modelFile.getFullPath(), newModelFile.getFullPath())); //$NON-NLS-1$
298+
}
283299

284300
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
285301
manager.connect(modelFile.getFullPath(), LocationKind.IFILE, null);
286302
DSModel model = null;
287303
IDocumentAttributeNode attrName, attrClass;
288304
try {
289305
ITextFileBuffer buf = manager.getTextFileBuffer(modelFile.getFullPath(), LocationKind.IFILE);
290-
if (buf == null)
306+
if (buf == null) {
291307
return null;
308+
}
292309

293310
IDocument doc = buf.getDocument();
294311
model = new DSModel(doc, false);
@@ -300,8 +317,9 @@ private Change createChange(IType type) throws CoreException {
300317
attrName = component.getDocumentAttribute(IDSConstants.ATTRIBUTE_COMPONENT_NAME);
301318
attrClass = component.getImplementation().getDocumentAttribute(IDSConstants.ATTRIBUTE_IMPLEMENTATION_CLASS);
302319
} finally {
303-
if (model != null)
320+
if (model != null) {
304321
model.dispose();
322+
}
305323

306324
manager.disconnect(modelFile.getFullPath(), LocationKind.IFILE, null);
307325
}

ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/DSAnnotationCompilationParticipant.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,26 @@ public boolean isAnnotationProcessor() {
117117
public boolean isActive(IJavaProject project) {
118118
IPreferencesService prefs = Platform.getPreferencesService();
119119
boolean enabled = prefs.getBoolean(Activator.PLUGIN_ID, Activator.PREF_ENABLED, false, new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE });
120-
if (!enabled)
120+
if (!enabled) {
121121
return false;
122+
}
122123

123124
IProject iproject = project.getProject();
124-
if (!iproject.isOpen() || !PluginProject.isPluginProject(iproject))
125+
if (!iproject.isOpen() || !PluginProject.isPluginProject(iproject)) {
125126
return false;
127+
}
126128

127-
if (WorkspaceModelManager.isBinaryProject(project.getProject()))
129+
if (WorkspaceModelManager.isBinaryProject(project.getProject())) {
128130
return false;
131+
}
129132
return true;
130133
}
131134

132135
@Override
133136
public int aboutToBuild(IJavaProject project) {
134-
if (debug.isDebugging())
137+
if (debug.isDebugging()) {
135138
debug.trace(String.format("About to build project: %s", project.getElementName())); //$NON-NLS-1$
139+
}
136140

137141
int result = READY_FOR_BUILD;
138142

@@ -220,8 +224,9 @@ private static ProjectState getState(IJavaProject project, int[] result) {
220224

221225
if (state == null) {
222226
state = new ProjectState();
223-
if (result != null && result.length > 0)
227+
if (result != null && result.length > 0) {
224228
result[0] = NEEDS_FULL_BUILD;
229+
}
225230
}
226231

227232
try {
@@ -237,8 +242,9 @@ private static ProjectState getState(IJavaProject project, int[] result) {
237242
private static ProjectState loadState(IProject project) throws IOException {
238243
File stateFile = getStateFile(project);
239244
if (!stateFile.canRead()) {
240-
if (debug.isDebugging())
245+
if (debug.isDebugging()) {
241246
debug.trace(String.format("Missing or invalid project state file: %s", stateFile)); //$NON-NLS-1$
247+
}
242248

243249
return null;
244250
}
@@ -248,8 +254,9 @@ private static ProjectState loadState(IProject project) throws IOException {
248254

249255
if (debug.isDebugging()) {
250256
debug.trace(String.format("Loaded state for project: %s", project.getName())); //$NON-NLS-1$
251-
for (String cuKey : state.getCompilationUnits())
257+
for (String cuKey : state.getCompilationUnits()) {
252258
debug.trace(String.format("%s -> %s", cuKey, state.getModelFiles(cuKey))); //$NON-NLS-1$
259+
}
253260
}
254261

255262
return state;
@@ -274,28 +281,32 @@ public void buildFinished(IJavaProject project) {
274281
IResource file;
275282
if (cu != null && cu.getElementType() == IJavaElement.COMPILATION_UNIT
276283
&& (file = cu.getResource()) != null && file.exists()
277-
&& file.getProject().equals(project.getProject()))
284+
&& file.getProject().equals(project.getProject())) {
278285
exists = true;
286+
}
279287
} catch (JavaModelException e) {
280288
Activator.log(e);
281289
}
282290

283291
if (!exists) {
284-
if (debug.isDebugging())
292+
if (debug.isDebugging()) {
285293
debug.trace(String.format("Mapped CU %s no longer exists.", cuKey)); //$NON-NLS-1$
294+
}
286295

287296
Collection<String> dsKeys = state.removeMappings(cuKey);
288-
if (dsKeys != null)
297+
if (dsKeys != null) {
289298
abandoned.addAll(dsKeys);
299+
}
290300
}
291301
}
292302

293303
// retain abandoned files that are still mapped elsewhere
294304
HashSet<String> retained = new HashSet<>();
295305
for (String cuKey : state.getCompilationUnits()) {
296306
Collection<String> dsKeys = state.getModelFiles(cuKey);
297-
if (dsKeys != null)
307+
if (dsKeys != null) {
298308
retained.addAll(dsKeys);
309+
}
299310
}
300311

301312
try {

ds/org.eclipse.pde.ds.annotations/src/org/eclipse/pde/ds/internal/annotations/DSAnnotationPropertyPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ private Link createLink(Composite composite, String text) {
152152
link.addSelectionListener(new SelectionListener() {
153153
@Override
154154
public void widgetSelected(SelectionEvent e) {
155-
if (PreferencesUtil.createPreferenceDialogOn(getShell(), Activator.PLUGIN_ID, new String[] { Activator.PLUGIN_ID }, null).open() == Window.OK)
155+
if (PreferencesUtil.createPreferenceDialogOn(getShell(), Activator.PLUGIN_ID, new String[] { Activator.PLUGIN_ID }, null).open() == Window.OK) {
156156
refreshWidgets();
157+
}
157158
}
158159

159160
@Override

0 commit comments

Comments
 (0)