Search in sources :

Example 21 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JavaNavigation method getPackageFragmentRootContent.

public List<JarEntry> getPackageFragmentRootContent(IJavaProject project, int hash) throws JavaModelException {
    IPackageFragmentRoot packageFragmentRoot = getPackageFragmentRoot(project, hash);
    if (packageFragmentRoot == null) {
        return NO_ENTRIES;
    }
    Object[] rootContent = getPackageFragmentRootContent(packageFragmentRoot);
    return convertToJarEntry(rootContent, packageFragmentRoot);
}
Also used : IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 22 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class JavaNavigation method getHierarchicalPackageParent.

public Object getHierarchicalPackageParent(IPackageFragment child) {
    String name = child.getElementName();
    IPackageFragmentRoot parent = (IPackageFragmentRoot) child.getParent();
    int index = name.lastIndexOf('.');
    if (index != -1) {
        String realParentName = name.substring(0, index);
        IPackageFragment element = parent.getPackageFragment(realParentName);
        if (element.exists()) {
            try {
                if (fFoldPackages && isEmpty(element) && findSinglePackageChild(element, parent.getChildren()) != null) {
                    return getHierarchicalPackageParent(element);
                }
            } catch (JavaModelException e) {
            // ignore
            }
            return element;
        }
    /*else { // bug 65240
                IResource resource= element.getResource();
                if (resource != null) {
                    return resource;
                }
            }*/
    }
    //        }
    return parent;
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 23 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class CopyModifications method copy.

public void copy(IPackageFragment pack, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
    add(pack, javaArgs, null);
    ResourceMapping mapping = JavaElementResourceMapping.create(pack);
    if (mapping != null) {
        add(mapping, resourceArgs, null);
    }
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) javaArgs.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    // the new name yet, so we use the current package name.
    if (!pack.hasSubpackages() && (!newPack.exists() || pack.equals(newPack))) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addCopyDelta(pack.getResource(), resourceArgs);
    } else {
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        CopyArguments arguments = new CopyArguments(resourceDestination, resourceArgs.getExecutionLog());
        IResource[] resourcesToCopy = collectResourcesOfInterest(pack);
        for (int i = 0; i < resourcesToCopy.length; i++) {
            IResource toCopy = resourcesToCopy[i];
            getResourceModifications().addCopyDelta(toCopy, arguments);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CopyArguments(org.eclipse.ltk.core.refactoring.participants.CopyArguments) JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 24 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class MoveModifications method move.

public void move(IPackageFragment pack, MoveArguments args) throws CoreException {
    add(pack, args, null);
    if (pack.getResource() == null)
        return;
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) args.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    if (!pack.hasSubpackages() && !newPack.exists()) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addMove(pack.getResource(), new MoveArguments(resourceDestination, args.getUpdateReferences()));
    } else {
        IContainer resourceSource = (IContainer) pack.getResource();
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        MoveArguments arguments = new MoveArguments(resourceDestination, args.getUpdateReferences());
        IResource[] resourcesToMove = collectResourcesOfInterest(pack);
        Set<IResource> allMembers = new HashSet<IResource>(Arrays.asList(resourceSource.members()));
        for (int i = 0; i < resourcesToMove.length; i++) {
            IResource toMove = resourcesToMove[i];
            getResourceModifications().addMove(toMove, arguments);
            allMembers.remove(toMove);
        }
        for (Iterator<IResource> iter = allMembers.iterator(); iter.hasNext(); ) {
            IResource element = iter.next();
            if (element instanceof IFile) {
                getResourceModifications().addDelete(element);
                iter.remove();
            }
        }
        if (allMembers.isEmpty()) {
            getResourceModifications().addDelete(resourceSource);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) HashSet(java.util.HashSet)

Example 25 with IPackageFragmentRoot

use of org.eclipse.jdt.core.IPackageFragmentRoot in project che by eclipse.

the class ReorgUtils method isArchiveOrExternalMember.

public static boolean isArchiveOrExternalMember(IJavaElement[] elements) {
    for (int i = 0; i < elements.length; i++) {
        IJavaElement element = elements[i];
        IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        if (root != null && (root.isArchive() || root.isExternal()))
            return true;
    }
    return false;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)171 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)94 Test (org.junit.Test)91 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)77 OrganizeImportsOperation (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation)67 IChooseImportQuery (org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.IChooseImportQuery)67 IJavaProject (org.eclipse.jdt.core.IJavaProject)30 File (java.io.File)26 IJavaElement (org.eclipse.jdt.core.IJavaElement)20 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)16 IResource (org.eclipse.core.resources.IResource)16 IPath (org.eclipse.core.runtime.IPath)13 ArrayList (java.util.ArrayList)12 Path (org.eclipse.core.runtime.Path)11 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)11 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IType (org.eclipse.jdt.core.IType)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)8 IFolder (org.eclipse.core.resources.IFolder)7