Skip to content

Commit 725856b

Browse files
committed
Add checkstyle and formater rules, reformat code
1 parent dea0251 commit 725856b

38 files changed

+2812
-2569
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="true">
4+
<local-check-config name="KNIME Checkstyle" location="/org.knime.scijava.scripting.node/res/KNIMECheckstyle5.0.xml" type="project" description="">
5+
<additional-data name="protect-config-file" value="false"/>
6+
</local-check-config>
7+
<fileset name="all" enabled="true" check-config-name="KNIME Checkstyle" local="true">
8+
<file-match-pattern match-pattern="." include-pattern="true"/>
9+
</fileset>
10+
</fileset-config>

org.knime.scijava.scripting.base/.project

+6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
<arguments>
3636
</arguments>
3737
</buildCommand>
38+
<buildCommand>
39+
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
40+
<arguments>
41+
</arguments>
42+
</buildCommand>
3843
</buildSpec>
3944
<natures>
4045
<nature>org.eclipse.jdt.core.javanature</nature>
4146
<nature>org.eclipse.pde.PluginNature</nature>
47+
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
4248
</natures>
4349
</projectDescription>

org.knime.scijava.scripting.base/.settings/org.eclipse.jdt.core.prefs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
287287
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
288288
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
289289
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
290-
org.eclipse.jdt.core.formatter.tabulation.char=tab
290+
org.eclipse.jdt.core.formatter.tabulation.char=space
291291
org.eclipse.jdt.core.formatter.tabulation.size=4
292292
org.eclipse.jdt.core.formatter.use_on_off_tags=false
293293
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
cleanup.add_default_serial_version_id=true
2+
cleanup.add_generated_serial_version_id=false
3+
cleanup.add_missing_annotations=true
4+
cleanup.add_missing_deprecated_annotations=true
5+
cleanup.add_missing_methods=false
6+
cleanup.add_missing_nls_tags=false
7+
cleanup.add_missing_override_annotations=true
8+
cleanup.add_missing_override_annotations_interface_methods=true
9+
cleanup.add_serial_version_id=false
10+
cleanup.always_use_blocks=true
11+
cleanup.always_use_parentheses_in_expressions=false
12+
cleanup.always_use_this_for_non_static_field_access=false
13+
cleanup.always_use_this_for_non_static_method_access=false
14+
cleanup.convert_functional_interfaces=false
15+
cleanup.convert_to_enhanced_for_loop=false
16+
cleanup.correct_indentation=false
17+
cleanup.format_source_code=false
18+
cleanup.format_source_code_changes_only=false
19+
cleanup.insert_inferred_type_arguments=false
20+
cleanup.make_local_variable_final=true
21+
cleanup.make_parameters_final=true
22+
cleanup.make_private_fields_final=true
23+
cleanup.make_type_abstract_if_missing_method=false
24+
cleanup.make_variable_declarations_final=true
25+
cleanup.never_use_blocks=false
26+
cleanup.never_use_parentheses_in_expressions=true
27+
cleanup.organize_imports=true
28+
cleanup.qualify_static_field_accesses_with_declaring_class=false
29+
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
30+
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
31+
cleanup.qualify_static_member_accesses_with_declaring_class=true
32+
cleanup.qualify_static_method_accesses_with_declaring_class=false
33+
cleanup.remove_private_constructors=true
34+
cleanup.remove_redundant_type_arguments=true
35+
cleanup.remove_trailing_whitespaces=false
36+
cleanup.remove_trailing_whitespaces_all=true
37+
cleanup.remove_trailing_whitespaces_ignore_empty=false
38+
cleanup.remove_unnecessary_casts=true
39+
cleanup.remove_unnecessary_nls_tags=true
40+
cleanup.remove_unused_imports=true
41+
cleanup.remove_unused_local_variables=false
42+
cleanup.remove_unused_private_fields=true
43+
cleanup.remove_unused_private_members=false
44+
cleanup.remove_unused_private_methods=true
45+
cleanup.remove_unused_private_types=true
46+
cleanup.sort_members=false
47+
cleanup.sort_members_all=false
48+
cleanup.use_anonymous_class_creation=false
49+
cleanup.use_blocks=true
50+
cleanup.use_blocks_only_for_return_and_throw=false
51+
cleanup.use_lambda=true
52+
cleanup.use_parentheses_in_expressions=false
53+
cleanup.use_this_for_non_static_field_access=false
54+
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
55+
cleanup.use_this_for_non_static_method_access=false
56+
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
57+
cleanup.use_type_arguments=false
58+
cleanup_profile=_eclipse-cs org.knime.scijava.scripting.base
59+
cleanup_settings_version=2
160
eclipse.preferences.version=1
2-
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
61+
formatter_profile=_eclipse-cs org.knime.scijava.scripting.base
362
formatter_settings_version=12
63+
jautodoc.cleanup.add_header=false
64+
jautodoc.cleanup.replace_header=false

