Search in sources :

Example 1 with RefactoringSessionDescriptor

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

the class RefactoringSessionReader method readSession.

/**
	 * Reads a refactoring history descriptor from the specified input object.
	 *
	 * @param source
	 *            the input source
	 * @return a corresponding refactoring history descriptor, or
	 *         <code>null</code>
	 * @throws CoreException
	 *             if an error occurs while reading form the input source
	 */
public RefactoringSessionDescriptor readSession(final InputSource source) throws CoreException {
    fSessionFound = false;
    try {
        //$NON-NLS-1$
        source.setSystemId("/");
        createParser(SAXParserFactory.newInstance()).parse(source, this);
        if (!fSessionFound)
            throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringSessionReader_no_session, null));
        if (fRefactoringDescriptors != null) {
            if (//$NON-NLS-1$
            fVersion == null || "".equals(fVersion))
                throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.MISSING_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_missing_version_information, null));
            if (!IRefactoringSerializationConstants.CURRENT_VERSION.equals(fVersion))
                throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.UNSUPPORTED_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_unsupported_version_information, null));
            return new RefactoringSessionDescriptor((RefactoringDescriptor[]) fRefactoringDescriptors.toArray(new RefactoringDescriptor[fRefactoringDescriptors.size()]), fVersion, fComment);
        }
    } catch (IOException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } catch (ParserConfigurationException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } catch (SAXParseException exception) {
        String message = Messages.format(RefactoringCoreMessages.RefactoringSessionReader_invalid_contents_at, new Object[] { Integer.toString(exception.getLineNumber()), Integer.toString(exception.getColumnNumber()) });
        throwCoreException(exception, message);
    } catch (SAXException exception) {
        throwCoreException(exception, exception.getLocalizedMessage());
    } finally {
        fRefactoringDescriptors = null;
        fVersion = null;
        fComment = null;
        fLocator = null;
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DefaultRefactoringDescriptor(org.eclipse.ltk.internal.core.refactoring.history.DefaultRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CoreException(org.eclipse.core.runtime.CoreException) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor) SAXException(org.xml.sax.SAXException)

Example 2 with RefactoringSessionDescriptor

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

the class RefactoringHistoryManager method getCachedSession.

/**
	 * Returns the cached refactoring session descriptor.
	 *
	 * @param store
	 *            the file store of the descriptor
	 * @param projectName
	 *            project name, or <code>null</code> for the workspace
	 * @param input
	 *            the input stream where to read the descriptor
	 * @return the cached refactoring session descriptor
	 * @throws CoreException
	 *             if an error occurs while reading the session
	 */
private RefactoringSessionDescriptor getCachedSession(final IFileStore store, String projectName, final InputStream input) throws CoreException {
    if (store.equals(fCachedStore) && fCachedDescriptor != null)
        return fCachedDescriptor;
    final RefactoringSessionDescriptor descriptor;
    try {
        descriptor = new RefactoringSessionReader(false, projectName).readSession(new InputSource(input));
        fCachedDescriptor = descriptor;
        fCachedStore = store;
        return descriptor;
    } catch (CoreException e) {
        throw new CoreException(new MultiStatus(RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_IO_ERROR, new IStatus[] { e.getStatus() }, Messages.format(RefactoringCoreMessages.RefactoringHistoryManager_error_reading_file, BasicElementLabels.getURLPart(store.toURI().toString())), null));
    }
}
Also used : InputSource(org.xml.sax.InputSource) RefactoringSessionReader(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader) CoreException(org.eclipse.core.runtime.CoreException) MultiStatus(org.eclipse.core.runtime.MultiStatus) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Example 3 with RefactoringSessionDescriptor

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

the class RefactoringHistoryService method readRefactoringHistory.

/**
	 * {@inheritDoc}
	 */
public RefactoringHistory readRefactoringHistory(final InputStream stream, final int flags) throws CoreException {
    Assert.isNotNull(stream);
    Assert.isTrue(flags >= RefactoringDescriptor.NONE);
    final List list = new ArrayList();
    final RefactoringSessionDescriptor descriptor = new RefactoringSessionReader(false, null).readSession(new InputSource(stream));
    if (descriptor != null) {
        final RefactoringDescriptor[] descriptors = descriptor.getRefactorings();
        if (flags > RefactoringDescriptor.NONE) {
            for (int index = 0; index < descriptors.length; index++) {
                final int current = descriptors[index].getFlags();
                if ((current | flags) == current)
                    list.add(descriptors[index]);
            }
        } else
            list.addAll(Arrays.asList(descriptors));
    }
    final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[list.size()];
    for (int index = 0; index < list.size(); index++) proxies[index] = new RefactoringDescriptorProxyAdapter((RefactoringDescriptor) list.get(index));
    return new RefactoringHistoryImplementation(proxies);
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) InputSource(org.xml.sax.InputSource) RefactoringSessionReader(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader) RefactoringDescriptorProxy(org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy) ArrayList(java.util.ArrayList) List(java.util.List) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Example 4 with RefactoringSessionDescriptor

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

the class RefactoringHistoryManager method requestDescriptor.

/**
	 * Requests the resolved refactoring descriptor associated with the given
	 * proxy.
	 *
	 * @param proxy
	 *            the refactoring descriptor proxy
	 * @param monitor
	 *            the progress monitor to use
	 * @return the associated refactoring descriptor, or <code>null</code>
	 */
RefactoringDescriptor requestDescriptor(final RefactoringDescriptorProxy proxy, final IProgressMonitor monitor) {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_resolving_information, 2);
        final long stamp = proxy.getTimeStamp();
        if (stamp >= 0) {
            InputStream input = null;
            try {
                final IFileStore folder = fHistoryStore.getFileStore(stampToPath(stamp));
                final IFileStore file = folder.getChild(RefactoringHistoryService.NAME_HISTORY_FILE);
                if (file.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists()) {
                    input = new BufferedInputStream(file.openInputStream(EFS.NONE, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
                    final RefactoringSessionDescriptor descriptor = getCachedSession(file, fProjectName, input);
                    if (descriptor != null) {
                        final RefactoringDescriptor[] descriptors = descriptor.getRefactorings();
                        for (int index = 0; index < descriptors.length; index++) {
                            final RefactoringDescriptor refactoringDescriptor = descriptors[index];
                            if (refactoringDescriptor.getTimeStamp() == stamp) {
                                return refactoringDescriptor;
                            }
                        }
                    }
                }
            } catch (CoreException exception) {
                RefactoringCorePlugin.log(exception);
            } finally {
                try {
                    if (input != null)
                        input.close();
                } catch (IOException exception) {
                    RefactoringCorePlugin.log(exception);
                }
            }
        }
    } finally {
        monitor.done();
    }
    return null;
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Example 5 with RefactoringSessionDescriptor

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

the class RefactoringHistoryService method writeRefactoringDescriptors.

/**
	 * {@inheritDoc}
	 */
public void writeRefactoringDescriptors(final RefactoringDescriptorProxy[] proxies, final OutputStream stream, final int flags, final boolean time, IProgressMonitor monitor) throws CoreException {
    Assert.isNotNull(proxies);
    Assert.isNotNull(stream);
    Assert.isTrue(flags >= RefactoringDescriptor.NONE);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 100 * proxies.length);
        connect();
        final List list = new ArrayList(proxies.length);
        for (int index = 0; index < proxies.length; index++) {
            final RefactoringDescriptor descriptor = proxies[index].requestDescriptor(new SubProgressMonitor(monitor, 100));
            if (descriptor != null) {
                final int current = descriptor.getFlags();
                if ((current | flags) == current)
                    list.add(descriptor);
            }
        }
        final RefactoringDescriptor[] descriptors = new RefactoringDescriptor[list.size()];
        list.toArray(descriptors);
        RefactoringHistoryManager.writeRefactoringSession(stream, new RefactoringSessionDescriptor(descriptors, IRefactoringSerializationConstants.CURRENT_VERSION, null), time);
    } finally {
        disconnect();
    }
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) ListenerList(org.eclipse.core.runtime.ListenerList) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) RefactoringSessionDescriptor(org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)

Aggregations

RefactoringSessionDescriptor (org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)5 RefactoringDescriptor (org.eclipse.ltk.core.refactoring.RefactoringDescriptor)4 CoreException (org.eclipse.core.runtime.CoreException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ListenerList (org.eclipse.core.runtime.ListenerList)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 RefactoringSessionReader (org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader)2 InputSource (org.xml.sax.InputSource)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 RefactoringDescriptorProxy (org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy)1 DefaultRefactoringDescriptor (org.eclipse.ltk.internal.core.refactoring.history.DefaultRefactoringDescriptor)1