Example usage for org.eclipse.jdt.core IPackageFragmentRoot getUnderlyingResource

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getUnderlyingResource

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getUnderlyingResource.

Prototype

IResource getUnderlyingResource() throws JavaModelException;

Source Link

Document

Returns the smallest underlying resource that contains this element, or null if this element is not contained in a resource.

Usage

From source file:com.google.gdt.eclipse.designer.util.DefaultModuleProvider.java

License:Open Source License

/**
 * @return the module {@link IFile} with given id, may be <code>null</code>.
 *//*from w w w. j av a2  s. c om*/
private static IFile getModuleFile(IJavaProject javaProject, String moduleId) throws Exception {
    String moduleFileName = moduleId.replace('.', '/') + ".gwt.xml";
    for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) {
        // check only in source folders
        if (packageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
            continue;
        }
        // check IFolder of source folder
        IContainer sourceFolder = (IContainer) packageFragmentRoot.getUnderlyingResource();
        IFile moduleFile = sourceFolder.getFile(new Path(moduleFileName));
        if (moduleFile.exists()) {
            return moduleFile;
        }
    }
    // not found
    return null;
}

From source file:com.google.gdt.eclipse.designer.wizards.model.common.ClientPackageSelectionDialogField.java

License:Open Source License

/**
 * Return strings presentation of package.
 *///from www .j a va2  s. com
private static String getPackageString(IPackageFragment packageFragment) {
    try {
        if (packageFragment != null) {
            IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) packageFragment.getParent();
            IJavaProject javaProject = packageFragmentRoot.getJavaProject();
            if (packageFragmentRoot.getUnderlyingResource() == javaProject.getUnderlyingResource()) {
                return javaProject.getElementName() + "/" + packageFragment.getElementName();
            } else {
                return javaProject.getElementName() + "/" + packageFragmentRoot.getElementName() + "/"
                        + packageFragment.getElementName();
            }
        }
        return "";
    } catch (Throwable e) {
        throw ReflectionUtils.propagate(e);
    }
}

From source file:de.loskutov.bco.editors.BytecodeSourceMapper.java

License:Open Source License

/**
 *
 *///from ww  w  . j  a va 2 s  .c  o  m
protected char[] findSource(IType type, IBinaryType info, IClassFile cf, BitSet decompilerFlags) {

    IPackageFragment pkgFrag = type.getPackageFragment();
    IPackageFragmentRoot root = (IPackageFragmentRoot) pkgFrag.getParent();
    String pkg = type.getPackageFragment().getElementName().replace('.', '/');

    String classFile = new String(info.getFileName());
    int p = classFile.lastIndexOf('/');
    classFile = classFile.substring(p + 1);

    StringBuffer source = new StringBuffer();
    String location = null;
    String className = pkg + "/" + classFile;
    if (root.isArchive()) {
        location = getArchivePath(root);
        DecompiledClass decompiledClass = decompileFromArchive(source, location, className, decompilerFlags);
        classToDecompiled.put(cf, decompiledClass);
    } else {
        try {
            location = root.getUnderlyingResource().getLocation().toOSString() + "/" + className;
            DecompiledClass decompiledClass = decompile(source, location, decompilerFlags);
            classToDecompiled.put(cf, decompiledClass);
        } catch (JavaModelException e) {
            BytecodeOutlinePlugin.log(e, IStatus.ERROR);
        }
    }

    source.append("\n\n// DECOMPILED FROM: ");
    source.append(location).append("\n");
    return source.toString().toCharArray();
}

From source file:de.loskutov.bco.editors.BytecodeSourceMapper.java

License:Open Source License

private static String getArchivePath(IPackageFragmentRoot root) {
    String archivePath = null;//from   ww w .j a  va  2  s .  c  o m
    IResource resource;

    try {
        if ((resource = root.getUnderlyingResource()) != null) {
            // jar in workspace
            archivePath = resource.getLocation().toOSString();
        } else {
            // external jar
            archivePath = root.getPath().toOSString();
        }
    } catch (JavaModelException e) {
        BytecodeOutlinePlugin.log(e, IStatus.ERROR);
    }
    return archivePath;
}

From source file:org.eclipse.jem.internal.beaninfo.core.BeanInfoCacheController.java

License:Open Source License

