Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
ASM tests Copyright (c) 2002-2005 France Telecom All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 package com.facebook.presto.byteCode;
 import java.util.Map;
 import static com.facebook.presto.byteCode.ParameterizedType.typeFromPathName;
 public class ClassInfoLoader
     public static ClassInfoLoader createClassInfoLoader(Iterable<ClassDefinitionclassDefinitionsClassLoader classLoader)
         ImmutableMap.Builder<ParameterizedTypeClassNodeclassNodes = ImmutableMap.builder();
         for (ClassDefinition classDefinition : classDefinitions) {
             ClassNode classNode = new ClassNode();
             classNodes.put(classDefinition.getType(), classNode);
         return new ClassInfoLoader(, ImmutableMap.<ParameterizedTypebyte[]>of(), classLoadertrue);
     public static ClassInfoLoader createByteCodeInfoLoader(Map<ParameterizedTypebyte[]> byteCodesClassLoader classLoaderboolean loadMethodNodes)
         return new ClassInfoLoader(ImmutableMap.<ParameterizedTypeClassNode>of(), byteCodesclassLoaderloadMethodNodes);
     private final Map<ParameterizedTypeClassNodeclassNodes;
     private final Map<ParameterizedTypebyte[]> byteCodes;
     private final ClassLoader classLoader;
     private final Map<ParameterizedTypeClassInfoclassInfoCache = new HashMap<>();
     private final boolean loadMethodNodes;
     public ClassInfoLoader(Map<ParameterizedTypeClassNodeclassNodesMap<ParameterizedTypebyte[]> byteCodesClassLoader classLoaderboolean loadMethodNodes)
         this. = ImmutableMap.copyOf(classNodes);
         this. = ImmutableMap.copyOf(byteCodes);
         this. = classLoader;
         this. = loadMethodNodes;
     public ClassInfo loadClassInfo(ParameterizedType type)
         ClassInfo classInfo = .get(type);
         if (classInfo == null) {
             classInfo = readClassInfoQuick(type);
         return classInfo;
         // check for user supplied class node
         ClassNode classNode = .get(type);
         if (classNode != null) {
             return new ClassInfo(thisclassNode);
         // check for user supplied byte code
         ClassReader classReader;
         byte[] byteCode = .get(type);
         if (byteCode != null) {
             classReader = new ClassReader(byteCode);
        else {
            // load class file from class loader
            String classFileName = type.getClassName() + ".class";
            try (InputStream is = .getResourceAsStream(classFileName)) {
                classReader = new ClassReader(is);
            catch (IOException e) {
                // check if class is already loaded
                try {
                    Class<?> aClass = .loadClass(type.getJavaClassName());
                    return new ClassInfo(thisaClass);
                catch (ClassNotFoundException e1) {
                    throw new RuntimeException("Class not found " + typee);
        if () {
            // slower version that loads all operations
            classNode = new ClassNode();
            classReader.accept(new CheckClassAdapter(classNodefalse), .);
            return new ClassInfo(thisclassNode);
        else {
            // optimized version
            int header = classReader.header;
            int access = classReader.readUnsignedShort(header);
            char[] buf = new char[2048];
            // read super class name
            int superClassIndex = classReader.getItem(classReader.readUnsignedShort(header + 4));
            ParameterizedType superClass;
            if (superClassIndex == 0) {
                superClass = null;
            else {
                superClass = typeFromPathName(classReader.readUTF8(superClassIndexbuf));
            // read each interface name
            int interfaceCount = classReader.readUnsignedShort(header + 6);
            ImmutableList.Builder<ParameterizedTypeinterfaces = ImmutableList.builder();
            header += 8;
            for (int i = 0; i < interfaceCount; ++i) {
                header += 2;
            return new ClassInfo(, null);
New to GrepCode? Check out our FAQ X