Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants ClassTag

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants ClassTag

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants ClassTag.

Prototype

int ClassTag

To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants ClassTag.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryTypeConverter.java

License:Open Source License

public ImportReference[] buildImports(ClassFileReader reader) {
    // add remaining references to the list of type names
    // (code extracted from BinaryIndexer#extractReferenceFromConstantPool(...))
    int[] constantPoolOffsets = reader.getConstantPoolOffsets();
    int constantPoolCount = constantPoolOffsets.length;
    for (int i = 0; i < constantPoolCount; i++) {
        int tag = reader.u1At(constantPoolOffsets[i]);
        char[] name = null;
        switch (tag) {
        case ClassFileConstants.MethodRefTag:
        case ClassFileConstants.InterfaceMethodRefTag:
            int constantPoolIndex = reader.u2At(constantPoolOffsets[i] + 3);
            int utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[constantPoolIndex] + 3)];
            name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
            break;
        case ClassFileConstants.ClassTag:
            utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[i] + 1)];
            name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
            break;
        }/*from ww w . j av a 2 s  .  c  o m*/
        if (name == null || (name.length > 0 && name[0] == '['))
            break; // skip over array references
        this.typeNames.add(CharOperation.splitOn('/', name));
    }

    // convert type names into import references
    int typeNamesLength = this.typeNames.size();
    ImportReference[] imports = new ImportReference[typeNamesLength];
    char[][][] set = this.typeNames.set;
    int index = 0;
    for (int i = 0, length = set.length; i < length; i++) {
        char[][] typeName = set[i];
        if (typeName != null) {
            imports[index++] = new ImportReference(typeName, new long[typeName.length]/*dummy positions*/,
                    false/*not on demand*/, 0);
        }
    }
    return imports;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.BinaryIndexer.java

License:Open Source License

/**
 * Extract all type, method, field and interface method references from the constant pool
 *//*from   w  ww  .j  a  v a  2 s  .com*/
