--- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java Tue Sep 05 13:40:14 2017 +0200
+++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java Wed Oct 18 13:25:49 2017 -0700
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * @LastModified: Oct 2017
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -48,12 +49,12 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Vector;
import jdk.xml.internal.JdkXmlFeatures;
/**
@@ -68,9 +69,9 @@
// Name of this function call
private QName _fname;
// Arguments to this function call (might not be any)
- private final Vector _arguments;
+ private final List<Expression> _arguments;
// Empty argument list, used for certain functions
- private final static Vector EMPTY_ARG_LIST = new Vector(0);
+ private final static List<Expression> EMPTY_ARG_LIST = new ArrayList<>(0);
// Valid namespaces for Java function-call extension
protected final static String EXT_XSLTC =
@@ -122,9 +123,9 @@
// External Java function's class/method/signature
private String _className;
- private Class _clazz;
+ private Class<?> _clazz;
private Method _chosenMethod;
- private Constructor _chosenConstructor;
+ private Constructor<?> _chosenConstructor;
private MethodType _chosenMethodType;
// Encapsulates all unsupported external function calls
@@ -156,7 +157,7 @@
public Class<?> type;
public int distance;
- public JavaType(Class type, int distance){
+ public JavaType(Class<?> type, int distance){
this.type = type;
this.distance = distance;
}
@@ -294,7 +295,7 @@
}
- public FunctionCall(QName fname, Vector arguments) {
+ public FunctionCall(QName fname, List<Expression> arguments) {
_fname = fname;
_arguments = arguments;
_type = null;
@@ -314,7 +315,7 @@
if (_arguments != null) {
final int n = _arguments.size();
for (int i = 0; i < n; i++) {
- final Expression exp = (Expression)_arguments.elementAt(i);
+ final Expression exp = _arguments.get(i);
exp.setParser(parser);
exp.setParent(this);
}
@@ -435,18 +436,18 @@
_fname.clearNamespace(); // HACK!!!
final int n = _arguments.size();
- final Vector argsType = typeCheckArgs(stable);
+ final List<Type> argsType = typeCheckArgs(stable);
final MethodType args = new MethodType(Type.Void, argsType);
final MethodType ptype =
lookupPrimop(stable, _fname.getLocalPart(), args);
if (ptype != null) {
for (int i = 0; i < n; i++) {
- final Type argType = (Type) ptype.argsType().elementAt(i);
- final Expression exp = (Expression)_arguments.elementAt(i);
+ final Type argType = (Type) ptype.argsType().get(i);
+ final Expression exp = _arguments.get(i);
if (!argType.identicalTo(exp.getType())) {
try {
- _arguments.setElementAt(new CastExpr(exp, argType), i);
+ _arguments.set(i, new CastExpr(exp, argType));
}
catch (TypeCheckError e) {
throw new TypeCheckError(this); // invalid conversion
@@ -462,7 +463,7 @@
public Type typeCheckConstructor(SymbolTable stable) throws TypeCheckError{
- final Vector constructors = findConstructors();
+ final List<Constructor<?>> constructors = findConstructors();
if (constructors == null) {
// Constructor not found in this class
throw new TypeCheckError(ErrorMsg.CONSTRUCTOR_NOT_FOUND,
@@ -472,23 +473,22 @@
final int nConstructors = constructors.size();
final int nArgs = _arguments.size();
- final Vector argsType = typeCheckArgs(stable);
+ final List<Type> argsType = typeCheckArgs(stable);
// Try all constructors
int bestConstrDistance = Integer.MAX_VALUE;
_type = null; // reset
for (int j, i = 0; i < nConstructors; i++) {
// Check if all parameters to this constructor can be converted
- final Constructor constructor =
- (Constructor)constructors.elementAt(i);
- final Class[] paramTypes = constructor.getParameterTypes();
+ final Constructor<?> constructor = constructors.get(i);
+ final Class<?>[] paramTypes = constructor.getParameterTypes();
Class<?> extType;
int currConstrDistance = 0;
for (j = 0; j < nArgs; j++) {
// Convert from internal (translet) type to external (Java) type
extType = paramTypes[j];
- final Type intType = (Type)argsType.elementAt(j);
+ final Type intType = argsType.get(j);
JavaType match = _internal2Java.maps(intType, new JavaType(extType, 0));
if (match != null) {
currConstrDistance += match.distance;
@@ -556,7 +556,7 @@
|| _namespace_format == NAMESPACE_FORMAT_PACKAGE)
hasThisArgument = true;
- Expression firstArg = (Expression)_arguments.elementAt(0);
+ Expression firstArg = _arguments.get(0);
Type firstArgType = (Type)firstArg.typeCheck(stable);
if (_namespace_format == NAMESPACE_FORMAT_CLASS
@@ -566,7 +566,7 @@
hasThisArgument = true;
if (hasThisArgument) {
- _thisArgument = (Expression) _arguments.elementAt(0);
+ _thisArgument = _arguments.get(0);
_arguments.remove(0); nArgs--;
if (firstArgType instanceof ObjectType) {
_className = ((ObjectType) firstArgType).getJavaClassName();
@@ -592,30 +592,30 @@
}
}
- final Vector methods = findMethods();
+ final List<Method> methods = findMethods();
if (methods == null) {
// Method not found in this class
throw new TypeCheckError(ErrorMsg.METHOD_NOT_FOUND_ERR, _className + "." + name);
}
- Class extType = null;
+ Class<?> extType = null;
final int nMethods = methods.size();
- final Vector argsType = typeCheckArgs(stable);
+ final List<Type> argsType = typeCheckArgs(stable);
// Try all methods to identify the best fit
int bestMethodDistance = Integer.MAX_VALUE;
_type = null; // reset internal type
for (int j, i = 0; i < nMethods; i++) {
// Check if all paramteters to this method can be converted
- final Method method = (Method)methods.elementAt(i);
- final Class[] paramTypes = method.getParameterTypes();
+ final Method method = (Method)methods.get(i);
+ final Class<?>[] paramTypes = method.getParameterTypes();
int currMethodDistance = 0;
for (j = 0; j < nArgs; j++) {
// Convert from internal (translet) type to external (Java) type
extType = paramTypes[j];
- final Type intType = (Type)argsType.elementAt(j);
+ final Type intType = argsType.get(j);
JavaType match = _internal2Java.maps(intType, new JavaType(extType, 0));
if (match != null) {
currMethodDistance += match.distance;
@@ -683,18 +683,16 @@
/**
* Type check the actual arguments of this function call.
*/
- public Vector typeCheckArgs(SymbolTable stable) throws TypeCheckError {
- final Vector result = new Vector();
- final Enumeration e = _arguments.elements();
- while (e.hasMoreElements()) {
- final Expression exp = (Expression)e.nextElement();
- result.addElement(exp.typeCheck(stable));
+ public List<Type> typeCheckArgs(SymbolTable stable) throws TypeCheckError {
+ final List<Type> result = new ArrayList<>();
+ for (Expression exp : _arguments) {
+ result.add(exp.typeCheck(stable));
}
return result;
}
protected final Expression argument(int i) {
- return (Expression)_arguments.elementAt(i);
+ return _arguments.get(i);
}
protected final Expression argument() {
@@ -706,7 +704,7 @@
}
protected final void setArgument(int i, Expression exp) {
- _arguments.setElementAt(exp, i);
+ _arguments.set(i, exp);
}
/**
@@ -795,7 +793,7 @@
// <TransletClass>.class.getModule().addReads(
generateAddReads(classGen, methodGen, clazz);
- Class[] paramTypes = _chosenConstructor.getParameterTypes();
+ Class<?>[] paramTypes = _chosenConstructor.getParameterTypes();
LocalVariableGen[] paramTemp = new LocalVariableGen[n];
// Backwards branches are prohibited if an uninitialized object is
@@ -856,7 +854,7 @@
translateUnallowedExtension(cpg, il);
final String clazz = _chosenMethod.getDeclaringClass().getName();
- Class[] paramTypes = _chosenMethod.getParameterTypes();
+ Class<?>[] paramTypes = _chosenMethod.getParameterTypes();
// Generate call to Module.addReads:
@@ -960,9 +958,9 @@
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
- private Vector findMethods() {
+ private List<Method> findMethods() {
- Vector result = null;
+ List<Method> result = null;
final String namespace = _fname.getNamespace();
if (_className != null && _className.length() > 0) {
@@ -1003,9 +1001,9 @@
&& methods[i].getParameterTypes().length == nArgs)
{
if (result == null) {
- result = new Vector();
+ result = new ArrayList<>();
}
- result.addElement(methods[i]);
+ result.add(methods[i]);
}
}
}
@@ -1022,9 +1020,8 @@
* after stripping its namespace or <code>null</code>
* if no such methods exist.
*/
- private Vector findConstructors() {
- Vector result = null;
- final String namespace = _fname.getNamespace();
+ private List<Constructor<?>> findConstructors() {
+ List<Constructor<?>> result = null;
final int nArgs = _arguments.size();
try {
@@ -1037,20 +1034,17 @@
}
}
- final Constructor[] constructors = _clazz.getConstructors();
+ final Constructor<?>[] constructors = _clazz.getConstructors();
- for (int i = 0; i < constructors.length; i++) {
- final int mods = constructors[i].getModifiers();
- // Is it public, static and same number of args ?
- if (Modifier.isPublic(mods) &&
- constructors[i].getParameterTypes().length == nArgs)
- {
- if (result == null) {
- result = new Vector();
+ for (Constructor<?> constructor : constructors) {
+ final int mods = constructor.getModifiers();
+ // Is it public, static and same number of args ?
+ if (Modifier.isPublic(mods) && constructor.getParameterTypes().length == nArgs) {
+ if (result == null) {
+ result = new ArrayList<>();
+ } result.add(constructor);
}
- result.addElement(constructors[i]);
- }
- }
+ }
}
catch (ClassNotFoundException e) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
@@ -1064,10 +1058,10 @@
/**
* Compute the JVM signature for the class.
*/
- static final String getSignature(Class clazz) {
+ static final String getSignature(Class<?> clazz) {
if (clazz.isArray()) {
final StringBuffer sb = new StringBuffer();
- Class cl = clazz;
+ Class<?> cl = clazz;
while (cl.isArray()) {
sb.append("[");
cl = cl.getComponentType();
@@ -1120,7 +1114,7 @@
static final String getSignature(Method meth) {
final StringBuffer sb = new StringBuffer();
sb.append('(');
- final Class[] params = meth.getParameterTypes(); // avoid clone
+ final Class<?>[] params = meth.getParameterTypes(); // avoid clone
for (int j = 0; j < params.length; j++) {
sb.append(getSignature(params[j]));
}
@@ -1131,10 +1125,10 @@
/**
* Compute the JVM constructor descriptor for the constructor.
*/
- static final String getSignature(Constructor cons) {
+ static final String getSignature(Constructor<?> cons) {
final StringBuffer sb = new StringBuffer();
sb.append('(');
- final Class[] params = cons.getParameterTypes(); // avoid clone
+ final Class<?>[] params = cons.getParameterTypes(); // avoid clone
for (int j = 0; j < params.length; j++) {
sb.append(getSignature(params[j]));
}
@@ -1144,13 +1138,13 @@
/**
* Return the signature of the current method
*/
- private String getMethodSignature(Vector argsType) {
+ private String getMethodSignature(List<Type> argsType) {
final StringBuffer buf = new StringBuffer(_className);
buf.append('.').append(_fname.getLocalPart()).append('(');
int nArgs = argsType.size();
for (int i = 0; i < nArgs; i++) {
- final Type intType = (Type)argsType.elementAt(i);
+ final Type intType = argsType.get(i);
buf.append(intType.toString());
if (i < nArgs - 1) buf.append(", ");
}