Search in sources :

Example 36 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project n4js by eclipse.

the class ECMA6TestSuite method test.

/**
 * generated instances of the tests will use this base implementation
 */
@Override
@Test
public void test() throws Exception {
    if (this.parserN4JS == null) {
        throw new Error("parser instance is null");
    }
    String code = TestCodeProvider.getContentsFromFileEntry(config.entry, config.resourceName);
    if (code == null) {
        throw new Error("test data code instance is null");
    }
    Analyser analyser = createAnalyzer(code);
    XtextResourceSet resourceSet = resourceSetProvider.get();
    URI uri = URI.createURI(config.entry.getName());
    // we do the same here
    if (code.contains("flags: [onlyStrict]")) {
        // by using the proper file extension
        uri = uri.trimFileExtension().appendFileExtension("n4js");
    }
    Script script = doParse(code, uri, resourceSet, analyser);
    if (config.isValidator()) {
        // thus the negative tests will likely succeed for bogus reasons
        throw new IllegalStateException(config.entry.getName());
    }
    // try {
    analyser.analyse(script, config.entry.getName(), code);
// } catch (AssertionError e) {
// System.out.println(config.entry.getName());
// throw e;
// }
}
Also used : Script(org.eclipse.n4js.n4JS.Script) NegativeAnalyser(org.eclipse.n4js.analysis.NegativeAnalyser) Analyser(org.eclipse.n4js.analysis.Analyser) PositiveAnalyser(org.eclipse.n4js.analysis.PositiveAnalyser) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Example 37 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project n4js by eclipse.

the class BuiltInTypeScopePluginTest method testLoadingBuiltInTypes.

@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
    XtextResourceSet resourceSet = (XtextResourceSet) resourceSetProvider.get(null);
    resourceSet.setClasspathURIContext(N4JSResource.class.getClassLoader());
    BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
    IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
    Assert.assertNotNull(anyType);
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) N4JSResource(org.eclipse.n4js.resource.N4JSResource) BuiltInTypeScope(org.eclipse.n4js.ts.scoping.builtin.BuiltInTypeScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 38 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project dsl-devkit by dsldevkit.

the class DeployJob method deployCheckConfiguration.

/**
 * Creates a new instance of {@link DeployJob}.
 *
 * @throws DeployException
 *           a general deployment exception.
 */
private void deployCheckConfiguration() throws DeployException {
    List<IFile> checkCfgFiles = getCheckConfigurationFiles();
    if (checkCfgFiles.isEmpty()) {
        return;
    }
    if (checkCfgFiles.size() != 1) {
        showTooManyCheckConfigurationDialog();
        return;
    }
    IFile file = checkCfgFiles.get(0);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPathVariableManager pathMan = workspace.getPathVariableManager();
    if (pathMan.validateName(CheckCfgConstants.CHECK_CFG_VAR_NAME).isOK() && pathMan.validateValue(file.getFullPath()).isOK()) {
        try {
            pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, file.getLocationURI());
        } catch (CoreException e) {
            LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
            throw new DeployException(e);
        }
    } else {
        LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
        throw new DeployException();
    }
    XtextResourceSet rs = new XtextResourceSet();
    String uriString = pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME).toString();
    URI uri = URI.createURI(uriString, true);
    Resource resource = rs.createResource(uri);
    try {
        resource.load(new FileInputStream(new File(pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME))), rs.getLoadOptions());
        rs.getURIResourceMap().put(uri, resource);
        EcoreUtil.resolveAll(resource);
        CheckConfiguration checkConfig = (CheckConfiguration) resource.getContents().get(0);
        assert checkConfig != null;
    } catch (IOException e) {
        LOGGER.error(NLS.bind(Messages.DeployJob_ExceptionWhileReadingTheCheckConfigurationFile, uriString), e);
        throw new DeployException(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) FileInputStream(java.io.FileInputStream) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IWorkspace(org.eclipse.core.resources.IWorkspace) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 39 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project metalib by softlang.

the class Tests method annotatedParse.

/**
 * Helper for parsing a model and annotating it with the warnings and
 * errors the parsing process generated
 */
public Pair<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>> annotatedParse(final CharSequence s) {
    try {
        final XtextResourceSet resourceSet = new XtextResourceSet();
        final FSM parsed = this.parseHelper.parse(s, resourceSet);
        EList<Resource> _resources = resourceSet.getResources();
        final Resource resource = IterableExtensions.<Resource>last(_resources);
        EList<Resource.Diagnostic> _warnings = resource.getWarnings();
        EList<Resource.Diagnostic> _errors = resource.getErrors();
        Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>> _mappedTo = Pair.<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>of(_warnings, _errors);
        return Pair.<FSM, Pair<EList<Resource.Diagnostic>, EList<Resource.Diagnostic>>>of(parsed, _mappedTo);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : FSM(org.softlang.metalib.xtext.fsml.fsml.FSM) EList(org.eclipse.emf.common.util.EList) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 40 with XtextResourceSet

use of org.eclipse.xtext.resource.XtextResourceSet in project gemoc-studio by eclipse.

the class TestXtextSerializer2 method loadGexpressionTestFile.

public static void loadGexpressionTestFile() {
    // Getting the serializer
    GExpressionsStandaloneSetup setup = new GExpressionsStandaloneSetup();
    Injector injector = setup.createInjectorAndDoEMFRegistration();
    GexpressionsPackage.eINSTANCE.eClass();
    Serializer serializer = injector.getInstance(Serializer.class);
    // Load the model
    URI modelURI = URI.createFileURI("/home/flatombe/thesis/gemoc/git/gemoc-dev/org/eclipse/gemoc/GEL/org.eclipse.gemoc.gel.gexpressions.test/model/test.gexpressions");
    XtextResourceSet resSet = injector.getInstance(XtextResourceSet.class);
    resSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
    Resource resource = resSet.getResource(modelURI, true);
    GProgram program = (GProgram) resource.getContents().get(0);
    List<GExpression> exps = program.getExpressions();
    for (GExpression exp : exps) {
        // Serializing
        String s = serializer.serialize(exp);
        System.out.println(s);
    }
}
Also used : GExpression(org.eclipse.gemoc.gexpressions.GExpression) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) GProgram(org.eclipse.gemoc.gexpressions.GProgram) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) GExpressionsStandaloneSetup(org.eclipse.gemoc.gexpressions.xtext.GExpressionsStandaloneSetup) Serializer(org.eclipse.xtext.serializer.impl.Serializer)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)177 Resource (org.eclipse.emf.ecore.resource.Resource)81 XtextResource (org.eclipse.xtext.resource.XtextResource)77 Test (org.junit.Test)57 StringInputStream (org.eclipse.xtext.util.StringInputStream)42 URI (org.eclipse.emf.common.util.URI)33 EObject (org.eclipse.emf.ecore.EObject)20 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)19 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 Grammar (org.eclipse.xtext.Grammar)10 Issue (org.eclipse.xtext.validation.Issue)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)8 File (java.io.File)7 ArrayList (java.util.ArrayList)7 EList (org.eclipse.emf.common.util.EList)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 Before (org.junit.Before)7 Injector (com.google.inject.Injector)6 IOException (java.io.IOException)6 Diagnostic (org.eclipse.emf.common.util.Diagnostic)5