@Override protected void configure() { this.<Resource.Factory>bind(Resource.Factory.class).to(JavaResource.Factory.class); this.<IResourceValidator>bind(IResourceValidator.class).toInstance(IResourceValidator.NULL); this.<IGenerator>bind(IGenerator.class).to(IGenerator.NullGenerator.class); this.<IEncodingProvider>bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class); this.<IResourceServiceProvider>bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class); this.<IContainer.Manager>bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class); this.<IResourceDescription.Manager>bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class); this.<IQualifiedNameProvider>bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class); this.<String>bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java"); this.<String>bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("org.eclipse.xtext.java.Java"); this.<IJvmTypeProvider.Factory>bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class); this.<ClassLoader>bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader()); this.<IReferableElementsUnloader>bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class); final IResourceDescriptionsProvider _function = (ResourceSet it) -> { return ChunkedResourceDescriptions.findInEmfObject(it); }; this.<IResourceDescriptionsProvider>bind(IResourceDescriptionsProvider.class).toInstance(_function); }
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResult(model); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); assertFalse(partiallyReparse.getRootNode().getText(), partiallyReparse.hasSyntaxErrors()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); }
protected void replaceAndReparse(String model, int offset, int length, String inserted, boolean expectSameRoot) throws Exception { final XtextResource resource = getResourceFromString(model); resource.setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { InternalEObject internalEObject = (InternalEObject) root; internalEObject.eSetProxyURI(resource.getURI().appendFragment(resource.getURIFragment(internalEObject))); internalEObject.eAdapters().clear(); }}); assertEquals(1, resource.getContents().size()); EObject wasObject = resource.getContents().get(0); assertNotNull(wasObject.eContainer()); assertNotSame(wasObject.eResource(), wasObject.eContainer().eResource()); resource.update(offset, length, inserted); assertEquals(1, resource.getContents().size()); EObject newRoot = resource.getContents().get(0); assertEquals(expectSameRoot, wasObject == newRoot); if (!expectSameRoot) { assertTrue(((InternalEObject)wasObject).eIsProxy()); assertNotSame(resource, wasObject.eResource()); } assertSame(resource, newRoot.eResource()); }
protected void replaceAndReparse(String model, int offset, int length, String change, String expectedReparseRegion) throws Exception { IParseResult parseResult = getParseResultAndExpect(model, UNKNOWN_EXPECTATION); PartialParsingPointers parsingPointers = getPartialParser().calculatePartialParsingPointers(parseResult, offset, length); String reparseRegion = getPartialParser().insertChangeIntoReplaceRegion(parsingPointers .getDefaultReplaceRootNode(), new ReplaceRegion(offset, length, change)); assertEquals(expectedReparseRegion, reparseRegion); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); getPartialParser().setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); IParseResult partiallyReparse = reparse(parseResult, offset, length, change); assertTrue("unloaded", unloaded.get()); String expectedReparseModel = model.substring(0, offset) + change + model.substring(offset + length); assertEquals(expectedReparseModel, partiallyReparse.getRootNode().getText()); compareWithFullParse(model, offset, length, change); }
@Test public void testUnloadReferables() throws Exception { resource.reparse(simpleModel); final Wrapper<Boolean> unloaded = Wrapper.wrap(Boolean.FALSE); resource.setUnloader(new IReferableElementsUnloader() { @Override public void unloadRoot(EObject root) { unloaded.set(Boolean.TRUE); } }); resource.reparse(simpleModel); assertTrue("unloaded", unloaded.get()); }
@Override public void configure(Binder binder) { super.configure(binder); binder.bind(IDefaultResourceDescriptionStrategy.class).to(SCTResourceDescriptionStrategy.class); // https://github.com/Yakindu/statecharts/issues/1199 binder.bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.NullUnloader.class); }
public void setUnloader(IReferableElementsUnloader unloader) { this.unloader = unloader; }
public IReferableElementsUnloader getUnloader() { return unloader; }
public Class<? extends IReferableElementsUnloader> bindIReferableElementsUnloader() { return XtextReferableElementsUnloader.class; }
public void setUnloader(final IReferableElementsUnloader unloader) { this.unloader = unloader; }
/** * Unloads type model instances. * * @return Class<{@link N4JSUnloader}> */ public Class<? extends IReferableElementsUnloader> bindIReferableElementsUnloader() { return N4JSUnloader.class; }