Search in sources :

Example 1 with RefactoringSessionTransformer

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

the class RefactoringHistoryManager method transformDescriptor.

/**
	 * Transforms the specified refactoring descriptor into a DOM node.
	 *
	 * @param descriptor
	 *            the descriptor to transform
	 * @param projects
	 *            <code>true</code> to include project information,
	 *            <code>false</code> otherwise
	 * @return the DOM node representing the refactoring descriptor
	 * @throws CoreException
	 *             if an error occurs while transforming the descriptor
	 */
private static Document transformDescriptor(final RefactoringDescriptor descriptor, final boolean projects) throws CoreException {
    final RefactoringSessionTransformer transformer = new RefactoringSessionTransformer(projects);
    try {
        transformer.beginSession(null, IRefactoringSerializationConstants.CURRENT_VERSION);
        try {
            final String id = descriptor.getID();
            transformer.beginRefactoring(id, descriptor.getTimeStamp(), descriptor.getProject(), descriptor.getDescription(), descriptor.getComment(), descriptor.getFlags());
            final Map arguments = getArgumentMap(descriptor);
            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();
    }
    return transformer.getResult();
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) RefactoringSessionTransformer(org.eclipse.ltk.internal.core.refactoring.RefactoringSessionTransformer) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 2 with RefactoringSessionTransformer

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

HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 RefactoringSessionTransformer (org.eclipse.ltk.internal.core.refactoring.RefactoringSessionTransformer)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 RefactoringDescriptor (org.eclipse.ltk.core.refactoring.RefactoringDescriptor)1 Document (org.w3c.dom.Document)1