com.google.inject.Binder Java Examples

The following examples show how to use com.google.inject.Binder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonTypesContribution.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void configure(Binder binder) {
	binder.bind(IQualifiedNameConverter.class);
	
	binder.bind(BuilderDeltaConverter.class);
	binder.bind(DeltaConverter.class);
	binder.bind(TypeURIHelper.class);
	
	binder.bind(TypeResourceUnloader.class);
	binder.bind(JavaChangeQueueFiller.class);
	
	binder.bind(IEagerContribution.class).to(ListenerRegistrar.class);

	binder.bind(TraceRegionSerializer.class);
	binder.bind(ITraceForTypeRootProvider.class).to(TraceForTypeRootProvider.class);
	binder.bind(FolderAwareTrace.class);
	binder.bind(ZipFileAwareTrace.class);
	binder.bind(OppositeFileOpenerContributor.class).to(ClassFileBasedOpenerContributor.class);
}
 
Example #2
Source File: Binders.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static <T> ScopedBindingBuilder bindMapToInstancesOf(Binder binder, TypeLiteral<Map<String, T>> type) {
  	return bindMapToInstancesOf(binder, type, new Function<T,String>() {
  	   @Override
  	   public String apply(T service) {
  	      return Injectors.getServiceName(service);
  	   }
  	});
}
 
Example #3
Source File: XadesProfileCore.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
public <T> void addMultibinding(final Class<T> from, final Class<? extends T> to)
{
    if (null == from || null == to)
        throw new NullPointerException();

    this.bindings.add(new BindingAction()
    {
        @Override
        public void bind(Binder b)
        {
            Multibinder multibinder = Multibinder.newSetBinder(b, from);
            multibinder.addBinding().to(to);
        }
    });
}
 
Example #4
Source File: JsonKinesisDecoderModule.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder)
{
    bindRowDecoder(binder, JsonKinesisRowDecoder.class);

    bindFieldDecoder(binder, JsonKinesisFieldDecoder.class);
    bindFieldDecoder(binder, RFC2822JsonKinesisFieldDecoder.class);
    bindFieldDecoder(binder, ISO8601JsonKinesisFieldDecoder.class);
    bindFieldDecoder(binder, SecondsSinceEpochJsonKinesisFieldDecoder.class);
    bindFieldDecoder(binder, MillisecondsSinceEpochJsonKinesisFieldDecoder.class);
    bindFieldDecoder(binder, CustomDateTimeJsonKinesisFieldDecoder.class);
}
 
Example #5
Source File: AbstractDomainmodelUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void configureCodeMinding(Binder binder) {
	try {
		Class.forName("org.eclipse.jface.text.codemining.ICodeMiningProvider");
		binder.bind(ICodeMiningProvider.class)
			.to(DomainmodelCodeMiningProvider.class);
		binder.bind(IReconcileStrategyFactory.class).annotatedWith(Names.named("codeMinding"))
			.to(XtextCodeMiningReconcileStrategy.Factory.class);
	} catch(ClassNotFoundException ignore) {
		// no bindings if code mining is not available at runtime
	}
}
 
Example #6
Source File: CommandExecutorModule.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Binder binder)
{
    //binder.bind(CommandExecutor.class).to(SimpleCommandExecutor.class).in(Scopes.SINGLETON);
    binder.bind(CommandExecutor.class).to(DockerCommandExecutor.class).in(Scopes.SINGLETON);
    binder.bind(SimpleCommandExecutor.class).in(Scopes.SINGLETON);
}
 
Example #7
Source File: RestModuleTest.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testBindProviders(@Mocked final Binder binder) {
    underTest.configure(binder);
    new Verifications() {{
        binder.bind(MyProvider1.class).in(Scopes.SINGLETON);
        binder.bind(MyProvider2.class).in(Scopes.SINGLETON);
    }};
}
 
