Example usage for org.eclipse.jdt.core.util IConstantPoolConstant CONSTANT_Utf8

List of usage examples for org.eclipse.jdt.core.util IConstantPoolConstant CONSTANT_Utf8

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.util IConstantPoolConstant CONSTANT_Utf8.

Prototype

int CONSTANT_Utf8

To view the source code for org.eclipse.jdt.core.util IConstantPoolConstant CONSTANT_Utf8.

Click Source Link

Usage

From source file:com.siteview.mde.internal.ui.search.dependencies.PackageFinder.java

License:Open Source License

static void computeReferencedTypes(IClassFileReader cfr, Set packages) {

    char[][] interfaces = cfr.getInterfaceNames();
    if (interfaces != null) {
        for (int i = 0; i < interfaces.length; i++) {
            //note: have to convert names like Ljava/lang/Object; to java.lang.Object
            packages.add(getPackage(new String(interfaces[i]).replace('/', '.')));
        }// w w w.  j a va  2s  . co  m
    }

    char[] scn = cfr.getSuperclassName();
    if (scn != null) {
        packages.add(getPackage(new String(scn).replace('/', '.')));
    }

    IFieldInfo[] fieldInfo = cfr.getFieldInfos();
    for (int i = 0; i < fieldInfo.length; i++) {

        String fieldName = new String(fieldInfo[i].getDescriptor());
        if (!isPrimitiveTypeSignature(fieldName)) {
            String fieldDescriptor = extractFullyQualifiedTopLevelType(fieldName);
            packages.add(getPackage(new String(fieldDescriptor)));
        }
    }

    IMethodInfo[] methodInfo = cfr.getMethodInfos();
    for (int i = 0; i < methodInfo.length; i++) {
        IExceptionAttribute exceptionAttribute = methodInfo[i].getExceptionAttribute();
        if (exceptionAttribute != null) {
            char[][] exceptionNames = exceptionAttribute.getExceptionNames();
            for (int j = 0; j < exceptionNames.length; j++) {
                packages.add(getPackage(new String(exceptionNames[j]).replace('/', '.')));
            }
        }

        String descriptor = new String(methodInfo[i].getDescriptor());
        //add parameter types
        String[] parameterTypes = Signature.getParameterTypes(descriptor);
        for (int j = 0; j < parameterTypes.length; j++) {
            //have to parse to convert [Ljava/lang/String; to java.lang.String
            if (!isPrimitiveTypeSignature(parameterTypes[j])) {
                packages.add(getPackage(new String(extractFullyQualifiedTopLevelType(parameterTypes[j]))));
            }
        }
        //add return type
        String returnType = Signature.getReturnType(descriptor);
        if (!isPrimitiveTypeSignature(returnType)) {
            returnType = extractFullyQualifiedTopLevelType(returnType);
            packages.add(getPackage(returnType));
        }
    }

    // Is there more to extract from the constant pool??
    IConstantPoolEntry entry;
    IConstantPool pool = cfr.getConstantPool();
    int length = pool.getConstantPoolCount();
    for (int i = 1; i < length; i++) {
        switch (pool.getEntryKind(i)) {
        case IConstantPoolConstant.CONSTANT_Class:
            // add reference to the class
            entry = pool.decodeEntry(i);
            //note: may have to convert names like Ljava/lang/Object; to java.lang.Object
            String className = new String(entry.getClassInfoName()).replace('/', '.');
            className = className.indexOf(';') >= 0 ? extractFullyQualifiedTopLevelType(className) : className;
            packages.add(getPackage(className));
            break;

        case IConstantPoolConstant.CONSTANT_NameAndType:
            // add reference to the name and type
            entry = pool.decodeEntry(i);
            int descIndex = entry.getNameAndTypeInfoDescriptorIndex();
            if (pool.getEntryKind(descIndex) == IConstantPoolConstant.CONSTANT_Utf8) {
                entry = pool.decodeEntry(descIndex);
                char[] type = entry.getUtf8Value();
                if (type[0] == '(') {
                    // Method signature.

                    //add parameter types
                    String descriptor = new String(type);
                    String[] parameterTypes = Signature.getParameterTypes(descriptor);
                    for (int j = 0; j < parameterTypes.length; j++) {
                        if (!isPrimitiveTypeSignature(parameterTypes[j])) {
                            packages.add(getPackage(extractFullyQualifiedTopLevelType(parameterTypes[j])));
                        }
                    }
                    //add return type
                    String returnType = Signature.getReturnType(descriptor);
                    if (!isPrimitiveTypeSignature(returnType)) {
                        returnType = extractFullyQualifiedTopLevelType(returnType);
                        packages.add(getPackage(returnType));
                    }

                } else {
                    // Field type.
                    String typeString = new String(type);
                    if (!isPrimitiveTypeSignature(typeString)) {
                        packages.add(getPackage(extractFullyQualifiedTopLevelType(typeString)));
                    }
                }
            }
            break;
        }
    }
    packages.remove(""); // removes default package if it exists //$NON-NLS-1$
}

