Example usage for org.eclipse.jdt.internal.core JarEntryResource setParent

List of usage examples for org.eclipse.jdt.internal.core JarEntryResource setParent

Introduction

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

Prototype

public void setParent(Object parent) 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.JarPackageFragment.java

License:Open Source License

/**
 * Compute all the non-java resources according to the given entry names.
 *//* www .j  a  va  2 s .c  om*/
private Object[] computeNonJavaResources(ArrayList entryNames) {
    int length = entryNames.size();
    if (length == 0)
        return JavaElementInfo.NO_NON_JAVA_RESOURCES;
    HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
    HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>
    ArrayList topJarEntries = new ArrayList();
    for (int i = 0; i < length; i++) {
        String resName = (String) entryNames.get(i);
        // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
        if (!com.codenvy.ide.ext.java.server.internal.core.util.Util.isJavaLikeFileName(resName)) {
            IPath filePath = new Path(resName);
            IPath childPath = filePath.removeFirstSegments(this.names.length);
            if (jarEntries.containsKey(childPath)) {
                // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222665
                continue;
            }
            JarEntryFile file = new JarEntryFile(filePath.lastSegment(), manager);
            jarEntries.put(childPath, file);
            if (childPath.segmentCount() == 1) {
                file.setParent(this);
                topJarEntries.add(file);
            } else {
                IPath parentPath = childPath.removeLastSegments(1);
                while (parentPath.segmentCount() > 0) {
                    ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
                    if (parentChildren == null) {
                        Object dir = new JarEntryDirectory(parentPath.lastSegment());
                        jarEntries.put(parentPath, dir);
                        childrenMap.put(parentPath, parentChildren = new ArrayList());
                        parentChildren.add(childPath);
                        if (parentPath.segmentCount() == 1) {
                            topJarEntries.add(dir);
                            break;
                        }
                        childPath = parentPath;
                        parentPath = childPath.removeLastSegments(1);
                    } else {
                        parentChildren.add(childPath);
                        break; // all parents are already registered
                    }
                }
            }
        }
    }
    Iterator entries = childrenMap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        IPath entryPath = (IPath) entry.getKey();
        ArrayList entryValue = (ArrayList) entry.getValue();
        JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
        int size = entryValue.size();
        IJarEntryResource[] children = new IJarEntryResource[size];
        for (int i = 0; i < size; i++) {
            JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
            child.setParent(jarEntryDirectory);
            children[i] = child;
        }
        jarEntryDirectory.setChildren(children);
        if (entryPath.segmentCount() == 1) {
            jarEntryDirectory.setParent(this);
        }
    }
    return topJarEntries.toArray(new Object[topJarEntries.size()]);
}

From source file:org.eclipse.che.jdt.internal.core.JarPackageFragment.java

License:Open Source License

/**
 * Compute all the non-java resources according to the given entry names.
 *//*ww  w . j  av a 2 s  .c o  m*/
private Object[] computeNonJavaResources(ArrayList entryNames) {
    int length = entryNames.size();
    if (length == 0)
        return JavaElementInfo.NO_NON_JAVA_RESOURCES;
    HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
    HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>
    ArrayList topJarEntries = new ArrayList();
    for (int i = 0; i < length; i++) {
        String resName = (String) entryNames.get(i);
        // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
        if (!org.eclipse.che.jdt.internal.core.util.Util.isJavaLikeFileName(resName)) {
            IPath filePath = new Path(resName);
            IPath childPath = filePath.removeFirstSegments(this.names.length);
            if (jarEntries.containsKey(childPath)) {
                // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222665
                continue;
            }
            JarEntryFile file = new JarEntryFile(filePath.lastSegment(), manager);
            jarEntries.put(childPath, file);
            if (childPath.segmentCount() == 1) {
                file.setParent(this);
                topJarEntries.add(file);
            } else {
                IPath parentPath = childPath.removeLastSegments(1);
                while (parentPath.segmentCount() > 0) {
                    ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
                    if (parentChildren == null) {
                        Object dir = new JarEntryDirectory(parentPath.lastSegment());
                        jarEntries.put(parentPath, dir);
                        childrenMap.put(parentPath, parentChildren = new ArrayList());
                        parentChildren.add(childPath);
                        if (parentPath.segmentCount() == 1) {
                            topJarEntries.add(dir);
                            break;
                        }
                        childPath = parentPath;
                        parentPath = childPath.removeLastSegments(1);
                    } else {
                        parentChildren.add(childPath);
                        break; // all parents are already registered
                    }
                }
            }
        }
    }
    Iterator entries = childrenMap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        IPath entryPath = (IPath) entry.getKey();
        ArrayList entryValue = (ArrayList) entry.getValue();
        JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
        int size = entryValue.size();
        IJarEntryResource[] children = new IJarEntryResource[size];
        for (int i = 0; i < size; i++) {
            JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
            child.setParent(jarEntryDirectory);
            children[i] = child;
        }
        jarEntryDirectory.setChildren(children);
        if (entryPath.segmentCount() == 1) {
            jarEntryDirectory.setParent(this);
        }
    }
    return topJarEntries.toArray(new Object[topJarEntries.size()]);
}

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

License:Open Source License

/**
 * Compute all the non-java resources according to the given entry names.
 */// w  ww  . j  a  v a2  s.  com
private Object[] computeNonJavaResources(ArrayList entryNames) {
    int length = entryNames.size();
    if (length == 0)
        return JavaElementInfo.NO_NON_JAVA_RESOURCES;
    HashMap jarEntries = new HashMap(); // map from IPath to IJarEntryResource
    HashMap childrenMap = new HashMap(); // map from IPath to ArrayList<IJarEntryResource>

    // GROOVY start
    boolean isInteresting = LanguageSupportFactory.isInterestingProject(this.getJavaProject().getProject());
    // GROOVY end

    ArrayList topJarEntries = new ArrayList();
    for (int i = 0; i < length; i++) {
        String resName = (String) entryNames.get(i);
        // consider that a .java file is not a non-java resource (see bug 12246 Packages view shows .class and .java files when JAR has source)
        // GROOVY start 
        // we want to show uncompiled groovy scripts that are coming in from a jar file
        /* old {
        if (!Util.isJavaLikeFileName(resName)) {
        } new */
        if ((!Util.isJavaLikeFileName(resName)
                || (isInteresting && LanguageSupportFactory.isInterestingSourceFile(resName)))) {
            // GROOVY end
            IPath filePath = new Path(resName);
            IPath childPath = filePath.removeFirstSegments(this.names.length);
            if (jarEntries.containsKey(childPath)) {
                // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222665
                continue;
            }
            JarEntryFile file = new JarEntryFile(filePath.lastSegment());
            jarEntries.put(childPath, file);
            if (childPath.segmentCount() == 1) {
                file.setParent(this);
                topJarEntries.add(file);
            } else {
                IPath parentPath = childPath.removeLastSegments(1);
                while (parentPath.segmentCount() > 0) {
                    ArrayList parentChildren = (ArrayList) childrenMap.get(parentPath);
                    if (parentChildren == null) {
                        Object dir = new JarEntryDirectory(parentPath.lastSegment());
                        jarEntries.put(parentPath, dir);
                        childrenMap.put(parentPath, parentChildren = new ArrayList());
                        parentChildren.add(childPath);
                        if (parentPath.segmentCount() == 1) {
                            topJarEntries.add(dir);
                            break;
                        }
                        childPath = parentPath;
                        parentPath = childPath.removeLastSegments(1);
                    } else {
                        parentChildren.add(childPath);
                        break; // all parents are already registered
                    }
                }
            }
        }
    }
    Iterator entries = childrenMap.entrySet().iterator();
    while (entries.hasNext()) {
        Map.Entry entry = (Map.Entry) entries.next();
        IPath entryPath = (IPath) entry.getKey();
        ArrayList entryValue = (ArrayList) entry.getValue();
        JarEntryDirectory jarEntryDirectory = (JarEntryDirectory) jarEntries.get(entryPath);
        int size = entryValue.size();
        IJarEntryResource[] children = new IJarEntryResource[size];
        for (int i = 0; i < size; i++) {
            JarEntryResource child = (JarEntryResource) jarEntries.get(entryValue.get(i));
            child.setParent(jarEntryDirectory);
            children[i] = child;
        }
        jarEntryDirectory.setChildren(children);
        if (entryPath.segmentCount() == 1) {
            jarEntryDirectory.setParent(this);
        }
    }
    return topJarEntries.toArray(new Object[topJarEntries.size()]);
}

From source file:org.jboss.tools.common.model.ui.editor.ModelObjectStorageEditorInput.java

License:Open Source License

IJarEntryResource findJarEntryFile() {
    XModelObject o = object;//from   w w  w . j  a  v  a 2 s. c  om
    JarEntryFile f = null;
    JarEntryResource current = null;
    String packageName = "";
    List<String> parts = new ArrayList<String>();
    List<XModelObject> os = new ArrayList<XModelObject>();
    while (o != null && o.getFileType() != XModelObject.SYSTEM) {
        String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o)
                : o.getFileType() == XModelObject.FOLDER ? o.getAttributeValue(XModelObjectConstants.ATTR_NAME)
                        : null;
        if (part != null) {
            parts.add(0, part);
            os.add(0, o);
            if (f == null) {
                f = new JarEntryFile(part) {
                    public InputStream getContents() throws CoreException {
                        return storage.getContents();
                    }
                };
                current = f;
            } else {
                if (packageName.length() > 0) {
                    packageName = part + "." + packageName;
                } else {
                    packageName = part;
                }
                JarEntryDirectory d = new JarEntryDirectory(part);
                current.setParent(d);
                current = d;
            }

        }
        o = o.getParent();
    }
    //      if(!(o instanceof JarSystemImpl)) return null;
    String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION), o.getModel().getProperties());

    IProject p = EclipseResourceUtil.getProject(o);
    IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
    if (jp == null)
        return null;

    IPackageFragmentRoot root = null;

    try {
        IPackageFragmentRoot[] rs = jp.getAllPackageFragmentRoots();
        for (IPackageFragmentRoot r : rs) {
            if (r.getResource() != null && r.getResource().exists()
                    && r.getResource().getLocation().toString().equals(file)) {
                root = r;
            } else if (r.getPath() != null && r.getPath().toString().equals(file)) {
                root = r;
            }
        }
    } catch (CoreException e) {
        ModelUIPlugin.getDefault().logError(e);
    }

    if (root == null) {
        root = jp.getPackageFragmentRoot(file);
    }

    if (root == null) {
        return null;
    }

    if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) {
        IPackageFragment pf = root.getPackageFragment(packageName);
        f.setParent(pf);
    } else {
        current.setParent(root);
        if (!(o instanceof JarSystemImpl)) {
            Object q = root;
            NonJavaResource nj = null;
            for (int i = 0; i < parts.size(); i++) {
                IResource ri = (IResource) os.get(i).getAdapter(IResource.class);
                if (ri == null) {
                    return f;
                }
                nj = new NonJavaResource(q, ri);
                q = nj;
            }
            if (nj != null) {
                return nj;
            }
        }
    }

    return f;
}

