Search in sources :

Example 46 with IFolder

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

the class RenamePackageTest method testHierarchicalToSuperpackage.

@Test
@Ignore
public void testHierarchicalToSuperpackage() throws Exception {
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "a.b", "a.b.b", "a", "p" }, new String[][] { { "B" }, { "BB" }, {} }, "a", true);
    IPackageFragment thisPackage = rename.fPackages[0];
    IFolder src = (IFolder) getRoot().getResource();
    IFolder a = src.getFolder("a");
    IFolder ab = src.getFolder("a/b");
    IFolder abb = src.getFolder("a/b/b");
    ParticipantTesting.reset();
    String[] createHandles = {};
    String[] deleteHandles = {};
    String[] moveHandles = ParticipantTesting.createHandles(ab.getFile("B.java"), abb.getFile("BB.java"));
    String[] renameHandles = ParticipantTesting.createHandles(JavaElementUtil.getPackageAndSubpackages(thisPackage));
    rename.createAndPerform(RefactoringStatus.OK);
    rename.checkExpectedState();
    ParticipantTesting.testCreate(createHandles);
    ParticipantTesting.testDelete(deleteHandles);
    ParticipantTesting.testMove(moveHandles, new MoveArguments[] { new MoveArguments(a, true), new MoveArguments(ab, true) });
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments("a", true), new RenameArguments("a.b", true) });
    performUndo();
    rename.checkOriginalState();
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with IFolder

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

the class RenamePackageTest method testHierarchicalToSubpackage.

@Test
@Ignore
public void testHierarchicalToSubpackage() throws Exception {
    fRenameSubpackages = true;
    PackageRename rename = new PackageRename(new String[] { "a", "a.b", "a.b.c", "a.b.c.d", "p" }, new String[][] { {}, { "B" }, { "C" }, { "D" } }, "a.b", true);
    IPackageFragment thisPackage = rename.fPackages[0];
    IFolder src = (IFolder) getRoot().getResource();
    IFolder ab = src.getFolder("a/b");
    IFolder abc = ab.getFolder("c");
    IFolder abcd = abc.getFolder("d");
    IFolder abb = ab.getFolder("b");
    IFolder abbc = abb.getFolder("c");
    IFolder abbcd = abbc.getFolder("d");
    ParticipantTesting.reset();
    String[] createHandles = ParticipantTesting.createHandles(abb, abbc, abbcd);
    String[] deleteHandles = {};
    String[] moveHandles = ParticipantTesting.createHandles(ab.getFile("B.java"), abc.getFile("C.java"), abcd.getFile("D.java"));
    String[] renameHandles = ParticipantTesting.createHandles(JavaElementUtil.getPackageAndSubpackages(thisPackage));
    rename.createAndPerform(RefactoringStatus.WARNING);
    rename.checkExpectedState();
    ParticipantTesting.testCreate(createHandles);
    ParticipantTesting.testDelete(deleteHandles);
    ParticipantTesting.testMove(moveHandles, new MoveArguments[] { new MoveArguments(abb, true), new MoveArguments(abbc, true), new MoveArguments(abbcd, true) });
    ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(rename.getNewPackageName(rename.fPackageNames[0]), true), new RenameArguments(rename.getNewPackageName(rename.fPackageNames[1]), true), new RenameArguments(rename.getNewPackageName(rename.fPackageNames[2]), true), new RenameArguments(rename.getNewPackageName(rename.fPackageNames[3]), true) });
    performUndo();
    rename.checkOriginalState();
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 with IFolder

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

the class RenamePackageTest method helper2.

