@Override public Set<Binding> getGuiceBindingsRt(Grammar grammar) { BindFactory factory = new BindFactory(); if (!XbaseGeneratorFragment.doesUseXbase(grammar)) { if(isGenerateStub) { factory.addTypeToType(IScopeProvider.class.getName(), getScopeProviderName(grammar, getNaming())); } else { factory.addTypeToType(IScopeProvider.class.getName(), getLocalScopeProvider().getName()); } factory.addConfiguredBinding( IScopeProvider.class.getName() + "Delegate", "binder.bind(" + IScopeProvider.class.getName() + ".class" + ").annotatedWith(com.google.inject.name.Names.named(" + AbstractDeclarativeScopeProvider.class.getName() + ".NAMED_DELEGATE" + ")).to(" + getLocalScopeProvider().getName() + ".class)"); factory.addTypeToType(IGlobalScopeProvider.class.getName(), getGlobalScopeProvider().getName()); } factory.addConfiguredBinding(IgnoreCaseLinking.class.getSimpleName(), "binder.bindConstant().annotatedWith(" + IgnoreCaseLinking.class.getName() + ".class).to(" + isIgnoreCase() + ")"); return factory.getBindings(); }
@Test public void testGetElementByClasspathURIEObject() throws Exception { with(ImportUriTestLanguageStandaloneSetup.class); Main main = (Main) getModel("import 'classpath:/org/eclipse/xtext/linking/05.importuritestlanguage'\n" + "type Bar extends Foo"); Type bar = main.getTypes().get(0); Type foo = bar.getExtends(); assertNotNull(foo); assertFalse(foo.eIsProxy()); // we don't put contextual classpath:/ uris into the index thus // they are partially normalized if (Platform.isRunning()) { assertEquals("bundleresource", EcoreUtil.getURI(foo).scheme()); } else { assertEquals("file", EcoreUtil.getURI(foo).scheme()); } IScopeProvider scopeProvider = get(IScopeProvider.class); IScope scope = scopeProvider.getScope(bar, ImportedURIPackage.Literals.TYPE__EXTENDS); Iterable<IEObjectDescription> elements = scope.getElements(foo); assertEquals(1, size(elements)); assertEquals(EcoreUtil2.getPlatformResourceOrNormalizedURI(foo), elements.iterator().next().getEObjectURI()); }
/** * Override to get scope based on the context, otherwise we might get scope for main language, while context is from * sub-language. */ @Override protected IScope getScope(EObject context, EReference reference) { IScopeProvider scopeProvider = N4LanguageUtils.getServiceForContext(context, IScopeProvider.class) .orElse(super.getScopeProvider()); if (getScopeProvider() == null) throw new IllegalStateException("scopeProvider must not be null."); try { registerImportedNamesAdapter(scopeProvider, context); return scopeProvider.getScope(context, reference); } finally { unRegisterImportedNamesAdapter(scopeProvider); } }
/** * Sets the scope provider to use as delegate for the local scope provider. This delegate is used to handle imported * elements. The customization makes elements that name is equal to the resource name both referenceable by e.g * my/pack/A/A as well as my/pack/A if the resource name is A. In this delegate later the import of the built in * types should be made. */ public void configureIScopeProviderDelegate(Binder binder) { binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class) .annotatedWith( com.google.inject.name.Names .named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) .to(N4JSImportedNamespaceAwareLocalScopeProvider.class); }
protected void unRegisterImportedNamesAdapter(IScopeProvider scopeProvider) { if (scopeProvider instanceof AbstractGlobalScopeDelegatingScopeProvider) { AbstractGlobalScopeDelegatingScopeProvider provider = (AbstractGlobalScopeDelegatingScopeProvider) scopeProvider; provider.setWrapper(null); } else if (scopeProvider instanceof IDelegatingScopeProvider) { IDelegatingScopeProvider delegatingScopeProvider = (IDelegatingScopeProvider) scopeProvider; unRegisterImportedNamesAdapter(delegatingScopeProvider.getDelegate()); } }
protected void registerImportedNamesAdapter(IScopeProvider scopeProvider, EObject context) { if (scopeProvider instanceof AbstractGlobalScopeDelegatingScopeProvider) { AbstractGlobalScopeDelegatingScopeProvider provider = (AbstractGlobalScopeDelegatingScopeProvider) scopeProvider; ImportedNamesAdapter adapter = getImportedNamesAdapter(context); provider.setWrapper(adapter); } else if (scopeProvider instanceof IDelegatingScopeProvider) { IDelegatingScopeProvider delegatingScopeProvider = (IDelegatingScopeProvider) scopeProvider; registerImportedNamesAdapter(delegatingScopeProvider.getDelegate(), context); } }
@Override public void setUp() throws Exception { super.setUp(); with(new IgnoreCaseNamespacesTestLanguageStandaloneSetup() { @Override public Injector createInjector() { return Guice.createInjector(new IgnoreCaseNamespacesTestLanguageRuntimeModule() { @Override public void configureIScopeProviderDelegate(Binder binder) { binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(OtherWildcardLocalScopeProvider.class); } }); } }); }
@Override public void setUp() throws Exception { super.setUp(); XtextStandaloneSetup.doSetup(); with(new LazyLinkingTestLanguageRuntimeModule() { @Override public Class<? extends IScopeProvider> bindIScopeProvider() { return org.eclipse.xtext.linking.lazy.Bug281990Test.RecursiveScopeProvider.class; } }); new LazyLinkingTestLanguageStandaloneSetup().register(getInjector()); }
/** {@inheritDoc} */ @Override public Set<Binding> getGuiceBindingsRt(final Grammar grammar) { final BindFactory bindFactory = new BindFactory(); final String prefix = GrammarUtil.getNamespace(grammar) + ".scoping." + GrammarUtil.getName(grammar); bindFactory.addTypeToType(IScopeProvider.class.getName(), prefix + "ScopeProvider"); bindFactory.addTypeToType(IScopeNameProvider.class.getName(), prefix + "ScopeNameProvider"); bindFactory.addTypeToType(ILinkingService.class.getName(), "com.avaloq.tools.ddk.xtext.linking.LinkingService"); return bindFactory.getBindings(); }
public Class<? extends IScopeProvider> bindIScopeProvider() { return PkmntcgoScopeProvider.class; }
public void configureIScopeProviderDelegate(Binder binder) { binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(ImportedNamespaceAwareLocalScopeProvider.class); }
public Class<? extends IScopeProvider> bindIScopeProvider() { return TypesScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return RegularExpressionScopeProvider.class; }
/** * Returns the scope provider which is injected here but is used by the computer which does not support DI. */ public IScopeProvider getScopeProvider() { return scopeProvider; }
@Override public Class<? extends IScopeProvider> bindIScopeProvider() { return N4JSScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return MyDslScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return BromiumScopeProvider.class; }
public void configureIScopeProviderDelegate(Binder binder) { binder.bind(IScopeProvider.class).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(XImportSectionNamespaceScopeProvider.class); }
public Class<? extends IScopeProvider> bindIScopeProvider() { return LcDslScopeProvider.class; }
@Override public Class<? extends IScopeProvider> bindIScopeProvider() { return KronusLocalScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return DslScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return RestauranteScopeProvider.class; }
public Class<? extends IScopeProvider> bindIScopeProvider() { return OCCIScopeProvider.class; }
@Override public Class<? extends IScopeProvider> bindIScopeProvider() { return IBatchScopeProvider.class; }
@Override public void configureLinkingIScopeProvider(com.google.inject.Binder binder) { binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(org.eclipse.xtext.linking.LinkingScopeProviderBinding.class) .to(org.eclipse.xtext.xbase.scoping.batch.IBatchScopeProvider.class); }
@Override public void configureSerializerIScopeProvider(com.google.inject.Binder binder) { binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class).annotatedWith(org.eclipse.xtext.serializer.tokens.SerializerScopeProviderBinding.class) .to(org.eclipse.xtext.xbase.serializer.SerializerScopeProvider.class); }
@SuppressWarnings("deprecation") public void configureIScopeProviderDelegate(com.google.inject.Binder binder) { binder.bind(org.eclipse.xtext.scoping.IScopeProvider.class) .annotatedWith(Names.named(org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) .to(org.eclipse.xtext.xbase.scoping.XbaseImportedNamespaceScopeProvider.class); }
public void setDelegate(IScopeProvider delegate) { this.delegate = delegate; }
@Override public IScopeProvider getDelegate() { return delegate; }