Search in sources :

Example 1 with IStreamContentAccessor

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IErlModel(org.erlide.engine.model.root.IErlModel) InputStream(java.io.InputStream) ITypedElement(org.eclipse.compare.ITypedElement) IOException(java.io.IOException) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) ResourceNode(org.eclipse.compare.ResourceNode) IErlElement(org.erlide.engine.model.IErlElement) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) IDocument(org.eclipse.jface.text.IDocument) IResource(org.eclipse.core.resources.IResource)

Example 2 with IStreamContentAccessor

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with IStreamContentAccessor

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);
}
Also used : IEntity(org.whole.lang.model.IEntity) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 4 with IStreamContentAccessor

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;
}
Also used : IResourceProvider(org.eclipse.compare.IResourceProvider) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor)

Example 5 with IStreamContentAccessor

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();
                }
            }
        }
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) InputStream(java.io.InputStream) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) WrappedException(org.eclipse.emf.common.util.WrappedException)

Aggregations

IStreamContentAccessor (org.eclipse.compare.IStreamContentAccessor)7 CoreException (org.eclipse.core.runtime.CoreException)4 Document (org.eclipse.jface.text.Document)3 IDocument (org.eclipse.jface.text.IDocument)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 WrappedException (org.eclipse.emf.common.util.WrappedException)2 IResourceProvider (org.eclipse.compare.IResourceProvider)1 ITypedElement (org.eclipse.compare.ITypedElement)1 ResourceNode (org.eclipse.compare.ResourceNode)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlElement (org.erlide.engine.model.IErlElement)1 IErlModel (org.erlide.engine.model.root.IErlModel)1 IErlModule (org.erlide.engine.model.root.IErlModule)1 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)1 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)1 IEntity (org.whole.lang.model.IEntity)1