com.google.inject.Provider Java Examples

The following examples show how to use com.google.inject.Provider. 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: CheckQuickfixImplRegistryImpl.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public Collection<ICoreQuickfixProvider> getCoreQuickfixProviders(final String language) {
  Collection<ICoreQuickfixProvider> providers = Lists.newArrayList();
  for (ICheckImplDescriptor v : Sets.newHashSet(getDescriptors(language))) {
    if (v instanceof Provider<?>) {
      final ICoreQuickfixProvider provider = ((Provider<ICoreQuickfixProvider>) v).get();
      if (provider == null) { // may be null if specified target class could not be found
        removeLanguageDescriptor(language, v);
      } else {
        providers.add(provider);
      }
    }
  }
  return providers;
}
 
Example #2
Source File: HiveS3Module.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    S3FileSystemType type = buildConfigObject(HiveS3TypeConfig.class).getS3FileSystemType();
    if (type == S3FileSystemType.PRESTO) {
        bindSecurityMapping(binder);

        newSetBinder(binder, ConfigurationInitializer.class).addBinding().to(PrestoS3ConfigurationInitializer.class).in(Scopes.SINGLETON);
        configBinder(binder).bindConfig(HiveS3Config.class);

        binder.bind(PrestoS3FileSystemStats.class).toInstance(PrestoS3FileSystem.getFileSystemStats());
        Provider<CatalogName> catalogName = binder.getProvider(CatalogName.class);
        newExporter(binder).export(PrestoS3FileSystemStats.class)
                .as(generator -> generator.generatedNameOf(PrestoS3FileSystem.class, catalogName.get().toString()));
    }
    else if (type == S3FileSystemType.EMRFS) {
        validateEmrFsClass();
        newSetBinder(binder, ConfigurationInitializer.class).addBinding().to(EmrFsS3ConfigurationInitializer.class).in(Scopes.SINGLETON);
    }
    else if (type == S3FileSystemType.HADOOP_DEFAULT) {
        // configuration is done using Hadoop configuration files
    }
    else {
        throw new RuntimeException("Unknown file system type: " + type);
    }
}
 
Example #3
Source File: KeyValueSetPropertyEditorPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param editorProvider a guice injected provider of KeyValuePropertyEditorPanel Instances
 */
@Inject
public KeyValueSetPropertyEditorPanel(Provider<KeyValuePropertyEditorPanel> editorProvider) {
  this.editorProvider = requireNonNull(editorProvider, "editorProvider");

  initComponents();

  itemsTable.setModel(new ItemsTableModel());

  setPreferredSize(new Dimension(350, 200));

  itemsTable.getSelectionModel().addListSelectionListener((ListSelectionEvent evt) -> {
    if (evt.getValueIsAdjusting()) {
      return;
    }

    handleSelectionChanged();
  });
}
 
Example #4
Source File: ObjectMapperModule.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectMapper get()
{
    ObjectMapper mapper = objectMapper;
    if (mapper == null) {
        final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
        AnnotationIntrospector defaultAI = new JacksonAnnotationIntrospector();
        MapperBuilder<?,?> builder = JsonMapper.builder()
                .injectableValues(new GuiceInjectableValues(injector))
                .annotationIntrospector(new AnnotationIntrospectorPair(guiceIntrospector, defaultAI))
                .addModules(modulesToAdd);
        for (Provider<? extends Module> provider : providedModules) {
            builder = builder.addModule(provider.get());
        }
        mapper = builder.build();

      /*
  } else {
        // 05-Feb-2017, tatu: _Should_ be fine, considering instances are now (3.0) truly immutable.
      //    But if this turns out to be problematic, may need to consider addition of `copy()`
      //    back in databind
      mapper = mapper.copy();
      */
  }
  return mapper;
}
 
Example #5
Source File: HoverFeedbackPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} that is used to stroke hover feedback.
 *
 * @return The {@link Color} that is used to stroke hover feedback.
 */