From source file:org.eclipse.pde.internal.ui.search.dependencies.PackageFinder.java

License:Open Source License

static void computeReferencedTypes(IClassFileReader cfr, Set<String> packages) {

    char[][] interfaces = cfr.getInterfaceNames();
    if (interfaces != null) {
        for (int i = 0; i < interfaces.length; i++) {
            //note: have to convert names like Ljava/lang/Object; to java.lang.Object
            packages.add(getPackage(new String(interfaces[i]).replace('/', '.')));
        }/* w w w  . j  a va  2s .com*/
    }

    char[] scn = cfr.getSuperclassName();
    if (scn != null) {
        packages.add(getPackage(new String(scn).replace('/', '.')));
    }

    IFieldInfo[] fieldInfo = cfr.getFieldInfos();
    for (int i = 0; i < fieldInfo.length; i++) {

        String fieldName = new String(fieldInfo[i].getDescriptor());
        if (!isPrimitiveTypeSignature(fieldName)) {
            String fieldDescriptor = extractFullyQualifiedTopLevelType(fieldName);
            packages.add(getPackage(new String(fieldDescriptor)));
        }
    }

    IMethodInfo[] methodInfo = cfr.getMethodInfos();
    for (int i = 0; i < methodInfo.length; i++) {
        IExceptionAttribute exceptionAttribute = methodInfo[i].getExceptionAttribute();
        if (exceptionAttribute != null) {
            char[][] exceptionNames = exceptionAttribute.getExceptionNames();
            for (int j = 0; j < exceptionNames.length; j++) {
                packages.add(getPackage(new String(exceptionNames[j]).replace('/', '.')));
            }
        }

        String descriptor = new String(methodInfo[i].getDescriptor());
        //add parameter types
        String[] parameterTypes = Signature.getParameterTypes(descriptor);
        for (int j = 0; j < parameterTypes.length; j++) {
            //have to parse to convert [Ljava/lang/String; to java.lang.String
            if (!isPrimitiveTypeSignature(parameterTypes[j])) {
                packages.add(getPackage(new String(extractFullyQualifiedTopLevelType(parameterTypes[j]))));
            }
        }
        //add return type
        String returnType = Signature.getReturnType(descriptor);
        if (!isPrimitiveTypeSignature(returnType)) {
            returnType = extractFullyQualifiedTopLevelType(returnType);
            packages.add(getPackage(returnType));
        }
    }

    // Is there more to extract from the constant pool??
    IConstantPoolEntry entry;
    IConstantPool pool = cfr.getConstantPool();
    int length = pool.getConstantPoolCount();
    for (int i = 1; i < length; i++) {
        switch (pool.getEntryKind(i)) {
        case IConstantPoolConstant.CONSTANT_Class:
            // add reference to the class
            entry = pool.decodeEntry(i);
            //note: may have to convert names like Ljava/lang/Object; to java.lang.Object
            String className = new String(entry.getClassInfoName()).replace('/', '.');
            className = className.indexOf(';') >= 0 ? extractFullyQualifiedTopLevelType(className) : className;
            packages.add(getPackage(className));
            break;

        case IConstantPoolConstant.CONSTANT_NameAndType:
            // add reference to the name and type
            entry = pool.decodeEntry(i);
            int descIndex = entry.getNameAndTypeInfoDescriptorIndex();
            if (pool.getEntryKind(descIndex) == IConstantPoolConstant.CONSTANT_Utf8) {
                entry = pool.decodeEntry(descIndex);
                char[] type = entry.getUtf8Value();
                if (type[0] == '(') {
                    // Method signature.

                    //add parameter types
                    String descriptor = new String(type);
                    String[] parameterTypes = Signature.getParameterTypes(descriptor);
                    for (int j = 0; j < parameterTypes.length; j++) {
                        if (!isPrimitiveTypeSignature(parameterTypes[j])) {
                            packages.add(getPackage(extractFullyQualifiedTopLevelType(parameterTypes[j])));
                        }
                    }
                    //add return type
                    String returnType = Signature.getReturnType(descriptor);
                    if (!isPrimitiveTypeSignature(returnType)) {
                        returnType = extractFullyQualifiedTopLevelType(returnType);
                        packages.add(getPackage(returnType));
                    }

                } else {
                    // Field type.
                    String typeString = new String(type);
                    if (!isPrimitiveTypeSignature(typeString)) {
                        packages.add(getPackage(extractFullyQualifiedTopLevelType(typeString)));
                    }
                }
            }
            break;
        }
    }
    packages.remove(""); // removes default package if it exists //$NON-NLS-1$
}