org.knime.scijava.scripting.base/src/org/knime/scijava/scripting/base/CommandCompileProductHelper.java

+36-36
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,41 @@
1010

1111
public class CommandCompileProductHelper implements CompileProductHelper {
1212

13-
private final CommandInfo m_info;
14-
private final Context m_context;
15-
16-
public CommandCompileProductHelper(CommandInfo info, Context context) {
17-
m_info = info;
18-
m_context = context;
19-
}
20-
21-
@Override
22-
public Iterable<ModuleItem<?>> inputs() {
23-
return m_info.inputs();
24-
}
25-
26-
@Override
27-
public ModuleInfo getModuleInfo() {
28-
return m_info;
29-
}
30-
31-
@Override
32-
public Module createModule(final ScriptLanguage lang)
33-
throws ModuleException {
34-
final Module module = m_info.createModule();
35-
m_context.inject(module);
36-
37-
return module;
38-
}
39-
40-
@Override
41-
public void resetModule(Module m) {
42-
for (final String input : m.getInputs().keySet()) {
43-
m.setResolved(input, false);
44-
}
45-
for (final String output : m.getOutputs().keySet()) {
46-
m.setResolved(output, false);
47-
}
48-
}
13+
private final CommandInfo m_info;
14+
private final Context m_context;
15+
16+
public CommandCompileProductHelper(CommandInfo info, Context context) {
17+
m_info = info;
18+
m_context = context;
19+
}
20+
21+
@Override
22+
public Iterable<ModuleItem<?>> inputs() {
23+
return m_info.inputs();
24+
}
25+
26+
@Override
27+
public ModuleInfo getModuleInfo() {
28+
return m_info;
29+
}
30+
31+
@Override
32+
public Module createModule(final ScriptLanguage lang)
33+
throws ModuleException {
34+
final Module module = m_info.createModule();
35+
m_context.inject(module);
36+
37+
return module;
38+
}
39+
40+
@Override
41+
public void resetModule(Module m) {
42+
for (final String input : m.getInputs().keySet()) {
43+
m.setResolved(input, false);
44+
}
45+
for (final String output : m.getOutputs().keySet()) {
46+
m.setResolved(output, false);
47+
}
48+
}
4949

5050
}

org.knime.scijava.scripting.base/src/org/knime/scijava/scripting/base/CompileHelper.java