@SuppressWarnings("serial")
protected Color getHoverStroke() {
	Provider<Color> hoverFeedbackColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultHoverFeedbackPartFactory.HOVER_FEEDBACK_COLOR_PROVIDER));
	return hoverFeedbackColorProvider == null
			? DefaultHoverFeedbackPartFactory.DEFAULT_HOVER_FEEDBACK_COLOR
			: hoverFeedbackColorProvider.get();
}
 
Example #6
Source File: SelectionFeedbackPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the primary selection {@link Color}.
 *
 * @return The primary selection {@link Color}.
 */
protected Color getPrimarySelectionColor() {
	@SuppressWarnings("serial")
	Provider<Color> connectedColorProvider = getViewer()
			.getAdapter(AdapterKey.get(new TypeToken<Provider<Color>>() {
			}, DefaultSelectionFeedbackPartFactory.PRIMARY_SELECTION_FEEDBACK_COLOR_PROVIDER));
	return connectedColorProvider == null
			? DefaultSelectionFeedbackPartFactory.DEFAULT_PRIMARY_SELECTION_FEEDBACK_COLOR
			: connectedColorProvider.get();
}
 
Example #7
Source File: DefaultMergeViewer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected DefaultMergeEditor createMergeEditor() {
	@SuppressWarnings("unchecked")
	Provider<DefaultMergeEditor> mergeEditorProvider = (Provider<DefaultMergeEditor>) getCompareConfiguration()
			.getProperty(DefaultMergeEditor.PROVIDER);
	DefaultMergeEditor mergeEditor = mergeEditorProvider.get();
	return mergeEditor;
}
 
Example #8
Source File: PartialEditingContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Provider<? extends StatefulFactory> getStatefulFactoryProvider() {
	final Provider<? extends StatefulFactory> delegate = super.getStatefulFactoryProvider();
	return new Provider<StatefulFactory>() {
		@Override
		public StatefulFactory get() {
			StatefulFactory result = delegate.get();
			result.getDelegate().setParser(partialContentAssistParser);
			if (rule != null) {
				partialContentAssistParser.initializeFor(rule);
			}
			return result;
		}
	};
}
 
Example #9
Source File: MultibinderPlannerNamespace.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
@Override
public SourceType findSource(Location location, ContextPlanner planner, List<String> sourcePath) {
    Provider<Source> sourceProvider = sourceBindings.get(keyFor(sourcePath));
    if (sourceProvider == null) {
        return null;
    }
    SourceUnitGenerator adapter = new SourceUnitGenerator(planner.getGambitScope());
    return adapter.apply(sourcePath, sourceProvider);
}
 
Example #10
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
Example #11
Source File: InMemoryTransactionService.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Inject
public InMemoryTransactionService(Configuration conf, DiscoveryService discoveryService,
                                  Provider<TransactionManager> txManagerProvider) {

  this.discoveryService = discoveryService;
  this.txManagerProvider = txManagerProvider;
  this.serviceName = conf.get(TxConstants.Service.CFG_DATA_TX_DISCOVERY_SERVICE_NAME,
                              TxConstants.Service.DEFAULT_DATA_TX_DISCOVERY_SERVICE_NAME);

  address = conf.get(TxConstants.Service.CFG_DATA_TX_BIND_ADDRESS, TxConstants.Service.DEFAULT_DATA_TX_BIND_ADDRESS);
  port = conf.getInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, TxConstants.Service.DEFAULT_DATA_TX_BIND_PORT);

  // Retrieve the number of threads for the service
  threads = conf.getInt(TxConstants.Service.CFG_DATA_TX_SERVER_THREADS,
                        TxConstants.Service.DEFAULT_DATA_TX_SERVER_THREADS);
  ioThreads = conf.getInt(TxConstants.Service.CFG_DATA_TX_SERVER_IO_THREADS,
                          TxConstants.Service.DEFAULT_DATA_TX_SERVER_IO_THREADS);

  maxReadBufferBytes = conf.getInt(TxConstants.Service.CFG_DATA_TX_THRIFT_MAX_READ_BUFFER,
                                   TxConstants.Service.DEFAULT_DATA_TX_THRIFT_MAX_READ_BUFFER);

  LOG.info("Configuring TransactionService" +
             ", address: " + address +
             ", port: " + port +
             ", threads: " + threads +
             ", io threads: " + ioThreads +
             ", max read buffer (bytes): " + maxReadBufferBytes);
}
 
