Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFormatException printStackTrace

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFormatException printStackTrace

Introduction

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

Prototype

@Override
    public void printStackTrace() 

Source Link

Usage

From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.java

License:Open Source License

/**
* Creates the type info from the given class file on disk and
* adds it to the given list of infos.//from   w ww  . jav a 2 s .  c o m
*/
protected IBinaryType createInfoFromClassFile(Openable handle, IResource file) {
    IBinaryType info = null;
    try {
        info = Util.newClassFileReader(file);
    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (java.io.IOException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (CoreException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    }
    this.infoToHandle.put(info, handle);
    return info;
}

From source file:org.eclipse.jdt.internal.core.hierarchy.HierarchyBuilder.java

License:Open Source License

/**
* Create a type info from the given class file in a jar and adds it to the given list of infos.
*//*from   w ww  .j a  v  a2  s  .  c  om*/
protected IBinaryType createInfoFromClassFileInJar(Openable classFile) {
    PackageFragment pkg = (PackageFragment) classFile.getParent();
    String classFilePath = Util.concatWith(pkg.names, classFile.getElementName(), '/');
    IBinaryType info = null;
    java.util.zip.ZipFile zipFile = null;
    try {
        zipFile = ((JarPackageFragmentRoot) pkg.getParent()).getJar();
        info = org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.read(zipFile, classFilePath);
    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (java.io.IOException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (CoreException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } finally {
        JavaModelManager.getJavaModelManager().closeZipFile(zipFile);
    }
    this.infoToHandle.put(info, classFile);
    return info;
}

From source file:org.eclipse.wst.xml.core.internal.contentmodel.tapestry.travelpackage.TapestryClassLoader.java

License:Open Source License

public List<String> loadParametersFromParentClass(IPackageFragmentRoot root, String classFileName) {
    List<String> list = new ArrayList<String>();
    if (classFileName.indexOf('/') < 0)
        return list;
    String packageName = classFileName.substring(0, classFileName.lastIndexOf('/')).replace('/', '.');
    String className = classFileName.substring(classFileName.lastIndexOf('/') + 1) + ".class";
    try {/*w w  w  .  jav  a 2  s. co  m*/
        PackageFragment packInstance = (PackageFragment) root.getPackageFragment(packageName);
        for (Object packo : packInstance.getChildrenOfType(IJavaElement.CLASS_FILE)) {
            ClassFile packi = (ClassFile) packo;
            if (packi.getElementName().equals(className)) {
                ClassFileReader reader = null;
                try {
                    reader = new ClassFileReader(packi.getBytes(), null);
                } catch (ClassFormatException e) {
                    e.printStackTrace();
                }

                if (reader.getFields() != null)
                    for (IBinaryField field : reader.getFields()) {
                        boolean parameter = false;
                        if (field.getAnnotations() == null)
                            continue;
                        for (IBinaryAnnotation anno : field.getAnnotations()) {
                            if (String.valueOf(anno.getTypeName()).endsWith("/Parameter;")) {
                                parameter = true;
                                break;
                            }
                        }
                        if (parameter) {
                            list.add(String.valueOf(field.getName()));
                        }
                    }
                String parentClassName = String.valueOf(reader.getSuperclassName());
                if (parentClassName != null && !parentClassName.isEmpty()
                        && !parentClassName.equals("java/lang/Object")) {
                    list.addAll(loadParametersFromParentClass(root, parentClassName));
                }
                return list;
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return list;
}

From source file:org.eclipse.wst.xml.ui.internal.contentassist.tapestry.TapestryRootComponentsProposalComputer.java

License:Open Source License

/**
 * Get custom component attribute templates
 * /*from   ww  w.j  a  v  a 2  s . c  om*/
 * @param project
 * @param contextTypeId
 * @param nodeName
 * @param tapestryClassLoader
 * @return
 */
public List<Template> getCustomComponentsAttributes(IProject project, String contextTypeId, String nodeName,
        TapestryClassLoader tapestryClassLoader) {
    components.clear();
    String prefix = nodeName.substring(0, nodeName.indexOf(':'));
    try {
        final IFile res = project.getFile(TapestryContants.CUSTOM_COMPONENTS_FILE);
        if (res == null || prefix == null)
            return components;
        List<ComponentPackage> packageList = loadCustomComponentsPackageListWithPrefix(res, prefix);
        IPackageFragmentRoot[] roots = JavaCore.create(project).getAllPackageFragmentRoots();
        for (ComponentPackage cp : packageList) {
            for (IPackageFragmentRoot root : roots) {
                if (cp.isArchive() == root.isArchive() && cp.getFragmentRoot().equals(root.getElementName())) {
                    IPackageFragment packInstance = root.getPackageFragment(cp.getPath());
                    if (!root.isArchive()) {
                        //If current custom component is in source directory
                        if (packInstance != null) {
                            IJavaElement[] elements = packInstance.getChildren();
                            for (IJavaElement ele : elements) {
                                if (ele.getElementType() == IJavaElement.COMPILATION_UNIT
                                        && ele.getElementName().endsWith(".java")) {
                                    String name = ele.getElementName().substring(0,
                                            ele.getElementName().indexOf('.'));
                                    if ((prefix + ":" + name).toLowerCase().equals(nodeName)) {
                                        goThroughClass((ICompilationUnit) ele, contextTypeId);
                                        return components;
                                    }
                                }
                            }
                        }
                    } else if (packInstance instanceof PackageFragment) {
                        //Current custom component is in jar files
                        for (Object packo : ((PackageFragment) packInstance)
                                .getChildrenOfType(IJavaElement.CLASS_FILE)) {
                            ClassFile packi = (ClassFile) packo;
                            String className = packi.getElementName().substring(0,
                                    packi.getElementName().indexOf('.'));
                            if (className.indexOf('$') < 0
                                    && (prefix + ":" + className.toLowerCase()).equals(nodeName)) {
                                TapestryCoreComponents component = null;
                                try {
                                    component = tapestryClassLoader.loadComponentAttributesFromClassFile(root,
                                            prefix, packi);
                                } catch (ClassFormatException e) {
                                    e.printStackTrace();
                                }
                                if (component != null) {
                                    for (String paramName : component.getPamameters()) {
                                        Template template = new Template(paramName,
                                                "add attribute " + paramName, contextTypeId,
                                                buildAttributeInsertCode(paramName), true);
                                        components.add(template);
                                    }
                                    return components;
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.summer.sdt.internal.core.hierarchy.HierarchyBuilder.java

License:Open Source License

/**
* Create a type info from the given class file in a jar and adds it to the given list of infos.
*//*from  w  w w . j av  a2  s  . c om*/
protected IBinaryType createInfoFromClassFileInJar(Openable classFile) {
    PackageFragment pkg = (PackageFragment) classFile.getParent();
    String classFilePath = Util.concatWith(pkg.names, classFile.getElementName(), '/');
    IBinaryType info = null;
    java.util.zip.ZipFile zipFile = null;
    try {
        zipFile = ((JarPackageFragmentRoot) pkg.getParent()).getJar();
        info = org.summer.sdt.internal.compiler.classfmt.ClassFileReader.read(zipFile, classFilePath);
    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (java.io.IOException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } catch (CoreException e) {
        if (TypeHierarchy.DEBUG) {
            e.printStackTrace();
        }
        return null;
    } finally {
        JavaModelManager.getJavaModelManager().closeZipFile(zipFile);
    }
    this.infoToHandle.put(info, classFile);
    return info;
}