Example usage for org.eclipse.jdt.internal.core JavaModelManager getInfo

List of usage examples for org.eclipse.jdt.internal.core JavaModelManager getInfo

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core JavaModelManager getInfo.

Prototype

public synchronized Object getInfo(IJavaElement element) 

Source Link

Document

Returns the info for the element.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

public static ClassFileReader classFileReader(IType type) {
    IClassFile classFile = type.getClassFile();
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    if (classFile.isOpen())
        return (ClassFileReader) manager.getInfo(type);

    PackageFragment pkg = (PackageFragment) type.getPackageFragment();
    IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
    try {// ww w . j a v a  2  s .  co  m
        if (!root.isArchive())
            return Util.newClassFileReader(((JavaElement) type).resource());

        ZipFile zipFile = null;
        try {
            IPath zipPath = root.getPath();
            if (JavaModelManager.ZIP_ACCESS_VERBOSE)
                System.out.println("(" + Thread.currentThread()
                        + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$   //$NON-NLS-2$
            zipFile = manager.getZipFile(zipPath);
            String classFileName = classFile.getElementName();
            String path = Util.concatWith(pkg.names, classFileName, '/');
            return ClassFileReader.read(zipFile, path);
        } finally {
            manager.closeZipFile(zipFile);
        }
    } catch (ClassFormatException e) {
        // invalid class file: return null
    } catch (CoreException e) {
        // cannot read class file: return null
    } catch (IOException e) {
        // cannot read class file: return null
    }
    return null;
}

From source file:org.eclipse.jdt.internal.core.CompilationUnit.java

License:Open Source License

/**
 * @see ICompilationUnit#getImports()/* w ww .j  a  v a2  s  .  com*/
 */
public IImportDeclaration[] getImports() throws JavaModelException {
    IImportContainer container = getImportContainer();
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    Object info = manager.getInfo(container);
    if (info == null) {
        if (manager.getInfo(this) != null)
            // CU was opened, but no import container, then no imports
            return NO_IMPORTS;
        else {
            open(null); // force opening of CU
            info = manager.getInfo(container);
            if (info == null)
                // after opening, if no import container, then no imports
                return NO_IMPORTS;
        }
    }
    IJavaElement[] elements = ((ImportContainerInfo) info).children;
    int length = elements.length;
    IImportDeclaration[] imports = new IImportDeclaration[length];
    System.arraycopy(elements, 0, imports, 0, length);
    return imports;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

public static ClassFileReader classFileReader(IType type) {
    IClassFile classFile = type.getClassFile();
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    if (classFile.isOpen())
        return (ClassFileReader) manager.getInfo(type);

    PackageFragment pkg = (PackageFragment) type.getPackageFragment();
    IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
    try {/*from   w  w  w.  ja  va 2 s.c  o m*/
        if (!root.isArchive())
            return Util.newClassFileReader(((JavaElement) type).resource());

        ZipFile zipFile = null;
        try {
            IPath zipPath = root.getPath();
            if (JavaModelManager.ZIP_ACCESS_VERBOSE)
                System.out.println("(" + Thread.currentThread() //$NON-NLS-1$
                        + ") [MatchLocator.classFileReader()] Creating ZipFile on " + zipPath); //$NON-NLS-1$
            zipFile = manager.getZipFile(zipPath);
            String classFileName = classFile.getElementName();
            String path = Util.concatWith(pkg.names, classFileName, '/');
            return ClassFileReader.read(zipFile, path);
        } finally {
            manager.closeZipFile(zipFile);
        }
    } catch (ClassFormatException e) {
        // invalid class file: return null
    } catch (CoreException e) {
        // cannot read class file: return null
    } catch (IOException e) {
        // cannot read class file: return null
    }
    return null;
}