Example usage for org.eclipse.jdt.core.util IExceptionAttribute getExceptionNames

List of usage examples for org.eclipse.jdt.core.util IExceptionAttribute getExceptionNames

Introduction

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

Prototype

char[][] getExceptionNames();

Source Link

Document

Answer back the exception names of the exception attribute.

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 av a2s.c o 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 v a  2  s . c  o  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.tools.internal.versioning.JavaClassVersionCompare.java

License:Open Source License

/**
 * check two IExceptionAttribute instances to see if there is any change
 * @param className name of the class to which the method denoted by <code>methodName</code> belongs
 * @param methodName name of the method to which exceptionsAttribute1(exceptionsAttribute2) belongs 
 * @param exceptionsAttribute1//  ww w.  j a  v  a  2 s.com
 * @param exceptionsAttribute2
 */
private void checkExceptions(String className, String methodName, IExceptionAttribute exceptionsAttribute1,
        IExceptionAttribute exceptionsAttribute2) {
    List exceptionList1 = null;
    List exceptionList2 = null;
    if (exceptionsAttribute1 != null && exceptionsAttribute2 != null) {
        exceptionList1 = generateList(exceptionsAttribute1.getExceptionNames());
        exceptionList2 = generateList(exceptionsAttribute2.getExceptionNames());
    } else if (exceptionsAttribute1 != null) {
        exceptionList1 = generateList(exceptionsAttribute1.getExceptionNames());
    } else if (exceptionsAttribute2 != null) {
        exceptionList2 = generateList(exceptionsAttribute2.getExceptionNames());
    } else {
        return;
    }
    StringBuffer newAddedExceptions = new StringBuffer();
    if (exceptionList1 != null) {
        // check what is new added
        for (Iterator iterator1 = exceptionList1.iterator(); iterator1.hasNext();) {
            // get a exception from exceptionList1
            String exception1 = (String) iterator1.next();
            if (exceptionList2 != null) {
                // check if the exception is in exceptionList2
                if (!exceptionList2.remove(exception1)) {
                    newAddedExceptions.append(exception1);
                    newAddedExceptions.append(COMMA_MARK);
                }
            } else {
                // if exceptionList2 is null, it is new added
                newAddedExceptions.append(exception1);
                newAddedExceptions.append(COMMA_MARK);
            }
        }
        if (!newAddedExceptions.toString().trim().equals(EMPTY_STRING)) {
            Object[] msg = { newAddedExceptions.toString(), methodName, className };
            finalResult.merge(resultStatusHandler(IStatus.INFO,
                    IVersionCompare.CLASS_DETAIL_STATUS | IVersionCompare.MINOR_CHANGE,
                    NLS.bind(Messages.JavaClassVersionCompare_newAddedExceptionMsg, msg), null));
        }
    }
    if (exceptionList2 != null) {
        StringBuffer notExistExceptions = new StringBuffer();
        // check what does no longer exist
        for (Iterator iterator2 = exceptionList2.iterator(); iterator2.hasNext();) {
            String exception2 = (String) iterator2.next();
            notExistExceptions.append(exception2);
            notExistExceptions.append(COMMA_MARK);
        }
        if (!notExistExceptions.toString().trim().equals(EMPTY_STRING)) {
            Object[] msg2 = { notExistExceptions.toString(), methodName, className };
            finalResult.merge(resultStatusHandler(IStatus.INFO,
                    IVersionCompare.CLASS_DETAIL_STATUS | IVersionCompare.MINOR_CHANGE,
                    NLS.bind(Messages.JavaClassVersionCompare_noLongerExistExceptionMsg, msg2), null));
        }
    }
}