Skip to content

Commit fba79df

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of ant/org.eclipse.ant.core
1 parent f4e6c12 commit fba79df

File tree

7 files changed

+42
-57
lines changed

7 files changed

+42
-57
lines changed

ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntCorePreferences.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,9 @@ private URL getClasspathEntryURL(Bundle bundle, String library) throws IOExcepti
663663
}
664664
}
665665

666-
if (urlFile == null || !urlFile.exists())
666+
if (urlFile == null || !urlFile.exists()) {
667667
return null;
668+
}
668669

669670
String path = urlFile.getAbsolutePath();
670671
return new URL(IAntCoreConstants.FILE_PROTOCOL + (urlFile.isDirectory() ? path + "/" : path)); //$NON-NLS-1$
@@ -1231,11 +1232,12 @@ private Map<BundleRevision, Integer> computeCounts(List<Relation> mappings) {
12311232
BundleRevision from = mapping.from;
12321233
Integer fromCount = counts.get(from);
12331234
BundleRevision to = mapping.to;
1234-
if (to == null)
1235+
if (to == null) {
12351236
counts.put(from, Integer.valueOf(0));
1236-
else {
1237-
if (counts.get(to) == null)
1237+
} else {
1238+
if (counts.get(to) == null) {
12381239
counts.put(to, Integer.valueOf(0));
1240+
}
12391241
fromCount = fromCount == null ? Integer.valueOf(1) : Integer.valueOf(fromCount.intValue() + 1);
12401242
counts.put(from, fromCount);
12411243
}

ant/org.eclipse.ant.core/src/org/eclipse/ant/core/AntRunner.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ private String[] getArray(String args) {
140140
}
141141
waitingForQuote = true;
142142
} else {
143-
if (!(token.equals(",") || token.equals(" "))) //$NON-NLS-1$ //$NON-NLS-2$
143+
if (!(token.equals(",") || token.equals(" "))) { //$NON-NLS-1$ //$NON-NLS-2$
144144
result.add(token);
145+
}
145146
}
146147
}
147148
}
@@ -281,7 +282,7 @@ private void basicConfigure(Class<?> classInternalAntRunner, Object runner) thro
281282
setProperties(runner, classInternalAntRunner);
282283

283284
if (arguments != null && arguments.length > 0) {
284-
Method setArguments = classInternalAntRunner.getMethod("setArguments", new Class[] { String[].class }); //$NON-NLS-1$
285+
Method setArguments = classInternalAntRunner.getMethod("setArguments", String[].class); //$NON-NLS-1$
285286
setArguments.invoke(runner, new Object[] { arguments });
286287
}
287288
}
@@ -319,7 +320,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
319320

320321
// set the custom classpath
321322
if (customClasspath != null) {
322-
Method setCustomClasspath = classInternalAntRunner.getMethod("setCustomClasspath", new Class[] { URL[].class }); //$NON-NLS-1$
323+
Method setCustomClasspath = classInternalAntRunner.getMethod("setCustomClasspath", URL[].class); //$NON-NLS-1$
323324
setCustomClasspath.invoke(runner, new Object[] { customClasspath });
324325
}
325326

@@ -360,7 +361,7 @@ public void run(IProgressMonitor monitor) throws CoreException {
360361

361362
// set execution targets
362363
if (targets != null) {
363-
Method setExecutionTargets = classInternalAntRunner.getMethod("setExecutionTargets", new Class[] { String[].class }); //$NON-NLS-1$
364+
Method setExecutionTargets = classInternalAntRunner.getMethod("setExecutionTargets", String[].class); //$NON-NLS-1$
364365
setExecutionTargets.invoke(runner, new Object[] { targets });
365366
}
366367

@@ -400,7 +401,7 @@ private void setProperties(Object runner, Class<?> classInternalAntRunner) throw
400401

401402
// add property files
402403
if (propertyFiles != null) {
403-
Method addPropertyFiles = classInternalAntRunner.getMethod("addPropertyFiles", new Class[] { String[].class }); //$NON-NLS-1$
404+
Method addPropertyFiles = classInternalAntRunner.getMethod("addPropertyFiles", String[].class); //$NON-NLS-1$
404405
addPropertyFiles.invoke(runner, new Object[] { propertyFiles });
405406
}
406407
}

