use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.
the class DiagnosticResolution method apply.
public WorkspaceEdit apply() {
DiagnosticModificationContext modificationContext = factory.createModificationContext();
try {
XtextResource resource = options.getResource();
URI uri = resource.getURI();
ILanguageServerAccess access = options.getLanguageServerAccess();
WorkspaceEdit edit = new WorkspaceEdit();
ChangeConverter2 changeConverter = modificationContext.getConverterFactory().create(edit, access);
ResourceSet resourceSet = access.newLiveScopeResourceSet(uri);
XtextResource tmpResource = (XtextResource) resourceSet.getResource(uri, true);
CodeActionParams params = options.getCodeActionParams();
int offset = options.getDocument().getOffSet(params.getRange().getStart());
EObjectAtOffsetHelper helper = new EObjectAtOffsetHelper();
EObject obj = helper.resolveContainedElementAt(tmpResource, offset);
IChangeSerializer serializer = modificationContext.getSerializer();
serializer.addModification(obj, modification);
serializer.applyModifications(changeConverter);
return edit;
} catch (Exception exc) {
throw new WrappedException(exc);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.
the class GrammarSerializerTest method testSerializeGrammar.
@Test
public void testSerializeGrammar() throws Exception {
String string = readFileIntoString("org/eclipse/xtext/parser/unorderedGroups/UnorderedGroupsTestLanguage.xtext");
XtextResource resource = getResourceFromString(string);
resource.getResourceSet().getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE);
resource.save(new ByteArrayOutputStream(), null);
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.
the class IndentationAwareLanguageTest method parseAndValidate.
private Tree parseAndValidate(final CharSequence s) {
final Tree result = this.parse(s);
this.validationTestHelper.assertNoIssues(result);
Resource _eResource = result.eResource();
final XtextResource resource = ((XtextResource) _eResource);
final ICompositeNode node = resource.getParseResult().getRootNode();
this.invariantChecker.checkInvariant(node);
return result;
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testNoException_01.
@Test
public void testNoException_01() throws Exception {
String grammar = "grammar test with org.eclipse.xtext.common.Terminals import 'http://www.eclipse.org/emf/2002/Ecore' as ecore generate test 'http://test'\n" + "CompositeModel: (model+=Model)+;\n" + "Model: id=NestedModelId (':' value=Fraction)? ('#' vector=Vector)? ('+' dots=Dots)? ';'\n" + "ModelId returns ecore::EString: ID '.' ID;\n" + "NestedModelId : ModelId '.' ModelId;\n" + "Fraction returns EBigDecimal: INT ('/' INT)?;\n" + "Vector : '(' INT I";
XtextResource resource = getResourceFromStringAndExpect(grammar, 10);
for (Resource.Diagnostic d : resource.getErrors()) {
Assert.assertFalse(d instanceof ExceptionDiagnostic);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method testBug_280413_04.
@Test
public void testBug_280413_04() throws Exception {
String grammar = "grammar test with org.eclipse.xtext.testlanguages.SimpleExpressionsTestLanguage\n" + "generate test 'http://test'\n" + "import 'classpath:/org/eclipse/xtext/testlanguages/SimpleExpressionsTestLanguage.ecore' as mm\n" + "Atom returns mm::Atom: name=ID;\n";
XtextResource resource = getResourceFromStringAndExpect(grammar, 1);
Assert.assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
TransformationDiagnostic diagnostic = (TransformationDiagnostic) resource.getErrors().get(0);
Assert.assertEquals(grammar.indexOf("mm::Atom"), diagnostic.getOffset());
Assert.assertEquals("mm::Atom".length(), diagnostic.getLength());
}
Aggregations