aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2017-01-28 19:21:08 +0000
committerClaude Brisson <cbrisson@apache.org>2017-01-28 19:21:08 +0000
commit23e6d0faeb4648ec700481fb3f01214bd81f4f79 (patch)
tree9dcf8c9be8710fa85f2dd31ea18604584445882f /velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
parent34e78d04e1edf70a291f2acbf9d891466bc9582a (diff)
downloadapache-velocity-engine-23e6d0faeb4648ec700481fb3f01214bd81f4f79.tar.gz
[engine] full code review (foreach loops and some other problems detected by code analysis tools)
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1780734 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java')
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java63
1 files changed, 29 insertions, 34 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
index 574ace7c..1e9fb2ec 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
@@ -361,14 +361,13 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
private void initializeIntrospection()
{
String[] uberspectors = configuration.getStringArray(RuntimeConstants.UBERSPECT_CLASSNAME);
- for (int i=0; i <uberspectors.length;i++)
+ for (String rm : uberspectors)
{
- String rm = uberspectors[i];
Object o = null;
try
{
- o = ClassUtils.getNewInstance( rm );
+ o = ClassUtils.getNewInstance(rm);
}
catch (ClassNotFoundException cnfe)
{
@@ -379,11 +378,11 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
}
catch (InstantiationException ie)
{
- throw new VelocityException("Could not instantiate class '" + rm + "'", ie);
+ throw new VelocityException("Could not instantiate class '" + rm + "'", ie);
}
catch (IllegalAccessException ae)
{
- throw new VelocityException("Cannot access class '" + rm + "'", ae);
+ throw new VelocityException("Cannot access class '" + rm + "'", ae);
}
if (!(o instanceof Uberspect))
@@ -396,27 +395,25 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
throw new VelocityException(err);
}
- Uberspect u = (Uberspect)o;
+ Uberspect u = (Uberspect) o;
if (u instanceof RuntimeServicesAware)
{
- ((RuntimeServicesAware)u).setRuntimeServices(this);
+ ((RuntimeServicesAware) u).setRuntimeServices(this);
}
if (uberSpect == null)
{
uberSpect = u;
- }
- else
+ } else
{
if (u instanceof ChainableUberspector)
{
- ((ChainableUberspector)u).wrap(uberSpect);
+ ((ChainableUberspector) u).wrap(uberSpect);
uberSpect = u;
- }
- else
+ } else
{
- uberSpect = new LinkingUberspector(uberSpect,u);
+ uberSpect = new LinkingUberspector(uberSpect, u);
}
}
}
@@ -797,9 +794,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
String[] referenceinsertion = configuration.getStringArray(RuntimeConstants.EVENTHANDLER_REFERENCEINSERTION);
if ( referenceinsertion != null )
{
- for ( int i=0; i < referenceinsertion.length; i++ )
+ for (String aReferenceinsertion : referenceinsertion)
{
- EventHandler ev = initializeSpecificEventHandler(referenceinsertion[i],RuntimeConstants.EVENTHANDLER_REFERENCEINSERTION,ReferenceInsertionEventHandler.class);
+ EventHandler ev = initializeSpecificEventHandler(aReferenceinsertion, RuntimeConstants.EVENTHANDLER_REFERENCEINSERTION, ReferenceInsertionEventHandler.class);
if (ev != null)
eventCartridge.addReferenceInsertionEventHandler((ReferenceInsertionEventHandler) ev);
}
@@ -808,9 +805,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
String[] methodexception = configuration.getStringArray(RuntimeConstants.EVENTHANDLER_METHODEXCEPTION);
if ( methodexception != null )
{
- for ( int i=0; i < methodexception.length; i++ )
+ for (String aMethodexception : methodexception)
{
- EventHandler ev = initializeSpecificEventHandler(methodexception[i],RuntimeConstants.EVENTHANDLER_METHODEXCEPTION,MethodExceptionEventHandler.class);
+ EventHandler ev = initializeSpecificEventHandler(aMethodexception, RuntimeConstants.EVENTHANDLER_METHODEXCEPTION, MethodExceptionEventHandler.class);
if (ev != null)
eventCartridge.addMethodExceptionHandler((MethodExceptionEventHandler) ev);
}
@@ -819,9 +816,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
String[] includeHandler = configuration.getStringArray(RuntimeConstants.EVENTHANDLER_INCLUDE);
if ( includeHandler != null )
{
- for ( int i=0; i < includeHandler.length; i++ )
+ for (String anIncludeHandler : includeHandler)
{
- EventHandler ev = initializeSpecificEventHandler(includeHandler[i],RuntimeConstants.EVENTHANDLER_INCLUDE,IncludeEventHandler.class);
+ EventHandler ev = initializeSpecificEventHandler(anIncludeHandler, RuntimeConstants.EVENTHANDLER_INCLUDE, IncludeEventHandler.class);
if (ev != null)
eventCartridge.addIncludeEventHandler((IncludeEventHandler) ev);
}
@@ -830,9 +827,9 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
String[] invalidReferenceSet = configuration.getStringArray(RuntimeConstants.EVENTHANDLER_INVALIDREFERENCES);
if ( invalidReferenceSet != null )
{
- for ( int i=0; i < invalidReferenceSet.length; i++ )
+ for (String anInvalidReferenceSet : invalidReferenceSet)
{
- EventHandler ev = initializeSpecificEventHandler(invalidReferenceSet[i],RuntimeConstants.EVENTHANDLER_INVALIDREFERENCES,InvalidReferenceEventHandler.class);
+ EventHandler ev = initializeSpecificEventHandler(anInvalidReferenceSet, RuntimeConstants.EVENTHANDLER_INVALIDREFERENCES, InvalidReferenceEventHandler.class);
if (ev != null)
{
eventCartridge.addInvalidReferenceEventHandler((InvalidReferenceEventHandler) ev);
@@ -1024,10 +1021,10 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
String[] userdirective = configuration.getStringArray("userdirective");
- for( int i = 0; i < userdirective.length; i++)
+ for (String anUserdirective : userdirective)
{
- loadDirective(userdirective[i]);
- log.debug("Loaded User Directive: {}", userdirective[i]);
+ loadDirective(anUserdirective);
+ log.debug("Loaded User Directive: {}", anUserdirective);
}
}
@@ -1072,8 +1069,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
*/
private void updateSharedDirectivesMap()
{
- Map tmp = new HashMap(runtimeDirectives);
- runtimeDirectivesShared = tmp;
+ runtimeDirectivesShared = new HashMap(runtimeDirectives);
}
/**
@@ -1192,8 +1188,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
{
requireInitialization();
- Parser parser = new Parser(this);
- return parser;
+ return new Parser(this);
}
/**
@@ -1218,7 +1213,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
{
requireInitialization();
- Parser parser = (Parser) parserPool.get();
+ Parser parser = parserPool.get();
boolean keepParser = true;
if (parser == null)
{
@@ -1501,11 +1496,11 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices
StringBuilder template = new StringBuilder("#");
template.append(vmName);
template.append("(");
- for( int i = 0; i < params.length; i++)
- {
- template.append(" $");
- template.append(params[i]);
- }
+ for (String param : params)
+ {
+ template.append(" $");
+ template.append(param);
+ }
template.append(" )");
return evaluate(context, writer, logTag, template.toString());