Search in sources :

Example 41 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class DeltaProcessor method updateRootIndex.

/*
     * Updates the index of the given root (assuming it's an addition or a removal).
     * This is done recusively, pkg being the current package.
     */
private void updateRootIndex(PackageFragmentRoot root, String[] pkgName, IResourceDelta delta) {
    Openable pkg = root.getPackageFragment(pkgName);
    updateIndex(pkg, delta);
    IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
    for (int i = 0, length = children.length; i < length; i++) {
        IResourceDelta child = children[i];
        IResource resource = child.getResource();
        if (resource instanceof IFolder) {
            String[] subpkgName = Util.arrayConcat(pkgName, resource.getName());
            updateRootIndex(root, subpkgName, child);
        }
    }
}
Also used : IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class JavaElementResourceMapping method getPackageFragmentTraversals.

private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        if (pack.exists()) {
            // folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167
            Object[] nonJavaResources = pack.getNonJavaResources();
            for (int i = 0; i < nonJavaResources.length; i++) {
                Object resource = nonJavaResources[i];
                if (resource instanceof IFolder) {
                    res.add(new ResourceTraversal(new IResource[] { (IResource) resource }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 43 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class JavaElementResourceMapping method getRemotePackageFragmentTraversals.

private static ResourceTraversal[] getRemotePackageFragmentTraversals(IPackageFragment pack, RemoteResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        IResource[] remoteMembers = context.fetchRemoteMembers(container, monitor);
        if (remoteMembers == null) {
            remoteMembers = context.fetchMembers(container, monitor);
        }
        if (remoteMembers != null) {
            for (int i = 0; i < remoteMembers.length; i++) {
                IResource member = remoteMembers[i];
                if (member instanceof IFolder && JavaConventionsUtil.validatePackageName(member.getName(), pack).getSeverity() == IStatus.ERROR) {
                    res.add(new ResourceTraversal(new IResource[] { member }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 44 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class RenameNonPrivateFieldTest method createPropertiesFromTestFile.

private IFile createPropertiesFromTestFile(String propertyName) throws IOException, CoreException {
    IFolder pack = (IFolder) getPackageP().getResource();
    IFile file = pack.getFile(propertyName + ".properties");
    String fileName = getInputTestFileName(propertyName);
    fileName = fileName.substring(0, fileName.length() - ".java".length()) + ".properties";
    InputStream inputStream = getFileInputStream(fileName);
    file.create(inputStream, true, null);
    return file;
}
Also used : IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 45 with IFolder

use of org.eclipse.core.resources.IFolder in project che by eclipse.

the class RenamePackageTest method testPackageRenameWithResource1.

@Test
public void testPackageRenameWithResource1() throws Exception {
    IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
    StringBuffer buf = new StringBuffer();
    buf.append("package org.test;\n");
    buf.append("public class MyClass {\n");
    buf.append("	org.test.MyClass me;\n");
    buf.append("}\n");
    fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
    IFile file = ((IFolder) getRoot().getResource()).getFile("x.properties");
    byte[] content = "This is about 'org.test' and more".getBytes();
    file.create(new ByteArrayInputStream(content), true, null);
    file.refreshLocal(IResource.DEPTH_ONE, null);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setJavaElement(fragment);
    descriptor.setNewName("org.test2");
    descriptor.setUpdateReferences(true);
    descriptor.setUpdateQualifiedNames(true);
    descriptor.setFileNamePatterns("*.properties");
    Refactoring refactoring = createRefactoring(descriptor);
    RefactoringStatus status = performRefactoring(refactoring);
    if (status != null)
        assertTrue(status.toString(), status.isOK());
    RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
    IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
    IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
    checkMappingUnchanged(jm, rm, new Object[] { getRoot().getJavaProject(), getRoot(), file });
    IFile newFile = ((IContainer) getRoot().getResource()).getFile(new Path("x.properties"));
    assertEquals("This is about 'org.test2' and more", getContents(newFile));
    checkMappingChanged(jm, rm, new Object[][] { { fragment, getRoot().getPackageFragment("org.test2") } });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResourceMapper(org.eclipse.ltk.core.refactoring.IResourceMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IContainer(org.eclipse.core.resources.IContainer) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15