ant/org.eclipse.ant.core/src/org/eclipse/ant/core/TargetInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ public boolean isDefault() {
100100

101101
@Override
102102
public boolean equals(Object obj) {
103-
if (!(obj instanceof TargetInfo)) {
103+
if (!(obj instanceof TargetInfo other)) {
104104
return false;
105105
}
106-
TargetInfo other = (TargetInfo) obj;
107106
return getName().equals(other.getName());
108107
}
109108

ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntClasspathEntry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ public AntClasspathEntry(URL url) {
8080

8181
@Override
8282
public boolean equals(Object obj) {
83-
if (obj instanceof IAntClasspathEntry) {
84-
IAntClasspathEntry other = (IAntClasspathEntry) obj;
83+
if (obj instanceof IAntClasspathEntry other) {
8584
return entryString.equals(other.getLabel());
8685
}
8786
return false;

ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InputHandlerSetter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ protected void setInputHandler(Project project, String inputHandlerClassname) {
3535
handler = (InputHandler) (Class.forName(inputHandlerClassname).getConstructor().newInstance());
3636
}
3737
catch (ClassCastException e) {
38-
String msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_handler_does_not_implement_InputHandler5, new Object[] {
39-
inputHandlerClassname });
38+
String msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_handler_does_not_implement_InputHandler5, inputHandlerClassname);
4039
throw new BuildException(msg, e);
4140
}
4241
catch (Exception e) {
43-
String msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unable_to_instantiate_input_handler_class, new Object[] {
44-
inputHandlerClassname, e.getClass().getName() });
42+
String msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unable_to_instantiate_input_handler_class, inputHandlerClassname, e.getClass().getName());
4543
throw new BuildException(msg, e);
4644
}
4745
}

ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ protected void addBuildListeners(Project project, boolean log) {
253253
}
254254
}
255255
catch (ClassCastException e) {
256-
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_not_an_instance_of_apache_ant_BuildListener, new Object[] {
257-
className });
256+
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_not_an_instance_of_apache_ant_BuildListener, className);
258257
if (log) {
259258
logMessage(null, message, Project.MSG_ERR);
260259
}
@@ -281,8 +280,9 @@ private void setProperties(Project project, boolean substituteVariables) {
281280
// do nothing
282281
}
283282
}
284-
if (value != null)
283+
if (value != null) {
285284
project.setUserProperty(entry.getKey(), value);
285+
}
286286
}
287287
// may have properties set (always have the Ant process ID)
288288
// using the Arguments and not the Properties page
@@ -337,17 +337,15 @@ private void setTasks(Project project) {
337337
project.checkTaskClass(taskClass);
338338
}
339339
catch (BuildException e) {
340-
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Error_setting_Ant_task, new Object[] {
341-
task.getTaskName() }), e);
340+
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Error_setting_Ant_task, task.getTaskName()), e);
342341
AntCorePlugin.getPlugin().getLog().log(status);
343342
continue;
344343
}
345344
}
346345
project.addTaskDefinition(task.getTaskName(), taskClass);
347346
}
348347
catch (ClassNotFoundException e) {
349-
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Class_not_found_for_task, new Object[] {
350-
task.getClassName(), task.getTaskName() }), e);
348+
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Class_not_found_for_task, task.getClassName(), task.getTaskName()), e);
351349
AntCorePlugin.getPlugin().getLog().log(status);
352350
}
353351
}
@@ -369,8 +367,7 @@ private void setTypes(Project project) {
369367
project.addDataTypeDefinition(type.getTypeName(), typeClass);
370368
}
371369
catch (ClassNotFoundException e) {
372-
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Class_not_found_for_type, new Object[] {
373-
type.getClassName(), type.getTypeName() }), e);
370+
IStatus status = new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, AntCorePlugin.ERROR_RUNNING_BUILD, MessageFormat.format(InternalAntMessages.InternalAntRunner_Class_not_found_for_type, type.getClassName(), type.getTypeName()), e);
374371
AntCorePlugin.getPlugin().getLog().log(status);
375372
}
376373
}
@@ -386,12 +383,10 @@ private void setTypes(Project project) {
386383
protected void parseBuildFile(Project project) {
387384
File buildFile = new File(getBuildFileLocation());
388385
if (!buildFile.exists()) {
389-
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Buildfile_does_not_exist, new Object[] {
390-
buildFile.getAbsolutePath() }));
386+
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Buildfile_does_not_exist, buildFile.getAbsolutePath()));
391387
}
392388
if (!buildFile.isFile()) {
393-
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Buildfile_is_not_a_file, new Object[] {
394-
buildFile.getAbsolutePath() }));
389+
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Buildfile_is_not_a_file, buildFile.getAbsolutePath()));
395390
}
396391

