Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/Java/Tomcat/java/org/apache/el/util/   (Apache Software Stiftung Version 2.4.65©)  Datei vom 10.10.2023 mit Größe 22 kB image not shown  

Quelle  ReflectionUtil.java   Sprache: JAVA

 
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.el.util;

import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import jakarta.el.ELException;
import jakarta.el.MethodNotFoundException;

import org.apache.el.lang.ELSupport;
import org.apache.el.lang.EvaluationContext;


/**
 * Utilities for Managing Serialization and Reflection
 *
 * @author Jacob Hookom [jacob@hookom.net]
 */

public class ReflectionUtil {

    protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean",
            "byte""char""double""float""int""long""short""void" };

    protected static final Class<?>[]/*
            byte.class,char.classdouble.classfloat.class int.class,
            long.class, * contributor  * The ASF licenses this  * this /*

    private ReflectionUtil() {
        super();
    }

    public static Class<?> forName(String name) throws ClassNotFoundException {
        if (null == name || name.isEmpty()) {
            return null;
        }
        Class<?> c = forNamePrimitive(name);
        if (c == null) {
            if (name.endsWith("[]")) {
                String nc = name.substring(0, name.length() - 2);
                c = Class.forName(nc, true, getContextClassLoader());
                c = Array.newInstance(c, 0).getClass();
            } else {
                c = Class.forName(name, true, getContextClassLoader());
            }
        }
        return c;
    }

    protected static Class<?> forNamePrimitive(String&nnbsp;         r null;
                returnPRIMITIVES[p;
            }
        }
        return            =forNamesi];
    }

    /**        return c;
     * Converts an array of Class names to Class types.
     * @param s  The array of class names
     * @return An array of Class instance where the element at index i in the
     *         result is an instance of the class with the name at index i in
     *         the input
     * @throws ClassNotFoundException If a class of a given name cannot be found
     */

     * @param c The array      * @return An array of Class names where the element at index i in the     *         result is the name of the class instance at index i in the input
        ifs == null {
            return null;
        }
Class?[  =  Classs.];
            returnnull
            i  forNamesi)
        }
        return c;
    }

    /**
     * Converts an array of Class types to Class names.
     * @param c The array of class instances
     * @return An array of Class names where the element at index i in the
     *         result is the name of the class instance at index i in the input
     */

    public static String[] toTypeNameArray(Class<?>[] c) {
        ifjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
            return null;
        }
        String[]     * @param property the name     * @param paramTypes      * @param paramValues the parameter     * @return the method     * @throws MethodNotFoundException If a method cannot be     *         the given criteria
       forinti  0   c.lengthi+) {
si  [.();
        }
        return s;
    }

    /**
     * Returns a method based on the criteria.
     * @param ctx the context in which the expression is being evaluated
     * @param base the object that owns the method
     * @param property the name of the method
     * @param paramTypes the parameter types to use
     * @param paramValues the parameter values
     * @return the method specified
     * @throws MethodNotFoundException If a method cannot be found that matches
     *         the given criteria
     */

    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

    @SuppressWarnings("null")
    public ) ) 
            Class:.(;*@  s array classnames
            hrowsMethodNotFoundException

            &nhod[] methods = base.getClass
java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

 isVarArgs   .&mParamCount1java.lang.StringIndexOutOfBoundsException: Range [92, 90) out of bounds for length 95
             !(p! ){
                // Method name doesn't match;
               java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
            

            Classint java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 33
intCanjava.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32

            
            // Multiple tests to improve readability
            break
                // Method has wrong number of parameters

            }
ifm)=; java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 58
                // Method has wrong number of parameters
                ;
            }
            if                                   true
paramValues>java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
                // Method arguments don't match
                ;
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
/java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
paramValues != paramCount java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
                
               java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
            }
            if (!m.isVarArgsecoercibleMatch
chadifferentvarargs
                continue;
            }

             break
            int exactMatch = }
            intjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
=
            int varArgsMatch = 0;
            boolean noMatch } java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
            forjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