private void extractReferenceFromConstantPool(byte[] contents, ClassFileReader reader)
        throws ClassFormatException {
    int[] constantPoolOffsets = reader.getConstantPoolOffsets();
    int constantPoolCount = constantPoolOffsets.length;
    for (int i = 1; i < constantPoolCount; i++) {
        int tag = reader.u1At(constantPoolOffsets[i]);
        /**
         * u1 tag
         * u2 class_index
         * u2 name_and_type_index
         */
        char[] name = null;
        char[] type = null;
        switch (tag) {
        case ClassFileConstants.FieldRefTag:
            // add reference to the class/interface and field name and type
            name = extractName(constantPoolOffsets, reader, i);
            addFieldReference(name);
            break;
        case ClassFileConstants.MethodRefTag:
            // add reference to the class and method name and type
        case ClassFileConstants.InterfaceMethodRefTag:
            // add reference to the interface and method name and type
            name = extractName(constantPoolOffsets, reader, i);
            type = extractType(constantPoolOffsets, reader, i);
            if (CharOperation.equals(INIT, name)) {
                // get class name and see if it's a local type or not
                char[] className = extractClassName(constantPoolOffsets, reader, i);
                boolean localType = false;
                if (className != null) {
                    for (int c = 0, max = className.length; c < max; c++) {
                        switch (className[c]) {
                        case '/':
                            className[c] = '.';
                            break;
                        case '$':
                            localType = true;
                            break;
                        }
                    }
                }
                // add a constructor reference, use class name to extract arg count if it's a local type to remove synthetic parameter
                addConstructorReference(className, extractArgCount(type, localType ? className : null));
            } else {
                // add a method reference
                addMethodReference(name, extractArgCount(type, null));
            }
            break;
        case ClassFileConstants.ClassTag:
            // add a type reference
            name = extractClassReference(constantPoolOffsets, reader, i);
            if (name.length > 0 && name[0] == '[')
                break; // skip over array references
            name = replace('/', '.', name); // so that it looks like java.lang.String
            addTypeReference(name);

            // also add a simple reference on each segment of the qualification (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=24741)
            char[][] qualification = CharOperation.splitOn('.', name);
            for (int j = 0, length = qualification.length; j < length; j++) {
                addNameReference(qualification[j]);
            }
            break;
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java

License:Open Source License

/**
 * Watch out: String/Integer & Class constants require a LDC or a LDCW opcode depending on their index
 * in the constant pool. This method tries to prioritize constants with low index,
 * to avoid that they get a high index in the target class, which will lead to invalid
 * copied LDC operations.//from  w ww . j  av  a  2 s . c  o m
 * @param nConstants number of constants in the src constant pool
 */
private void copyAllNonWideConstants(int nConstants, ReferenceBinding srcTeamBinding,
        ReferenceBinding dstType) {
    Iterator<ConstantPoolObject> it = this._reader.getNonWideConstantIterator(nConstants);
    if (!dstType.isTeam() && dstType.isRole())
        dstType = dstType.enclosingType();
    while (it.hasNext()) {
        ConstantPoolObject src_cpo = it.next();
        ConstantPoolObject dst_cpo = src_cpo.isClass()
                ? new ConstantPoolObject(ClassFileConstants.ClassTag,
                        ConstantPoolObjectMapper.mapClass(srcTeamBinding, src_cpo.getClassObject(), dstType))
                : src_cpo;
        this._writer.writeConstantPoolObject(dst_cpo);
    }
}

From source file:org.springframework.ide.eclipse.core.java.typehierarchy.BytecodeTypeHierarchyClassReader.java

License:Open Source License

public TypeHierarchyElement readTypeHierarchy(InputStream stream) {
    try {//  w w  w .ja v  a 2s.c om
        DataInputStream dis = new DataInputStream(new BufferedInputStream(stream));
        int magic = dis.readInt(); // magic 0xCAFEBABE
        if (magic != 0xCAFEBABE) {
            throw new IllegalStateException("not bytecode, magic was 0x" + Integer.toString(magic, 16));
        }
        skip(dis, 4);

        int constantPoolCount = dis.readShort();
        Object[] constantPoolData = new Object[constantPoolCount];
        for (int i = 1; i < constantPoolCount; i++) {
            int tag = dis.readByte();
            switch (tag) {
            case ClassFileConstants.Utf8Tag:
                constantPoolData[i] = dis.readUTF();
                break;
            case ClassFileConstants.IntegerTag:
                skip(dis, 4);
                break;
            case ClassFileConstants.FloatTag:
                skip(dis, 4);
                break;
            case ClassFileConstants.LongTag:
                skip(dis, 8);
                i++;
                break;
            case ClassFileConstants.DoubleTag:
                skip(dis, 8);
                i++;
                break;
            case ClassFileConstants.ClassTag:
                constantPoolData[i] = dis.readShort();
                break;
            case ClassFileConstants.StringTag:
                skip(dis, 2);
                break;
            case ClassFileConstants.FieldRefTag:
                skip(dis, 4);
                break;
            case ClassFileConstants.MethodRefTag:
                skip(dis, 4);
                break;
            case ClassFileConstants.InterfaceMethodRefTag:
                skip(dis, 4);
                break;
            case ClassFileConstants.NameAndTypeTag:
                skip(dis, 4);
                break;
            case 15: // ClassFileConstants.MethodHandleTag
                skip(dis, 3);
                break;
            case 16: // ClassFileConstants.MethodTypeTag
                skip(dis, 2);
                break;
            case 18: // ClassFileConstants.InvokeDynamicTag
                skip(dis, 4);
                break;
            }
        }

        skip(dis, 2);

        // classname
        short classNameIndex = dis.readShort();
        short classNameUTF8index = (Short) constantPoolData[classNameIndex];
        char[] className = ((String) constantPoolData[classNameUTF8index]).toCharArray();

        // superclass name
        short superclassNameIndex = dis.readShort();
        char[] superclassName = null;
        if (superclassNameIndex != 0) {
            short superclassNameUTF8index = (Short) constantPoolData[superclassNameIndex];
            superclassName = ((String) constantPoolData[superclassNameUTF8index]).toCharArray();
        }

        // interfaces
        short interfacesCount = dis.readShort();
        char[][] interfaceNames = null;
        if (interfacesCount != 0) {
            interfaceNames = new char[interfacesCount][];
            for (int i = 0; i < interfacesCount; i++) {
                short interfaceNameIndex = dis.readShort();
                short interfaceNameUTF8index = (Short) constantPoolData[interfaceNameIndex];
                interfaceNames[i] = ((String) constantPoolData[interfaceNameUTF8index]).toCharArray();
            }
        }

        return new TypeHierarchyElement(className, superclassName, interfaceNames);
    } catch (Exception e) {
        SpringCore.log(e);
    }

    return null;
}