Search in sources :

Example 6 with RefactoringDescriptorProxy

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.

the class RefactoringHistorySerializer method processHistoryNotification.

/**
	 * Processes the history event.
	 *
	 * @param store
	 *            the file store
	 * @param event
	 *            the history event
	 * @param name
	 *            the project name, or <code>null</code>
	 * @throws CoreException
	 *             if an error occurs
	 */
private void processHistoryNotification(final IFileStore store, final RefactoringHistoryEvent event, final String name) throws CoreException {
    final RefactoringDescriptorProxy proxy = event.getDescriptor();
    final int type = event.getEventType();
    final RefactoringHistoryManager manager = new RefactoringHistoryManager(store, name);
    final NullProgressMonitor monitor = new NullProgressMonitor();
    if (type == RefactoringHistoryEvent.PUSHED || type == RefactoringHistoryEvent.ADDED) {
        final RefactoringDescriptor descriptor = proxy.requestDescriptor(monitor);
        if (descriptor != null)
            manager.addRefactoringDescriptor(descriptor, type == RefactoringHistoryEvent.ADDED, monitor);
    } else if (type == RefactoringHistoryEvent.POPPED)
        manager.removeRefactoringDescriptors(new RefactoringDescriptorProxy[] { proxy }, monitor, RefactoringCoreMessages.RefactoringHistoryService_updating_history);
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy)

Example 7 with RefactoringDescriptorProxy

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.

the class RefactoringHistoryService method deleteRefactoringDescriptors.

/**
	 * Deletes the specified refactoring descriptors from their associated
	 * refactoring histories.
	 *
	 * @param proxies
	 *            the refactoring descriptor proxies
	 * @param query
	 *            the refactoring descriptor delete query to use
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while deleting the refactoring
	 *             descriptors. Reasons include:
	 *             <ul>
	 *             <li>The refactoring history has an illegal format, contains
	 *             illegal arguments or otherwise illegal information.</li>
	 *             <li>An I/O error occurs while deleting the refactoring
	 *             descriptors from the refactoring history.</li>
	 *             </ul>
	 *
	 * @see IRefactoringCoreStatusCodes#REFACTORING_HISTORY_FORMAT_ERROR
	 * @see IRefactoringCoreStatusCodes#REFACTORING_HISTORY_IO_ERROR
	 */
public void deleteRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies, final IRefactoringDescriptorDeleteQuery query, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(proxies);
    Assert.isNotNull(query);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings, proxies.length + 300);
        final Set set = new HashSet(proxies.length);
        for (int index = 0; index < proxies.length; index++) {
            if (query.proceed(proxies[index]).isOK())
                set.add(proxies[index]);
            monitor.worked(1);
        }
        if (!set.isEmpty()) {
            final RefactoringDescriptorProxy[] delete = (RefactoringDescriptorProxy[]) set.toArray(new RefactoringDescriptorProxy[set.size()]);
            deleteRefactoringDescriptors(delete, new SubProgressMonitor(monitor, 300));
            for (int index = 0; index < delete.length; index++) fireRefactoringHistoryEvent(delete[index], RefactoringHistoryEvent.DELETED);
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) HashSet(java.util.HashSet) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 8 with RefactoringDescriptorProxy

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.

the class RefactoringHistoryService method getRefactoringHistory.

/**
	 * {@inheritDoc}
	 */
public RefactoringHistory getRefactoringHistory(final IProject[] projects, final long start, final long end, final int flags, IProgressMonitor monitor) {
    Assert.isNotNull(projects);
    Assert.isTrue(start >= 0);
    Assert.isTrue(end >= start);
    Assert.isTrue(flags >= RefactoringDescriptor.NONE);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 3 * projects.length);
        final Set set = new HashSet();
        if (flags > RefactoringDescriptor.NONE) {
            for (int index = 0; index < projects.length; index++) {
                final IProject project = projects[index];
                if (project.isAccessible()) {
                    final RefactoringDescriptorProxy[] proxies = getProjectHistory(project, start, end, flags, new SubProgressMonitor(monitor, 1)).getDescriptors();
                    filterRefactoringDescriptors(proxies, set, false, flags, new SubProgressMonitor(monitor, 2));
                }
            }
        } else {
            for (int index = 0; index < projects.length; index++) {
                final IProject project = projects[index];
                if (project.isAccessible()) {
                    final RefactoringDescriptorProxy[] proxies = getProjectHistory(project, start, end, RefactoringDescriptor.NONE, new SubProgressMonitor(monitor, 3)).getDescriptors();
                    for (int offset = 0; offset < proxies.length; offset++) set.add(proxies[offset]);
                }
            }
        }
        final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[set.size()];
        set.toArray(proxies);
        return new RefactoringHistoryImplementation(proxies);
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) HashSet(java.util.HashSet) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 9 with RefactoringDescriptorProxy

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.