397392
if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
@@ -463,8 +458,8 @@ public List<TargetInfo> getTargets() {
463458
}
464459
if (!defaultFound) {
465460
// default target must exist
466-
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Default_target_does_not_exist, new Object[] { "'", //$NON-NLS-1$
467-
defaultTarget, "'" })); //$NON-NLS-1$
461+
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Default_target_does_not_exist, "'", //$NON-NLS-1$
462+
defaultTarget, "'")); //$NON-NLS-1$
468463
}
469464
return infos;
470465
}
@@ -551,7 +546,7 @@ private void printArguments(Project project) {
551546
sb.append(extraArgument);
552547
sb.append(' ');
553548
}
554-
project.log(MessageFormat.format(InternalAntMessages.InternalAntRunner_Arguments, new Object[] { sb.toString().trim() }));
549+
project.log(MessageFormat.format(InternalAntMessages.InternalAntRunner_Arguments, sb.toString().trim()));
555550
}
556551

557552
private void createMonitorBuildListener(Project project) {
@@ -680,8 +675,7 @@ private void run(List<String> argList) {
680675
}
681676

682677
if (!projectHelp) {
683-
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Build_file, new Object[] {
684-
getBuildFileLocation() }), Project.MSG_INFO);
678+
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Build_file, getBuildFileLocation()), Project.MSG_INFO);
685679

686680
setTasks(getCurrentProject());
687681
setTypes(getCurrentProject());
@@ -814,14 +808,12 @@ protected BuildLogger createLogger() {
814808
buildLogger = (BuildLogger) (Class.forName(loggerClassname).getConstructor().newInstance());
815809
}
816810
catch (ClassCastException e) {
817-
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_not_an_instance_of_apache_ant_BuildLogger, new Object[] {
818-
loggerClassname });
811+
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_not_an_instance_of_apache_ant_BuildLogger, loggerClassname);
819812
logMessage(null, message, Project.MSG_ERR);
820813
throw new BuildException(message, e);
821814
}
822815
catch (Exception e) {
823-
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unable_to_instantiate_logger, new Object[] {
824-
loggerClassname });
816+
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unable_to_instantiate_logger, loggerClassname);
825817
logMessage(null, message, Project.MSG_ERR);
826818
throw new BuildException(message, e);
827819
}
@@ -1011,12 +1003,10 @@ protected String getAntVersionNumber() throws BuildException {
10111003
antVersionNumber = versionNumber;
10121004
}
10131005
catch (IOException ioe) {
1014-
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_load_the_version_information, new Object[] {
1015-
ioe.getMessage() }), ioe);
1006+
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_load_the_version_information, ioe.getMessage()), ioe);
10161007
}
10171008
catch (NullPointerException npe) {
1018-
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_load_the_version_information, new Object[] {
1019-
npe.getMessage() }), npe);
1009+
throw new BuildException(MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_load_the_version_information, npe.getMessage()), npe);
10201010
}
10211011
}
10221012
return antVersionNumber;
@@ -1185,8 +1175,7 @@ private boolean processCommandLine(List<String> commands) {
11851175
}
11861176
catch (IOException e) {
11871177
// just log message and ignore exception
1188-
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_write_to_log_file, new Object[] {
1189-
arg }), Project.MSG_ERR);
1178+
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Could_not_write_to_log_file, arg), Project.MSG_ERR);
11901179
return false;
11911180
}
11921181

