src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 47712 bde0215f1f70
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 39907
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.bcel.internal.generic.IFEQ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 39907
diff changeset
    30
import com.sun.org.apache.bcel.internal.generic.InstructionConst;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.bcel.internal.generic.InstructionList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.bcel.internal.generic.InvokeInstruction;
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
    33
import com.sun.org.apache.bcel.internal.generic.LDC;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.bcel.internal.generic.NEW;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.bcel.internal.generic.PUSH;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    37
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.IntType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MultiHashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ObjectType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    49
import java.lang.reflect.Constructor;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    50
import java.lang.reflect.Method;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    51
import java.lang.reflect.Modifier;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    52
import java.util.ArrayList;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    53
import java.util.Collections;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    54
import java.util.HashMap;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    55
import java.util.List;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
    56
import java.util.Map;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
    57
import java.util.Objects;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 39801
diff changeset
    58
import jdk.xml.internal.JdkXmlFeatures;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * @author Erwin Bolwidt <ejb@klomp.org>
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * @author Todd Miller
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
class FunctionCall extends Expression {
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    // Name of this function call
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    private QName  _fname;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    // Arguments to this function call (might not be any)
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    72
    private final List<Expression> _arguments;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    // Empty argument list, used for certain functions
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    74
    private final static List<Expression> EMPTY_ARG_LIST = new ArrayList<>(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    // Valid namespaces for Java function-call extension
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    protected final static String EXT_XSLTC =
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        TRANSLET_URI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    protected final static String JAVA_EXT_XSLTC =
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        EXT_XSLTC + "/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    protected final static String EXT_XALAN =
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        "http://xml.apache.org/xalan";
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    protected final static String JAVA_EXT_XALAN =
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        "http://xml.apache.org/xalan/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    protected final static String JAVA_EXT_XALAN_OLD =
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        "http://xml.apache.org/xslt/java";
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    protected final static String EXSLT_COMMON =
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        "http://exslt.org/common";
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    protected final static String EXSLT_MATH =
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        "http://exslt.org/math";
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    protected final static String EXSLT_SETS =
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        "http://exslt.org/sets";
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    protected final static String EXSLT_DATETIME =
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        "http://exslt.org/dates-and-times";
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    protected final static String EXSLT_STRINGS =
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        "http://exslt.org/strings";
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   107
    protected final static String XALAN_CLASSPACKAGE_NAMESPACE =
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   108
        "xalan://";
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   109
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    // Namespace format constants
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    protected final static int NAMESPACE_FORMAT_JAVA = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    protected final static int NAMESPACE_FORMAT_CLASS = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    protected final static int NAMESPACE_FORMAT_PACKAGE = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    protected final static int NAMESPACE_FORMAT_CLASS_OR_PACKAGE = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    // Namespace format
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    private int _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * Stores reference to object for non-static Java calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
    Expression _thisArgument = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    // External Java function's class/method/signature
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    private String      _className;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   126
    private Class<?>    _clazz;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    private Method      _chosenMethod;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   128
    private Constructor<?> _chosenConstructor;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    private MethodType  _chosenMethodType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    // Encapsulates all unsupported external function calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    private boolean    unresolvedExternal;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    // If FunctionCall is a external java constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    private boolean     _isExtConstructor = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    // If the java method is static
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    private boolean       _isStatic = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    // Legal conversions between internal and Java types.
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   141
    private static final MultiHashtable<Type, JavaType> _internal2Java = new MultiHashtable<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    // Legal conversions between Java and internal types.
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   144
    private static final Map<Class<?>, Type> JAVA2INTERNAL;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    // The mappings between EXSLT extension namespaces and implementation classes
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   147
    private static final Map<String, String> EXTENSIONNAMESPACE;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    // Extension functions that are implemented in BasisLibrary
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   150
    private static final Map<String, String> EXTENSIONFUNCTION;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     * inner class to used in internal2Java mappings, contains
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     * the Java type and the distance between the internal type and
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     * the Java type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    static class JavaType {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   157
        public Class<?>  type;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
        public int distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   160
        public JavaType(Class<?> type, int distance){
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
            this.type = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
            this.distance = distance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        }
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   164
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   165
        @Override
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   166
        public int hashCode() {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   167
            return Objects.hashCode(this.type);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   168
        }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   169
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   170
        @Override
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   171
        public boolean equals(Object query) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   172
            if (query == null) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   173
                return false;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   174
            }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   175
            if (query.getClass().isAssignableFrom(JavaType.class)) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   176
                return ((JavaType)query).type.equals(type);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   177
            } else {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   178
                return query.equals(type);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   179
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     * Defines 2 conversion tables:
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     * 1. From internal types to Java types and
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * 2. From Java types to internal types.
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * These two tables are used when calling external (Java) functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    static {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   190
        final Class<?> nodeClass, nodeListClass;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        try {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   192
            nodeClass     = Class.forName("org.w3c.dom.Node");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   193
            nodeListClass = Class.forName("org.w3c.dom.NodeList");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        catch (ClassNotFoundException e) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   196
            ErrorMsg err = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR,"org.w3c.dom.Node or NodeList");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   197
            throw new Error(err.toString());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        }
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   199
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   200
        // -- Internal to Java --------------------------------------------
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   201
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   202
        // Type.Boolean -> { boolean(0), Boolean(1), Object(2) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   203
        _internal2Java.put(Type.Boolean, new JavaType(Boolean.TYPE, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   204
        _internal2Java.put(Type.Boolean, new JavaType(Boolean.class, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   205
        _internal2Java.put(Type.Boolean, new JavaType(Object.class, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   206
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   207
        // Type.Real -> { double(0), Double(1), float(2), long(3), int(4),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   208
        //                short(5), byte(6), char(7), Object(8) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   209
        _internal2Java.put(Type.Real, new JavaType(Double.TYPE, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   210
        _internal2Java.put(Type.Real, new JavaType(Double.class, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   211
        _internal2Java.put(Type.Real, new JavaType(Float.TYPE, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   212
        _internal2Java.put(Type.Real, new JavaType(Long.TYPE, 3));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   213
        _internal2Java.put(Type.Real, new JavaType(Integer.TYPE, 4));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   214
        _internal2Java.put(Type.Real, new JavaType(Short.TYPE, 5));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   215
        _internal2Java.put(Type.Real, new JavaType(Byte.TYPE, 6));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   216
        _internal2Java.put(Type.Real, new JavaType(Character.TYPE, 7));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   217
        _internal2Java.put(Type.Real, new JavaType(Object.class, 8));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   218
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   219
        // Type.Int must be the same as Type.Real
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   220
        _internal2Java.put(Type.Int, new JavaType(Double.TYPE, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   221
        _internal2Java.put(Type.Int, new JavaType(Double.class, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   222
        _internal2Java.put(Type.Int, new JavaType(Float.TYPE, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   223
        _internal2Java.put(Type.Int, new JavaType(Long.TYPE, 3));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   224
        _internal2Java.put(Type.Int, new JavaType(Integer.TYPE, 4));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   225
        _internal2Java.put(Type.Int, new JavaType(Short.TYPE, 5));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   226
        _internal2Java.put(Type.Int, new JavaType(Byte.TYPE, 6));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   227
        _internal2Java.put(Type.Int, new JavaType(Character.TYPE, 7));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   228
        _internal2Java.put(Type.Int, new JavaType(Object.class, 8));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   229
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   230
        // Type.String -> { String(0), Object(1) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   231
        _internal2Java.put(Type.String, new JavaType(String.class, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   232
        _internal2Java.put(Type.String, new JavaType(Object.class, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   233
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   234
        // Type.NodeSet -> { NodeList(0), Node(1), Object(2), String(3) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   235
        _internal2Java.put(Type.NodeSet, new JavaType(nodeListClass, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   236
        _internal2Java.put(Type.NodeSet, new JavaType(nodeClass, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   237
        _internal2Java.put(Type.NodeSet, new JavaType(Object.class, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   238
        _internal2Java.put(Type.NodeSet, new JavaType(String.class, 3));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   239
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   240
        // Type.Node -> { Node(0), NodeList(1), Object(2), String(3) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   241
        _internal2Java.put(Type.Node, new JavaType(nodeListClass, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   242
        _internal2Java.put(Type.Node, new JavaType(nodeClass, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   243
        _internal2Java.put(Type.Node, new JavaType(Object.class, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   244
        _internal2Java.put(Type.Node, new JavaType(String.class, 3));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   245
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   246
        // Type.ResultTree -> { NodeList(0), Node(1), Object(2), String(3) }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   247
        _internal2Java.put(Type.ResultTree, new JavaType(nodeListClass, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   248
        _internal2Java.put(Type.ResultTree, new JavaType(nodeClass, 1));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   249
        _internal2Java.put(Type.ResultTree, new JavaType(Object.class, 2));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   250
        _internal2Java.put(Type.ResultTree, new JavaType(String.class, 3));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   251
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   252
        _internal2Java.put(Type.Reference, new JavaType(Object.class, 0));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   253
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   254
        _internal2Java.makeUnmodifiable();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   255
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   256
        Map<Class<?>, Type> java2Internal = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   257
        Map<String, String> extensionNamespaceTable = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   258
        Map<String, String> extensionFunctionTable = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   259
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   260
        // Possible conversions between Java and internal types
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   261
        java2Internal.put(Boolean.TYPE, Type.Boolean);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   262
        java2Internal.put(Void.TYPE, Type.Void);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   263
        java2Internal.put(Character.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   264
        java2Internal.put(Byte.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   265
        java2Internal.put(Short.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   266
        java2Internal.put(Integer.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   267
        java2Internal.put(Long.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   268
        java2Internal.put(Float.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   269
        java2Internal.put(Double.TYPE, Type.Real);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   270
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   271
        java2Internal.put(String.class, Type.String);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   272
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   273
        java2Internal.put(Object.class, Type.Reference);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   274
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   275
        // Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   276
        java2Internal.put(nodeListClass, Type.NodeSet);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   277
        java2Internal.put(nodeClass, Type.NodeSet);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   278
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   279
        // Initialize the extension namespace table
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   280
        extensionNamespaceTable.put(EXT_XALAN, "com.sun.org.apache.xalan.internal.lib.Extensions");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   281
        extensionNamespaceTable.put(EXSLT_COMMON, "com.sun.org.apache.xalan.internal.lib.ExsltCommon");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   282
        extensionNamespaceTable.put(EXSLT_MATH, "com.sun.org.apache.xalan.internal.lib.ExsltMath");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   283
        extensionNamespaceTable.put(EXSLT_SETS, "com.sun.org.apache.xalan.internal.lib.ExsltSets");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   284
        extensionNamespaceTable.put(EXSLT_DATETIME, "com.sun.org.apache.xalan.internal.lib.ExsltDatetime");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   285
        extensionNamespaceTable.put(EXSLT_STRINGS, "com.sun.org.apache.xalan.internal.lib.ExsltStrings");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   286
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   287
        // Initialize the extension function table
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   288
        extensionFunctionTable.put(EXSLT_COMMON + ":nodeSet", "nodeset");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   289
        extensionFunctionTable.put(EXSLT_COMMON + ":objectType", "objectType");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   290
        extensionFunctionTable.put(EXT_XALAN + ":nodeset", "nodeset");
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   291
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   292
        JAVA2INTERNAL = Collections.unmodifiableMap(java2Internal);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   293
        EXTENSIONNAMESPACE = Collections.unmodifiableMap(extensionNamespaceTable);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   294
        EXTENSIONFUNCTION = Collections.unmodifiableMap(extensionFunctionTable);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   295
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   298
    public FunctionCall(QName fname, List<Expression> arguments) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        _fname = fname;
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
        _arguments = arguments;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        _type = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    public FunctionCall(QName fname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        this(fname, EMPTY_ARG_LIST);
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    public String getName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        return(_fname.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   312
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    public void setParser(Parser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
        super.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        if (_arguments != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            final int n = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
            for (int i = 0; i < n; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   318
                final Expression exp = _arguments.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                exp.setParser(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                exp.setParent(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    public String getClassNameFromUri(String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   327
        String className = EXTENSIONNAMESPACE.get(uri);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        if (className != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
            return className;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
            if (uri.startsWith(JAVA_EXT_XSLTC)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                int length = JAVA_EXT_XSLTC.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
            else if (uri.startsWith(JAVA_EXT_XALAN)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
                int length = JAVA_EXT_XALAN.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
            else if (uri.startsWith(JAVA_EXT_XALAN_OLD)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
                int length = JAVA_EXT_XALAN_OLD.length() + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                return (uri.length() > length) ? uri.substring(length) : EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                int index = uri.lastIndexOf('/');
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                return (index > 0) ? uri.substring(index+1) : uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
     * Type check a function call. Since different type conversions apply,
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
     * type checking is different for standard and external (Java) functions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   355
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    public Type typeCheck(SymbolTable stable)
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        throws TypeCheckError
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
        if (_type != null) return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        String local = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        if (isExtension()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
            _fname = new QName(null, null, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
            return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        else if (isStandard()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
            return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        // Handle extension functions (they all have a namespace)
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                _className = getClassNameFromUri(namespace);
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                final int pos = local.lastIndexOf('.');
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                if (pos > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                    _isStatic = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
                    if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
                        _namespace_format = NAMESPACE_FORMAT_PACKAGE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                        _className = _className + "." + local.substring(0, pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
                        _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
                        _className = local.substring(0, pos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                    _fname = new QName(namespace, null, local.substring(pos + 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
                    if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
                        try {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   393
                            _clazz = ObjectFactory.findProviderClass(_className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
                            _namespace_format = NAMESPACE_FORMAT_CLASS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
                        catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
                            _namespace_format = NAMESPACE_FORMAT_PACKAGE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
                        _namespace_format = NAMESPACE_FORMAT_JAVA;
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
                    if (local.indexOf('-') > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
                        local = replaceDash(local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   407
                    String extFunction = EXTENSIONFUNCTION.get(namespace + ":" + local);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
                    if (extFunction != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
                        _fname = new QName(null, null, extFunction);
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                        return typeCheckStandard(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                        _fname = new QName(namespace, null, local);
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                return typeCheckExternal(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
            catch (TypeCheckError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
                ErrorMsg errorMsg = e.getErrorMsg();
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
                if (errorMsg == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                    final String name = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                    errorMsg = new ErrorMsg(ErrorMsg.METHOD_NOT_FOUND_ERR, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                getParser().reportError(ERROR, errorMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
                return _type = Type.Void;
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
     * Type check a call to a standard function. Insert CastExprs when needed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
     * If as a result of the insertion of a CastExpr a type check error is
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
     * thrown, then catch it and re-throw it with a new "this".
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
    public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        _fname.clearNamespace();        // HACK!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        final int n = _arguments.size();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   439
        final List<Type> argsType = typeCheckArgs(stable);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        final MethodType args = new MethodType(Type.Void, argsType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
        final MethodType ptype =
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
            lookupPrimop(stable, _fname.getLocalPart(), args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        if (ptype != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
            for (int i = 0; i < n; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   446
                final Type argType = (Type) ptype.argsType().get(i);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   447
                final Expression exp = _arguments.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
                if (!argType.identicalTo(exp.getType())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
                    try {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   450
                        _arguments.set(i, new CastExpr(exp, argType));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
                    catch (TypeCheckError e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
                        throw new TypeCheckError(this); // invalid conversion
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
            _chosenMethodType = ptype;
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
            return _type = ptype.resultType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        throw new TypeCheckError(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
    public Type typeCheckConstructor(SymbolTable stable) throws TypeCheckError{
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   466
        final List<Constructor<?>> constructors = findConstructors();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
        if (constructors == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            // Constructor not found in this class
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
            throw new TypeCheckError(ErrorMsg.CONSTRUCTOR_NOT_FOUND,
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        final int nConstructors = constructors.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        final int nArgs = _arguments.size();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   476
        final List<Type> argsType = typeCheckArgs(stable);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
        // Try all constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
        int bestConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        _type = null;                   // reset
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
        for (int j, i = 0; i < nConstructors; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            // Check if all parameters to this constructor can be converted
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   483
            final Constructor<?> constructor = constructors.get(i);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   484
            final Class<?>[] paramTypes = constructor.getParameterTypes();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   486
            Class<?> extType;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
            int currConstrDistance = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
            for (j = 0; j < nArgs; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
                // Convert from internal (translet) type to external (Java) type
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
                extType = paramTypes[j];
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   491
                final Type intType = argsType.get(j);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   492
                JavaType match = _internal2Java.maps(intType, new JavaType(extType, 0));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
                if (match != null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   494
                    currConstrDistance += match.distance;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
                else if (intType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                    ObjectType objectType = (ObjectType)intType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
                    if (objectType.getJavaClass() == extType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
                        continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
                    else if (extType.isAssignableFrom(objectType.getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
                        currConstrDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
                        currConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
                    // no mapping available
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
                    currConstrDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
            if (j == nArgs && currConstrDistance < bestConstrDistance ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
                _chosenConstructor = constructor;
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
                _isExtConstructor = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
                bestConstrDistance = currConstrDistance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                _type = (_clazz != null) ? Type.newObjectType(_clazz)
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                    : Type.newObjectType(_className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        if (_type != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
            return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
        throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
     * Type check a call to an external (Java) method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
     * The method must be static an public, and a legal type conversion
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
     * must exist for all its arguments and its return type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
     * Every method of name <code>_fname</code> is inspected
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
     * as a possible candidate.
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
    public Type typeCheckExternal(SymbolTable stable) throws TypeCheckError {
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
        int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
        final String name = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
        // check if function is a contructor 'new'
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
        if (_fname.getLocalPart().equals("new")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
            return typeCheckConstructor(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
        // check if we are calling an instance method
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
            boolean hasThisArgument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
            if (nArgs == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
                _isStatic = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
            if (!_isStatic) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
                if (_namespace_format == NAMESPACE_FORMAT_JAVA
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                    || _namespace_format == NAMESPACE_FORMAT_PACKAGE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
                    hasThisArgument = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   559
                Expression firstArg = _arguments.get(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
                Type firstArgType = (Type)firstArg.typeCheck(stable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                if (_namespace_format == NAMESPACE_FORMAT_CLASS
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
                    && firstArgType instanceof ObjectType
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
                    && _clazz != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                    && _clazz.isAssignableFrom(((ObjectType)firstArgType).getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                    hasThisArgument = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                if (hasThisArgument) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   569
                    _thisArgument = _arguments.get(0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                    _arguments.remove(0); nArgs--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                    if (firstArgType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                        _className = ((ObjectType) firstArgType).getJavaClassName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                        throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
            else if (_className.length() == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
                /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
                 * Warn user if external function could not be resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
                 * Warning will _NOT_ be issued is the call is properly
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
                 * wrapped in an <xsl:if> or <xsl:when> element. For details
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
                 * see If.parserContents() and When.parserContents()
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
                final Parser parser = getParser();
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
                if (parser != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
                    reportWarning(this, parser, ErrorMsg.FUNCTION_RESOLVE_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
                                  _fname.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
                unresolvedExternal = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
                return _type = Type.Int;        // use "Int" as "unknown"
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   595
        final List<Method> methods = findMethods();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        if (methods == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
            // Method not found in this class
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
            throw new TypeCheckError(ErrorMsg.METHOD_NOT_FOUND_ERR, _className + "." + name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   602
        Class<?> extType = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
        final int nMethods = methods.size();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   604
        final List<Type> argsType = typeCheckArgs(stable);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
        // Try all methods to identify the best fit
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
        int bestMethodDistance  = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        _type = null;                       // reset internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
        for (int j, i = 0; i < nMethods; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
            // Check if all paramteters to this method can be converted
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   611
            final Method method = (Method)methods.get(i);
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   612
            final Class<?>[] paramTypes = method.getParameterTypes();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
            int currMethodDistance = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
            for (j = 0; j < nArgs; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
                // Convert from internal (translet) type to external (Java) type
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
                extType = paramTypes[j];
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   618
                final Type intType = argsType.get(j);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   619
                JavaType match = _internal2Java.maps(intType, new JavaType(extType, 0));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
                if (match != null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   621
                    currMethodDistance += match.distance;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
                    // no mapping available
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
                    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
                    // Allow a Reference type to match any external (Java) type at
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
                    // the moment. The real type checking is performed at runtime.
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
                    if (intType instanceof ReferenceType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
                       currMethodDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
                    else if (intType instanceof ObjectType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
                        ObjectType object = (ObjectType)intType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
                        if (extType.getName().equals(object.getJavaClassName()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
                            currMethodDistance += 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
                        else if (extType.isAssignableFrom(object.getJavaClass()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
                            currMethodDistance += 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
                        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
                            currMethodDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
                        currMethodDistance = Integer.MAX_VALUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
            if (j == nArgs) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
                  // Check if the return type can be converted
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
                  extType = method.getReturnType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 29945
diff changeset
   653
                  _type = JAVA2INTERNAL.get(extType);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
                  if (_type == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
                      _type = Type.newObjectType(extType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
                  // Use this method if all parameters & return type match
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
                  if (_type != null && currMethodDistance < bestMethodDistance) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
                      _chosenMethod = method;
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
                      bestMethodDistance = currMethodDistance;
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
        // It is an error if the chosen method is an instance menthod but we don't
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        // have a this argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        if (_chosenMethod != null && _thisArgument == null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
            !Modifier.isStatic(_chosenMethod.getModifiers())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
            throw new TypeCheckError(ErrorMsg.NO_JAVA_FUNCT_THIS_REF, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        if (_type != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
            if (_type == Type.NodeSet) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
                getXSLTC().setMultiDocument(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
            return _type;
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        throw new TypeCheckError(ErrorMsg.ARGUMENT_CONVERSION_ERR, getMethodSignature(argsType));
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
     * Type check the actual arguments of this function call.
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   686
    public List<Type> typeCheckArgs(SymbolTable stable) throws TypeCheckError {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   687
        final List<Type> result = new ArrayList<>();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   688
        for (Expression exp : _arguments) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   689
            result.add(exp.typeCheck(stable));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    protected final Expression argument(int i) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   695
        return _arguments.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
    protected final Expression argument() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
        return argument(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
    protected final int argumentCount() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
        return _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
    protected final void setArgument(int i, Expression exp) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   707
        _arguments.set(i, exp);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
     * Compile the function call and treat as an expression
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
     * Update true/false-lists.
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   714
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    public void translateDesynthesized(ClassGenerator classGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
                                       MethodGenerator methodGen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
        Type type = Type.Boolean;
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
        if (_chosenMethodType != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
            type = _chosenMethodType.resultType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
        translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
        if ((type instanceof BooleanType) || (type instanceof IntType)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
            _falseList.add(il.append(new IFEQ(null)));
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
     * Translate a function call. The compiled code will leave the function's
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
     * return value on the JVM's stack.
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
     */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   735
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
        final int n = argumentCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
        final ConstantPoolGen cpg = classGen.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        final InstructionList il = methodGen.getInstructionList();
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
        final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 17538
diff changeset
   741
        final boolean isExtensionFunctionEnabled = classGen.getParser().getXSLTC()
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 39801
diff changeset
   742
                .getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
        // Translate calls to methods in the BasisLibrary
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
        if (isStandard() || isExtension()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
            // append "F" to the function's name
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
            final String name = _fname.toString().replace('-', '_') + "F";
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
            String args = Constants.EMPTYSTRING;
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
            // Special precautions for some method calls
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
            if (name.equals("sumF")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
                args = DOM_INTF_SIG;
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
                il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
            else if (name.equals("normalize_spaceF")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
                if (_chosenMethodType.toSignature(args).
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
                    equals("()Ljava/lang/String;")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
                    args = "I"+DOM_INTF_SIG;
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
                    il.append(methodGen.loadContextNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
                    il.append(methodGen.loadDOM());
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
            // Invoke the method in the basis library
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
            index = cpg.addMethodref(BASIS_LIBRARY_CLASS, name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
                                     _chosenMethodType.toSignature(args));
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
        // Add call to BasisLibrary.unresolved_externalF() to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        // run-time error message for unsupported external functions
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
        else if (unresolvedExternal) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
            index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
                                     "unresolved_externalF",
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
                                     "(Ljava/lang/String;)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
            il.append(new PUSH(cpg, _fname.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
            il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
        else if (_isExtConstructor) {
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 17538
diff changeset
   786
            if (isSecureProcessing && !isExtensionFunctionEnabled)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
                translateUnallowedExtension(cpg, il);
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
            final String clazz =
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
                _chosenConstructor.getDeclaringClass().getName();
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   791
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   792
            // Generate call to Module.addReads:
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   793
            //   <TransletClass>.class.getModule().addReads(
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   794
            generateAddReads(classGen, methodGen, clazz);
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   795
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   796
            Class<?>[] paramTypes = _chosenConstructor.getParameterTypes();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            LocalVariableGen[] paramTemp = new LocalVariableGen[n];
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
            // Backwards branches are prohibited if an uninitialized object is
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
            // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
            // We don't know whether this code might contain backwards branches
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
            // so we mustn't create the new object until after we've created
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
            // the suspect arguments to its constructor.  Instead we calculate
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
            // the values of the arguments to the constructor first, store them
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
            // in temporary variables, create the object and reload the
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
            // arguments from the temporaries to avoid the problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
                Type expType = exp.getType();
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
                // Convert the argument to its Java type
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
                expType.translateTo(classGen, methodGen, paramTypes[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
                paramTemp[i] =
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
                    methodGen.addLocalVariable("function_call_tmp"+i,
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
                                               expType.toJCType(),
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   818
                                               null, null);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   819
                paramTemp[i].setStart(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   820
                        il.append(expType.STORE(paramTemp[i].getIndex())));
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   821
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
            il.append(new NEW(cpg.addClass(_className)));
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 39907
diff changeset
   825
            il.append(InstructionConst.DUP);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
                final Expression arg = argument(i);
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   829
                paramTemp[i].setEnd(
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   830
                        il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
            final StringBuffer buffer = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
            buffer.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
            for (int i = 0; i < paramTypes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
                buffer.append(getSignature(paramTypes[i]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
            buffer.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
            buffer.append("V");
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
            index = cpg.addMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
                                     "<init>",
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
            il.append(new INVOKESPECIAL(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
            // Convert the return type back to our internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
            (Type.Object).translateFrom(classGen, methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
                                _chosenConstructor.getDeclaringClass());
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
        // Invoke function calls that are handled in separate classes
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
        else {
21467
ed77f0ff062c 8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents: 17538
diff changeset
   853
            if (isSecureProcessing && !isExtensionFunctionEnabled)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
                translateUnallowedExtension(cpg, il);
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
            final String clazz = _chosenMethod.getDeclaringClass().getName();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   857
            Class<?>[] paramTypes = _chosenMethod.getParameterTypes();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   859
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   860
            // Generate call to Module.addReads:
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   861
            //   <TransletClass>.class.getModule().addReads(
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   862
            //        Class.forName(<clazz>).getModule());
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   863
            generateAddReads(classGen, methodGen, clazz);
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   864
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
            // Push "this" if it is an instance method
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
            if (_thisArgument != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
                _thisArgument.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
            for (int i = 0; i < n; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
                final Expression exp = argument(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
                exp.translate(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
                // Convert the argument to its Java type
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
                exp.startIterator(classGen, methodGen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
                exp.getType().translateTo(classGen, methodGen, paramTypes[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
            final StringBuffer buffer = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
            buffer.append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
            for (int i = 0; i < paramTypes.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
                buffer.append(getSignature(paramTypes[i]));
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
            buffer.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
            buffer.append(getSignature(_chosenMethod.getReturnType()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
            if (_thisArgument != null && _clazz.isInterface()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
                index = cpg.addInterfaceMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
                                     _fname.getLocalPart(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
                il.append(new INVOKEINTERFACE(index, n+1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
                index = cpg.addMethodref(clazz,
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
                                     _fname.getLocalPart(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
                                     buffer.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
                il.append(_thisArgument != null ? (InvokeInstruction) new INVOKEVIRTUAL(index) :
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
                          (InvokeInstruction) new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
            // Convert the return type back to our internal type
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
            _type.translateFrom(classGen, methodGen,
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
                                _chosenMethod.getReturnType());
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   906
    private void generateAddReads(ClassGenerator classGen, MethodGenerator methodGen,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   907
                          String clazz) {
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   908
        final ConstantPoolGen cpg = classGen.getConstantPool();
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   909
        final InstructionList il = methodGen.getInstructionList();
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   910
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   911
        // Generate call to Module.addReads:
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   912
        //   <TransletClass>.class.getModule().addReads(
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   913
        //        Class.forName(<clazz>).getModule());
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   914
        // Class.forName may throw ClassNotFoundException.
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   915
        // This is OK as it will caught higher up the stack in
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   916
        // TransformerImpl.transform() and wrapped into a
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   917
        // TransformerException.
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   918
        methodGen.markChunkStart();
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   919
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   920
        int index = cpg.addMethodref(CLASS_CLASS,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   921
                                     GET_MODULE,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   922
                                     GET_MODULE_SIG);
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   923
        int index2 = cpg.addMethodref(CLASS_CLASS,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   924
                                      FOR_NAME,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   925
                                      FOR_NAME_SIG);
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   926
        il.append(new LDC(cpg.addString(classGen.getClassName())));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   927
        il.append(new INVOKESTATIC(index2));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   928
        il.append(new INVOKEVIRTUAL(index));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   929
        il.append(new LDC(cpg.addString(clazz)));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   930
        il.append(new INVOKESTATIC(index2));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   931
        il.append(new INVOKEVIRTUAL(index));
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   932
        index = cpg.addMethodref(MODULE_CLASS,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   933
                                 ADD_READS,
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   934
                                 ADD_READS_SIG);
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   935
        il.append(new INVOKEVIRTUAL(index));
46174
5611d2529b49 8163121: BCEL: update to the latest 6.0 release
joehw
parents: 39907
diff changeset
   936
        il.append(InstructionConst.POP);
39801
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   937
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   938
        methodGen.markChunkEnd();
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   939
    }
3d0df6c4665a 8153082: Update XSLT compiler to generate classes that invoke addReads
dfuchs
parents: 35335
diff changeset
   940
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
   941
    @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
        return "funcall(" + _fname + ", " + _arguments + ')';
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
    public boolean isStandard() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
        return (namespace == null) || (namespace.equals(Constants.EMPTYSTRING));
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
    public boolean isExtension() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
        final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        return (namespace != null) && (namespace.equals(EXT_XSLTC));
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
     * Returns a vector with all methods named <code>_fname</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
     * after stripping its namespace or <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
     * if no such methods exist.
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   961
    private List<Method> findMethods() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   963
          List<Method> result = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
          final String namespace = _fname.getNamespace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
          if (_className != null && _className.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
            final int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
            try {
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   969
                if (_clazz == null) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   970
                    final boolean isSecureProcessing = getXSLTC().isSecureProcessing();
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   971
                    final boolean isExtensionFunctionEnabled = getXSLTC()
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents: 39801
diff changeset
   972
                            .getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION);
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   973
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   974
                    //Check if FSP and SM - only then process with loading
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   975
                    if (namespace != null && isSecureProcessing
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   976
                            && isExtensionFunctionEnabled
35335
7fd7d8444b50 8134861: XSLT: Extension func call cause exception if namespace URI contains partial package name
aefimov
parents: 33349
diff changeset
   977
                            && (namespace.startsWith(JAVA_EXT_XALAN)
7fd7d8444b50 8134861: XSLT: Extension func call cause exception if namespace URI contains partial package name
aefimov
parents: 33349
diff changeset
   978
                            || namespace.startsWith(JAVA_EXT_XSLTC)
7fd7d8444b50 8134861: XSLT: Extension func call cause exception if namespace URI contains partial package name
aefimov
parents: 33349
diff changeset
   979
                            || namespace.startsWith(JAVA_EXT_XALAN_OLD)
29945
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   980
                            || namespace.startsWith(XALAN_CLASSPACKAGE_NAMESPACE))) {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   981
                        _clazz = getXSLTC().loadExternalFunction(_className);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   982
                    } else {
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   983
                        _clazz = ObjectFactory.findProviderClass(_className, true);
4912169d22d3 8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents: 25868
diff changeset
   984
                    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
                if (_clazz == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
                  final ErrorMsg msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
                        new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
                  getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
              final String methodName = _fname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
              final Method[] methods = _clazz.getMethods();
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
              for (int i = 0; i < methods.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
                final int mods = methods[i].getModifiers();
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
                // Is it public and same number of args ?
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
                if (Modifier.isPublic(mods)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
                    && methods[i].getName().equals(methodName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
                    && methods[i].getParameterTypes().length == nArgs)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
                  if (result == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1004
                    result = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
                  }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1006
                  result.add(methods[i]);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
            catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
                  final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
                  getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
          return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
     * Returns a vector with all constructors named <code>_fname</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
     * after stripping its namespace or <code>null</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
     * if no such methods exist.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1023
    private List<Constructor<?>> findConstructors() {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1024
        List<Constructor<?>> result = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
        final int nArgs = _arguments.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
          if (_clazz == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1029
            _clazz = ObjectFactory.findProviderClass(_className, true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
            if (_clazz == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
              final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
              getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1037
          final Constructor<?>[] constructors = _clazz.getConstructors();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1039
            for (Constructor<?> constructor : constructors) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1040
                final int mods = constructor.getModifiers();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1041
                // Is it public, static and same number of args ?
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1042
                if (Modifier.isPublic(mods) && constructor.getParameterTypes().length == nArgs) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1043
                    if (result == null) {
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1044
                        result = new ArrayList<>();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1045
                    }   result.add(constructor);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
                }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1047
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
        catch (ClassNotFoundException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
          final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
          getParser().reportError(Constants.ERROR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
        return result;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
     * Compute the JVM signature for the class.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1061
    static final String getSignature(Class<?> clazz) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
        if (clazz.isArray()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
            final StringBuffer sb = new StringBuffer();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1064
            Class<?> cl = clazz;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
            while (cl.isArray()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
                sb.append("[");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
                cl = cl.getComponentType();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
            sb.append(getSignature(cl));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
            return sb.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
        else if (clazz.isPrimitive()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
            if (clazz == Integer.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
                return "I";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
            else if (clazz == Byte.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
                return "B";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
            else if (clazz == Long.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
                return "J";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
            else if (clazz == Float.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
                return "F";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
            else if (clazz == Double.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
                return "D";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
            else if (clazz == Short.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
                return "S";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
            else if (clazz == Character.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
                return "C";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
            else if (clazz == Boolean.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
                return "Z";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
            else if (clazz == Void.TYPE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
                return "V";
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
                final String name = clazz.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
                ErrorMsg err = new ErrorMsg(ErrorMsg.UNKNOWN_SIG_TYPE_ERR,name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
                throw new Error(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
            return "L" + clazz.getName().replace('.', '/') + ';';
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
     * Compute the JVM method descriptor for the method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
    static final String getSignature(Method meth) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
        final StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
        sb.append('(');
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1117
        final Class<?>[] params = meth.getParameterTypes(); // avoid clone
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
        for (int j = 0; j < params.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
            sb.append(getSignature(params[j]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
        return sb.append(')').append(getSignature(meth.getReturnType()))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
            .toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
     * Compute the JVM constructor descriptor for the constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1128
    static final String getSignature(Constructor<?> cons) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
        final StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
        sb.append('(');
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1131
        final Class<?>[] params = cons.getParameterTypes(); // avoid clone
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
        for (int j = 0; j < params.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
            sb.append(getSignature(params[j]));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
        return sb.append(")V").toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
     * Return the signature of the current method
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1141
    private String getMethodSignature(List<Type> argsType) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
        final StringBuffer buf = new StringBuffer(_className);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
        buf.append('.').append(_fname.getLocalPart()).append('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
        int nArgs = argsType.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
        for (int i = 0; i < nArgs; i++) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
  1147
            final Type intType = argsType.get(i);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
            buf.append(intType.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
            if (i < nArgs - 1) buf.append(", ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
        buf.append(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
        return buf.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
     * To support EXSLT extensions, convert names with dash to allowable Java names:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
     * e.g., convert abc-xyz to abcXyz.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
     * Note: dashes only appear in middle of an EXSLT function or element name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
    protected static String replaceDash(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
        char dash = '-';
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12458
diff changeset
  1164
        final StringBuilder buff = new StringBuilder("");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
        for (int i = 0; i < name.length(); i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
        if (i > 0 && name.charAt(i-1) == dash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
            buff.append(Character.toUpperCase(name.charAt(i)));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
        else if (name.charAt(i) != dash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
            buff.append(name.charAt(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
        return buff.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
     * Translate code to call the BasisLibrary.unallowed_extensionF(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
     * method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
    private void translateUnallowedExtension(ConstantPoolGen cpg,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
                                             InstructionList il) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
        int index = cpg.addMethodref(BASIS_LIBRARY_CLASS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
                                     "unallowed_extension_functionF",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
                                     "(Ljava/lang/String;)V");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
        il.append(new PUSH(cpg, _fname.toString()));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
        il.append(new INVOKESTATIC(index));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
}