Example usage for org.eclipse.jdt.core IJarEntryResource getParent

List of usage examples for org.eclipse.jdt.core IJarEntryResource getParent

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJarEntryResource getParent.

Prototype

Object getParent();

Source Link

Document

Returns the parent of this jar entry resource.

Usage

From source file:com.cisco.yangide.core.YangJarFileEntryResource.java

License:Open Source License

private Object resolveParent(IJarEntryResource parent, IPath path) {
    if (path.segmentCount() > 0) {
        for (IJarEntryResource element : parent.getChildren()) {
            if (path.segment(0).equals(element.getName())) {
                return resolveParent(element, path.removeFirstSegments(1));
            }/*from  w  w  w  . j  ava2s  .  co m*/
        }
    }
    return parent.getParent();
}

From source file:com.iw.plugins.spindle.ui.util.Revealer.java

License:Mozilla Public License

/**
 * @param useSelection//from   w ww.ja v  a2  s  . c  o m
 * @return
 */
private static ISelection checkSelectionForJarEntryFile(ISelection useSelection, IJavaProject jproject) {
    if (useSelection.isEmpty() || !(useSelection instanceof IStructuredSelection))
        return useSelection;

    IStructuredSelection structured = (IStructuredSelection) useSelection;
    Object first = structured.getFirstElement();
    if (structured.size() > 1 || !(first instanceof IJarEntryResource))
        return useSelection;

    IJarEntryResource jarResource = (IJarEntryResource) first;

    IPath path = jarResource.getFullPath().removeFileExtension();
    String name = path.lastSegment();

    IPackageFragment[] fragments = null;
    try {
        if (jproject != null) {

            IPackageFragment frag = (IPackageFragment) jarResource.getParent();
            if (frag != null)
                fragments = new IPackageFragment[] { frag };

        } else {
            fragments = JarEntryFileUtil.getPackageFragments(ResourcesPlugin.getWorkspace().getRoot(),
                    jarResource);
        }
        if (fragments.length != 1)
            return useSelection;

        // check to see if there is an IClassFile in the package
        IJavaElement[] children = fragments[0].getChildren();
        if (children.length > 0) {
            IClassFile revealInstead = null;
            for (int i = 0; i < children.length; i++) {
                if (children[i].getElementType() != IJavaElement.CLASS_FILE)
                    continue;

                revealInstead = (IClassFile) children[i];
                String temp = revealInstead.getElementName();
                temp = temp.substring(0, temp.length() - 6);
                if (temp.equals(name))
                    return new StructuredSelection(revealInstead);
            }
            if (revealInstead != null)
                return new StructuredSelection(revealInstead);
        }
        return new StructuredSelection(fragments[0]);

    } catch (CoreException e) {
        UIPlugin.log(e);
    }
    return useSelection;
}

From source file:org.eclipse.xtext.builder.smap.XbaseBreakpointUtil.java

License:Open Source License

public SourceRelativeURI getBreakpointURI(IEditorInput input) {
    Object adapter = input.getAdapter(IResource.class);
    if (adapter != null)
        return null;
    if (input instanceof IStorageEditorInput) {
        IStorage storage;/*w  w  w.  j  a  v  a 2s  . co  m*/
        try {
            storage = ((IStorageEditorInput) input).getStorage();
            if (storage instanceof IResource)
                return null;
            if (storage instanceof IJarEntryResource) {
                IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
                if (!jarEntryResource.getPackageFragmentRoot().isArchive())
                    return null;
                Object parent = jarEntryResource.getParent();
                if (parent instanceof IPackageFragment) {
                    String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
                    return new SourceRelativeURI(path + "/" + storage.getName());
                } else if (parent instanceof IPackageFragmentRoot) {
                    return new SourceRelativeURI(storage.getName());
                }
            }
        } catch (CoreException e) {
            logger.error("Error finding breakpoint URI", e);
            return null;
        }
    } else if (input instanceof IClassFileEditorInput) {
        IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
        if (classFile == null) {
            return null;
        }
        ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
        if (traceToSource == null)
            return null;
        for (ILocationInResource loc : traceToSource.getAllAssociatedLocations())
            return loc.getSrcRelativeResourceURI();
        return null;
    }
    return null;
}