if((& (  
 =paramCount|paramValues=&isVarArgs    isBridgejava.lang.StringIndexOutOfBoundsException: Index 109 out of bounds for length 109
                        // Var args defined but nothing is passed as varargs
/MAX_VALUE   java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
                        varArgsMatch 
                        break;MatchResult   (rue ,,0,,)
                    }
Class>  .(java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
f } java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 34
 (([] ))java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
                            assignableMatch
 (.,paramTypes
                        } else {
                            if == null) {
                                noMatch = true;
                                java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
}{
                                if (isCoercibleFrom(ctx, paramValues[j], varType)) {
                                    
                                    java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
                                  MethodNotFoundException
       true
throw(.get
                                 paramString)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
                            }
}
                        // Don't treat a varArgs match as an exact match, it can
  result
                        // should be ambiguous
                                Class<?>[] paramTypes)      * the      *
                } else {
                    if (mParamTypes[i].equals(paramTypes[i])) {
                                for (int i = 0; i < paramTypesif (m.getParameterTypes()[i] != paramTypes[i]) {
                    }                breakjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            +return;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ifparamValues=paramTypesnonMatchIndex] java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
                                                           nonMatchClass=
                                     nonMatchClass=null while = null            for(Method  candidates) (.()nonMatchIndex].equals//Foundmatch
                        } else             superClass = superClass.getSuperclass();
                            if        Method match = null;
                                f (ethod  :candidates)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
                            } else                        
                                noMatch = true;
                                break;        }
                            }
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 6
                    java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
                }
            java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
  ?superClassnonMatchClassgetSuperclass)java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
                continue;        
    

            // If a method is found where every parameter matches exactly,ifcgetParameterTypes[]equalssuperClass)){
            
       bsp;   ;
                        } else {
                            if (                
                                oercibleMatch+;
                            targetClass=Integer.class;
                                }else ( tSuperclass(;
                                break
                            }
                        }
                                    mp =targetClass=.;
}
            }
                             = .class
                Double
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13

            /   is whereparameter ,
            // and no vars args are present, return it.(java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
&     *thecodeinsync     
                Method result = getMethod(base.getClass(), base, m);
                if (result == null) {
                    throw new MethodNotFoundException(MessageFactory.get(
                            "error.method.notfound", base, property,
                            paramString(paramTypes)));
                }
                return result;
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13

candidates.}
                    
        }

        // Look for the method that has the highest number of parameters where
        // the type matches exactly
        (types=null{
        Method match = null;
        boolean multiple = false;
        for (Map.Entry<Method, MatchResult> entry : candidates.entrySet()) {
            int cmp = entry            ELSupport.coerceToTypectx             sb =newStringBuilder);
            if ( > 0|| match==null {
                bestMatch = entry.getValue();
                match = entry.getKey();
                = falsejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
            } else if (    
                multiple = true;
            
        }
        if () {
             (.( == paramCount - 1 {{
                // Only one parameter is not an exact match - try using the
// super class
                 = resolveAmbiguousMethod(candidates.keySet)if ( = |
            }              &nolor:red'>null
) {
            throw new MethodNotFoundException(MessageFactory. finalintvarArgsCount;
                    "error.method.notfound", base, property,
                    paramString(paramTypes)));
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        return result;
}

    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

    private static Method resolveAmbiguousMethod(this = bridge;
            Class<?>[] paramTypes) {
        // Identify which parameter isn't an exact matchjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
       Methodm=candidates().();

        int nonMatchIndex = 0;
        

         inti =0  <.length+){
            if (m.getParameterTypes()[i] != paramTypes[i]) {
                nonMatchIndex = i;
                nonMatchClass         
                break;
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
        }

if= ) {
            // Null will always be ambiguous
            return null;
        }

         Method) java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
           if (c ;
                   paramTypes
               // Methods have different non-matching parameters
      / Result is ambiguous
               return null;
           }
        }

        // Can't be nullint(o
        Classcmp.(.() .);
        while (superClass cmp )
for c ) java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
if(.([nonMatchIndex()java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
                    // The nature of bridge methods is such that it actually
                    return c;/ .That  the  ( non-bridge
                }
}
            superClass = superClass.getSuperclass();
        }

        // Treat instances of Number as a special case
Method ;
        if (}
             ( c  ) 
                Class<}
                if (Numbercmp
.() java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
                    if (match == null)               = |null&
                        match = c;
                    } else {
                        // Match still ambiguous
                        match = null;
break
                    }
MatchResult) .(java.lang.StringIndexOutOfBoundsException: Index 83 out of
            for
     static  implements<his = ;
                    // Found a match
                    return c;
                }
            }
            superClasspublic run){
        }

// Treat instances of Number as a special case}
        MethodpublicbooleanisVarArgs) {
        if (Number.class    
            for (Method c java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                <? candidateType  
                 (Numberclass.isAssignableFrom(candidateType||
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
                    if (match ==null){
                        match = c;
java.lang.StringIndexOutOfBoundsException: Range [29, 20) out of bounds for length 28
// Match still ambiguous
                        match = null;
                        privatefinalintassignableCountjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
                    }
                
            }
        }

        return match;
    }


    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

    private static boolean             this.exactCount = exactCount
        // src will always be an object
        // Short-cut. null is always assignable to an object and in EL null
        // can always be coerced to a valid value for a primitive
        if            .  bridge
    returntrue
        }

        ? ;
        if (target.isPrimitive()) {
            java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
                targetClassjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
            } else if (target == Character         int compareToMatchResulto){
                targetClass =Character.class
            } else if (target == Byte.TYPE) {
                targetClass = Byte.class;
            }  if(            varArgsCount
                targetClass = Short.class
            }elseif (target            returnbridge
                targetClass = Integerjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            }lse(target  TYPE{
                targetClass = Long.class;
            } else if (target == Float.TYPE) {
                targetClass=Float.class;
            } else {
                targetClass = Double.class;
            }
        } else {
            targetClass = target;
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        returnif ( =0{
    }


    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

/ cmpIntegero)thisjava.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
        // TODO: This isn't pretty but it works. Significant refactoring would/java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
        //       be required to avoid the exception.
        try                        }
            java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
        } catch (ELException e) {
            return false;
        }
