You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/21 17:42:01 UTC
[commons-bsf] branch master updated: Always use blocks.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bsf.git
The following commit(s) were added to refs/heads/master by this push:
new 5780469 Always use blocks.
5780469 is described below
commit 578046990bbb547d0ba78f5909d8f17b84bbcf0a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Nov 21 12:41:57 2020 -0500
Always use blocks.
---
src/main/java/org/apache/bsf/BSF_Log.java | 93 ++++++++++++++----
.../org/apache/bsf/engines/jacl/JaclEngine.java | 12 ++-
.../bsf/engines/javascript/JavaScriptEngine.java | 15 ++-
.../apache/bsf/engines/jython/JythonEngine.java | 40 ++++----
.../java/org/apache/bsf/util/BSFClassLoader.java | 5 +-
src/main/java/org/apache/bsf/util/CodeBuffer.java | 5 +-
src/main/java/org/apache/bsf/util/EngineUtils.java | 55 +++++++----
src/main/java/org/apache/bsf/util/MethodUtils.java | 106 +++++++++++++--------
.../org/apache/bsf/util/ScriptSymbolTable.java | 5 +-
src/main/java/org/apache/bsf/util/StringUtils.java | 80 +++++++++-------
src/main/java/org/apache/bsf/util/cf/CFDriver.java | 35 +++----
.../java/org/apache/bsf/util/cf/CodeFormatter.java | 40 ++++----
.../event/generator/EventAdapterGenerator.java | 9 +-
13 files changed, 318 insertions(+), 182 deletions(-)
diff --git a/src/main/java/org/apache/bsf/BSF_Log.java b/src/main/java/org/apache/bsf/BSF_Log.java
index 761dff8..2500d48 100644
--- a/src/main/java/org/apache/bsf/BSF_Log.java
+++ b/src/main/java/org/apache/bsf/BSF_Log.java
@@ -130,13 +130,17 @@ public class BSF_Log // implements org.apache.commons.logging.Log
catch (ClassNotFoundException e)// o.k., so we do not use org.apache.commons.logging in this run
{
- if (iDebug>1) e.printStackTrace();
+ if (iDebug>1) {
+ e.printStackTrace();
+ }
oac_LogFactory_=null; // make sure it does not get used
oac_LogFactoryGetLog_String_=null; // make sure it does not get used
}
catch (NoSuchMethodException e)// o.k., so we do not use org.apache.commons.logging in this run
{
- if (iDebug>1) e.printStackTrace();
+ if (iDebug>1) {
+ e.printStackTrace();
+ }
oac_LogFactory_=null; // make sure it does not get used
oac_LogFactoryGetLog_String_=null; // make sure it does not get used
}
@@ -183,7 +187,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void debug(Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -196,7 +203,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void debug(Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -209,7 +219,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void error(Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -221,7 +234,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void error(Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -235,7 +251,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void fatal(Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -247,7 +266,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void fatal(Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
// ((org.apache.commons.logging.Log) oac_logger).fatal(msg, t);
@@ -260,7 +282,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void info (Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -272,7 +297,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void info (Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -286,7 +314,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void trace(Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -298,7 +329,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void trace(Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -312,7 +346,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
// --------------------------------------------------------------------
public void warn (Object msg)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -324,7 +361,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public void warn (Object msg, Throwable t)
{
- if (oac_logger==null) return; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -352,7 +392,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public boolean isErrorEnabled()
{
- if (oac_logger==null) return false; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return false; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -365,7 +408,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public boolean isFatalEnabled()
{
- if (oac_logger==null) return false; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return false; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -378,7 +424,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public boolean isInfoEnabled ()
{
- if (oac_logger==null) return false; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return false; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -391,7 +440,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public boolean isTraceEnabled()
{
- if (oac_logger==null) return false; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return false; // no org.apache.commons.logging.Log object ?
+ }
try
{
@@ -404,7 +456,10 @@ public class BSF_Log // implements org.apache.commons.logging.Log
public boolean isWarnEnabled ()
{
- if (oac_logger==null) return false; // no org.apache.commons.logging.Log object ?
+ if (oac_logger==null)
+ {
+ return false; // no org.apache.commons.logging.Log object ?
+ }
try
{
diff --git a/src/main/java/org/apache/bsf/engines/jacl/JaclEngine.java b/src/main/java/org/apache/bsf/engines/jacl/JaclEngine.java
index bb7e1e2..52a3544 100644
--- a/src/main/java/org/apache/bsf/engines/jacl/JaclEngine.java
+++ b/src/main/java/org/apache/bsf/engines/jacl/JaclEngine.java
@@ -83,14 +83,18 @@ public class JaclEngine extends BSFEngineImpl {
Object internalRep = result.getInternalRep();
// if the object has a corresponding Java type, unwrap it
- if (internalRep instanceof ReflectObject)
+ if (internalRep instanceof ReflectObject) {
return ReflectObject.get(interp,result);
- if (internalRep instanceof TclString)
+ }
+ if (internalRep instanceof TclString) {
return result.toString();
- if (internalRep instanceof TclDouble)
+ }
+ if (internalRep instanceof TclDouble) {
return new Double(TclDouble.get(interp,result));
- if (internalRep instanceof TclInteger)
+ }
+ if (internalRep instanceof TclInteger) {
return new Integer(TclInteger.get(interp,result));
+ }
return result;
} catch (TclException e) {
diff --git a/src/main/java/org/apache/bsf/engines/javascript/JavaScriptEngine.java b/src/main/java/org/apache/bsf/engines/javascript/JavaScriptEngine.java
index 069daa1..ff5465d 100644
--- a/src/main/java/org/apache/bsf/engines/javascript/JavaScriptEngine.java
+++ b/src/main/java/org/apache/bsf/engines/javascript/JavaScriptEngine.java
@@ -76,9 +76,10 @@ public class JavaScriptEngine extends BSFEngineImpl {
Object fun = global.get(method, global);
// NOTE: Source and line arguments are nonsense in a call().
// Any way to make these arguments *sensible?
- if (fun == Scriptable.NOT_FOUND)
+ if (fun == Scriptable.NOT_FOUND) {
throw new EvaluatorException("function " + method +
" not found.", "none", 0);
+ }
cx.setOptimizationLevel(-1);
cx.setGeneratingDebug(false);
@@ -91,8 +92,9 @@ public class JavaScriptEngine extends BSFEngineImpl {
// ScriptRuntime.call(cx, fun, global, args, global);
- if (retval instanceof Wrapper)
+ if (retval instanceof Wrapper) {
retval = ((Wrapper) retval).unwrap();
+ }
}
catch (Throwable t) {
handleError(t);
@@ -140,8 +142,9 @@ public class JavaScriptEngine extends BSFEngineImpl {
source, lineNo,
null);
- if (retval instanceof NativeJavaObject)
+ if (retval instanceof NativeJavaObject) {
retval = ((NativeJavaObject) retval).unwrap();
+ }
}
catch (Throwable t) { // includes JavaScriptException, rethrows Errors
@@ -154,8 +157,9 @@ public class JavaScriptEngine extends BSFEngineImpl {
}
private void handleError(Throwable t) throws BSFException {
- if (t instanceof WrappedException)
+ if (t instanceof WrappedException) {
t = ((WrappedException) t).getWrappedException();
+ }
String message = null;
Throwable target = t;
@@ -182,8 +186,9 @@ public class JavaScriptEngine extends BSFEngineImpl {
message = "Stack Overflow";
}
- if (message == null)
+ if (message == null) {
message = t.toString();
+ }
if (t instanceof Error && !(t instanceof StackOverflowError)) {
// Re-throw Errors because we're supposed to let the JVM see it
diff --git a/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java b/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
index dcbfc04..8938399 100644
--- a/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
+++ b/src/main/java/org/apache/bsf/engines/jython/JythonEngine.java
@@ -59,8 +59,9 @@ public class JythonEngine extends BSFEngineImpl {
if (args != null) {
pyargs = new PyObject[args.length];
- for (int i = 0; i < pyargs.length; i++)
- pyargs[i] = Py.java2py(args[i]);
+ for (int i = 0; i < pyargs.length; i++) {
+ pyargs[i] = Py.java2py(args[i]);
+ }
}
if (object != null) {
@@ -70,8 +71,9 @@ public class JythonEngine extends BSFEngineImpl {
PyObject m = interp.get(method);
- if (m == null)
- m = interp.eval(method);
+ if (m == null) {
+ m = interp.eval(method);
+ }
if (m != null) {
return unwrap(m.__call__(pyargs));
}
@@ -119,8 +121,9 @@ public class JythonEngine extends BSFEngineImpl {
Object result = interp.eval ("bsf_temp_fn()");
- if (result instanceof PyJavaInstance)
- result = ((PyJavaInstance)result).__tojava__(Object.class);
+ if (result instanceof PyJavaInstance) {
+ result = ((PyJavaInstance)result).__tojava__(Object.class);
+ }
return result;
} catch (PyException e) {
throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
@@ -137,8 +140,9 @@ public class JythonEngine extends BSFEngineImpl {
String scriptStr = byteify(script.toString ());
importPackage(scriptStr);
Object result = interp.eval (scriptStr);
- if (result instanceof PyJavaInstance)
- result = ((PyJavaInstance)result).__tojava__(Object.class);
+ if (result instanceof PyJavaInstance) {
+ result = ((PyJavaInstance)result).__tojava__(Object.class);
+ }
return result;
} catch (PyException e) {
throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
@@ -178,15 +182,18 @@ public class JythonEngine extends BSFEngineImpl {
importPackage(scriptStr);
int newline = scriptStr.indexOf("\n");
- if (newline > -1)
- scriptStr = scriptStr.substring(0, newline);
+ if (newline > -1) {
+ scriptStr = scriptStr.substring(0, newline);
+ }
try {
- if (interp.buffer.length() > 0)
- interp.buffer.append("\n");
+ if (interp.buffer.length() > 0) {
+ interp.buffer.append("\n");
+ }
interp.buffer.append(scriptStr);
- if (!(interp.runsource(interp.buffer.toString())))
- interp.resetbuffer();
+ if (!(interp.runsource(interp.buffer.toString()))) {
+ interp.resetbuffer();
+ }
} catch (PyException e) {
interp.resetbuffer();
throw new BSFException(BSFException.REASON_EXECUTION_ERROR,
@@ -228,8 +235,9 @@ public class JythonEngine extends BSFEngineImpl {
public Object unwrap(PyObject result) {
if (result != null) {
Object ret = result.__tojava__(Object.class);
- if (ret != Py.NoConversion)
- return ret;
+ if (ret != Py.NoConversion) {
+ return ret;
+ }
}
return result;
}
diff --git a/src/main/java/org/apache/bsf/util/BSFClassLoader.java b/src/main/java/org/apache/bsf/util/BSFClassLoader.java
index 73ed492..e25c801 100644
--- a/src/main/java/org/apache/bsf/util/BSFClassLoader.java
+++ b/src/main/java/org/apache/bsf/util/BSFClassLoader.java
@@ -57,8 +57,9 @@ class BSFClassLoader extends ClassLoader {
name + "'");
}
}
- if (resolve)
- resolveClass (c);
+ if (resolve) {
+ resolveClass (c);
+ }
return c;
}
private byte[] loadClassData (String name) throws Exception {
diff --git a/src/main/java/org/apache/bsf/util/CodeBuffer.java b/src/main/java/org/apache/bsf/util/CodeBuffer.java
index fa3e87a..42789b8 100644
--- a/src/main/java/org/apache/bsf/util/CodeBuffer.java
+++ b/src/main/java/org/apache/bsf/util/CodeBuffer.java
@@ -256,8 +256,9 @@ public class CodeBuffer
{
ObjInfo ret = (ObjInfo)symbolTable.get(symbol);
- if (ret == null && parent != null)
- ret = parent.getSymbol(symbol);
+ if (ret == null && parent != null) {
+ ret = parent.getSymbol(symbol);
+ }
return ret;
}
diff --git a/src/main/java/org/apache/bsf/util/EngineUtils.java b/src/main/java/org/apache/bsf/util/EngineUtils.java
index 7296609..9b05efb 100644
--- a/src/main/java/org/apache/bsf/util/EngineUtils.java
+++ b/src/main/java/org/apache/bsf/util/EngineUtils.java
@@ -216,15 +216,25 @@ public class EngineUtils {
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Number)
{
- if (args[i] instanceof Byte) argTypes[i] = byte.class;
- else if (args[i] instanceof Integer) argTypes[i] = int.class;
- else if (args[i] instanceof Long) argTypes[i] = long.class;
- else if (args[i] instanceof Float) argTypes[i] = float.class;
- else if (args[i] instanceof Double ) argTypes[i] = double.class;
- else if (args[i] instanceof Short ) argTypes[i] = short.class;
+ if (args[i] instanceof Byte) {
+ argTypes[i] = byte.class;
+ } else if (args[i] instanceof Integer) {
+ argTypes[i] = int.class;
+ } else if (args[i] instanceof Long) {
+ argTypes[i] = long.class;
+ } else if (args[i] instanceof Float) {
+ argTypes[i] = float.class;
+ } else if (args[i] instanceof Double ) {
+ argTypes[i] = double.class;
+ } else if (args[i] instanceof Short ) {
+ argTypes[i] = short.class;
+ }
}
- else if (args[i] instanceof Boolean) argTypes[i] = boolean.class;
- else if (args[i] instanceof Character) argTypes[i] = char.class;
+ else if (args[i] instanceof Boolean) {
+ argTypes[i] = boolean.class;
+ } else if (args[i] instanceof Character) {
+ argTypes[i] = char.class;
+ }
}
m = MethodUtils.getMethod (beanClass, methodName, argTypes,
@@ -303,12 +313,13 @@ public class EngineUtils {
// if args is null the NullPointerException will get caught
// below and the right thing'll happen .. ugly but works
for (int i = 0; i < args.length; i++) {
- if (args[i] instanceof Number)
+ if (args[i] instanceof Number) {
argTypes[i] = byte.class;
- else if (args[i] instanceof Boolean)
+ } else if (args[i] instanceof Boolean) {
argTypes[i] = boolean.class;
- else if (args[i] instanceof Character)
+ } else if (args[i] instanceof Character) {
argTypes[i] = char.class;
+ }
}
obj = ReflectionUtils.createBean (null, className,
argTypes, args);
@@ -334,24 +345,25 @@ public class EngineUtils {
*/
public static String getTypeSignatureString (Class cl) {
if (cl.isPrimitive ()) {
- if (cl == boolean.class)
+ if (cl == boolean.class) {
return "Z";
- else if (cl == byte.class)
+ } else if (cl == byte.class) {
return "B";
- else if (cl == char.class)
+ } else if (cl == char.class) {
return "C";
- else if (cl == short.class)
+ } else if (cl == short.class) {
return "S";
- else if (cl == int.class)
+ } else if (cl == int.class) {
return "I";
- else if (cl == long.class)
+ } else if (cl == long.class) {
return "J";
- else if (cl == float.class)
+ } else if (cl == float.class) {
return "F";
- else if (cl == double.class)
+ } else if (cl == double.class) {
return "D";
- else
+ } else {
return "V";
+ }
} else {
StringBuffer sb = new StringBuffer ("L");
sb.append (cl.getName ());
@@ -411,8 +423,9 @@ public class EngineUtils {
} catch (ClassNotFoundException e) {
// try to load it from the temp dir using my own class loader
try {
- if (bsfCL == null)
+ if (bsfCL == null) {
bsfCL = new BSFClassLoader ();
+ }
bsfCL.setTempDir (mgr.getTempDir ());
return bsfCL.loadClass (name);
} catch (ClassNotFoundException e2) {
diff --git a/src/main/java/org/apache/bsf/util/MethodUtils.java b/src/main/java/org/apache/bsf/util/MethodUtils.java
index 8a0dc34..b9881bf 100644
--- a/src/main/java/org/apache/bsf/util/MethodUtils.java
+++ b/src/main/java/org/apache/bsf/util/MethodUtils.java
@@ -65,9 +65,9 @@ public class MethodUtils {
*/
void addItem (Object newEntry)
{
- if(size()==0)
+ if(size()==0) {
addElement(newEntry);
- else
+ } else
{
Class[] newargs=entryGetParameterTypes(newEntry);
boolean keep=true;
@@ -78,15 +78,18 @@ public class MethodUtils {
Object oldEntry=e.nextElement();
// CAVEAT: Implicit references to enclosing class!
Class[] oldargs=entryGetParameterTypes(oldEntry);
- if(areMethodConvertable(oldargs,newargs))
+ if(areMethodConvertable(oldargs,newargs)) {
removeElement(oldEntry); // New more specific; discard old
- else if(areMethodConvertable(newargs,oldargs))
+ } else if(areMethodConvertable(newargs,oldargs))
+ {
keep=false; // Old more specific; discard new
// Else they're tied. Keep both and hope someone beats both.
}
- if(keep)
+ }
+ if(keep) {
addElement(newEntry);
}
+ }
}
/** Obtain the single Most Specific entry-point. If there is no clear
@@ -99,15 +102,17 @@ public class MethodUtils {
Class[] argTypes,boolean isStaticReference)
throws NoSuchMethodException
{
- if(size()==1)
+ if(size()==1) {
return firstElement();
+ }
if(size()>1)
{
StringBuffer buf=new StringBuffer();
Enumeration e=elements();
buf.append(e.nextElement());
- while(e.hasMoreElements())
+ while(e.hasMoreElements()) {
buf.append(" and ").append(e.nextElement());
+ }
throw new NoSuchMethodException (callToString(targetClass,
methodName,
argTypes,
@@ -124,12 +129,15 @@ public class MethodUtils {
*/
static private boolean areMethodConvertable(Class[] parms,Class[] args)
{
- if(parms.length!=args.length)
- return false;
-
- for(int i=0;i<parms.length;++i)
- if(!isMethodConvertable(parms[i],args[i]))
+ if(parms.length!=args.length) {
return false;
+ }
+
+ for(int i=0;i<parms.length;++i) {
+ if(!isMethodConvertable(parms[i],args[i])) {
+ return false;
+ }
+ }
return true;
}
@@ -140,11 +148,13 @@ public class MethodUtils {
Class[] argTypes,boolean isStaticReference)
{
StringBuffer buf = new StringBuffer();
- if(isStaticReference)
- buf.append("static ");
+ if(isStaticReference) {
+ buf.append("static ");
+ }
buf.append(StringUtils.getClassName(targetClass));
- if(methodName!=null)
- buf.append(".").append(methodName);
+ if(methodName!=null) {
+ buf.append(".").append(methodName);
+ }
buf.append("(");
if (argTypes != null && argTypes.length>0) {
if(false)
@@ -159,9 +169,9 @@ public class MethodUtils {
buf.append(",").append(StringUtils.getClassName(argTypes[i]));
}
}
+ } else {
+ buf.append("[none]");
}
- else
- buf.append("[none]");
buf.append(")");
return buf.toString();
}
@@ -275,9 +285,9 @@ public class MethodUtils {
" resolved to instance " + m);
}
return m;
- }
- else
+ } else {
return targetClass.getConstructor (argTypes);
+ }
} catch (NoSuchMethodException e) {
// no-args has no alternatives!
@@ -325,9 +335,10 @@ public class MethodUtils {
&&
// 15.11.2.1 APPLICABLE: Parameters match arguments
areMethodConvertable(entryGetParameterTypes(mi),argTypes)
- )
- // 15.11.2.2 MORE SPECIFIC displace less specific.
- best.addItem(mi);
+ ) {
+ // 15.11.2.2 MORE SPECIFIC displace less specific.
+ best.addItem(mi);
+ }
}
// May throw NoSuchMethodException; we pass in info needed to
@@ -451,8 +462,9 @@ public class MethodUtils {
*/
static private boolean isMethodConvertable(Class parm, Class arg)
{
- if (parm.equals(arg)) // If same class, short-circuit now!
- return true;
+ if (parm.equals(arg)) {
+ return true;
+ }
// Accept any type EXCEPT primitives (which can't have null values).
if (arg == null)
@@ -465,16 +477,18 @@ public class MethodUtils {
// does it successfully handle arrays of primatives?
while(parm.isArray())
{
- if(!arg.isArray())
- return false; // Unequal array depth
- else
+ if(!arg.isArray()) {
+ return false; // Unequal array depth
+ } else
{
parm=parm.getComponentType();
arg=arg.getComponentType();
}
}
if(arg.isArray())
- return false; // Unequal array depth
+ {
+ return false; // Unequal array depth
+ }
// Despite its name, the 1.1.6 docs say that this function does
// NOT return true for all legal ASSIGNMENT CONVERSIONS
@@ -484,8 +498,9 @@ public class MethodUtils {
// to the type represented by this Class object via
// an identity conversion or via a widening reference
// conversion."
- if(parm.isAssignableFrom(arg))
- return true;
+ if(parm.isAssignableFrom(arg)) {
+ return true;
+ }
// That leaves us the Widening Primitives case. Four possibilities:
// void (can only convert to void), boolean (can only convert to boolean),
@@ -493,24 +508,33 @@ public class MethodUtils {
// numerics by promoting to int or larger)
if(parm.equals(Void.TYPE) || parm.equals(Boolean.TYPE) ||
- arg.equals(Void.TYPE) || arg.equals(Boolean.TYPE))
- return false;
+ arg.equals(Void.TYPE) || arg.equals(Boolean.TYPE)) {
+ return false;
+ }
Class[] primTypes={ Character.TYPE, Byte.TYPE, Short.TYPE, Integer.TYPE,
Long.TYPE, Float.TYPE, Double.TYPE };
int parmscore,argscore;
- for(parmscore=0;parmscore<primTypes.length;++parmscore)
- if (parm.equals(primTypes[parmscore]))
- break;
+ for(parmscore=0;parmscore<primTypes.length;++parmscore) {
+ if (parm.equals(primTypes[parmscore])) {
+ break;
+ }
+ }
if(parmscore>=primTypes.length)
- return false; // Off the end
+ {
+ return false; // Off the end
+ }
- for(argscore=0;argscore<primTypes.length;++argscore)
- if (arg.equals(primTypes[argscore]))
- break;
+ for(argscore=0;argscore<primTypes.length;++argscore) {
+ if (arg.equals(primTypes[argscore])) {
+ break;
+ }
+ }
if(argscore>=primTypes.length)
- return false; // Off the end
+ {
+ return false; // Off the end
+ }
// OK if ordered AND NOT char-to-smaller-than-int
return (argscore<parmscore && (argscore!=0 || parmscore>2) );
diff --git a/src/main/java/org/apache/bsf/util/ScriptSymbolTable.java b/src/main/java/org/apache/bsf/util/ScriptSymbolTable.java
index 6164391..30ca5c4 100644
--- a/src/main/java/org/apache/bsf/util/ScriptSymbolTable.java
+++ b/src/main/java/org/apache/bsf/util/ScriptSymbolTable.java
@@ -37,8 +37,9 @@ class ScriptSymbolTable extends Hashtable
{
Object ret = super.get(key);
- if (ret == null && parentTable != null)
- ret = parentTable.get(key);
+ if (ret == null && parentTable != null) {
+ ret = parentTable.get(key);
+ }
return ret;
}
diff --git a/src/main/java/org/apache/bsf/util/StringUtils.java b/src/main/java/org/apache/bsf/util/StringUtils.java
index 304e1b4..a4126da 100644
--- a/src/main/java/org/apache/bsf/util/StringUtils.java
+++ b/src/main/java/org/apache/bsf/util/StringUtils.java
@@ -69,14 +69,14 @@ public class StringUtils
// Ensure that escape sequences are passed through properly.
public static String cleanString(String str)
{
- if (str == null)
- return null;
- else
+ if (str == null) {
+ return null;
+ } else
{
char[] charArray = str.toCharArray();
StringBuffer sBuf = new StringBuffer();
- for (int i = 0; i < charArray.length; i++)
+ for (int i = 0; i < charArray.length; i++) {
switch (charArray[i])
{
case '\"' : sBuf.append("\\\"");
@@ -90,6 +90,7 @@ public class StringUtils
default : sBuf.append(charArray[i]);
break;
}
+ }
return sBuf.toString();
}
@@ -101,13 +102,15 @@ public class StringUtils
*/
public static String getChars(int numberOfChars, char theChar)
{
- if (numberOfChars <= 0)
- return "";
+ if (numberOfChars <= 0) {
+ return "";
+ }
StringBuffer sRet = new StringBuffer(numberOfChars);
- for (int i = 0; i < numberOfChars; i++)
- sRet.append(theChar);
+ for (int i = 0; i < numberOfChars; i++) {
+ sRet.append(theChar);
+ }
return sRet.toString();
}
@@ -290,8 +293,9 @@ public class StringUtils
}
public static String getValidIdentifierName(String identifierName)
{
- if (identifierName == null || identifierName.length() == 0)
- return null;
+ if (identifierName == null || identifierName.length() == 0) {
+ return null;
+ }
StringBuffer strBuf = new StringBuffer();
@@ -314,54 +318,63 @@ public class StringUtils
}
public static boolean isValidIdentifierName(String identifierName)
{
- if (identifierName == null || identifierName.length() == 0)
- return false;
+ if (identifierName == null || identifierName.length() == 0) {
+ return false;
+ }
char[] chars = identifierName.toCharArray();
- if (!Character.isJavaIdentifierStart(chars[0]))
- return false;
-
- for (int i = 1; i < chars.length; i++)
- if (!Character.isJavaIdentifierPart(chars[i]))
+ if (!Character.isJavaIdentifierStart(chars[0])) {
return false;
+ }
+
+ for (int i = 1; i < chars.length; i++) {
+ if (!Character.isJavaIdentifierPart(chars[i])) {
+ return false;
+ }
+ }
return true;
}
public static boolean isValidPackageName(String packageName)
{
- if (packageName == null)
- return false;
- else if (packageName.length() == 0)
- // Empty is ok.
- return true;
+ if (packageName == null) {
+ return false;
+ } else if (packageName.length() == 0) {
+ // Empty is ok.
+ return true;
+ }
StringTokenizer strTok = new StringTokenizer(packageName, ".", true);
// Should have an odd number of tokens (including '.' delimiters).
- if (strTok.countTokens() % 2 != 1)
- return false;
+ if (strTok.countTokens() % 2 != 1) {
+ return false;
+ }
// Must start with a valid identifier name.
- if (!isValidIdentifierName(strTok.nextToken()))
- return false;
+ if (!isValidIdentifierName(strTok.nextToken())) {
+ return false;
+ }
// ... followed by 0 or more of ".ValidIdentifier".
while (strTok.hasMoreTokens())
{
// Must be a '.'.
- if (!strTok.nextToken().equals("."))
+ if (!strTok.nextToken().equals(".")) {
return false;
+ }
// Must be a valid identifier name.
if (strTok.hasMoreTokens())
{
- if (!isValidIdentifierName(strTok.nextToken()))
- return false;
- }
- else
+ if (!isValidIdentifierName(strTok.nextToken())) {
+ return false;
+ }
+ } else {
return false;
}
+ }
return true;
}
@@ -405,8 +418,9 @@ public class StringUtils
break;
}
- for (i = 0; i < arrayDim; i++)
- classNameBuf.append("[]");
+ for (i = 0; i < arrayDim; i++) {
+ classNameBuf.append("[]");
+ }
return classNameBuf.toString();
}
diff --git a/src/main/java/org/apache/bsf/util/cf/CFDriver.java b/src/main/java/org/apache/bsf/util/cf/CFDriver.java
index 3071228..cddaffd 100644
--- a/src/main/java/org/apache/bsf/util/cf/CFDriver.java
+++ b/src/main/java/org/apache/bsf/util/cf/CFDriver.java
@@ -82,18 +82,19 @@ public class CFDriver
for (int i = 0; i < argv.length; i += 2)
{
- if (argv[i].startsWith("-i"))
- inFile = argv[i + 1];
- else if (argv[i].startsWith("-o"))
- outFile = argv[i + 1];
- else if (argv[i].startsWith("-m"))
+ if (argv[i].startsWith("-i")) {
+ inFile = argv[i + 1];
+ } else if (argv[i].startsWith("-o")) {
+ outFile = argv[i + 1];
+ } else if (argv[i].startsWith("-m")) {
maxLine = argv[i + 1];
- else if (argv[i].startsWith("-st"))
- indStep = argv[i + 1];
- else if (argv[i].startsWith("-d"))
+ } else if (argv[i].startsWith("-st")) {
+ indStep = argv[i + 1];
+ } else if (argv[i].startsWith("-d")) {
delim = argv[i + 1];
- else if (argv[i].startsWith("-sd"))
- sDelim = argv[i + 1];
+ } else if (argv[i].startsWith("-sd")) {
+ sDelim = argv[i + 1];
+ }
}
if (inFile != null)
@@ -160,16 +161,18 @@ public class CFDriver
}
}
- if (delim != null)
- cf.setDelimiters(delim);
+ if (delim != null) {
+ cf.setDelimiters(delim);
+ }
- if (sDelim != null)
- cf.setStickyDelimiters(sDelim);
+ if (sDelim != null) {
+ cf.setStickyDelimiters(sDelim);
+ }
cf.formatCode(in, out);
+ } else {
+ printHelp();
}
- else
- printHelp();
}
private static void printError(String errMsg)
{
diff --git a/src/main/java/org/apache/bsf/util/cf/CodeFormatter.java b/src/main/java/org/apache/bsf/util/cf/CodeFormatter.java
index 94d4a77..f025c33 100644
--- a/src/main/java/org/apache/bsf/util/cf/CodeFormatter.java
+++ b/src/main/java/org/apache/bsf/util/cf/CodeFormatter.java
@@ -122,9 +122,9 @@ public class CodeFormatter
indent = origIndent;
hangingIndent = indent + indentationStep;
printLine(line, out);
+ } else {
+ out.println();
}
- else
- out.println();
}
}
catch (IOException e)
@@ -216,8 +216,9 @@ public class CodeFormatter
tokBuf.append(ch);
break;
default :
- if (ch > 31)
- tokBuf.append(ch);
+ if (ch > 31) {
+ tokBuf.append(ch);
+ }
break;
}
}
@@ -227,8 +228,9 @@ public class CodeFormatter
{
tokBuf.append(ch);
- if (ch == '/' && i > 0 && source[i - 1] == '*')
- inCPP_Comment = false;
+ if (ch == '/' && i > 0 && source[i - 1] == '*') {
+ inCPP_Comment = false;
+ }
}
else
{
@@ -251,8 +253,9 @@ public class CodeFormatter
case '*' :
tokBuf.append(ch);
- if (i > 0 && source[i - 1] == '/')
- inCPP_Comment = true;
+ if (i > 0 && source[i - 1] == '/') {
+ inCPP_Comment = true;
+ }
break;
case '\'' :
case '\"' :
@@ -273,8 +276,9 @@ public class CodeFormatter
tokBuf.append(ch);
origIndent -= indentationStep;
- if (i == 0)
- indent = origIndent;
+ if (i == 0) {
+ indent = origIndent;
+ }
break;
default :
if (ch > 31)
@@ -290,9 +294,9 @@ public class CodeFormatter
tokBuf.append(ch);
addTok(targetBuf, tokBuf, out);
tokBuf.setLength(0);
- }
- else
- tokBuf.append(ch);
+ } else {
+ tokBuf.append(ch);
+ }
}
break;
}
@@ -301,13 +305,15 @@ public class CodeFormatter
}
}
- if (tokBuf.length() > 0)
- addTok(targetBuf, tokBuf, out);
+ if (tokBuf.length() > 0) {
+ addTok(targetBuf, tokBuf, out);
+ }
String lastLine = targetBuf.toString().trim();
- if (lastLine.length() > 0)
- out.println(indent, lastLine);
+ if (lastLine.length() > 0) {
+ out.println(indent, lastLine);
+ }
}
/**
* Sets the set of delimiters; default set is <code>"(+"</code>.
diff --git a/src/main/java/org/apache/bsf/util/event/generator/EventAdapterGenerator.java b/src/main/java/org/apache/bsf/util/event/generator/EventAdapterGenerator.java
index 78c2872..223c38a 100644
--- a/src/main/java/org/apache/bsf/util/event/generator/EventAdapterGenerator.java
+++ b/src/main/java/org/apache/bsf/util/event/generator/EventAdapterGenerator.java
@@ -244,10 +244,11 @@ public class EventAdapterGenerator
logger.debug("cached: "+cached);
try
{
- if (!listenerType.isAssignableFrom(cached))
- finalAdapterClassName = adapterClassName + "_" + suffixIndex++;
- else
- return cached;
+ if (!listenerType.isAssignableFrom(cached)) {
+ finalAdapterClassName = adapterClassName + "_" + suffixIndex++;
+ } else {
+ return cached;
+ }
}
catch(VerifyError ex)
{