+75-75
Original file line numberDiff line numberDiff line change
@@ -23,89 +23,89 @@
2323
*/
2424
public class CompileHelper {
2525

26-
private File m_tempDir;
27-
private String m_script;
26+
private File m_tempDir;
27+
private String m_script;
2828

29-
private Context m_context;
30-
private Writer m_errorWriter;
31-
private Writer m_outputWriter;
29+
private Context m_context;
30+
private Writer m_errorWriter;
31+
private Writer m_outputWriter;
3232

33-
/**
34-
* Constructor
35-
*
36-
* @param context
37-
* @param outputWriter
38-
* @throws IOException
39-
*/
40-
public CompileHelper(Context context, Writer errorWriter,
41-
Writer outputWriter) throws IOException {
33+
/**
34+
* Constructor
35+
*
36+
* @param context
37+
* @param outputWriter
38+
* @throws IOException
39+
*/
40+
public CompileHelper(Context context, Writer errorWriter,
41+
Writer outputWriter) throws IOException {
4242

43-
m_errorWriter = errorWriter;
44-
m_outputWriter = outputWriter;
45-
m_tempDir = FileUtil.createTempDir("ScriptingNode");
43+
m_errorWriter = errorWriter;
44+
m_outputWriter = outputWriter;
45+
m_tempDir = FileUtil.createTempDir("ScriptingNode");
4646

47-
m_context = context;
48-
}
47+
m_context = context;
48+
}
4949

50-
/*
51-
* Write script code from the current settings to a file in the temp
52-
* directory.
53-
*/
54-
private void writeScriptToFile(final ScriptLanguage lang) {
55-
try (Writer w = new FileWriter(
56-
new File(m_tempDir, "script." + lang.getExtensions().get(0)))) {
57-
w.write(m_script);
58-
w.close();
59-
} catch (IOException exc) {
60-
exc.printStackTrace();
61-
}
62-
}
50+
/*
51+
* Write script code from the current settings to a file in the temp
52+
* directory.
53+
*/
54+
private void writeScriptToFile(final ScriptLanguage lang) {
55+
try (Writer w = new FileWriter(
56+
new File(m_tempDir, "script." + lang.getExtensions().get(0)))) {
57+
w.write(m_script);
58+
w.close();
59+
} catch (IOException exc) {
60+
exc.printStackTrace();
61+
}
62+
}
6363

64-
/**
65-
* Compile the script from settings with the given language Note that
66-
* compilation may be done lazily.
67-
*
68-
* @param language
69-
* for compiling the script
70-
* @return The resulting scriptInfo.
71-
* @throws ScriptException
72-
*/
73-
public CompileProductHelper compile(final String script,
74-
final ScriptLanguage language) throws ScriptException {
75-
setScript(script, language);
64+
/**
65+
* Compile the script from settings with the given language Note that
66+
* compilation may be done lazily.
67+
*
68+
* @param language
69+
* for compiling the script
70+
* @return The resulting scriptInfo.
71+
* @throws ScriptException
72+
*/
73+
public CompileProductHelper compile(final String script,
74+
final ScriptLanguage language) throws ScriptException {
75+
setScript(script, language);
7676

77-
if (language instanceof JavaScriptLanguage) {
78-
JavaEngine scriptEngine = (JavaEngine) language.getScriptEngine();
79-
scriptEngine.getContext().setErrorWriter(m_errorWriter);
80-
scriptEngine.getContext().setWriter(m_outputWriter);
81-
@SuppressWarnings("unchecked")
82-
Class<? extends Command> commandClass = (Class<? extends Command>) scriptEngine
83-
.compile(new StringReader(m_script));
84-
if (commandClass == null) {
85-
throw new ScriptException("");
86-
}
87-
return new CommandCompileProductHelper(
88-
new CommandInfo(commandClass), m_context);
89-
}
77+
if (language instanceof JavaScriptLanguage) {
78+
JavaEngine scriptEngine = (JavaEngine) language.getScriptEngine();
79+
scriptEngine.getContext().setErrorWriter(m_errorWriter);
80+
scriptEngine.getContext().setWriter(m_outputWriter);
81+
@SuppressWarnings("unchecked")
82+
Class<? extends Command> commandClass = (Class<? extends Command>) scriptEngine
83+
.compile(new StringReader(m_script));
84+
if (commandClass == null) {
85+
throw new ScriptException("");
86+
}
87+
return new CommandCompileProductHelper(
88+
new CommandInfo(commandClass), m_context);
89+
}
9090

91-
// create script module for execution
92-
final File scriptFile = new File(m_tempDir,
93-
"script." + language.getExtensions().get(0));
91+
// create script module for execution
92+
final File scriptFile = new File(m_tempDir,
93+
"script." + language.getExtensions().get(0));
9494

95-
final ScriptInfo info = new ScriptInfo(m_context,
96-
scriptFile.getAbsolutePath(), new StringReader(m_script));
97-
return new ScriptCompileProductHelper(info, m_context);
98-
}
95+
final ScriptInfo info = new ScriptInfo(m_context,
96+
scriptFile.getAbsolutePath(), new StringReader(m_script));
97+
return new ScriptCompileProductHelper(info, m_context);
98+
}
9999

100-
/**
101-
* Set the script to compile.
102-
*
103-
* @param script
104-
* @param language
105-
*/
106-
protected void setScript(final String script,
107-
final ScriptLanguage language) {
108-
m_script = script;
109-
writeScriptToFile(language);
110-
}
100+
/**
101+
* Set the script to compile.
102+
*
103+
* @param script
104+
* @param language
105+
*/
106+
protected void setScript(final String script,
107+
final ScriptLanguage language) {
108+
m_script = script;
109+
writeScriptToFile(language);
110+
}
111111
}

org.knime.scijava.scripting.base/src/org/knime/scijava/scripting/base/CompileProductHelper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*/
1515
public interface CompileProductHelper {
1616

17-
public Iterable<ModuleItem<?>> inputs();
17+
public Iterable<ModuleItem<?>> inputs();
1818

19-
public ModuleInfo getModuleInfo();
19+
public ModuleInfo getModuleInfo();
2020

21-
public Module createModule(ScriptLanguage language) throws ModuleException;
21+
public Module createModule(ScriptLanguage language) throws ModuleException;
2222

23-
public void resetModule(Module m);
23+
public void resetModule(Module m);
2424

2525
}

0 commit comments

Comments
 (0)