Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resource without errors from validator
Resource without errors from validator [message #1413756] Fri, 29 August 2014 10:50 Go to next message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Hi!

In my software I use an embedded xtext-editor to edit some text. As I use it inside a dialogbox, I always check if the resource that is used by the editor has some errors:

editor.getResource().getErrors().size() > 0


But since I recently refactored some of the Xtext-packages the resource seems to have no error if only validation fails. Nevertheless the errors the validator produces are marked inside the editor. I don't know what could have went wrong. Any ideas?!

Thanks in advance
Jonas
Re: Resource without errors from validator [message #1414157 is a reply to message #1413756] Sat, 30 August 2014 12:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13264
Registered: July 2009
Senior Member
How do you get the resource. maybe you should do what is decribed under "Validating Manually" in the docs

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resource without errors from validator [message #1414193 is a reply to message #1414157] Sat, 30 August 2014 15:13 Go to previous message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Hi!

I don't think that this mightbe a problem because before the refactoring it has been working quite good, but nevertheless I'll post my abstract wrapper for embedded xtext-editors here:

public abstract class AbstractXtextEditorAdapter implements IXEditor {

    private static final String PREFIX = "";
    private static final String SUFFIX = "";
    private EmbeddedEditorModelAccess partialEditorModelAccess;
    private EmbeddedEditor embeddedEditor;
    private XtextResource resource;
    private IXSerializer serializer;
    private Injector injector;
    
    /**
     * Constructor for your XtextEditorAdapter.
     * 
     * @param parent
     *            the parent Composite of the {@link EmbeddedEditor}
     * @param string
     *            the String that is initially set inside the Editor.
     */
    public AbstractXtextEditorAdapter(Composite parent, String string) {
        if (string == null) {
            string = "";
        }
        EmbeddedEditorFactory factory = getInjectorInstance().getInstance(EmbeddedEditorFactory.class);
        IEditedResourceProvider resourceProvider = new IEditedResourceProvider() {
            public XtextResource createResource() {

                XtextResourceSet rs = getInjectorInstance().getInstance(XtextResourceSet.class);
                rs.setClasspathURIContext(getClass());

                IResourceFactory resourceFactory = getInjectorInstance().getInstance(IResourceFactory.class);
                URI uri = URI.createURI("dummy:/inmemory" + getUniqueID() + "." + getFileExtension());
                resource = (XtextResource) resourceFactory.createResource(uri);
                rs.getResources().add(resource);

                EcoreUtil.resolveAll(resource);

                return resource;
            }
        };
        embeddedEditor = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations().withParent(parent);
        partialEditorModelAccess = embeddedEditor.createPartialEditor(PREFIX, string, SUFFIX, false);
        serializer = getSerializer();
    }

    /**
     * Generates an ID for the dummy-resource.
     * 
     * @return timeinmillis + random(0-9999);
     */
    protected long getUniqueID() {
        return System.currentTimeMillis() + (int) (Math.random() * 10000);
    }

    /**
     * Returns a unique instance of an {@link Injector}.
     * 
     * @return the {@link Injector}
     */
    protected final Injector getInjectorInstance() {
        if (injector == null) {
            injector = getInjector();
        }
        return injector;
    }

    @Override
    public EmbeddedEditor getEmbeddedEditor() {
        return embeddedEditor;
    }

    @Override
    public EmbeddedEditorModelAccess getEmbeddedEditorModelAccess() {
        return partialEditorModelAccess;
    }

    @Override
    public EObject getRootNode() {
        return resource.getContents().get(0);
    }

    @Override
    public String getContent() {
        return serializer.valueOf(getRootNode());
    }

    @Override
    public XtextResource getResource() {
        return resource;
    }

    /**
     * Should return an instance of an {@link Injector} you can get from your YourGrammarActivator
     * in Xtexts UI package.
     * 
     * @return {@link Injector} instance
     */
    protected abstract Injector getInjector();

    /**
     * Should return the fileextension of yourgrammar without a dot.
     * 
     * @return "yourGrammar"
     */
    protected abstract String getFileExtension();

    /**
     * Should return an instance of an IXSerializer for your grammar.
     * 
     * @return {@link IXSerializer} instance
     */
    protected abstract IXSerializer getSerializer();

}


As you may see in my previous post, I retrieve my resource by calling the wrapper's getResource()-method.

Any ideas?

Thanks and best regards
Jonas
Previous Topic:[Solved] [Xpand/Xtend] : metamodel importation
Next Topic:Strange Guice Injector error
Goto Forum:
  


Current Time: Mon Dec 09 08:28:35 GMT 2019

Powered by FUDForum. Page generated in 0.01414 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top