Example #12
Source File: TSOForHBaseCompactorTestModule.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example #13
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
	return cache.get(REFERENCE_DESCRIPTIONS_CACHE_KEY, getResource(), new Provider<List<IReferenceDescription>>(){
		@Override
		public List<IReferenceDescription> get() {
			return computeReferenceDescriptions();
		}});
}
 
Example #14
Source File: TSOMockModule.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example #15
Source File: DefaultModule.java    From bromium with MIT License 5 votes vote down vote up
@CheckedProvides(IOProvider.class)
public RequestFilter getRequestFilter(@Named(COMMAND) String command,
                                      IOProvider<List<EventDetector>> eventDetectorListProvider,
                                      Provider<RecordingState> recordingStateProvider,
                                      Provider<ReplayingState> replayingStateProvider,
                                      Provider<List<ConditionsUpdater>> conditionsUpdaters) throws IOException {
    switch (command) {
        case RECORD:
            return new RecordRequestFilter(recordingStateProvider.get(), eventDetectorListProvider.get());
        case REPLAY:
            return new ReplayRequestFilter(replayingStateProvider.get(), conditionsUpdaters.get());
        default:
            throw new NoSuchCommandException();
    }
}
 
Example #16
Source File: RenameLinkedMode.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public boolean start(IRenameElementContext renameElementContext, Provider<LinkedPositionGroup> provider, IProgressMonitor monitor) {
	if (renameElementContext == null)
		throw new IllegalArgumentException("RenameElementContext is null");
	this.linkedPositionGroup = provider.get();
	if (linkedPositionGroup == null || linkedPositionGroup.isEmpty())
		return false;
	this.editor = (XtextEditor) renameElementContext.getTriggeringEditor();
	this.focusEditingSupport = new FocusEditingSupport();
	ISourceViewer viewer = editor.getInternalSourceViewer();
	IDocument document = viewer.getDocument();
	originalSelection = viewer.getSelectedRange();
	currentPosition = linkedPositionGroup.getPositions()[0];
	originalName = getCurrentName();
	try {
		linkedModeModel = new LinkedModeModel();
		linkedModeModel.addGroup(linkedPositionGroup);
		linkedModeModel.forceInstall();
		linkedModeModel.addLinkingListener(new EditorSynchronizer());
		LinkedModeUI ui = new EditorLinkedModeUI(linkedModeModel, viewer);
		ui.setExitPolicy(new ExitPolicy(document));
		if (currentPosition.includes(originalSelection.x))
			ui.setExitPosition(viewer, originalSelection.x, 0, Integer.MAX_VALUE);
		ui.enter();
		if (currentPosition.includes(originalSelection.x)
				&& currentPosition.includes(originalSelection.x + originalSelection.y))
			viewer.setSelectedRange(originalSelection.x, originalSelection.y);
		if (viewer instanceof IEditingSupportRegistry) {
			IEditingSupportRegistry registry = (IEditingSupportRegistry) viewer;
			registry.register(focusEditingSupport);
		}
		openPopup();
		return true;
	} catch (BadLocationException e) {
		throw new WrappedException(e);
	}
}
 
Example #17
Source File: DataStoreModule.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
DataStore provideDataStore(@LocalDataStore Provider<DataStore> localDataStoreProvider,
                           @SystemDataStore Provider<DataStore> systemDataStoreProvider,
                           DataCenterConfiguration dataCenterConfiguration) {
    // Provides the unannotated version of the DataStore
    // If this is the system data center, return the local DataStore implementation
    // Otherwise return a proxy that delegates to local or remote system DataStores
    if (dataCenterConfiguration.isSystemDataCenter()) {
        return localDataStoreProvider.get();
    } else {
        return new DataStoreProviderProxy(localDataStoreProvider, systemDataStoreProvider);
    }
}
 