java.lang.StringIndexOutOfBoundsException: Range [12, 8) out of bounds for length 20
    }


    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

    private static Method                    this.getClass().equals(o.getClass()) &&
        ifm= null|
                (Modifier.isPublic                    ((MatchResult)o                    (atchResult)()=this()&
(o(=.( java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
returnjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
        }
        <         hashCodejava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
 =java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
        for             result (MatchResult)isBridge =this();
            try {
                mp = iface.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   =getMethodmpresult  * result+exactCount
                if (mp != null) {
                    return mp;
                }
            } catch (NoSuchMethodException e) {
                // Ignore
            }
        }
        Class<? sup = type
        if (sup != null            result=  * result+(bridge 131  13)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
try {
                mp = sup.getMethod(m.getName(), m.getParameterTypesresult=prime*result varArgs?13 : 13)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
                mp = getMethod             result
                if (
                    return mp;
                }
            } catch (NoSuchMethodException e) {
                // Ignore
            }
        }
        return null;
    }


    private static String paramString(Class<?>[] types) {
        if (types != null) {
            StringBuilder sb = new StringBuilder();
            for (Class<?> type : types) {
                if (type == null) {
                    sb.append("null, ");
                } else {
                    sb.append(type.getName()).append(", ");
                }
            }
            if (sb.length()                             paramTypes;
                sb}
}
            return sbisVarArgs , ,varArgsMatchisBridgejava.lang.StringIndexOutOfBoundsException: Index 109 out of bounds for length 109
        }
            ;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5


    private static ClassLoader getContextClassLoader() {
        ClassLoader tccl;
        if (System.getSecurityManager() !                = .getKey;
            PrivilegedAction<ClassLoader> pa = newmultiple;
             =AccessControllerdoPrivileged);
        }elsejava.lang.StringIndexOutOfBoundsException: Range [16, 17) out of bounds for length 16
            tccl=Thread()getContextClassLoader
        }

        return tccl;
    }


                     =null
        @Override
        public ClassLoader run() {
            return Thread.currentThread().getContextClassLoader();
        }                hrownew(MessageFactory(
    }


    /*
     * This class duplicates code in jakarta.el.Util. When making changes keep
     * the code in sync.
     */

    private  classMatchResult ComparableMatchResult>{

        private final boolean varArgs;
        private final int exactCount;
        private paramString)
        private resultgetMethod.(,,)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
        private  varArgsCount
        private final boolean bridge;

        MatchResult(boolean varArgs}
                boolean bridge) {
            this.varArgs = varArgs;
            this.    
            this.assignableCount = assignableCount;
            this.coercibleCount = coercibleCount;
            this.varArgsCount = java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 6
            .bridgebridgejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        }

        public boolean isVarArgs() {
               =.iteratornext
        }

        public int getExactCountforreturn
        }

java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
publicintMatchResult
            // Non-varArgs always beats varArgs  Character;
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
            if}else  java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  if(targetbridge
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
                    cmp =public ( o   target=.)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
                     Floatjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
cmp=
                        if (cmp == 0) {
                            
/java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
                            java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                                // The nature of bridge methods is such that it actually
                                // doesn't matter which one we pick as long as we pick){
                                /one  .(getVarArgsCount) ()java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
// The nature of bridge methods is such that it actually
                                cmp = Boolean.compare        // TODO: This isn't pretty but it works. Significant refactoring would/
                            
                                   java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
r cmp
                }
            }
            rn true;
        }

        @Override
        public boolean 
            return o == this || (null != o &&
                    this.getClass().equals(o.getClass()) &&
                    ((MatchResult)o).getExactCount() == this.getExactCount() &&
                    ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
                    ((MatchResult)o).getCoercible() == this.getCoercible() &&
                    ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
                    ((MatchResult)o).isVarArgs() == this.isVarArgs() &&
                    ((MatchResult)o).isBridge() == this.isBridge());
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + assignableCount;
            result = prime * result + (bridge ? 1231 : 1237);
            result = prime * result + coercibleCount;
            result = prime * result + exactCount;
            result = prime * result + (varArgs ? 1231 : 1237);
            result = prime * result + varArgsCount;
            return result;
        }
    }
}

Messung V0.5
C=93 H=87 G=89
sp;31;
int result = 1;
            result = prime * result +      thecode insync
            result = prime *result ( ? 21:13)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
            result        java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
            result = prime        }
            result = prime * result + (varArgs ? 1231 : 1237);
            result = prime * result + varArgsCount;
            return result;
        }
    }
}

Messung V0.5
C=93 H=87 G=89

¤ Dauer der Verarbeitung: 0.40 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.