Skip to content

Commit 0b28f22

Browse files
committed
refactoring of the code to be java 6 compliant
A lot of nasty stuff had to be done to make it Java 6 compliant. There were bugs emerging during the refactoring process.
1 parent 4e6e698 commit 0b28f22

32 files changed

Lines changed: 1444 additions & 1434 deletions

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
<artifactId>maven-compiler-plugin</artifactId>
106106
<version>2.5.1</version>
107107
<configuration>
108-
<source>1.7</source>
109-
<target>1.7</target>
108+
<source>1.6</source>
109+
<target>1.6</target>
110110
</configuration>
111111
</plugin>
112112
<plugin>
@@ -149,6 +149,7 @@
149149
<plugin>
150150
<groupId>org.apache.maven.plugins</groupId>
151151
<artifactId>maven-gpg-plugin</artifactId>
152+
<version>1.4</version>
152153
<executions>
153154
<execution>
154155
<id>sign-artifacts</id>

src/main/java/com/scriptbasic/Version.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ public class Version {
1717
public static final Long MINOR = 0L;
1818
public static final Long BUGFIX = 0L;
1919
public static final String version = MAJOR + "." + MINOR + "." + BUGFIX;
20-
public static final List<String> extensions = new LinkedList<>();
20+
public static final List<String> extensions = new LinkedList<String>();
2121
static {
2222
extensions.add("bas");
2323
extensions.add("sb");
2424
}
25-
public static final List<String> mimeTypes = new LinkedList<>();
25+
public static final List<String> mimeTypes = new LinkedList<String>();
2626
static {
2727
mimeTypes.add("application/x-scriptbasic");
2828
mimeTypes.add("application/x-basic");
2929
}
30-
public static final List<String> names = new LinkedList<>();
30+
public static final List<String> names = new LinkedList<String>();
3131
static {
3232
names.add("basic");
3333
names.add("sb4j");

src/main/java/com/scriptbasic/configuration/BasicConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ public String getConfigValue(final String key, final String defaultValue) {
9191
return configValue == null ? defaultValue : configValue;
9292
}
9393

94-
private final HashMap<String, List<String>> lists = new HashMap<>();
94+
private final HashMap<String, List<String>> lists = new HashMap<String, List<String>>();
9595

9696
@Override
9797
public List<String> getConfigValueList(final String key) {
9898
if (lists.containsKey(key)) {
9999
return lists.get(key);
100100
}
101-
List<String> list = new LinkedList<>();
101+
List<String> list = new LinkedList<String>();
102102
String keyi;
103103
String value;
104104
for (int i = 0; (keyi = key + "." + i) != null

src/main/java/com/scriptbasic/exceptions/GeneralAnalysisException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*/
1414
public abstract class GeneralAnalysisException extends AnalysisException {
1515

16-
public GeneralAnalysisException() {
16+
private static final long serialVersionUID = 1L;
17+
18+
public GeneralAnalysisException() {
1719
super();
1820
}
1921

src/main/java/com/scriptbasic/exceptions/LexicalException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
public abstract class LexicalException extends GeneralAnalysisException {
1111

12-
public LexicalException() {
12+
private static final long serialVersionUID = 1L;
13+
14+
public LexicalException() {
1315
super();
1416
}
1517

src/main/java/com/scriptbasic/exceptions/SyntaxException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
*/
1010
public abstract class SyntaxException extends GeneralAnalysisException {
1111

12-
public SyntaxException() {
12+
private static final long serialVersionUID = 1L;
13+
14+
public SyntaxException() {
1315
super();
1416
}
1517

src/main/java/com/scriptbasic/executors/BasicExtendedInterpreter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public void setFactory(final Factory factory) {
315315
this.factory = factory;
316316
}
317317

318-
private final Map<String, Class<?>> useMap = new HashMap<>();
318+
private final Map<String, Class<?>> useMap = new HashMap<String, Class<?>>();
319319

320320
/*
321321
* (non-Javadoc)
@@ -361,8 +361,8 @@ public void registerJavaMethod(final String alias, final Class<?> klass,
361361

362362
}
363363

364-
private final Stack<Command> commandStack = new Stack<>();
365-
private final Stack<Command> nextCommandStack = new Stack<>();
364+
private final Stack<Command> commandStack = new Stack<Command>();
365+
private final Stack<Command> nextCommandStack = new Stack<Command>();
366366

367367
/*
368368
* (non-Javadoc)

src/main/java/com/scriptbasic/executors/BasicMethodRegistry.java

Lines changed: 97 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -13,102 +13,108 @@
1313

1414
public class BasicMethodRegistry implements MethodRegistry {
1515

16-
private static String formKey(String alias, Class<?> klass) {
17-
return alias + "#" + klass.getName().replaceAll("\\$", ".");
18-
}
16+
private static String formKey(String alias, Class<?> klass) {
17+
return alias + "#" + klass.getName().replaceAll("\\$", ".");
18+
}
1919

20-
private static class RegistryItem {
21-
private String methodName;
22-
private Class<?> klass;
23-
private Class<?>[] args;
24-
}
20+
private static class RegistryItem {
21+
private String methodName;
22+
private Class<?> klass;
23+
private Class<?>[] args;
24+
}
2525

26-
private Map<String, RegistryItem> registry = new HashMap<>();
27-
private Map<String, RegistryItem> globalRegistry = new HashMap<>();
26+
private Map<String, RegistryItem> registry = new HashMap<String, RegistryItem>();
27+
private Map<String, RegistryItem> globalRegistry = new HashMap<String, RegistryItem>();
2828

29-
/* (non-Javadoc)
30-
* @see com.scriptbasic.executors.MethodRegistry#getJavaMethod(java.lang.Class, java.lang.String)
31-
*/
32-
@Override
33-
public Method getJavaMethod(Class<?> klass, String alias)
34-
throws ExecutionException {
35-
Method method = null;
36-
if (klass == null) {
37-
method = getJavaMethod(alias);
38-
} else {
39-
RegistryItem item = registry.get(formKey(alias, klass));
40-
if (item != null) {
41-
try {
42-
method = item.klass.getMethod(item.methodName, item.args);
43-
} catch (NoSuchMethodException | SecurityException e) {
44-
throw new BasicRuntimeException("Method '"
45-
+ item.methodName + "' from class '" + item.klass
46-
+ "' can not be accessed", e);
47-
}
48-
}
49-
}
50-
return method;
51-
}
29+
/*
30+
* (non-Javadoc)
31+
*
32+
* @see
33+
* com.scriptbasic.executors.MethodRegistry#getJavaMethod(java.lang.Class,
34+
* java.lang.String)
35+
*/
36+
@Override
37+
public Method getJavaMethod(Class<?> klass, String alias)
38+
throws ExecutionException {
39+
Method method = null;
40+
if (klass == null) {
41+
method = getJavaMethod(alias);
42+
} else {
43+
RegistryItem item = registry.get(formKey(alias, klass));
44+
if (item != null) {
45+
try {
46+
method = item.klass.getMethod(item.methodName, item.args);
47+
} catch (Exception e) {
48+
throw new BasicRuntimeException("Method '"
49+
+ item.methodName + "' from class '" + item.klass
50+
+ "' can not be accessed", e);
51+
}
52+
}
53+
}
54+
return method;
55+
}
5256

53-
private Method getJavaMethod(String alias) throws ExecutionException {
54-
RegistryItem item = globalRegistry.get(alias);
55-
Method method = null;
56-
if (item != null) {
57-
try {
58-
method = item.klass.getMethod(item.methodName, item.args);
59-
} catch (NoSuchMethodException | SecurityException e) {
60-
throw new BasicRuntimeException("Method '" + item.methodName
61-
+ "' from class '" + item.klass
62-
+ "' can not be accessed", e);
63-
}
64-
}
65-
return method;
66-
}
57+
private Method getJavaMethod(String alias) throws ExecutionException {
58+
RegistryItem item = globalRegistry.get(alias);
59+
Method method = null;
60+
if (item != null) {
61+
try {
62+
method = item.klass.getMethod(item.methodName, item.args);
63+
} catch (Exception e) {
64+
throw new BasicRuntimeException("Method '" + item.methodName
65+
+ "' from class '" + item.klass
66+
+ "' can not be accessed", e);
67+
}
68+
}
69+
return method;
70+
}
6771

68-
/*
69-
* Register an item in the global registry so that the program can use it
70-
* without specifying the class that the method belongs to. This makes it
71-
* possible to use these methods as simple functions in the BASIC program.
72-
* On the other hand this mechanism does not protect from name collisions.
73-
* If two different methods from two different classes use the same alias
74-
* then they can not be used as functions at the same time. In that case the
75-
* class alias also have to be used in the BASIC program.
76-
* <p>
77-
* This method registers the item containing the name of the method and also
78-
* the class and the argument types if a function with that name was not
79-
* registered yet. If there was already a function with the name registered
80-
* then it removes the previous registry from the store and registers
81-
* {@code null} as item, so that none of the methods can later be used as
82-
* simple functions.
83-
* <p>
84-
* Even though the functionality of evaluation of function calls is not
85-
* implemented in class or in this package if is good to note that if a
86-
* BASIC subroutine is defined with the same name as an alias then that will
87-
* rule.
88-
*
89-
* @param alias
90-
* @param item
91-
*/
92-
private void registerGlobal(String alias, RegistryItem item) {
93-
if (globalRegistry.containsKey(alias)) {
94-
globalRegistry.put(alias, null);
95-
} else {
96-
globalRegistry.put(alias, item);
97-
}
98-
}
72+
/*
73+
* Register an item in the global registry so that the program can use it
74+
* without specifying the class that the method belongs to. This makes it
75+
* possible to use these methods as simple functions in the BASIC program.
76+
* On the other hand this mechanism does not protect from name collisions.
77+
* If two different methods from two different classes use the same alias
78+
* then they can not be used as functions at the same time. In that case the
79+
* class alias also have to be used in the BASIC program. <p> This method
80+
* registers the item containing the name of the method and also the class
81+
* and the argument types if a function with that name was not registered
82+
* yet. If there was already a function with the name registered then it
83+
* removes the previous registry from the store and registers {@code null}
84+
* as item, so that none of the methods can later be used as simple
85+
* functions. <p> Even though the functionality of evaluation of function
86+
* calls is not implemented in class or in this package if is good to note
87+
* that if a BASIC subroutine is defined with the same name as an alias then
88+
* that will rule.
89+
*
90+
* @param alias
91+
*
92+
* @param item
93+
*/
94+
private void registerGlobal(String alias, RegistryItem item) {
95+
if (globalRegistry.containsKey(alias)) {
96+
globalRegistry.put(alias, null);
97+
} else {
98+
globalRegistry.put(alias, item);
99+
}
100+
}
99101

100-
/* (non-Javadoc)
101-
* @see com.scriptbasic.executors.MethodRegistry#registerJavaMethod(java.lang.String, java.lang.Class, java.lang.String, java.lang.Class)
102-
*/
103-
@Override
104-
public void registerJavaMethod(String alias, Class<?> klass,
105-
String methodName, Class<?>[] argumentTypes) {
106-
RegistryItem item = new RegistryItem();
107-
item.methodName = methodName;
108-
item.klass = klass;
109-
item.args = argumentTypes.clone();
110-
registry.put(formKey(alias, klass), item);
111-
registerGlobal(alias, item);
112-
}
102+
/*
103+
* (non-Javadoc)
104+
*
105+
* @see
106+
* com.scriptbasic.executors.MethodRegistry#registerJavaMethod(java.lang
107+
* .String, java.lang.Class, java.lang.String, java.lang.Class)
108+
*/
109+
@Override
110+
public void registerJavaMethod(String alias, Class<?> klass,
111+
String methodName, Class<?>[] argumentTypes) {
112+
RegistryItem item = new RegistryItem();
113+
item.methodName = methodName;
114+
item.klass = klass;
115+
item.args = argumentTypes.clone();
116+
registry.put(formKey(alias, klass), item);
117+
registerGlobal(alias, item);
118+
}
113119

114120
}

0 commit comments

Comments
 (0)