private RenamePackageProcessor helper2(String[] packageNames, String[][] packageFileNames, String newPackageName) throws Exception {
    ParticipantTesting.reset();
    IPackageFragment[] packages = new IPackageFragment[packageNames.length];
    ICompilationUnit[][] cus = new ICompilationUnit[packageFileNames.length][packageFileNames[0].length];
    for (int i = 0; i < packageNames.length; i++) {
        packages[i] = getRoot().createPackageFragment(packageNames[i], true, null);
        for (int j = 0; j < packageFileNames[i].length; j++) {
            cus[i][j] = createCUfromTestFile(packages[i], packageFileNames[i][j], packageNames[i].replace('.', '/') + "/");
        }
    }
    IPackageFragment thisPackage = packages[0];
    boolean hasSubpackages = thisPackage.hasSubpackages();
    IPath path = thisPackage.getParent().getPath();
    path = path.append(newPackageName.replace('.', '/'));
    IFolder target = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
    boolean targetExists = target.exists();
    boolean isRename = !targetExists && !thisPackage.hasSubpackages() && thisPackage.getResource().getParent().equals(target.getParent());
    String[] createHandles = null;
    String[] moveHandles = null;
    String[] deleteHandles = null;
    boolean doDelete = true;
    String[] renameHandles = null;
    if (isRename) {
        renameHandles = ParticipantTesting.createHandles(thisPackage, thisPackage.getResource());
    } else {
        renameHandles = ParticipantTesting.createHandles(thisPackage);
        IContainer loop = target;
        List handles = new ArrayList();
        while (loop != null && !loop.exists()) {
            handles.add(ParticipantTesting.createHandles(loop)[0]);
            loop = loop.getParent();
        }
        createHandles = (String[]) handles.toArray(new String[handles.size()]);
        IFolder source = (IFolder) thisPackage.getResource();
        deleteHandles = ParticipantTesting.createHandles(source);
        IResource[] members = source.members();
        List movedObjects = new ArrayList();
        for (int i = 0; i < members.length; i++) {
            if (members[i] instanceof IFolder) {
                doDelete = false;
            } else {
                movedObjects.add(members[i]);
            }
        }
        moveHandles = ParticipantTesting.createHandles(movedObjects.toArray());
    }
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(thisPackage, newPackageName);
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    setFilePatterns(descriptor);
    Refactoring refactoring = createRefactoring(descriptor);
    RefactoringStatus result = performRefactoring(refactoring);
    TestCase.assertEquals("preconditions were supposed to pass", null, result);
    if (isRename) {
        ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(newPackageName, fUpdateReferences), new RenameArguments(target.getName(), fUpdateReferences) });
    } else {
        ParticipantTesting.testRename(renameHandles, new RenameArguments[] { new RenameArguments(newPackageName, fUpdateReferences) });
        ParticipantTesting.testCreate(createHandles);
        List args = new ArrayList();
        for (int i = 0; i < packageFileNames[0].length; i++) {
            args.add(new MoveArguments(target, fUpdateReferences));
        }
        ParticipantTesting.testMove(moveHandles, (MoveArguments[]) args.toArray(new MoveArguments[args.size()]));
        if (doDelete) {
            ParticipantTesting.testDelete(deleteHandles);
        } else {
            ParticipantTesting.testDelete(new String[0]);
        }
    }
    if (hasSubpackages) {
        assertTrue("old package does not exist anymore", getRoot().getPackageFragment(packageNames[0]).exists());
    } else {
        assertTrue("package not renamed", !getRoot().getPackageFragment(packageNames[0]).exists());
    }
    IPackageFragment newPackage = getRoot().getPackageFragment(newPackageName);
    assertTrue("new package does not exist", newPackage.exists());
    for (int i = 0; i < packageFileNames.length; i++) {
        String packageName = (i == 0) ? newPackageName.replace('.', '/') + "/" : packageNames[i].replace('.', '/') + "/";
        for (int j = 0; j < packageFileNames[i].length; j++) {
            String s1 = getFileContents(getOutputTestFileName(packageFileNames[i][j], packageName));
            ICompilationUnit cu = (i == 0) ? newPackage.getCompilationUnit(packageFileNames[i][j] + ".java") : cus[i][j];
            //DebugUtils.dump("cu:" + cu.getElementName());
            String s2 = cu.getSource();
            //DebugUtils.dump("expected:" + s1);
            //DebugUtils.dump("was:" + s2);
            assertEqualLines("invalid update in file " + cu.getElementName(), s1, s2);
        }
    }
    RefactoringProcessor processor = ((ProcessorBasedRefactoring) refactoring).getProcessor();
    return (RenamePackageProcessor) processor;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenamePackageProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor) IPath(org.eclipse.core.runtime.IPath) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) List(java.util.List) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 49 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class StandaloneJobRepositoryMavenSetting method createMavenScriptsChildren.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.maven.ui.setting.repository.RepositoryMavenSetting#createMavenScriptsChildren(org.eclipse
     * .jface.preference.IPreferenceNode, org.talend.repository.model.RepositoryNode)
     */
@Override
public void createMavenScriptsChildren(IPreferenceNode parentNode, RepositoryNode node) {
    StandaloneJobRepositorySettingNode standaloneJobNode = new StandaloneJobRepositorySettingNode(parentNode.getId(), node);
    parentNode.add(standaloneJobNode);
    IFolder nodeFolder = DesignerMavenUiHelper.getNodeFolder(node);
    List<IPreferenceNode> standaloneJobChildrenNodes = createStandaloneJobChildrenNodes(nodeFolder, node, standaloneJobNode.getId(), true);
    for (IPreferenceNode n : standaloneJobChildrenNodes) {
        standaloneJobNode.add(n);
    }
}
Also used : StandaloneJobRepositorySettingNode(org.talend.designer.maven.job.setting.repository.standalone.node.StandaloneJobRepositorySettingNode) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) IFolder(org.eclipse.core.resources.IFolder)

Example 50 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class AutoConversionTypesEditor method applyChange.

private void applyChange() {
    try {
        IProject project = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
        IFolder prefsSettingFolder = ResourceUtils.getFolder(project, RepositoryConstants.SETTING_DIRECTORY, false);
        AutoConvertTypesUtils.save(typeModel.getBeansList(), AutoConvertTypesUtils.getTypeFile());
        prefsSettingFolder.refreshLocal(IResource.DEPTH_ONE, null);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

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