Skip to content

Commit

Permalink
Simplify. No change in functionality. (Reviewing r1653857)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1653972 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Konstantin Kolinko committed Jan 22, 2015
1 parent 6f2e74a commit 8dc60b9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions java/org/apache/jasper/compiler/ELFunctionMapper.java
Expand Up @@ -21,6 +21,9 @@
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


import javax.servlet.jsp.tagext.FunctionInfo; import javax.servlet.jsp.tagext.FunctionInfo;


Expand Down Expand Up @@ -166,14 +169,12 @@ private void doMap(ELNode.Nodes el)


// Only care about functions in ELNode's // Only care about functions in ELNode's
class Fvisitor extends ELNode.Visitor { class Fvisitor extends ELNode.Visitor {
private final ArrayList<ELNode.Function> funcs = private final List<ELNode.Function> funcs = new ArrayList<>();
new ArrayList<>(); private final Set<String> keySet = new HashSet<>();
private final HashMap<String, String> keyMap = new HashMap<>();
@Override @Override
public void visit(ELNode.Function n) throws JasperException { public void visit(ELNode.Function n) throws JasperException {
String key = n.getPrefix() + ":" + n.getName(); String key = n.getPrefix() + ":" + n.getName();
if (! keyMap.containsKey(key)) { if (keySet.add(key)) {
keyMap.put(key,"");
funcs.add(n); funcs.add(n);
} }
} }
Expand All @@ -186,7 +187,7 @@ public void visit(ELNode.Function n) throws JasperException {
// First locate all unique functions in this EL // First locate all unique functions in this EL
Fvisitor fv = new Fvisitor(); Fvisitor fv = new Fvisitor();
el.visit(fv); el.visit(fv);
ArrayList<ELNode.Function> functions = fv.funcs; List<ELNode.Function> functions = fv.funcs;


if (functions.size() == 0) { if (functions.size() == 0) {
return; return;
Expand Down Expand Up @@ -219,13 +220,13 @@ public void visit(ELNode.Function n) throws JasperException {
for (int i = 0; i < functions.size(); i++) { for (int i = 0; i < functions.size(); i++) {
ELNode.Function f = functions.get(i); ELNode.Function f = functions.get(i);
FunctionInfo funcInfo = f.getFunctionInfo(); FunctionInfo funcInfo = f.getFunctionInfo();
String key = f.getPrefix()+ ":" + f.getName(); String fnQName = f.getPrefix() + ":" + f.getName();
if (funcInfo == null) { if (funcInfo == null) {
// Added via Lambda or ImportHandler. EL will expect a // Added via Lambda or ImportHandler. EL will expect a
// function mapper even if one isn't used so just pass null // function mapper even if one isn't used so just pass null
ds.append(funcMethod + "(null, null, null, null);\n"); ds.append(funcMethod + "(null, null, null, null);\n");
} else { } else {
ds.append(funcMethod + "(\"" + key + "\", " + ds.append(funcMethod + "(\"" + fnQName + "\", " +
getCanonicalName(funcInfo.getFunctionClass()) + getCanonicalName(funcInfo.getFunctionClass()) +
".class, " + '\"' + f.getMethodName() + "\", " + ".class, " + '\"' + f.getMethodName() + "\", " +
"new Class[] {"); "new Class[] {");
Expand Down Expand Up @@ -261,25 +262,23 @@ public void visit(ELNode.Function n) throws JasperException {
ds.append("});\n"); ds.append("});\n");
} }
// Put the current name in the global function map // Put the current name in the global function map
gMap.put(f.getPrefix() + ':' + f.getName() + ':' + f.getUri(), gMap.put(fnQName + ':' + f.getUri(), decName);
decName);
} }
el.setMapName(decName); el.setMapName(decName);
} }


/** /**
* Find the name of the function mapper for an EL. Reuse a * Find the name of the function mapper for an EL. Reuse a
* previously generated one if possible. * previously generated one if possible.
* @param functions An ArrayList of ELNode.Function instances that * @param functions A List of ELNode.Function instances that
* represents the functions in an EL * represents the functions in an EL
* @return A previous generated function mapper name that can be used * @return A previous generated function mapper name that can be used
* by this EL; null if none found. * by this EL; null if none found.
*/ */
private String matchMap(ArrayList<ELNode.Function> functions) { private String matchMap(List<ELNode.Function> functions) {


String mapName = null; String mapName = null;
for (int i = 0; i < functions.size(); i++) { for (ELNode.Function f : functions) {
ELNode.Function f = functions.get(i);
String temName = gMap.get(f.getPrefix() + ':' + f.getName() + String temName = gMap.get(f.getPrefix() + ':' + f.getName() +
':' + f.getUri()); ':' + f.getUri());
if (temName == null) { if (temName == null) {
Expand Down

0 comments on commit 8dc60b9

Please sign in to comment.