Example #8
Source File: XadesProfileCore.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
public <T> T getInstance(
        Class<T> clazz,
        Module[] overridableModules,
        Module[] sealedModules) throws XadesProfileResolutionException
{
    Module userBindingsModule = new Module()
    {
        @Override
        public void configure(Binder b)
        {
            for (BindingAction ba : bindings)
            {
                ba.bind(b);
            }
        }
    };
    Module overridesModule = Modules.override(overridableModules).with(userBindingsModule);
    // Concat sealed modules with overrides module
    Module[] finalModules = Arrays.copyOf(sealedModules, sealedModules.length + 1);
    finalModules[finalModules.length - 1] = overridesModule;
    try
    {
        return Guice.createInjector(finalModules).getInstance(clazz);
    }
    catch (RuntimeException ex)
    {
        throw new XadesProfileResolutionException(ex.getMessage(), ex);
    }
}
 
Example #9
Source File: JavaGeneratorModule.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void configureGeneratorRoot(GeneratorEntry entry, Binder binder) {

	// TODO: replace binding with new to define JavaFlowConfiguration
	binder.bind(IFlowConfiguration.class).to(DefaultFlowConfiguration.AllFeaturesDisabled.class);
	
	binder.bind(IModelSequencer.class).to(ModelSequencer.class);
	binder.bind(BehaviorMapping.class).to(org.yakindu.sct.model.sexec.transformation.ng.BehaviorMapping.class);
	binder.bind(IExecutionFlowGenerator.class).to(JavaGenerator.class);
	binder.bind(GeneratorEntry.class).toInstance(entry);
}
 
Example #10
Source File: SharedStateContributionRegistryImplTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void createParentInjector() {
	injector = Guice.createInjector(new Module() {
		@Override
		public void configure(Binder binder) {
			binder.bind(CharSequence.class).to(String.class);
			binder.bind(String.class).toInstance("fromParentInjector");
		}
	});
}
 
Example #11
Source File: ExtendedSARLInjectorProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create the module for tests of the runtime libraries.
 *
 * @return the module.
 */
@SuppressWarnings("static-method")
protected Module createRuntimeTestModule() {
	return new Module() {

		@Override
		public void configure(Binder binder) {
			binder.bind(OnTheFlyJavaCompiler2.class).toProvider(JavaCompilerProvider.class).asEagerSingleton();
		}

	};
}
 
Example #12
Source File: TestModules.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void bindAuditRepository(Binder binder) {

            Class<? extends EntityAuditRepository> auditRepoImpl = AtlasRepositoryConfiguration.getAuditRepositoryImpl();

            //Map EntityAuditRepository interface to configured implementation
            binder.bind(EntityAuditRepository.class).to(auditRepoImpl).asEagerSingleton();

            if(Service.class.isAssignableFrom(auditRepoImpl)) {
                Class<? extends Service> auditRepoService = (Class<? extends Service>)auditRepoImpl;
                //if it's a service, make sure that it gets properly closed at shutdown
                Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder, Service.class);
                serviceBinder.addBinding().to(auditRepoService);
            }
        }
 
Example #13
Source File: AbstractOutlineTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureHighlightingLexer(Binder binder) {
	binder.bind(org.eclipse.xtext.parser.antlr.Lexer.class)
		.annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
		.to(org.eclipse.xtext.ui.tests.editor.outline.parser.antlr.internal.InternalOutlineTestLanguageLexer.class);
}
 
Example #14
Source File: InjectionScope.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> void bindSeeded(Binder binder, Key<T> key) {
    binder.bind(key).toProvider(() -> {
        throw new ProvisionException("Missing seed instance for " + key);
    }).in(annotation);
}
 
Example #15
Source File: AbstractTypesUiModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public void configureHighlightingTokenDefProvider(Binder binder) {
	binder.bind(ITokenDefProvider.class)
		.annotatedWith(Names.named(LexerIdeBindings.HIGHLIGHTING))
		.to(AntlrTokenDefProvider.class);
}
 
Example #16
Source File: AbstractSingleCodetemplateUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureContentAssistLexerProvider(Binder binder) {
	binder.bind(InternalSingleCodetemplateLexer.class).toProvider(LexerProvider.create(InternalSingleCodetemplateLexer.class));
}
 
