use of org.eclipse.compare.IStreamContentAccessor in project erlide_eclipse by erlang.
the class ErlStructureCreator method createStructureComparator.
@Override
protected IStructureComparator createStructureComparator(final Object element, final IDocument document0, final ISharedDocumentAdapter sharedDocumentAdapter, final IProgressMonitor monitor) throws CoreException {
IErlModule module = null;
final IErlModel model = ErlangEngine.getInstance().getModel();
String s = "";
IDocument document = document0;
if (element instanceof ResourceNode) {
final ResourceNode rn = (ResourceNode) element;
final IResource r = rn.getResource();
if (r instanceof IFile) {
final IFile f = (IFile) r;
final IErlElement e = model.findElement(r);
if (e instanceof IErlModule) {
module = (IErlModule) e;
}
if (document == null) {
try {
s = ErlStructureCreator.readString(f.getContents());
document = new Document(s);
} catch (final CoreException e1) {
}
}
}
} else if (document == null && element instanceof IStreamContentAccessor) {
try {
try (final InputStream contents = ((IStreamContentAccessor) element).getContents()) {
s = ErlStructureCreator.readString(contents);
} catch (final IOException e) {
}
document = new Document(s);
} catch (final CoreException ex) {
}
} else if (document != null) {
s = document.get();
}
if (module == null) {
String name = "comptemp";
if (element instanceof ITypedElement) {
final ITypedElement typedElement = (ITypedElement) element;
name = typedElement.getName();
}
module = model.getModuleFromText(model, name, s, null);
}
ErlNode root = null;
if (element != null && document != null) {
try {
module.open(null);
root = new RootErlNode(document, element);
recursiveMakeErlNodes(module, root, document);
} catch (final ErlModelException e) {
ErlLogger.warn(e);
}
}
return root;
}
use of org.eclipse.compare.IStreamContentAccessor in project erlide_eclipse by erlang.
the class ErlStructureCreator method getStructure.
/**
* @see IStructureCreator#getStructure
*/
@Override
public IStructureComparator getStructure(final Object input) {
String contents = null;
char[] buffer = null;
IDocument doc = CompareUI.getDocument(input);
if (doc == null) {
if (input instanceof IStreamContentAccessor) {
final IStreamContentAccessor sca = (IStreamContentAccessor) input;
try {
contents = ErlangCompareUtilities.readString(sca);
} catch (final CoreException ex) {
// return null indicates the error.
return null;
}
}
if (contents != null) {
final int n = contents.length();
buffer = new char[n];
contents.getChars(0, n, buffer, 0);
doc = new Document(contents);
setupDocument(doc);
}
}
try {
return createStructureComparator(input, doc, null, null);
} catch (final CoreException e) {
// TODO report error
ErlLogger.error(e);
}
return null;
}
use of org.eclipse.compare.IStreamContentAccessor in project whole by wholeplatform.
the class ModelMergeViewer method readSideModel.
protected void readSideModel(MergeSide side, Object input, String label) {
IEntity sideModel = null;
if (input != null)
try {
IStreamContentAccessor accessor = (IStreamContentAccessor) input;
// TODO
IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
sideModel = persistenceKit.readModel(new StreamPersistenceProvider(accessor.getContents()));
} catch (Exception e) {
E4Utils.reportError(getContext(), "Model Merge Viewer", "Unable to read the model", e);
// TODO ? sideModel = Status model instance with failure info
}
setSideModel(side, sideModel != null ? sideModel : CommonsEntityFactory.instance.createResolver(), label);
}
use of org.eclipse.compare.IStreamContentAccessor in project xtext-eclipse by eclipse.
the class DefaultMergeViewer method updateAsDocument.
protected Object updateAsDocument(Object object) {
if (object instanceof IResourceProvider && supportsSharedDocuments(object)) {
return object;
}
if (object instanceof IStreamContentAccessor) {
try {
StreamContentAccessorDelegate streamContentAccessorDelegate = new StreamContentAccessorDelegate((IStreamContentAccessor) object, createResourceProvider(object));
documentProvider.connect(streamContentAccessorDelegate);
inputObjectStreamContentAccessorMap.put(object, streamContentAccessorDelegate);
return documentProvider.getDocument(streamContentAccessorDelegate);
} catch (CoreException coreException) {
throw new WrappedException(coreException);
}
}
return object;
}
use of org.eclipse.compare.IStreamContentAccessor in project xtext-eclipse by eclipse.
the class StreamContentDocumentProvider method loadResource.
protected void loadResource(Object element, Resource resource) {
if (resource == null) {
return;
}
if (element instanceof IStreamContentAccessor) {
IStreamContentAccessor streamContentAccessor = (IStreamContentAccessor) element;
InputStream inputStream = null;
try {
inputStream = streamContentAccessor.getContents();
if (inputStream != null) {
resource.load(inputStream, Collections.singletonMap(XtextResource.OPTION_ENCODING, getEncoding(element)));
}
} catch (Exception exception) {
throw new WrappedException(exception);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Aggregations