Search in sources :

Example 1 with IssuesImpl

use of org.eclipse.emf.mwe.core.issues.IssuesImpl in project xtext-core by eclipse.

the class UriBasedReaderTest method testIssuesInOtherResource.

@Test
public void testIssuesInOtherResource() throws Exception {
    UriBasedReader reader = new UriBasedReader() {

        {
            getValidator().setStopOnError(false);
        }
    };
    reader.setClasspathURIContext(getClass());
    reader.addRegister(new XtextStandaloneSetup() {

        @Override
        public Injector createInjector() {
            return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() {

                @Override
                public void configureFileExtensions(Binder binder) {
                    binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("xtexterror");
                }
            });
        }

        @Override
        public void register(Injector injector) {
            EPackage.Registry.INSTANCE.put(XtextPackage.eINSTANCE.getNsURI(), XtextPackage.eINSTANCE);
            IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
            IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
            Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", resourceFactory);
            IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xtexterror", serviceProvider);
        }
    });
    final String errorURI = (getClass().getName() + "ResourceWithError").replace('.', '/') + ".xtexterror";
    final String loadingURI = "classpath:/" + (getClass().getName() + "LoadingResourceWithError").replace('.', '/') + ".xtexterror";
    reader.addUri(loadingURI);
    SlotEntry slotEntry = new SlotEntry();
    slotEntry.setType("Grammar");
    slotEntry.setFirstOnly(true);
    reader.addLoad(slotEntry);
    WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertFalse(issues.toString(), issues.hasErrors());
    reader.invoke(ctx, new NullProgressMonitor(), issues);
    assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
    assertEquals(1, issues.getErrors().length);
    final String errorString = issues.getErrors()[0].toString();
    assertFalse(errorString, errorString.contains(loadingURI));
    assertTrue(errorString, errorString.contains(errorURI));
}
Also used : NullProgressMonitor(org.eclipse.emf.mwe.core.monitor.NullProgressMonitor) WorkflowContextDefaultImpl(org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl) Grammar(org.eclipse.xtext.Grammar) Binder(com.google.inject.Binder) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Injector(com.google.inject.Injector) IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) IResourceFactory(org.eclipse.xtext.resource.IResourceFactory) XtextStandaloneSetup(org.eclipse.xtext.XtextStandaloneSetup) Test(org.junit.Test)

Example 2 with IssuesImpl

use of org.eclipse.emf.mwe.core.issues.IssuesImpl in project xtext-core by eclipse.

the class UriBasedReaderTest method testMissingUri.

@Test
public void testMissingUri() throws Exception {
    UriBasedReader reader = new UriBasedReader();
    reader.setClasspathURIContext(getClass());
    reader.addRegister(new XtextStandaloneSetup());
    // reader.setUri("classpath:/"+getClass().getName().replace('.', '/')+".xtext");
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertTrue(issues.hasErrors());
}
Also used : IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) XtextStandaloneSetup(org.eclipse.xtext.XtextStandaloneSetup) Test(org.junit.Test)

Example 3 with IssuesImpl

use of org.eclipse.emf.mwe.core.issues.IssuesImpl in project xtext-core by eclipse.

the class UriBasedReaderTest method testMissingRegistration.

@Test
public void testMissingRegistration() throws Exception {
    with(new XtextErrorStandaloneSetup());
    UriBasedReader reader = new UriBasedReader();
    reader.setClasspathURIContext(getClass());
    // reader.setRegister(new XtextStandaloneSetup());
    reader.addUri("classpath:/" + getClass().getName().replace('.', '/') + ".xtexterror");
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertTrue(issues.hasErrors());
}
Also used : IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) Test(org.junit.Test)

Example 4 with IssuesImpl

use of org.eclipse.emf.mwe.core.issues.IssuesImpl in project xtext-core by eclipse.

the class UriBasedReaderTest method testSimple.

@Test
public void testSimple() throws Exception {
    UriBasedReader reader = new UriBasedReader() {

        {
            getValidator().setStopOnError(false);
        }
    };
    reader.setClasspathURIContext(getClass());
    reader.addRegister(new XtextErrorStandaloneSetup());
    reader.addUri("classpath:/" + getClass().getName().replace('.', '/') + ".xtexterror");
    SlotEntry slotEntry = new SlotEntry();
    slotEntry.setType("Grammar");
    slotEntry.setFirstOnly(true);
    reader.addLoad(slotEntry);
    WorkflowContextDefaultImpl ctx = new WorkflowContextDefaultImpl();
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    assertFalse(issues.toString(), issues.hasErrors());
    reader.invoke(ctx, new NullProgressMonitor(), issues);
    assertTrue(ctx.get(slotEntry.getSlot()) instanceof Grammar);
    assertEquals(issues.toString(), 1, issues.getErrors().length);
}
Also used : NullProgressMonitor(org.eclipse.emf.mwe.core.monitor.NullProgressMonitor) WorkflowContextDefaultImpl(org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl) IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 5 with IssuesImpl

use of org.eclipse.emf.mwe.core.issues.IssuesImpl in project xtext-core by eclipse.

the class UriBasedReaderTest method testTransitiveReferences.

@SuppressWarnings("unchecked")
@Test
public void testTransitiveReferences() throws Exception {
    UriBasedReader reader = new UriBasedReader();
    reader.addRegister(new ImportUriTestLanguageStandaloneSetup());
    reader.addUri(pathTo2("importUriSubfolder/Start.importuritestlanguage"));
    SlotEntry slotEntry = new SlotEntry();
    slotEntry.setType("Type");
    reader.addLoad(slotEntry);
    WorkflowContext ctx = new WorkflowContextDefaultImpl();
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    try {
        reader.invoke(ctx, new NullProgressMonitor(), issues);
    } catch (Exception e) {
        System.out.println(issues);
        throw e;
    }
    List<Type> types = (List<Type>) ctx.get(slotEntry.getSlot());
    assertEquals(3, types.size());
    for (Type type : types) {
        if (type.getName().equals("Foo")) {
            assertEquals("Bar", type.getExtends().getName());
        } else if (type.getName().equals("Bar")) {
            assertEquals("Baz", type.getExtends().getName());
        } else {
            assertNull(type.getExtends());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.emf.mwe.core.monitor.NullProgressMonitor) Type(org.eclipse.xtext.linking.importedURI.Type) ImportUriTestLanguageStandaloneSetup(org.eclipse.xtext.linking.ImportUriTestLanguageStandaloneSetup) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) WorkflowContextDefaultImpl(org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl) IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) List(java.util.List) Test(org.junit.Test)

Aggregations

IssuesImpl (org.eclipse.emf.mwe.core.issues.IssuesImpl)5 Test (org.junit.Test)5 WorkflowContextDefaultImpl (org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl)3 NullProgressMonitor (org.eclipse.emf.mwe.core.monitor.NullProgressMonitor)3 Grammar (org.eclipse.xtext.Grammar)2 XtextStandaloneSetup (org.eclipse.xtext.XtextStandaloneSetup)2 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 List (java.util.List)1 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)1 ImportUriTestLanguageStandaloneSetup (org.eclipse.xtext.linking.ImportUriTestLanguageStandaloneSetup)1 Type (org.eclipse.xtext.linking.importedURI.Type)1 IResourceFactory (org.eclipse.xtext.resource.IResourceFactory)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1