Example #18
Source File: TSOForSnapshotFilterTestModule.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Provides
PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
    PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
    for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
        persistenceProcessorHandlers[i] = provider.get();
    }
    return persistenceProcessorHandlers;
}
 
Example #19
Source File: AbstractArchiveOptimalityTester.java    From opt4j with MIT License 5 votes vote down vote up
/**
 * Initializes the {@link Archive} with NUMBER_OF_INDIVIDUALS different
 * {@link Individual}s.
 * <p>
 * Therefore. three {@link Objective}s are added:
 * <ul>
 * <li>the first dimension is incremented</li>
 * <li>the second dimension is decremented</li>
 * <li>the third dimension is set randomly with a static seed.</li>
 * </ul>
 * 
 * @param injector
 *            the injector
 * @param archive
 *            the archive under test
 */
private void fillArchive(Injector injector, Archive archive) {
	Random r = new Random(100);
	Provider<Individual> individuals = injector.getProvider(Individual.class);

	first = null;
	last = null;
	randMin = null;
	int smallestRand = Integer.MAX_VALUE;
	for (int i = 0; i < NUMBER_OF_INDIVUDUALS; i++) {
		Individual individual = individuals.get();
		Objectives o = new Objectives();
		o.add(o1, i);
		o.add(o2, -i);
		int randomValue = r.nextInt(Integer.MAX_VALUE);
		o.add(o3, randomValue);
		individual.setObjectives(o);
		archive.update(individual);

		if (i == 0) {
			first = individual;
		}
		if (i == NUMBER_OF_INDIVUDUALS - 1) {
			last = individual;
		}
		if (randomValue < smallestRand) {
			randMin = individual;
			smallestRand = randomValue;
		}
	}
}
 
Example #20
Source File: AbstractTypeExpressionsUiModule.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
public Provider<? extends IAllContainersState> provideIAllContainersState() {
	return Access.getJavaProjectsState();
}
 
Example #21
Source File: AbstractDomainmodelUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends IAllContainersState> provideIAllContainersState() {
	return Access.getJavaProjectsState();
}
 
Example #22
Source File: AbstractBacktrackingLexerTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends InternalBacktrackingLexerTestLanguageLexer> provideInternalBacktrackingLexerTestLanguageLexer() {
	return LexerProvider.create(InternalBacktrackingLexerTestLanguageLexer.class);
}
 
Example #23
Source File: BuilderPreferencePage.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public void setCleanerProvider(Provider<DerivedResourceCleanerJob> cleanerProvider) {
	this.cleanerProvider = cleanerProvider;
}
 
Example #24
Source File: AbstractTwoContextsTestLanguageUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends IAllContainersState> provideIAllContainersState() {
	return Access.getJavaProjectsState();
}
 
Example #25
Source File: AbstractStatemachineUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends IAllContainersState> provideIAllContainersState() {
	return Access.getJavaProjectsState();
}
 
Example #26
Source File: AbstractTwoContextsTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends InternalTwoContextsTestLanguageLexer> provideInternalTwoContextsTestLanguageLexer() {
	return LexerProvider.create(InternalTwoContextsTestLanguageLexer.class);
}
 
Example #27
Source File: AbstractContentAssistTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends InternalContentAssistTestLanguageLexer> provideInternalContentAssistTestLanguageLexer() {
	return LexerProvider.create(InternalContentAssistTestLanguageLexer.class);
}
 
Example #28
Source File: EValidatorRegistrar.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void setCompositeProvider(Provider<CompositeEValidator> compositeProvider) {
	this.compositeProvider = compositeProvider;
}
 
Example #29
Source File: AbstractArithmeticsUiModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends LanguageRegistry> provideLanguageRegistry() {
	return AccessibleCodetemplatesActivator.getLanguageRegistry();
}
 
Example #30
Source File: AbstractFileAwareTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<? extends InternalFileAwareTestLanguageLexer> provideInternalFileAwareTestLanguageLexer() {
	return LexerProvider.create(InternalFileAwareTestLanguageLexer.class);
}