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/src/main/java/org/apache/velocity/runtime | |
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/src/main/java/org/apache/velocity/runtime')
15 files changed, 50 insertions, 44 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 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 ) ) { |