src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodType.java
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
equal deleted inserted replaced
47358:d07d5f7cab35 47359:e1a6c0168741
     1 /*
     1 /*
     2  * reserved comment block
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT REMOVE OR ALTER!
     3  * @LastModified: Oct 2017
     4  */
     4  */
     5 /*
     5 /*
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
     7  * contributor license agreements.  See the NOTICE file distributed with
     7  * contributor license agreements.  See the NOTICE file distributed with
     8  * this work for additional information regarding copyright ownership.
     8  * this work for additional information regarding copyright ownership.
    19  * limitations under the License.
    19  * limitations under the License.
    20  */
    20  */
    21 
    21 
    22 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
    22 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
    23 
    23 
    24 import java.util.Vector;
    24 import java.util.ArrayList;
       
    25 import java.util.List;
    25 
    26 
    26 /**
    27 /**
    27  * @author Jacek Ambroziak
    28  * @author Jacek Ambroziak
    28  * @author Santiago Pericas-Geertsen
    29  * @author Santiago Pericas-Geertsen
    29  */
    30  */
    30 public final class MethodType extends Type {
    31 public final class MethodType extends Type {
    31     private final Type _resultType;
    32     private final Type _resultType;
    32     private final Vector _argsType;
    33     private final List<Type> _argsType;
    33 
    34 
    34     public MethodType(Type resultType) {
    35     public MethodType(Type resultType) {
    35         _argsType = null;
    36         _argsType = null;
    36         _resultType = resultType;
    37         _resultType = resultType;
    37     }
    38     }
    38 
    39 
    39     public MethodType(Type resultType, Type arg1) {
    40     public MethodType(Type resultType, Type arg1) {
    40         if (arg1 != Type.Void) {
    41         if (arg1 != Type.Void) {
    41             _argsType = new Vector();
    42             _argsType = new ArrayList<>();
    42             _argsType.addElement(arg1);
    43             _argsType.add(arg1);
    43         }
    44         }
    44         else {
    45         else {
    45             _argsType = null;
    46             _argsType = null;
    46         }
    47         }
    47         _resultType = resultType;
    48         _resultType = resultType;
    48     }
    49     }
    49 
    50 
    50     public MethodType(Type resultType, Type arg1, Type arg2) {
    51     public MethodType(Type resultType, Type arg1, Type arg2) {
    51         _argsType = new Vector(2);
    52         _argsType = new ArrayList<>(2);
    52         _argsType.addElement(arg1);
    53         _argsType.add(arg1);
    53         _argsType.addElement(arg2);
    54         _argsType.add(arg2);
    54         _resultType = resultType;
    55         _resultType = resultType;
    55     }
    56     }
    56 
    57 
    57     public MethodType(Type resultType, Type arg1, Type arg2, Type arg3) {
    58     public MethodType(Type resultType, Type arg1, Type arg2, Type arg3) {
    58         _argsType = new Vector(3);
    59         _argsType = new ArrayList<>(3);
    59         _argsType.addElement(arg1);
    60         _argsType.add(arg1);
    60         _argsType.addElement(arg2);
    61         _argsType.add(arg2);
    61         _argsType.addElement(arg3);
    62         _argsType.add(arg3);
    62         _resultType = resultType;
    63         _resultType = resultType;
    63     }
    64     }
    64 
    65 
    65     public MethodType(Type resultType, Vector argsType) {
    66     public MethodType(Type resultType, List<Type> argsType) {
    66         _resultType = resultType;
    67         _resultType = resultType;
    67         _argsType = argsType.size() > 0 ? argsType : null;
    68         _argsType = argsType.size() > 0 ? argsType : null;
    68     }
    69     }
    69 
    70 
    70     public String toString() {
    71     public String toString() {
    71         StringBuffer result = new StringBuffer("method{");
    72         StringBuffer result = new StringBuffer("method{");
    72         if (_argsType != null) {
    73         if (_argsType != null) {
    73             final int count = _argsType.size();
    74             final int count = _argsType.size();
    74             for (int i=0; i<count; i++) {
    75             for (int i=0; i<count; i++) {
    75                 result.append(_argsType.elementAt(i));
    76                 result.append(_argsType.get(i));
    76                 if (i != (count-1)) result.append(',');
    77                 if (i != (count-1)) result.append(',');
    77             }
    78             }
    78         }
    79         }
    79         else {
    80         else {
    80             result.append("void");
    81             result.append("void");
    95         final StringBuffer buffer = new StringBuffer();
    96         final StringBuffer buffer = new StringBuffer();
    96         buffer.append('(');
    97         buffer.append('(');
    97         if (_argsType != null) {
    98         if (_argsType != null) {
    98             final int n = _argsType.size();
    99             final int n = _argsType.size();
    99             for (int i = 0; i < n; i++) {
   100             for (int i = 0; i < n; i++) {
   100                 buffer.append(((Type)_argsType.elementAt(i)).toSignature());
   101                 buffer.append((_argsType.get(i)).toSignature());
   101             }
   102             }
   102         }
   103         }
   103         return buffer
   104         return buffer
   104             .append(lastArgSig)
   105             .append(lastArgSig)
   105             .append(')')
   106             .append(')')
   117             final MethodType temp = (MethodType) other;
   118             final MethodType temp = (MethodType) other;
   118             if (_resultType.identicalTo(temp._resultType)) {
   119             if (_resultType.identicalTo(temp._resultType)) {
   119                 final int len = argsCount();
   120                 final int len = argsCount();
   120                 result = len == temp.argsCount();
   121                 result = len == temp.argsCount();
   121                 for (int i = 0; i < len && result; i++) {
   122                 for (int i = 0; i < len && result; i++) {
   122                     final Type arg1 = (Type)_argsType.elementAt(i);
   123                     final Type arg1 = _argsType.get(i);
   123                     final Type arg2 = (Type)temp._argsType.elementAt(i);
   124                     final Type arg2 = temp._argsType.get(i);
   124                     result = arg1.identicalTo(arg2);
   125                     result = arg1.identicalTo(arg2);
   125                 }
   126                 }
   126             }
   127             }
   127         }
   128         }
   128         return result;
   129         return result;
   135             if (_argsType != null) {
   136             if (_argsType != null) {
   136                 final int len = _argsType.size();
   137                 final int len = _argsType.size();
   137                 if (len == mtype._argsType.size()) {
   138                 if (len == mtype._argsType.size()) {
   138                     result = 0;
   139                     result = 0;
   139                     for (int i = 0; i < len; i++) {
   140                     for (int i = 0; i < len; i++) {
   140                         Type arg1 = (Type) _argsType.elementAt(i);
   141                         Type arg1 = _argsType.get(i);
   141                         Type arg2 = (Type) mtype._argsType.elementAt(i);
   142                         Type arg2 = mtype._argsType.get(i);
   142                         final int temp = arg1.distanceTo(arg2);
   143                         final int temp = arg1.distanceTo(arg2);
   143                         if (temp == Integer.MAX_VALUE) {
   144                         if (temp == Integer.MAX_VALUE) {
   144                             result = temp;  // return MAX_VALUE
   145                             result = temp;  // return MAX_VALUE
   145                             break;
   146                             break;
   146                         }
   147                         }
   159 
   160 
   160     public Type resultType() {
   161     public Type resultType() {
   161         return _resultType;
   162         return _resultType;
   162     }
   163     }
   163 
   164 
   164     public Vector argsType() {
   165     public List<Type> argsType() {
   165         return _argsType;
   166         return _argsType;
   166     }
   167     }
   167 
   168 
   168     public int argsCount() {
   169     public int argsCount() {
   169         return _argsType == null ? 0 : _argsType.size();
   170         return _argsType == null ? 0 : _argsType.size();