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;
// }
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations