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;
}
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));
}
}
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);
}
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;
}
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();
}
}
Aggregations