Search in sources :

Example 91 with XtextResource

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);
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) WrappedException(org.eclipse.emf.common.util.WrappedException) XtextResource(org.eclipse.xtext.resource.XtextResource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) WrappedException(org.eclipse.emf.common.util.WrappedException) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeConverter2(org.eclipse.xtext.ide.server.rename.ChangeConverter2) EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) EObject(org.eclipse.emf.ecore.EObject) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess)

Example 92 with XtextResource

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);
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 93 with XtextResource

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;
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 94 with XtextResource

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);
    }
}
Also used : ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 95 with XtextResource

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());
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)627 Test (org.junit.Test)367 Resource (org.eclipse.emf.ecore.resource.Resource)107 EObject (org.eclipse.emf.ecore.EObject)99 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)67 StringInputStream (org.eclipse.xtext.util.StringInputStream)67 URI (org.eclipse.emf.common.util.URI)62 Diagnostic (org.eclipse.emf.common.util.Diagnostic)55 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)55 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)46 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)40 Grammar (org.eclipse.xtext.Grammar)32 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)31 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)30 IFile (org.eclipse.core.resources.IFile)29 Issue (org.eclipse.xtext.validation.Issue)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)28 List (java.util.List)26 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)26 INode (org.eclipse.xtext.nodemodel.INode)23