the class RefactoringHistoryService method getProjectHistory.

/**
	 * {@inheritDoc}
	 */
public RefactoringHistory getProjectHistory(final IProject project, final long start, final long end, final int flags, IProgressMonitor monitor) {
    Assert.isNotNull(project);
    Assert.isTrue(project.exists());
    Assert.isTrue(start >= 0);
    Assert.isTrue(end >= 0);
    Assert.isTrue(flags >= RefactoringDescriptor.NONE);
    if (project.isOpen()) {
        if (monitor == null)
            monitor = new NullProgressMonitor();
        try {
            monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 120);
            final String name = project.getName();
            final RefactoringHistoryManager manager = getManager(name);
            if (manager != null) {
                RefactoringHistory history = manager.readRefactoringHistory(start, end, new SubProgressMonitor(monitor, 20));
                if (flags > RefactoringDescriptor.NONE) {
                    final Set set = new HashSet();
                    filterRefactoringDescriptors(history.getDescriptors(), set, false, flags, new SubProgressMonitor(monitor, 100));
                    history = new RefactoringHistoryImplementation((RefactoringDescriptorProxy[]) set.toArray(new RefactoringDescriptorProxy[set.size()]));
                }
                return history;
            }
        } finally {
            monitor.done();
        }
    }
    return NO_HISTORY;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) HashSet(java.util.HashSet) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) RefactoringHistory(org.eclipse.ltk.core.refactoring.history.RefactoringHistory) HashSet(java.util.HashSet)

Example 10 with RefactoringDescriptorProxy

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy in project che by eclipse.

the class RefactoringHistoryService method deleteRefactoringDescriptors.

/**
	 * Deletes the specified refactoring descriptors from their associated
	 * refactoring histories.
	 *
	 * @param proxies
	 *            the refactoring descriptor proxies
	 * @param monitor
	 *            the progress monitor to use, or <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while deleting the refactoring
	 *             descriptors. Reasons include:
	 *             <ul>
	 *             <li>The refactoring history has an illegal format, contains
	 *             illegal arguments or otherwise illegal information.</li>
	 *             <li>An I/O error occurs while deleting the refactoring
	 *             descriptors from the refactoring history.</li>
	 *             </ul>
	 *
	 * @see IRefactoringCoreStatusCodes#REFACTORING_HISTORY_FORMAT_ERROR
	 * @see IRefactoringCoreStatusCodes#REFACTORING_HISTORY_IO_ERROR
	 */
public void deleteRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(proxies);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings, proxies.length + 300);
        final Map projects = new HashMap();
        for (int index = 0; index < proxies.length; index++) {
            String project = proxies[index].getProject();
            if (//$NON-NLS-1$
            project == null || "".equals(project))
                project = RefactoringHistoryService.NAME_WORKSPACE_PROJECT;
            Collection collection = (Collection) projects.get(project);
            if (collection == null) {
                collection = new ArrayList();
                projects.put(project, collection);
            }
            collection.add(proxies[index]);
            monitor.worked(1);
        }
        final SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 300);
        try {
            final Set entries = projects.entrySet();
            subMonitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings, entries.size());
            for (final Iterator iterator = entries.iterator(); iterator.hasNext(); ) {
                final Map.Entry entry = (Map.Entry) iterator.next();
                final Collection collection = (Collection) entry.getValue();
                String project = (String) entry.getKey();
                if (project.equals(RefactoringHistoryService.NAME_WORKSPACE_PROJECT))
                    project = null;
                final RefactoringHistoryManager manager = getManager(project);
                if (manager != null)
                    manager.removeRefactoringDescriptors((RefactoringDescriptorProxy[]) collection.toArray(new RefactoringDescriptorProxy[collection.size()]), new SubProgressMonitor(subMonitor, 1), RefactoringCoreMessages.RefactoringHistoryService_deleting_refactorings);
                else
                    subMonitor.worked(1);
            }
        } finally {
            subMonitor.done();
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

RefactoringDescriptorProxy (org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy)14 HashSet (java.util.HashSet)10 Set (java.util.Set)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 ArrayList (java.util.ArrayList)4 IFileStore (org.eclipse.core.filesystem.IFileStore)4 BufferedInputStream (java.io.BufferedInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Iterator (java.util.Iterator)3 NodeList (org.w3c.dom.NodeList)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2