Skip to content

Commit c6984e0

Browse files
committed
JAVA ENGINE: Update:
* Fully updated for Java 7. * Warning fixed. * Code format and cleanup. * Added project specific Clean Up and Formatter settings.
1 parent 724ec51 commit c6984e0

10 files changed

Lines changed: 870 additions & 325 deletions

JavaEngine/.settings/org.eclipse.jdt.core.prefs

Lines changed: 282 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#Mon Sep 26 00:11:43 UYT 2011
2+
cleanup.add_default_serial_version_id=true
3+
cleanup.add_generated_serial_version_id=false
4+
cleanup.add_missing_annotations=true
5+
cleanup.add_missing_deprecated_annotations=true
6+
cleanup.add_missing_methods=true
7+
cleanup.add_missing_nls_tags=false
8+
cleanup.add_missing_override_annotations=true
9+
cleanup.add_missing_override_annotations_interface_methods=true
10+
cleanup.add_serial_version_id=true
11+
cleanup.always_use_blocks=true
12+
cleanup.always_use_parentheses_in_expressions=true
13+
cleanup.always_use_this_for_non_static_field_access=false
14+
cleanup.always_use_this_for_non_static_method_access=false
15+
cleanup.convert_to_enhanced_for_loop=true
16+
cleanup.correct_indentation=true
17+
cleanup.format_source_code=true
18+
cleanup.format_source_code_changes_only=false
19+
cleanup.make_local_variable_final=false
20+
cleanup.make_parameters_final=false
21+
cleanup.make_private_fields_final=true
22+
cleanup.make_type_abstract_if_missing_method=false
23+
cleanup.make_variable_declarations_final=true
24+
cleanup.never_use_blocks=false
25+
cleanup.never_use_parentheses_in_expressions=false
26+
cleanup.organize_imports=true
27+
cleanup.qualify_static_field_accesses_with_declaring_class=false
28+
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
29+
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
30+
cleanup.qualify_static_member_accesses_with_declaring_class=true
31+
cleanup.qualify_static_method_accesses_with_declaring_class=false
32+
cleanup.remove_private_constructors=true
33+
cleanup.remove_trailing_whitespaces=true
34+
cleanup.remove_trailing_whitespaces_all=true
35+
cleanup.remove_trailing_whitespaces_ignore_empty=false
36+
cleanup.remove_unnecessary_casts=true
37+
cleanup.remove_unnecessary_nls_tags=true
38+
cleanup.remove_unused_imports=true
39+
cleanup.remove_unused_local_variables=true
40+
cleanup.remove_unused_private_fields=true
41+
cleanup.remove_unused_private_members=true
42+
cleanup.remove_unused_private_methods=true
43+
cleanup.remove_unused_private_types=true
44+
cleanup.sort_members=false
45+
cleanup.sort_members_all=false
46+
cleanup.use_blocks=true
47+
cleanup.use_blocks_only_for_return_and_throw=false
48+
cleanup.use_parentheses_in_expressions=true
49+
cleanup.use_this_for_non_static_field_access=true
50+
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
51+
cleanup.use_this_for_non_static_method_access=true
52+
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
53+
cleanup_profile=_L2J Clean Up v0.2
54+
cleanup_settings_version=2
55+
eclipse.preferences.version=1
56+
formatter_profile=_L2J Formatter v0.1
57+
formatter_settings_version=12

JavaEngine/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</target>
6060

6161
<target name="jar" depends="compile" description="Create the jar file.">
62-
<jar destfile="${build.dist}/java-engine.jar">
62+
<jar destfile="${build.dist}/java-engine-1.7.jar">
6363
<fileset dir="${build.classes}" />
6464
<manifest>
6565
<attribute name="Built-By" value="${user.name}" />
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.l2jserver.script.java;
22