From source file:org.jboss.tools.common.core.resources.XModelObjectEditorInput.java

License:Open Source License

private static IEditorInput convertStorageEditorInput(IStorageEditorInput input) {
    if (input instanceof JarEntryEditorInput) {
        IProject project = null;/*from   w  w  w  .  j  a v  a  2  s. com*/
        JarEntryEditorInput j = (JarEntryEditorInput) input;
        if (j.getStorage() instanceof IJarEntryResource) {
            IJarEntryResource file = (IJarEntryResource) j.getStorage();
            String jarFile = file.getPackageFragmentRoot().getPath().toString();
            if (file.getPackageFragmentRoot().getResource() != null) {
                jarFile = file.getPackageFragmentRoot().getResource().getLocation().toString();
            }
            String entry = file.getName();
            IJarEntryResource r = file;
            while (r != null && r.getParent() instanceof IJarEntryResource) {
                r = (IJarEntryResource) r.getParent();
                entry = r.getName() + "/" + entry;
            }
            if (r != null && r.getParent() instanceof IPackageFragment) {
                IPackageFragment pf = (IPackageFragment) r.getParent();
                IJavaProject jp = pf.getJavaProject();
                if (jp != null)
                    project = jp.getProject();
                while (pf != null) {
                    String p = pf.getElementName();
                    entry = p + "/" + entry;
                    if (pf.getParent() instanceof IPackageFragment) {
                        pf = (IPackageFragment) pf.getParent();
                    } else {
                        pf = null;
                    }
                }
            } else if (r != null && r.getPackageFragmentRoot() != null) {
                IPackageFragmentRoot root = r.getPackageFragmentRoot();
                if (root.getJavaProject() != null) {
                    project = root.getJavaProject().getProject();
                }
            }
            IEditorInput result = createJarEntryEditorInput(project, jarFile, entry);
            if (result != null)
                return result;
        }
    }
    String[] entryInfo = parseJarEntryFileInput(input);
    if (entryInfo == null)
        return input;
    String jarFile = entryInfo[0];
    String entry = entryInfo[1];
    IEditorInput result = createJarEntryEditorInput(null, jarFile, entry);
    return (result == null || result instanceof NullEditorInput) ? input : result;
}

From source file:org.summer.dsl.builder.smap.XbaseBreakpointUtil.java

License:Open Source License

public URI getBreakpointURI(IEditorInput input) {
    Object adapter = input.getAdapter(IResource.class);
    if (adapter != null)
        return null;
    if (input instanceof IStorageEditorInput) {
        IStorage storage;//  w  w  w. j  av  a2  s.  c o  m
        try {
            storage = ((IStorageEditorInput) input).getStorage();
            if (storage instanceof IResource)
                return null;
            if (storage instanceof IJarEntryResource) {
                IJarEntryResource jarEntryResource = (IJarEntryResource) storage;
                if (!jarEntryResource.getPackageFragmentRoot().isArchive())
                    return null;
                Object parent = jarEntryResource.getParent();
                if (parent instanceof IPackageFragment) {
                    String path = ((IPackageFragment) parent).getElementName().replace('.', '/');
                    return URI.createURI(path + "/" + storage.getName());
                } else if (parent instanceof IPackageFragmentRoot) {
                    return URI.createURI(storage.getName());
                }
            }
        } catch (CoreException e) {
            logger.error(e);
            return null;
        }
    } else if (input instanceof IClassFileEditorInput) {
        IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
        if (classFile == null) {
            return null;
        }
        ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile);
        if (traceToSource == null)
            return null;
        for (ILocationInResource loc : traceToSource.getAllAssociatedLocations())
            return loc.getSrcRelativeResourceURI();
        return null;
    }
    return null;
}