diff options
author | Claude Brisson <claude@renegat.net> | 2021-02-25 16:45:03 +0100 |
---|---|---|
committer | Claude Brisson <claude@renegat.net> | 2021-02-25 16:45:03 +0100 |
commit | 746440121f2006e68e154aef91d98557a681b196 (patch) | |
tree | 2f365431837e3665c907d9a09480a7ce928e4734 /velocity-engine-core | |
parent | c0e3cc71f82fee3c4a1ebcffc398c70aef0f1dfa (diff) | |
download | apache-velocity-engine-746440121f2006e68e154aef91d98557a681b196.tar.gz |
Rebased what I could from PR #2 'Add generics parameters and remove unnecesary casts'
Diffstat (limited to 'velocity-engine-core')
25 files changed, 80 insertions, 65 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java index b23d746c..4d685441 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/Template.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/Template.java @@ -277,7 +277,7 @@ public class Template extends Resource * @throws MethodInvocationException When a method on a referenced object in the context could not invoked. * @since 1.6 */ - public void merge( Context context, Writer writer, List macroLibraries) + public void merge( Context context, Writer writer, List<String> macroLibraries) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException { try @@ -305,12 +305,12 @@ public class Template extends Resource /** * Set the macro libraries */ - List libTemplates = new ArrayList(); + List<Template> libTemplates = new ArrayList(); ica.setMacroLibraries(libTemplates); if (macroLibraries != null) { - for (String macroLibrary : (List<String>) macroLibraries) + for (String macroLibrary : macroLibraries) { /** * Build the macro library @@ -341,7 +341,7 @@ public class Template extends Resource catch (Exception e) { throw new RuntimeException("parse failed in template " + - (String) macroLibrary + ".", e); + macroLibrary + ".", e); } } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/VelocityContext.java b/velocity-engine-core/src/main/java/org/apache/velocity/VelocityContext.java index 4ab5181a..2ff326f0 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/VelocityContext.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/VelocityContext.java @@ -22,6 +22,7 @@ package org.apache.velocity; import org.apache.velocity.context.AbstractContext; import org.apache.velocity.context.Context; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -48,7 +49,9 @@ import java.util.Map; * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> * @version $Id$ */ -public class VelocityContext extends AbstractContext implements Cloneable +public class VelocityContext + extends AbstractContext + implements Cloneable, Serializable { /** * Version Id for serializable diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/FieldMethodizer.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/FieldMethodizer.java index eb29db0d..3428d1c6 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/app/FieldMethodizer.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/FieldMethodizer.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.HashMap; +import java.util.Map; /** * <p> @@ -65,7 +66,7 @@ import java.util.HashMap; public class FieldMethodizer { /** Hold the field objects by field name */ - private HashMap fieldHash = new HashMap(); + private Map<String, Field> fieldHash = new HashMap<>(); private Logger logger = LoggerFactory.getLogger(FieldMethodizer.class); /** @@ -148,7 +149,7 @@ public class FieldMethodizer Object value = null; try { - Field f = (Field) fieldHash.get( fieldName ); + Field f = fieldHash.get( fieldName ); if (f != null) { value = f.get(null); @@ -166,7 +167,7 @@ public class FieldMethodizer * Method that retrieves all public static fields * in the class we are methodizing. */ - private void inspect(Class clas) + private void inspect(Class<?> clas) { Field[] fields = clas.getFields(); for (Field field : fields) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java index b30d90f4..9661a964 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/MethodExceptionEventHandler.java @@ -48,5 +48,5 @@ public interface MethodExceptionEventHandler extends EventHandler * @return an object to insert in the page * @throws RuntimeException an exception to be thrown instead inserting an object */ - Object methodException(Context context, Class claz, String method, Exception e, Info info); + Object methodException(Context context, Class<?> claz, String method, Exception e, Info info); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java index d1d7c824..13a51532 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/PrintExceptions.java @@ -66,7 +66,7 @@ public class PrintExceptions implements MethodExceptionEventHandler, RuntimeServ * @param info template name and line, column informations * @return an object to insert in the page */ - public Object methodException(Context context, Class claz, String method, Exception e, Info info) + public Object methodException(Context context, Class<?> claz, String method, Exception e, Info info) { boolean showTemplateInfo = rs.getBoolean(SHOW_TEMPLATE_INFO, false); boolean showStackTrace = rs.getBoolean(SHOW_STACK_TRACE,false); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/ReportInvalidReferences.java b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/ReportInvalidReferences.java index c76aa17b..de09f84e 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/ReportInvalidReferences.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/app/event/implement/ReportInvalidReferences.java @@ -70,7 +70,7 @@ public class ReportInvalidReferences implements /** * List of InvalidReferenceInfo objects */ - List invalidReferences = new ArrayList(); + List<InvalidReferenceInfo> invalidReferences = new ArrayList(); /** * If true, stop at the first invalid reference and throw an exception. @@ -163,7 +163,7 @@ public class ReportInvalidReferences implements * All invalid references during the processing of this page. * @return a List of InvalidReferenceInfo objects */ - public List getInvalidReferences() + public List<InvalidReferenceInfo> getInvalidReferences() { return invalidReferences; } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/context/ChainedInternalContextAdapter.java b/velocity-engine-core/src/main/java/org/apache/velocity/context/ChainedInternalContextAdapter.java index 088251f7..2d77c4df 100755 --- a/velocity-engine-core/src/main/java/org/apache/velocity/context/ChainedInternalContextAdapter.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/context/ChainedInternalContextAdapter.java @@ -19,6 +19,7 @@ package org.apache.velocity.context; * under the License. */ +import org.apache.velocity.Template; import org.apache.velocity.app.event.EventCartridge; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.introspection.IntrospectionCacheData; @@ -211,7 +212,7 @@ public abstract class ChainedInternalContextAdapter implements InternalContextAd /** * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List) */ - public void setMacroLibraries(List macroLibraries) + public void setMacroLibraries(List<Template> macroLibraries) { wrappedContext.setMacroLibraries(macroLibraries); } @@ -219,7 +220,7 @@ public abstract class ChainedInternalContextAdapter implements InternalContextAd /** * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries() */ - public List getMacroLibraries() + public List<Template> getMacroLibraries() { return wrappedContext.getMacroLibraries(); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextAdapterImpl.java b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextAdapterImpl.java index 9ca91e47..2ed86669 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextAdapterImpl.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextAdapterImpl.java @@ -19,6 +19,7 @@ package org.apache.velocity.context; * under the License. */ +import org.apache.velocity.Template; import org.apache.velocity.app.event.EventCartridge; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.introspection.IntrospectionCacheData; @@ -226,7 +227,7 @@ public final class InternalContextAdapterImpl implements InternalContextAdapter * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List) * @since 1.6 */ - public void setMacroLibraries(List macroLibraries) + public void setMacroLibraries(List<Template> macroLibraries) { icb.setMacroLibraries(macroLibraries); } @@ -235,7 +236,7 @@ public final class InternalContextAdapterImpl implements InternalContextAdapter * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries() * @since 1.6 */ - public List getMacroLibraries() + public List<Template> getMacroLibraries() { return icb.getMacroLibraries(); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextBase.java b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextBase.java index c516dd91..d573e8e3 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextBase.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalContextBase.java @@ -19,12 +19,14 @@ package org.apache.velocity.context; * under the License. */ +import org.apache.velocity.Template; import org.apache.velocity.app.event.EventCartridge; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.introspection.IntrospectionCacheData; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Stack; /** @@ -52,7 +54,7 @@ class InternalContextBase implements InternalHousekeepingContext, InternalEventC /** * cache for node/context specific introspection information */ - private HashMap introspectionCache = new HashMap(33); + private Map<Object, IntrospectionCacheData> introspectionCache = new HashMap(33); /** * Template name stack. The stack top contains the current template name. @@ -220,7 +222,7 @@ class InternalContextBase implements InternalHousekeepingContext, InternalEventC /** * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List) */ - public void setMacroLibraries(List macroLibraries) + public void setMacroLibraries(List<Template> macroLibraries) { this.macroLibraries = macroLibraries; } @@ -228,7 +230,7 @@ class InternalContextBase implements InternalHousekeepingContext, InternalEventC /** * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries() */ - public List getMacroLibraries() + public List<Template> getMacroLibraries() { return macroLibraries; } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalHousekeepingContext.java b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalHousekeepingContext.java index 8a6b9d4e..11b03166 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalHousekeepingContext.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/context/InternalHousekeepingContext.java @@ -19,6 +19,7 @@ package org.apache.velocity.context; * under the License. */ +import org.apache.velocity.Template; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.util.introspection.IntrospectionCacheData; @@ -135,13 +136,13 @@ interface InternalHousekeepingContext * * @param macroLibraries list of macro libraries to set */ - void setMacroLibraries(List macroLibraries); + void setMacroLibraries(List<Template> macroLibraries); /** * Get the macro library list for the current template. * * @return List of macro library names */ - List getMacroLibraries(); + List<Template> getMacroLibraries(); } 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 39f3c0aa..17fd3d50 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 @@ -148,14 +148,14 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices * taken from the RUNTIME_DEFAULT_DIRECTIVES * property file. */ - private Map runtimeDirectives = new Hashtable(); + private Map<String, Directive> runtimeDirectives = new Hashtable<>(); /** * Copy of the actual runtimeDirectives that is shared between * parsers. Whenever directives are updated, the synchronized * runtimeDirectives is first updated and then an unsynchronized * copy of it is passed to parsers. */ - private Map runtimeDirectivesShared; + private Map<String, Directive> runtimeDirectivesShared; /** * Object that houses the configuration options for @@ -201,7 +201,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices * application for use in application supplied/specified * pluggable components */ - private Map applicationAttributes = null; + private Map<Object, Object> applicationAttributes = null; /** * Uberspector @@ -331,7 +331,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices this.parserPool = null; this.enabledScopeControls.clear(); this.resourceManager = null; - this.runtimeDirectives = new Hashtable(); + this.runtimeDirectives = new Hashtable<>(); this.runtimeDirectivesShared = null; this.uberSpect = null; this.stringInterning = false; @@ -345,7 +345,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices /* * and a store for the application attributes */ - applicationAttributes = new HashMap(); + applicationAttributes = new HashMap<>(); } /** @@ -1104,7 +1104,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices */ public Directive getDirective(String name) { - return (Directive) runtimeDirectivesShared.get(name); + return runtimeDirectivesShared.get(name); } /** @@ -1127,7 +1127,7 @@ public class RuntimeInstance implements RuntimeConstants, RuntimeServices */ private void updateSharedDirectivesMap() { - runtimeDirectivesShared = new HashMap(runtimeDirectives); + runtimeDirectivesShared = new HashMap<>(runtimeDirectives); } /** diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java index 7a1ea79c..b7961a5d 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/VelocimacroFactory.java @@ -95,7 +95,7 @@ public class VelocimacroFactory * map of the library Template objects * used for reload determination */ - private Map libModMap; + private Map<String, Twonk> libModMap; /** * C'tor for the VelociMacro factory. @@ -110,7 +110,7 @@ public class VelocimacroFactory * we always access in a synchronized(), so we * can use an unsynchronized hashmap */ - libModMap = new HashMap(); + libModMap = new HashMap<>(); vmManager = new VelocimacroManager(rsvc); } @@ -498,7 +498,7 @@ public class VelocimacroFactory * get the template from our map */ - Twonk tw = (Twonk) libModMap.get(lib); + Twonk tw = libModMap.get(lib); if (tw != null) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java index a1999c88..a4106ad6 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Parse.java @@ -253,14 +253,14 @@ public class Parse extends InputBase /** * Add the template name to the macro libraries list */ - List macroLibraries = context.getMacroLibraries(); + List<Template> macroLibraries = context.getMacroLibraries(); /** * if macroLibraries are not set create a new one */ if (macroLibraries == null) { - macroLibraries = new ArrayList(); + macroLibraries = new ArrayList<>(); } context.setMacroLibraries(macroLibraries); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java index 7811babf..77b9c5ce 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java @@ -86,6 +86,7 @@ public class RuntimeMacro extends Directive * * @return The name of this Velocimacro. */ + @Override public String getName() { return macroName; @@ -97,6 +98,7 @@ public class RuntimeMacro extends Directive * scope, we are within a #macro call. The macro name will instead * be used as the scope name when defining the body of a BlockMacro. */ + @Override public String getScopeName() { return "macro"; @@ -108,6 +110,7 @@ public class RuntimeMacro extends Directive * * @return The type of this directive. */ + @Override public int getType() { return LINE; @@ -250,6 +253,7 @@ public class RuntimeMacro extends Directive * @throws ParseErrorException * @throws MethodInvocationException */ + @Override public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, @@ -296,12 +300,12 @@ public class RuntimeMacro extends Directive */ if (vmProxy == null) { - List macroLibraries = context.getMacroLibraries(); + List<Template> macroLibraries = context.getMacroLibraries(); if (macroLibraries != null) { for (int i = macroLibraries.size() - 1; i >= 0; i--) { - o = rsvc.getVelocimacro(macroName, renderingTemplate, (Template)macroLibraries.get(i)); + o = rsvc.getVelocimacro(macroName, renderingTemplate, macroLibraries.get(i)); // get the first matching macro if (o != null) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java index 4fad8446..cba37d60 100755 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Scope.java @@ -36,7 +36,7 @@ import java.util.Set; public class Scope extends AbstractMap { private static final String setReturnValue = ""; - private Map storage; + private Map<Object, Object> storage; private Object replaced; private Scope parent; private Info info; @@ -62,7 +62,7 @@ public class Scope extends AbstractMap } } - private Map getStorage() + private Map<Object, Object> getStorage() { if (storage == null) { @@ -74,7 +74,7 @@ public class Scope extends AbstractMap /** * @return entry set */ - public Set entrySet() + public Set<Map.Entry<Object, Object>> entrySet() { return getStorage().entrySet(); } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java index 82a6d892..f628546c 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java @@ -71,7 +71,7 @@ public class ASTMap extends SimpleNode { int size = jjtGetNumChildren(); - Map objectMap = new LinkedHashMap(); + Map<Object, Object> objectMap = new LinkedHashMap<>(); for (int i = 0; i < size; i += 2) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java index 29a6739b..4d9b123d 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java @@ -157,7 +157,7 @@ public class ASTMethod extends SimpleNode * sadly, we do need recalc the values of the args, as this can * change from visit to visit */ - final Class[] paramClasses = + final Class<?>[] paramClasses = paramCount > 0 ? new Class[paramCount] : EMPTY_CLASS_ARRAY; for (int j = 0; j < paramCount; j++) @@ -178,7 +178,7 @@ public class ASTMethod extends SimpleNode StringBuilder plist = new StringBuilder(); for (int i = 0; i < params.length; i++) { - Class param = paramClasses[i]; + Class<?> param = paramClasses[i]; plist.append(param == null ? "null" : param.getName()); if (i < params.length - 1) plist.append(", "); @@ -342,7 +342,7 @@ public class ASTMethod extends SimpleNode /** * parameters classes */ - private final Class[] params; + private final Class<?>[] params; /** * whether the target object is of Class type @@ -353,7 +353,7 @@ public class ASTMethod extends SimpleNode */ private boolean classObject; - public MethodCacheKey(String methodName, Class[] params, boolean classObject) + public MethodCacheKey(String methodName, Class<?>[] params, boolean classObject) { /** * Should never be initialized with nulls, but to be safe we refuse @@ -412,7 +412,7 @@ public class ASTMethod extends SimpleNode * note we skip the null test for methodName and params * due to the earlier test in the constructor */ - for (Class param : params) + for (Class<?> param : params) { if (param != null) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java index d8039e9c..db4a7e53 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java @@ -68,7 +68,7 @@ public class ASTObjectArray extends SimpleNode int size = jjtGetNumChildren(); // since we know the amount of elements, initialize arraylist with proper size - List objectArray = new ArrayList(size); + List<Object> objectArray = new ArrayList<>(size); for (int i = 0; i < size; i++) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java index 0a36cf19..7ffc08f7 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/GetExecutor.java @@ -74,7 +74,7 @@ public class GetExecutor extends AbstractExecutor * @param clazz * @since 1.5 */ - protected void discover(final Class clazz) + protected void discover(final Class<?> clazz) { try { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java index 9de39929..cd597010 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MapSetExecutor.java @@ -44,10 +44,10 @@ public class MapSetExecutor discover(clazz); } - protected void discover (final Class clazz) + protected void discover (final Class<?> clazz) { - Class [] interfaces = clazz.getInterfaces(); - for (Class anInterface : interfaces) + Class<?> [] interfaces = clazz.getInterfaces(); + for (Class<?> anInterface : interfaces) { if (anInterface.equals(Map.class)) { diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java index eda542b6..b88f5bb6 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/MathUtils.java @@ -67,7 +67,7 @@ public abstract class MathUtils /** * The <code>Class</code>-object is key, the maximum-value is the value */ - private static final Map ints = new HashMap(); + private static final Map<Class<? extends Number>, BigDecimal> ints = new HashMap<>(); static { ints.put (Byte.class, BigDecimal.valueOf (Byte.MAX_VALUE)); @@ -80,7 +80,7 @@ public abstract class MathUtils /** * The "size" of the number-types - ascending. */ - private static final List typesBySize = new ArrayList(); + private static final List<Class<? extends Number>> typesBySize = new ArrayList(); static { typesBySize.add (Byte.class); diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java index fe145533..cabcb506 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java @@ -43,7 +43,7 @@ public class PropertyExecutor extends AbstractExecutor * @since 1.5 */ public PropertyExecutor(final Logger log, final Introspector introspector, - final Class clazz, final String property) + final Class<?> clazz, final String property) { this(log, introspector, clazz, property, false); } @@ -85,7 +85,7 @@ public class PropertyExecutor extends AbstractExecutor * @param clazz * @param property */ - protected void discover(final Class clazz, final String property) + protected void discover(final Class<?> clazz, final String property) { /* * this is gross and linear, but it keeps it straightforward. diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java index aa219591..b970d086 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/FileResourceLoader.java @@ -64,7 +64,7 @@ public class FileResourceLoader extends ResourceLoader * times of the files. This is synchronizedMap * instance. */ - private Map templatePaths = Collections.synchronizedMap(new HashMap()); + private Map<String, String> templatePaths = Collections.synchronizedMap(new HashMap()); /** * @see ResourceLoader#init(org.apache.velocity.util.ExtProperties) @@ -278,7 +278,7 @@ public class FileResourceLoader extends ResourceLoader boolean modified = true; String fileName = resource.getName(); - String path = (String) templatePaths.get(fileName); + String path = templatePaths.get(fileName); File currentFile = null; for (int i = 0; currentFile == null && i < paths.size(); i++) @@ -324,7 +324,7 @@ public class FileResourceLoader extends ResourceLoader */ public long getLastModified(Resource resource) { - String path = (String) templatePaths.get(resource.getName()); + String path = templatePaths.get(resource.getName()); File file = getFile(path, resource.getName()); if (file.canRead()) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java index f112a397..3dde84ad 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarHolder.java @@ -30,7 +30,9 @@ import java.io.InputStream; import java.net.JarURLConnection; import java.net.URL; import java.util.Enumeration; +import java.util.HashMap; import java.util.Hashtable; +import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -140,14 +142,14 @@ public class JarHolder /** * @return The entries of the jar as a hashtable. */ - public Hashtable getEntries() + public Map<String, String> getEntries() { - Hashtable allEntries = new Hashtable(559); + Map<String, String> allEntries = new HashMap<>(559); - Enumeration all = theJar.entries(); + Enumeration<JarEntry> all = theJar.entries(); while ( all.hasMoreElements() ) { - JarEntry je = (JarEntry)all.nextElement(); + JarEntry je = all.nextElement(); // We don't map plain directory entries if ( !je.isDirectory() ) diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java index 3adb3efb..49f4bdd3 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/JarResourceLoader.java @@ -74,14 +74,14 @@ public class JarResourceLoader extends ResourceLoader * Key = the entry *excluding* plain directories * Value = the JAR URL */ - private Map entryDirectory = new HashMap(559); + private Map<String, String> entryDirectory = new HashMap<>(559); /** * Maps JAR URLs to the actual JAR * Key = the JAR URL * Value = the JAR */ - private Map jarfiles = new HashMap(89); + private Map<String, JarHolder> jarfiles = new HashMap<>(89); /** * Called by Velocity to initialize the loader @@ -150,7 +150,7 @@ public class JarResourceLoader extends ResourceLoader { if ( jarfiles.containsKey(path) ) { - JarHolder theJar = (JarHolder)jarfiles.get(path); + JarHolder theJar = jarfiles.get(path); theJar.close(); } } @@ -159,7 +159,7 @@ public class JarResourceLoader extends ResourceLoader * Copy all the entries into the entryDirectory * It will overwrite any duplicate keys. */ - private void addEntries( Hashtable entries ) + private void addEntries( Map<String, String> entries ) { entryDirectory.putAll( entries ); } @@ -208,7 +208,7 @@ public class JarResourceLoader extends ResourceLoader if ( entryDirectory.containsKey( normalizedPath ) ) { - String jarurl = (String)entryDirectory.get( normalizedPath ); + String jarurl = entryDirectory.get( normalizedPath ); if ( jarfiles.containsKey( jarurl ) ) { |