private RootIndex createArchiveRootIndex(IPackageFragmentRoot rootArchive, String rootName, Index index) {
    long modStamp = IResource.NULL_STAMP;
    if (rootArchive.isExternal()) {
        modStamp = rootArchive.getPath().toFile().lastModified();
    } else {/*from w  w  w .j  a  va 2 s .  c o m*/
        try {
            modStamp = rootArchive.getUnderlyingResource().getModificationStamp();
        } catch (JavaModelException e) {
            BeaninfoPlugin.getPlugin().getLogger().log(e);
        }
    }
    return new ArchiveRootIndex(rootName, modStamp, index);
}

From source file:org.eclipse.jpt.common.core.internal.utility.PackageFragmentRootTools.java

License:Open Source License

private static boolean isFolder_(IPackageFragmentRoot pfr) throws JavaModelException {
    IResource resource = pfr.getUnderlyingResource();
    return (resource != null) && (resource.getType() == IResource.FOLDER);
}

From source file:org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.model.EntityDataModelProvider.java

License:Open Source License

protected IContainer getDefaultJavaSourceContainer() {
    JpaProject jpaProject = getTargetJpaProject();
    if (jpaProject == null) {
        return null;
    }/*from   w w  w . j a  va2s  .c  o  m*/
    IJavaProject javaProject = jpaProject.getJavaProject();
    try {
        for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) {
            if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) {
                return (IContainer) pfr.getUnderlyingResource();
            }
        }
    } catch (JavaModelException jme) {
        // fall through
        JptJpaUiPlugin.instance().logError(jme);
    }
    return null;
}

From source file:org.eclipse.jpt.jpa.ui.internal.wizards.entity.data.model.EntityDataModelProvider.java

License:Open Source License

protected IContainer getJavaSourceContainer() {
    String containerFullPath = getStringProperty(SOURCE_FOLDER);
    JpaProject jpaProject = getTargetJpaProject();
    if (jpaProject == null) {
        return null;
    }//from w ww. jav  a2s.com
    IJavaProject javaProject = jpaProject.getJavaProject();
    try {
        for (IPackageFragmentRoot pfr : javaProject.getPackageFragmentRoots()) {
            if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) {
                IContainer container = (IContainer) pfr.getUnderlyingResource();
                if (container.getFullPath().equals(new Path(containerFullPath))) {
                    return container;
                }
            }
        }
    } catch (JavaModelException jme) {
        // fall through
        JptJpaUiPlugin.instance().logError(jme);
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

/**
 * Returns the specified package fragment root in the given project, or
 * <code>null</code> if it does not exist.
 * If relative, the rootPath must be specified as a project relative path.
 * The empty path refers to the package fragment root that is the project
 * folder iteslf.//  w  ww .j a va2s.  c o m
 * If absolute, the rootPath refers to either an external jar, or a resource
 * internal to the workspace
 */
public IPackageFragmentRoot getPackageFragmentRoot(String projectName, String rootPath)
        throws JavaModelException {

    IJavaProject project = getJavaProject(projectName);
    if (project == null) {
        return null;
    }
    IPath path = new Path(rootPath);
    if (path.isAbsolute()) {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IResource resource = workspaceRoot.findMember(path);
        IPackageFragmentRoot root;
        if (resource == null) {
            // external jar
            root = project.getPackageFragmentRoot(rootPath);
        } else {
            // resource in the workspace
            root = project.getPackageFragmentRoot(resource);
        }
        return root;
    } else {
        IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
        if (roots == null || roots.length == 0) {
            return null;
        }
        for (int i = 0; i < roots.length; i++) {
            IPackageFragmentRoot root = roots[i];
            if (!root.isExternal() && root.getUnderlyingResource().getProjectRelativePath().equals(path)) {
                return root;
            }
        }
    }
    return null;
}

From source file:org.eclipse.wb.tests.designer.core.util.jdt.core.CodeUtilsTest.java

License:Open Source License

/**
 * Asserts that given {@link IPackageFragmentRoot} has same path in workspace as expected.
 */// w ww  .  ja  v  a2s.co  m
private static void assertPackageFragmentRootPath(String expectedPath, IPackageFragmentRoot packageFragmentRoot)
        throws Exception {
    assertEquals(expectedPath, packageFragmentRoot.getUnderlyingResource().getFullPath().toString());
}