Search in sources :

Example 6 with XtextResourceSet

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

the class FindReferencesTest method testFindReferencesTypeLiteralTwice.

@Test
public void testFindReferencesTypeLiteralTwice() throws Exception {
    createFile("find.references.test/src/Test." + fileExtension, "com.acme.OtherwiseUnused != com.acme.OtherwiseUnused");
    waitForBuild();
    XtextResourceSet set = get(XtextResourceSet.class);
    set.setClasspathURIContext(JavaCore.create(project));
    Resource resource = set.getResource(URI.createPlatformResourceURI("find.references.test/src/Test." + fileExtension, true), true);
    // obtain reference to type
    XBinaryOperation expression = (XBinaryOperation) resource.getContents().get(0);
    JvmType lookup = (JvmType) ((XAbstractFeatureCall) expression.getLeftOperand()).getFeature();
    final MockAcceptor mockAcceptor = new MockAcceptor();
    mockAcceptor.expect(expression.getLeftOperand(), lookup, XABSTRACT_FEATURE_CALL__FEATURE);
    mockAcceptor.expect(expression.getRightOperand(), lookup, XABSTRACT_FEATURE_CALL__FEATURE);
    findReferencesTester.checkFindReferences(lookup, "Java References to com.acme.OtherwiseUnused", mockAcceptor);
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) MockAcceptor(org.eclipse.xtext.xbase.ui.testing.FindReferencesTestUtil.MockAcceptor) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XBinaryOperation(org.eclipse.xtext.xbase.XBinaryOperation) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 7 with XtextResourceSet

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

the class FindReferencesTest method getResourceFor.

@Override
public XtextResource getResourceFor(InputStream stream) {
    try {
        XtextResourceSet set = get(XtextResourceSet.class);
        set.setClasspathURIContext(JavaCore.create(project));
        XtextResource result = (XtextResource) set.createResource(URI.createURI("Test." + fileExtension));
        result.load(stream, null);
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 8 with XtextResourceSet

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

the class NoJRESmokeTester method processFile.

@Override
public void processFile(String data) throws Exception {
    XtextResourceSet resourceSet = new XtextResourceSet();
    NoOpClassLoader classLoader = new NoOpClassLoader();
    resourceSet.setClasspathURIContext(classLoader);
    ClasspathTypeProviderFactory factory = new ClasspathTypeProviderFactory(classLoader, typeResourceServices);
    factory.createTypeProvider(resourceSet);
    EObject parsed = parseHelperNoJRE.parse(data, resourceSet);
    EcoreUtil.resolveAll(parsed);
    checkNoErrorsInValidator(data, (XtextResource) parsed.eResource());
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) ClasspathTypeProviderFactory(org.eclipse.xtext.common.types.access.ClasspathTypeProviderFactory)

Example 9 with XtextResourceSet

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

the class AbstractXbaseContentAssistTest method getResourceSet.

protected final XtextResourceSet getResourceSet() {
    XtextResourceSet resourceSet = get(XtextResourceSet.class);
    IJvmTypeProvider.Factory typeProviderFactory = new JdtTypeProviderFactory(this);
    typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    resourceSet.setClasspathURIContext(getJavaProject(resourceSet));
    return resourceSet;
}
Also used : JdtTypeProviderFactory(org.eclipse.xtext.common.types.access.jdt.JdtTypeProviderFactory) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider)

Example 10 with XtextResourceSet

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

the class GrammarParser method parse.

public Grammar parse(String rules) throws IOException {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource grammarResource = resourceSet.createResource(URI.createURI("Test.xtext"));
    grammarResource.load(new StringInputStream("grammar Test with org.eclipse.xtext.common.Terminals \n" + "generate test \"Test\"\n" + rules), null);
    EList<EObject> contents = grammarResource.getContents();
    assertEquals(1, contents.size());
    EObject root = contents.get(0);
    assertTrue(root instanceof Grammar);
    return (Grammar) root;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Grammar(org.eclipse.xtext.Grammar)

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