Example #17
Source File: AbstractRefactoringTestLanguage2UiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureContentAssistLexer(Binder binder) {
	binder.bind(Lexer.class)
		.annotatedWith(Names.named(LexerIdeBindings.CONTENT_ASSIST))
		.to(InternalRefactoringTestLanguage2Lexer.class);
}
 
Example #18
Source File: AbstractBug360834TestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureContentAssistLexer(Binder binder) {
	binder.bind(Lexer.class)
		.annotatedWith(Names.named(LexerIdeBindings.CONTENT_ASSIST))
		.to(InternalBug360834TestLanguageLexer.class);
}
 
Example #19
Source File: AbstractYangRuntimeModule.java    From yang-design-studio with Eclipse Public License 1.0 4 votes vote down vote up
public void configureIgnoreCaseLinking(com.google.inject.Binder binder) {
	binder.bindConstant().annotatedWith(org.eclipse.xtext.scoping.IgnoreCaseLinking.class).to(false);
}
 
Example #20
Source File: AbstractConcreteSyntaxValidationTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void configure(Binder binder) {
	properties = tryBindProperties(binder, "org/eclipse/xtext/validation/ConcreteSyntaxValidationTestLanguage.properties");
	super.configure(binder);
}
 
Example #21
Source File: AbstractBacktrackingBug325745TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureRuntimeLexer(Binder binder) {
	binder.bind(Lexer.class)
		.annotatedWith(Names.named(LexerBindings.RUNTIME))
		.to(InternalBacktrackingBug325745TestLanguageLexer.class);
}
 
Example #22
Source File: AbstractArithmeticsRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureIResourceDescriptions(Binder binder) {
	binder.bind(IResourceDescriptions.class).to(ResourceSetBasedResourceDescriptions.class);
}
 
Example #23
Source File: AbstractRegularExpressionRuntimeModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public void configureLanguageName(Binder binder) {
	binder.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("org.eclipse.n4js.regex.RegularExpression");
}
 
Example #24
Source File: KinesisDecoderModule.java    From presto-kinesis with Apache License 2.0 4 votes vote down vote up
public static void bindRowDecoder(Binder binder, Class<? extends KinesisRowDecoder> decoderClass)
{
    Multibinder<KinesisRowDecoder> rowDecoderBinder = Multibinder.newSetBinder(binder, KinesisRowDecoder.class);
    rowDecoderBinder.addBinding().to(decoderClass).in(Scopes.SINGLETON);
}
 
Example #25
Source File: AbstractContentAssistCustomizingTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureRuntimeLexer(Binder binder) {
	binder.bind(Lexer.class)
		.annotatedWith(Names.named(LexerBindings.RUNTIME))
		.to(InternalContentAssistCustomizingTestLanguageLexer.class);
}
 
Example #26
Source File: AbstractTypesUiModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public void configureIPreferenceStoreInitializer(Binder binder) {
	binder.bind(IPreferenceStoreInitializer.class)
		.annotatedWith(Names.named("RefactoringPreferences"))
		.to(RefactoringPreferences.Initializer.class);
}
 
Example #27
Source File: AbstractCrossReferenceProposalTestLanguageIdeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void configureContentAssistLexer(Binder binder) {
	binder.bind(Lexer.class)
		.annotatedWith(Names.named(LexerIdeBindings.CONTENT_ASSIST))
		.to(InternalCrossReferenceProposalTestLanguageLexer.class);
}
 
Example #28
Source File: AbstractGeneratorFragmentTests.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureGrammar(final Binder binder) {
  binder.<Grammar>bind(Grammar.class).toInstance(this.grammar);
}
 
Example #29
Source File: AbstractMultiRuleEnumTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureFileExtensions(Binder binder) {
	if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null)
		binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("multiruleenumtestlanguage");
}
 
Example #30
Source File: AbstractBug289524TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void configure(Binder binder) {
	properties = tryBindProperties(binder, "org/eclipse/xtext/parser/antlr/Bug289524TestLanguage.properties");
	super.configure(binder);
}