Search in sources :

Example 1 with IDerivedStateComputer

use of org.eclipse.xtext.resource.IDerivedStateComputer in project xtext-xtend by eclipse.

the class IndexingTest method doTestResourceDescriptionWithoutGetContents.

private void doTestResourceDescriptionWithoutGetContents(final String input) throws IOException {
    XtextResourceSet resourceSet = getResourceSet();
    new ClasspathTypeProvider(classLoader, resourceSet, null, null);
    final Wrapper<Boolean> wrapper = Wrapper.wrap(Boolean.FALSE);
    for (int i = 0; i < 10; i++) {
        DerivedStateAwareResource resource = (DerivedStateAwareResource) resourceSet.createResource(URI.createURI("Dummy" + i + ".xtend"));
        resource.setDerivedStateComputer(new IDerivedStateComputer() {

            @Override
            public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
                if (!preLinkingPhase) {
                    wrapper.set(Boolean.TRUE);
                }
                derivedStateComputer.installDerivedState(resource, preLinkingPhase);
            }

            @Override
            public void discardDerivedState(DerivedStateAwareResource resource) {
                derivedStateComputer.discardDerivedState(resource);
            }
        });
        String actualInput = input;
        if (i != 0) {
            actualInput = "import C" + (i + 1) + " " + actualInput;
            actualInput = "import C" + (i - 1) + " " + actualInput;
        }
        actualInput = String.format(actualInput, i, i + 1);
        resource.load(new StringInputStream(actualInput), null);
    }
    for (int i = 0; i < 10; i++) {
        Resource resource = resourceSet.getResources().get(i);
        for (IEObjectDescription description : resourceDescriptionManager.getResourceDescription(resource).getExportedObjects()) {
            description.getEObjectOrProxy();
        }
    }
    assertFalse(wrapper.get());
}
Also used : DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDerivedStateComputer(org.eclipse.xtext.resource.IDerivedStateComputer) ClasspathTypeProvider(org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)1 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)1 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)1 IDerivedStateComputer (org.eclipse.xtext.resource.IDerivedStateComputer)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1