3-
public class CompilationException extends Exception {
4-
5-
public CompilationException(String message) {
3+
public class CompilationException extends Exception
4+
{
5+
private static final long serialVersionUID = 1L;
6+
7+
public CompilationException(String message)
8+
{
69
super(message);
710
}
8-
9-
private static final long serialVersionUID = 1L;
10-
}
11+
}

JavaEngine/src/com/l2jserver/script/java/JavaCompiler.java

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2222
* POSSIBILITY OF SUCH DAMAGE.
2323
*/
24-
25-
/*
26-
* JavaCompiler.java
27-
* @author A. Sundararajan
28-
*/
29-
3024
package com.l2jserver.script.java;
3125

3226
import java.io.IOException;
@@ -39,91 +33,101 @@
3933

4034
import javax.tools.Diagnostic;
4135
import javax.tools.DiagnosticCollector;
36+
import javax.tools.JavaCompiler.CompilationTask;
4237
import javax.tools.JavaFileObject;
43-
import javax.tools.StandardJavaFileManager;
4438

4539
import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
4640

4741
/**
4842
* Simple interface to Java compiler using JSR 199 Compiler API.
43+
* @author A. Sundararajan
4944
*/
50-
public class JavaCompiler {
51-
52-
private javax.tools.JavaCompiler tool;
53-
private StandardJavaFileManager stdManager;
54-
55-
public JavaCompiler() {
45+
public class JavaCompiler
46+
{
47+
48+
private final javax.tools.JavaCompiler tool;
49+
50+
public JavaCompiler()
51+
{
5652
tool = new EclipseCompiler();
57-
stdManager = tool.getStandardFileManager(null, null, null);
5853
}
59-
60-
public Map<String, byte[]> compile(String source, String fileName) {
54+
55+
public Map<String, byte[]> compile(String source, String fileName)
56+
{
6157
PrintWriter err = new PrintWriter(System.err);
6258
return compile(source, fileName, err, null, null);
6359
}
64-
65-
public Map<String, byte[]> compile(String fileName, String source, Writer err) {
60+
61+
public Map<String, byte[]> compile(String fileName, String source, Writer err)
62+
{
6663
return compile(fileName, source, err, null, null);
6764
}
68-
69-
public Map<String, byte[]> compile(String fileName, String source, Writer err, String sourcePath) {
65+
66+
public Map<String, byte[]> compile(String fileName, String source, Writer err, String sourcePath)
67+
{
7068
return compile(fileName, source, err, sourcePath, null);
7169
}
72-
70+
7371
/**
7472
* compile given String source and return bytecodes as a Map.
75-
*
7673
* @param fileName source fileName to be used for error messages etc.
7774
* @param source Java source as String
7875
* @param err error writer where diagnostic messages are written
7976
* @param sourcePath location of additional .java source files
8077
* @param classPath location of additional .class files
8178
*/
82-
public Map<String, byte[]> compile(String fileName, String source, Writer err, String sourcePath, String classPath) {
79+
public Map<String, byte[]> compile(String fileName, String source, Writer err, String sourcePath, String classPath)
80+
{
8381
// to collect errors, warnings etc.
8482
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
85-
83+
8684
// create a new memory JavaFileManager
8785
MemoryJavaFileManager manager = new MemoryJavaFileManager();
88-
86+
8987
// prepare the compilation unit
9088
List<JavaFileObject> compUnits = new ArrayList<JavaFileObject>(1);
9189
compUnits.add(MemoryJavaFileManager.makeStringSource(fileName, source));
92-
90+
9391
// javac options
9492
List<String> options = new ArrayList<String>();
9593
options.add("-Xlint:all");
9694
options.add("-g");
9795
options.add("-deprecation");
98-
options.add("-1.6");
99-
if (sourcePath != null) {
96+
options.add("-1.7");
97+
if (sourcePath != null)
98+
{
10099
options.add("-sourcepath");
101100
options.add(sourcePath);
102101
}
103-
if (classPath != null) {
102+
if (classPath != null)
103+
{
104104
options.add("-classpath");
105105
options.add(classPath);
106106
}
107-
107+
108108
// create a compilation task
109-
javax.tools.JavaCompiler.CompilationTask task = tool.getTask(err, manager, diagnostics, options, null, compUnits);
110-
111-
if (task.call() == false) {
109+
CompilationTask task = tool.getTask(err, manager, diagnostics, options, null, compUnits);
110+
111+
if (task.call() == false)
112+
{
112113
PrintWriter perr = new PrintWriter(err);
113-
for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
114+
for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics())
115+
{
114116
perr.println(diagnostic.getMessage(Locale.getDefault()));
115117
}
116118
perr.flush();
117119
return null;
118120
}
119-
121+
120122
Map<String, byte[]> classBytes = manager.getClassBytes();
121-
try {
123+
try
124+
{
122125
manager.close();
123126
}
124-
catch (IOException exp) {
127+
catch (IOException exp)
128+
{
129+
//
125130
}
126-
127131
return classBytes;
128132
}
129-
}
133+
}

0 commit comments

Comments
 (0)