@@ -1262,7 +1251,7 @@ private void processUnrecognizedTargets(List<String> commands) {
12621251
String target = iterator.next();
12631252
if (!names.contains(target)) {
12641253
iterator.remove();
1265-
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_unknown_target, new Object[] { target });
1254+
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_unknown_target, target);
12661255
logMessage(currentProject, message, Project.MSG_WARN);
12671256
unknownTargetsFound = true;
12681257
}
@@ -1296,7 +1285,7 @@ protected void processUnrecognizedCommands(List<String> commands) {
12961285
}
12971286

12981287
// warn of ignored commands
1299-
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unknown_argument, new Object[] { s.substring(1) });
1288+
String message = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unknown_argument, s.substring(1));
13001289
logMessage(currentProject, message, Project.MSG_WARN);
13011290
}
13021291

@@ -1321,8 +1310,7 @@ protected void createLogFile(String fileName) throws FileNotFoundException, IOEx
13211310
// this stream is closed in the finally block of run(list)
13221311
out = new PrintStream(new FileOutputStream(logFile));
13231312
err = out;
1324-
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Using_file_as_build_log, new Object[] {
1325-
logFile.getCanonicalPath() }), Project.MSG_INFO);
1313+
logMessage(currentProject, MessageFormat.format(InternalAntMessages.InternalAntRunner_Using_file_as_build_log, logFile.getCanonicalPath()), Project.MSG_INFO);
13261314
if (buildLogger != null) {
13271315
buildLogger.setErrorPrintStream(err);
13281316
buildLogger.setOutputPrintStream(out);
@@ -1456,8 +1444,7 @@ protected void loadPropertyFiles() {
14561444
}
14571445
}
14581446
catch (IOException e) {
1459-
fEarlyErrorMessage = MessageFormat.format(InternalAntMessages.InternalAntRunner_could_not_load_property_file, new Object[] {
1460-
e.getMessage() });
1447+
fEarlyErrorMessage = MessageFormat.format(InternalAntMessages.InternalAntRunner_could_not_load_property_file, e.getMessage());
14611448
}
14621449
}
14631450

ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalProject.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ public Object createDataType(String typeName) throws BuildException {
8585
// DataType can have a "no arg" constructor or take a single
8686
// Project argument.
8787
try {
88-
ctor = typeClass.getConstructor(new Class[0]);
88+
ctor = typeClass.getConstructor();
8989
noArg = true;
9090
}
9191
catch (NoSuchMethodException nse) {
92-
ctor = typeClass.getConstructor(new Class[] { Project.class });
92+
ctor = typeClass.getConstructor(Project.class);
9393
noArg = false;
9494
}
9595

9696
Object o = null;
9797
if (noArg) {
98-
o = ctor.newInstance(new Object[0]);
98+
o = ctor.newInstance();
9999
} else {
100-
o = ctor.newInstance(new Object[] { this });
100+
o = ctor.newInstance(this);
101101
}
102102
if (o instanceof ProjectComponent) {
103103
((ProjectComponent) o).setProject(this);
@@ -123,8 +123,7 @@ public Object createDataType(String typeName) throws BuildException {
123123
thrown = ncdfe;
124124
}
125125
if (thrown != null) {
126-
String message = MessageFormat.format(InternalAntMessages.InternalProject_could_not_create_type, new Object[] { typeName,
127-
thrown.toString() });
126+
String message = MessageFormat.format(InternalAntMessages.InternalProject_could_not_create_type, typeName, thrown.toString());
128127
throw new BuildException(message, thrown);
129128
}
130129
// this line is actually unreachable

0 commit comments

Comments
 (0)