From source file:org.jboss.tools.common.model.ui.jarproperties.JarPropertiesTest.java

License:Open Source License

JarEntryFile getJarEntryFileForResource(IProject p, IResource file, String packageName, String fileName) {
    JarEntryFile f = new JarEntryFile(fileName);
    JarEntryResource current = f;

    IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
    if (jp == null)
        return null;

    IPackageFragmentRoot root = jp.getPackageFragmentRoot(file);
    if (root == null)
        return null;

    if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) {
        IPackageFragment pf = root.getPackageFragment(packageName);
        f.setParent(pf);//from ww w . ja v  a2 s .co m
    } else {
        current.setParent(root);
    }

    return f;
}

From source file:org.jboss.tools.common.text.ext.hyperlink.xml.FaceletSourceTagHyperlink.java

License:Open Source License

@Override
protected void doHyperlink(IRegion region) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart editorPart = page.getActiveEditor();
    // if we open taglib definition in jar file
    JarEntryFile current = null;/* w w  w  . ja va2 s.  c  om*/
    try {
        if (editorPart.getEditorInput() instanceof IStorageEditorInput
                && ((IStorageEditorInput) editorPart.getEditorInput()).getStorage() instanceof JarEntryFile) {
            current = (JarEntryFile) ((IStorageEditorInput) editorPart.getEditorInput()).getStorage();
        }
    } catch (CoreException e) {
        ExtensionsPlugin.getDefault().logError(e);
    }
    if (current != null) {
        String fileToOpenName = getFilePath(region);
        if (fileToOpenName != null) {
            //remove whitespaces and first '/'
            fileToOpenName = fileToOpenName.trim();
            if (fileToOpenName.indexOf('/') == 0) {
                fileToOpenName = fileToOpenName.substring(1);
            }
            int ii = fileToOpenName.lastIndexOf('/');
            String folder = ii < 0 ? "" : fileToOpenName.substring(0, ii);
            fileToOpenName = fileToOpenName.substring(ii + 1);
            JarEntryFile fileToOpen = new JarEntryFile(fileToOpenName);

            if (folder.length() > 0) {
                if (folder.startsWith("META-INF")) {
                    JarEntryResource r = null;
                    while (folder.length() > 0) {
                        int iii = folder.indexOf('/');
                        String name = iii < 0 ? folder : folder.substring(0, iii);
                        folder = iii < 0 ? "" : folder.substring(iii + 1);
                        fileToOpenName = fileToOpenName.substring(fileToOpenName.indexOf('/') + 1);
                        JarEntryResource r1 = new JarEntryDirectory(name);
                        r1.setParent(r != null ? r : current.getPackageFragmentRoot());
                        r = r1;
                    }
                    fileToOpen.setParent(r);
                } else {
                    IPackageFragment pf = current.getPackageFragmentRoot()
                            .getPackageFragment(folder.replace('/', '.'));
                    fileToOpen.setParent(pf);
                }
            } else {
                fileToOpen.setParent(current.getPackageFragmentRoot());
            }

            JarEntryEditorInput editorInputToOpenEditor = new JarEntryEditorInput(fileToOpen);
            IEditorPart openedEditor = openFileInEditor(editorInputToOpenEditor, fileToOpen.getName());
            if (openedEditor == null) {
                openFileFailed();
            }
        }
        return;
    } else if (editorPart.getEditorInput() instanceof IStorageEditorInput) {
        IStorageEditorInput modelObjectStorageEditorInput = (IStorageEditorInput) editorPart.getEditorInput();
        try {

            IStorage storage = modelObjectStorageEditorInput.getStorage();
            if (storage != null && getFilePath(region) != null) {
                if (openOnFromModelEditorIntup(storage.getFullPath(), getFilePath(region))) {
                    return;
                }
            }
        } catch (CoreException e) {
            ExtensionsPlugin.getDefault().logError(e);
        }
    }
    super.doHyperlink(region);
}