Search in sources :

Example 11 with RefactoringDescriptor

use of org.eclipse.ltk.core.refactoring.RefactoringDescriptor 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)

Example 12 with RefactoringDescriptor

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

the class RefactoringHistoryManager method readRefactoringDescriptors.

/**
	 * Reads default refactoring descriptors from the specified input stream.
	 *
	 * @param stream
	 *            the input stream where to read from
	 * @param collection
	 *            the list of descriptors read from the history
	 * @param monitor
	 *            the progress monitor to use
	 * @throws CoreException
	 *             if an error occurs while reading the descriptors
	 */
private static void readRefactoringDescriptors(final InputStream stream, final Collection collection, final IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RefactoringHistoryService_retrieving_history, 1);
        final RefactoringDescriptor[] results = new RefactoringSessionReader(true, null).readSession(new InputSource(new BufferedInputStream(stream))).getRefactorings();
        for (int index = 0; index < results.length; index++) collection.add(results[index]);
    } finally {
        monitor.done();
    }
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) InputSource(org.xml.sax.InputSource) RefactoringSessionReader(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader) BufferedInputStream(java.io.BufferedInputStream)

Example 13 with RefactoringDescriptor

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

the class RefactoringHistoryManager method writeRefactoringSession.

/**
	 * Writes refactoring session descriptor to the specified output stream.
	 *
	 * @param stream
	 *            the output stream where to write to
	 * @param descriptor
	 *            the refactoring session descriptors to write
	 * @param stamps
	 *            <code>true</code> to write time stamps as well,
	 *            <code>false</code> otherwise
	 * @throws CoreException
	 *             if an error occurs while writing the refactoring session
	 *             descriptor
	 */
public static void writeRefactoringSession(final OutputStream stream, final RefactoringSessionDescriptor descriptor, final boolean stamps) throws CoreException {
    final RefactoringSessionTransformer transformer = new RefactoringSessionTransformer(true);
    final RefactoringDescriptor[] descriptors = descriptor.getRefactorings();
    try {
        transformer.beginSession(descriptor.getComment(), descriptor.getVersion());
        for (int index = 0; index < descriptors.length; index++) {
            final RefactoringDescriptor current = descriptors[index];
            if (current != null) {
                try {
                    long stamp = stamps ? current.getTimeStamp() : -1;
                    transformer.beginRefactoring(current.getID(), stamp, current.getProject(), current.getDescription(), current.getComment(), current.getFlags());
                    final Map arguments = getArgumentMap(current);
                    if (arguments != null) {
                        checkArgumentMap(arguments);
                        for (final Iterator iterator = arguments.entrySet().iterator(); iterator.hasNext(); ) {
                            final Map.Entry entry = (Entry) iterator.next();
                            transformer.createArgument((String) entry.getKey(), (String) entry.getValue());
                        }
                    }
                } finally {
                    transformer.endRefactoring();
                }
            }
        }
    } finally {
        transformer.endSession();
    }
    final Document result = transformer.getResult();
    writeNode(stream, result);
}
Also used : RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) RefactoringSessionTransformer(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionTransformer) Document(org.w3c.dom.Document) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

RefactoringDescriptor (org.eclipse.ltk.core.refactoring.RefactoringDescriptor)13 RefactoringSessionDescriptor (org.eclipse.ltk.core.refactoring.RefactoringSessionDescriptor)4 ArrayList (java.util.ArrayList)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 ListenerList (org.eclipse.core.runtime.ListenerList)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)2 RefactoringDescriptorProxy (org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)2 RefactoringSessionReader (org.eclipse.ltk.internal.core.refactoring.RefactoringSessionReader)2 DefaultRefactoringDescriptor (org.eclipse.ltk.internal.core.refactoring.history.DefaultRefactoringDescriptor)2 InputSource (org.xml.sax.InputSource)2 SAXParseException (org.xml.sax.SAXParseException)2