com.google.inject.Injector Java Examples

The following examples show how to use com.google.inject.Injector. 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: SuroServer.java    From suro with Apache License 2.0 6 votes vote down vote up
public static void create(AtomicReference<Injector> injector, final Properties properties, Module... modules) throws Exception {
    // Create the injector
    injector.set(LifecycleInjector.builder()
            .withBootstrapModule(
                    new BootstrapModule() {
                        @Override
                        public void configure(BootstrapBinder binder) {
                            binder.bindConfigurationProvider().toInstance(
                                    new PropertiesConfigurationProvider(properties));
                        }
                    }
            )
            .withModules(
                    new RoutingPlugin(),
                    new ServerSinkPlugin(),
                    new SuroInputPlugin(),
                    new SuroDynamicPropertyModule(),
                    new SuroModule(),
                    StatusServer.createJerseyServletModule()
            )
            .withAdditionalModules(modules)
            .build().createInjector());
}
 
Example #2
Source File: MultipleSingletonPluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private String getMultipleSingletonStatusString(Multimap<Class<?>, Injector> singletonInstances,
		Map<Injector, String> injectors) {

	// sort to preserve output order
	List<Class<?>> sortedByClassName = new ArrayList<>(singletonInstances.keySet());
	Comparator<Class<?>> comparatorByClassName = new Comparator<>() {
		@Override
		public int compare(Class<?> c1, Class<?> c2) {
			return c1.getName().compareTo(c2.getName());
		}
	};
	Collections.sort(sortedByClassName, comparatorByClassName);

	String status = "";
	int multipleInstancesCount = 0;
	for (Class<?> singleton : sortedByClassName) {
		String outputForInstance = printInjectorsForInstances(singleton, injectors);
		if (outputForInstance.length() > 0) {
			status += outputForInstance;
			multipleInstancesCount++;
		}
	}
	status = "Found multiple instances for " + multipleInstancesCount + " singleton classes:\n" + status;
	return status;
}
 
Example #3
Source File: ConfigModuleTest.java    From testability-explorer with Apache License 2.0 6 votes vote down vote up
public void testParseMultipleClassesAndPackages() throws Exception {
  Injector injector = Guice.createInjector(new ConfigModule(new String[]{
      "-cp", "not/default/path",
              "com.google.FirstClass",
              "com.google.second.package",
              "com.google.third.package"}, outStream, errStream));
  CommandLineConfig commandLineConfig = injector.getInstance(CommandLineConfig.class);

  assertEquals("", err.toString());
  assertEquals("not/default/path", commandLineConfig.cp);
  List<String> expectedArgs = new ArrayList<String>();
  expectedArgs.add("com.google.FirstClass");
  expectedArgs.add("com.google.second.package");
  expectedArgs.add("com.google.third.package");
  assertNotNull(commandLineConfig.entryList);
  assertEquals(expectedArgs, commandLineConfig.entryList);
}
 
Example #4
Source File: GuiceModelParser.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
/**
 * Parse single guice element.
 *
 * @param injector injector instance
 * @param element  element to analyze
 * @return parsed descriptor or null if element is not supported (or intentionally skipped)
 */
public static BindingDeclaration parseElement(final Injector injector, final Element element) {
    final BindingDeclaration dec = element.acceptVisitor(ELEMENT_VISITOR);

    if (dec != null) {
        fillDeclaration(dec, injector);
        fillSource(dec, element);
        dec.setModule(BindingUtils.getModules(element).get(0));

        if (dec.getKey() != null) {
            final Class ann = dec.getKey().getAnnotationType();
            if (ann != null) {
                if (ann.getName().equals("com.google.inject.internal.Element")) {
                    dec.setSpecial(Collections.singletonList("multibinding"));
                }
                if (ann.getName().startsWith("com.google.inject.internal.RealOptionalBinder")) {
                    dec.setSpecial(Collections.singletonList("optional binding"));
                }
            }
        }
    }

    return dec;
}
 
Example #5
Source File: NotificationsService.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public void init( ServiceInfo info ) {
    super.init(info);
    smf = getApplicationContext().getBean(ServiceManagerFactory.class);
    emf = getApplicationContext().getBean(EntityManagerFactory.class);

    Properties props = (Properties)getApplicationContext().getBean("properties");
    metricsService = getApplicationContext().getBean(Injector.class).getInstance(MetricsFactory.class);
    postMeter = metricsService.getMeter(NotificationsService.class, "collection.post_requests");
    postTimer = metricsService.getTimer(this.getClass(), "collection.post_requests");
    JobScheduler jobScheduler = new JobScheduler(sm,em);
    String name = ApplicationQueueManagerImpl.getQueueNames( props );
    LegacyQueueScope queueScope = new LegacyQueueScopeImpl( name, LegacyQueueScope.RegionImplementation.LOCAL);
    queueManagerFactory = getApplicationContext().getBean( Injector.class ).getInstance(LegacyQueueManagerFactory.class);
    LegacyQueueManager legacyQueueManager = queueManagerFactory.getQueueManager(queueScope);
    applicationQueueManagerCache = getApplicationContext().getBean(Injector.class).getInstance(ApplicationQueueManagerCache.class);
    notificationQueueManager = applicationQueueManagerCache
        .getApplicationQueueManager(em, legacyQueueManager, jobScheduler, metricsService ,props);

    gracePeriod = JobScheduler.SCHEDULER_GRACE_PERIOD;
}
 
Example #6
Source File: StaticCapabilitiesProvisioningTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetGcdParticipantIdInRoutingTableCalledOnlyForGcdDiscoveryEntry() throws Exception {
    Set<DiscoveryEntry> discoveryEntries = createDiscoveryEntries("io.joynr",
                                                                  GlobalCapabilitiesDirectory.INTERFACE_NAME,
                                                                  GlobalDomainAccessController.INTERFACE_NAME);

    final String serializedDiscoveryEntries = objectMapper.writeValueAsString(discoveryEntries);
    Injector injector = createInjectorForJsonValue(serializedDiscoveryEntries);

    injector.getInstance(CapabilitiesProvisioning.class);

    ArgumentCaptor<String> gcdParticipantIdCaptor = ArgumentCaptor.forClass(String.class);
    verify(routingTable, times(1)).setGcdParticipantId(gcdParticipantIdCaptor.capture());
    String gcdParticpantId = gcdParticipantIdCaptor.getValue();
    assertTrue(gcdParticpantId.contains(GlobalCapabilitiesDirectory.INTERFACE_NAME));
}
 
Example #7
Source File: DirtyStateEditorSupportIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUpEditor() throws Exception {
	IResourceServiceProvider rsp = IResourceServiceProvider.Registry.INSTANCE
			.getResourceServiceProvider(URI.createURI("dummy.testlanguage"));
	rsp.get(Injector.class).injectMembers(this);
	IFile file = IResourcesSetupUtil.createFile("test/foo.testlanguage", "stuff foo");
	editor = openEditor(file);
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	editor.getSite().getPage().activate(editor);
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	events = new ArrayList<>();
	editor.getDirtyStateEditorSupport().getDirtyStateManager().addListener(e -> events.add(e));
	myDisplay = editor.getSite().getShell().getDisplay();
	myDisplay.getShells()[0].forceActive();
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	styledText = editor.getInternalSourceViewer().getTextWidget();
	styledText.setCaretOffset(9);
	styledText.setFocus();
	syncUtil.waitForReconciler(editor);
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	Thread.sleep(20);
	Assert.assertTrue(events.isEmpty());
}
 
Example #8
Source File: QueueResourceTest.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertDelayParameter() {

    Injector injector = StartupListener.INJECTOR;
    QueueResource queueResource = injector.getInstance( QueueResource.class );

    Assert.assertEquals( 0L, queueResource.convertDelayParameter( "" ).longValue() );
    Assert.assertEquals( 0L, queueResource.convertDelayParameter( "0" ).longValue() );
    Assert.assertEquals( 0L, queueResource.convertDelayParameter( "NONE" ).longValue() );
    Assert.assertEquals( 5L, queueResource.convertDelayParameter( "5" ).longValue() );

    try {
        queueResource.convertDelayParameter( "bogus value" );
        fail("Expected exception on bad value");
    } catch ( IllegalArgumentException expected ) {
        // pass
    }
}
 
Example #9
Source File: PlainInjectorTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testChildInjector() {
	Injector parentInjector = Guice.createInjector();
	Injector injector = parentInjector.createChildInjector(new Module() {
		@Override
		public void configure(Binder binder) {
			binder.bind(CharSequence.class).to(String.class);
		}
	});
	Assert.assertNotNull(injector.getExistingBinding(Key.get(CharSequence.class)));
	// Parent allows JIT bindings and those are always created in the ancestor
	Assert.assertNotNull(injector.getExistingBinding(Key.get(String.class)));
	CharSequence emptyString = injector.getInstance(CharSequence.class);
	Assert.assertEquals("", emptyString);
	Assert.assertNotNull(injector.getExistingBinding(Key.get(String.class)));
	Assert.assertNotNull(parentInjector.getExistingBinding(Key.get(String.class)));
}
 
Example #10
Source File: Main.java    From maven-artifacts-uploader with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Injector injector = Guice.createInjector(new MavenModule(), new MavenCommandOptionsModule(), new XmlModule());
    OptionalArgs optionalArgs = injector.getInstance(OptionalArgs.class);
    JCommander jCommander = JCommander.newBuilder().addObject(optionalArgs).build();
    jCommander.setProgramName("mvnUploader");
    jCommander.parse(args);

    if (optionalArgs.isHelp()){
        jCommander.usage();
    } else {
        logger.info("Welcome To Maven Artifacts Uploader");
        Uploader uploader = injector.getInstance(Uploader.class);
        uploader.uploadToRepository(Paths.get(optionalArgs.getPathToArtifacts()));
        logger.info("Done uploading all the artifacts!");
    }
}
 
Example #11
Source File: DotEditorUtils.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private static XtextResource doGetResource(Injector injector,
		InputStream in, URI uri) throws Exception {
	XtextResourceSet rs = injector.getInstance(XtextResourceSet.class);
	rs.setClasspathURIContext(DotEditorUtils.class);
	XtextResource resource = (XtextResource) injector
			.getInstance(IResourceFactory.class).createResource(uri);
	rs.getResources().add(resource);
	resource.load(in, null);
	if (resource instanceof LazyLinkingResource) {
		((LazyLinkingResource) resource)
				.resolveLazyCrossReferences(CancelIndicator.NullImpl);
	} else {
		EcoreUtil.resolveAll(resource);
	}
	return resource;
}
 
Example #12
Source File: JerseyProviderInstaller.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
public void install(final AbstractBinder binder, final Injector injector, final Class<Object> type) {
    final boolean hkExtension = isJerseyExtension(type);
    final boolean forceSingleton = isForceSingleton(type, hkExtension);
    // since jersey 2.26 internal hk Factory class replaced by java 8 Supplier
    if (is(type, Supplier.class)) {
        // register factory directly (without wrapping)
        bindFactory(binder, injector, type, hkExtension, forceSingleton);

    } else {
        // support multiple extension interfaces on one type
        final Set<Class<?>> extensions = Sets.intersection(EXTENSION_TYPES,
                GenericsResolver.resolve(type).getGenericsInfo().getComposingTypes());
        if (!extensions.isEmpty()) {
            for (Class<?> ext : extensions) {
                bindSpecificComponent(binder, injector, type, ext, hkExtension, forceSingleton);
            }
        } else {
            // no known extension found
            bindComponent(binder, injector, type, hkExtension, forceSingleton);
        }
    }
}
 
Example #13
Source File: GuiceFeature.java    From jrestless-examples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
	InjectionManager injectionManager = InjectionManagerProvider.getInjectionManager(context);
	ServiceLocator locator;
	if (injectionManager instanceof ImmediateHk2InjectionManager) {
		locator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
	} else if (injectionManager instanceof DelayedHk2InjectionManager) {
		locator = ((DelayedHk2InjectionManager) injectionManager).getServiceLocator();
	} else {
		throw new IllegalStateException("expected an hk2 injection manager");
	}
	GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
	// register all your modules, here
	Injector injector = Guice.createInjector(new GreetingModule());
	GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
	guiceBridge.bridgeGuiceInjector(injector);
	return true;
}
 
Example #14
Source File: AbstractXbaseUITestCase.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static IProject createPluginProject(String name) throws CoreException {
	Injector injector = XbaseActivator.getInstance().getInjector("org.eclipse.xtext.xbase.Xbase");
	PluginProjectFactory projectFactory = injector.getInstance(PluginProjectFactory.class);
	projectFactory.setProjectName(name);
	projectFactory.setBreeToUse(JREContainerProvider.PREFERRED_BREE);
	projectFactory.addFolders(Collections.singletonList("src"));
	projectFactory.addBuilderIds(
		JavaCore.BUILDER_ID, 
		"org.eclipse.pde.ManifestBuilder",
		"org.eclipse.pde.SchemaBuilder",
		XtextProjectHelper.BUILDER_ID);
	projectFactory.addProjectNatures(JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID);
	projectFactory.addRequiredBundles(Collections.singletonList("org.eclipse.xtext.xbase.lib"));
	IProject result = projectFactory.createProject(new NullProgressMonitor(), null);
	JavaProjectSetupUtil.makeJava8Compliant(JavaCore.create(result));
	JavaProjectSetupUtil.setUnixLineEndings(result);
	return result;
}
 
Example #15
Source File: Activator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public Injector getInjector(String language) {
	synchronized (injectors) {
		Injector injector = injectors.get(language);
		if (injector == null) {
			injectors.put(language, injector = createInjector(language));
		}
		return injector;
	}
}
 
Example #16
Source File: RefactoringTestLanguageInjectorProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Injector getInjector() {
	if (injector == null) {
		this.injector = internalCreateInjector();
		stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
	}
	return injector;
}
 
Example #17
Source File: Bug302128TestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug302128testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug302128testlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/2009/tmf/xtext/tests/bug302123")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/2009/tmf/xtext/tests/bug302123", Bug302128Package.eINSTANCE);
	}
}
 
Example #18
Source File: TestlanguagesActivator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public Injector getInjector(String language) {
	synchronized (injectors) {
		Injector injector = injectors.get(language);
		if (injector == null) {
			injectors.put(language, injector = createInjector(language));
		}
		return injector;
	}
}
 
Example #19
Source File: OutputManagerTest.java    From ffwd with Apache License 2.0 5 votes vote down vote up
public OutputManager createOutputManager() {
    final List<Module> modules = Lists.newArrayList();

    modules.add(new AbstractModule() {
        @Override
        protected void configure() {
            bind(new TypeLiteral<List<PluginSink>>() {
            }).toInstance(ImmutableList.of(sink));
            bind(AsyncFramework.class).toInstance(async);
            bind(new TypeLiteral<Map<String, String>>() {
            }).annotatedWith(Names.named("tags")).toInstance(tags);
            bind(new TypeLiteral<Map<String, String>>() {
            }).annotatedWith(Names.named("tagsToResource")).toInstance(tagsToResource);
            bind(new TypeLiteral<Map<String, String>>() {
            }).annotatedWith(Names.named("resource")).toInstance(resource);
            bind(new TypeLiteral<Set<String>>() {
            }).annotatedWith(Names.named("riemannTags")).toInstance(riemannTags);
            bind(new TypeLiteral<Set<String>>() {
            }).annotatedWith(Names.named("skipTagsForKeys")).toInstance(skipTagsForKeys);
            bind(Boolean.class)
                .annotatedWith(Names.named("automaticHostTag"))
                .toInstance(automaticHostTag);
            bind(String.class).annotatedWith(Names.named("host")).toInstance(host);
            bind(long.class).annotatedWith(Names.named("ttl")).toInstance(ttl);
            bind(Integer.class).annotatedWith(Names.named("rateLimit")).toProvider(Providers.of(rateLimit));
            bind(DebugServer.class).toInstance(debugServer);
            bind(OutputManagerStatistics.class).toInstance(statistics);
            bind(Filter.class).toInstance(filter);
            bind(OutputManager.class).to(CoreOutputManager.class);
            bind(Long.class).annotatedWith(Names.named("cardinalityLimit")).toProvider(Providers.of(cardinalityLimit));
            bind(Long.class).annotatedWith(Names.named("hyperLogLogPlusSwapPeriodMS")).toProvider(Providers.of(
                hyperLogLogPlusSwapPeriodMS));
        }
    });

    final Injector injector = Guice.createInjector(modules);

    return injector.getInstance(OutputManager.class);
}
 
Example #20
Source File: Bug348427TestLanguageStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/ui/common/tests/2011/bug348427TestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/ui/common/tests/2011/bug348427TestLanguage", Bug348427TestLanguagePackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug348427testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug348427testlanguage", serviceProvider);
}
 
Example #21
Source File: SceneModuleTest.java    From greenbeans with Apache License 2.0 5 votes vote down vote up
private Injector createInjector() {
	return Guice.createInjector(new SceneModule(parameters), new AbstractModule() {
		@Override
		protected void configure() {
			bind(WebInvoker.class).toInstance(mock(WebInvoker.class));
		}
	});
}
 
Example #22
Source File: TestUtils.java    From presto-kinesis with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to get the table description supplier.
 *
 * @param inj
 * @return
 */
public static KinesisTableDescriptionSupplier getTableDescSupplier(Injector inj)
{
    requireNonNull(inj, "Injector is missing in getTableDescSupplier");
    Supplier<Map<SchemaTableName, KinesisStreamDescription>> supplier =
            inj.getInstance(Key.get(new TypeLiteral<Supplier<Map<SchemaTableName, KinesisStreamDescription>>>() {}));
    requireNonNull(inj, "Injector cannot find any table description supplier");
    return (KinesisTableDescriptionSupplier) supplier;
}
 
Example #23
Source File: Bug462047LangInjectorProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Injector getInjector() {
	if (injector == null) {
		this.injector = internalCreateInjector();
		stateAfterInjectorCreation = GlobalRegistries.makeCopyOfGlobalState();
	}
	return injector;
}
 
Example #24
Source File: RegistrationMonitor.java    From ja-micro with Apache License 2.0 5 votes vote down vote up
@Inject
public RegistrationMonitor(Injector injector,
                           ServiceProperties serviceProps,
                           ExecutorService executorService) {
    this.injector = injector;
    this.serviceProps = serviceProps;
    this.executorService = executorService;
}
 
Example #25
Source File: Bug289524TestLanguageStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bug289524testlanguage", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("bug289524testlanguage", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://eclipse.org/xtext/Bug289524TestLanguage")) {
		EPackage.Registry.INSTANCE.put("http://eclipse.org/xtext/Bug289524TestLanguage", Bug289524TestPackage.eINSTANCE);
	}
}
 
Example #26
Source File: SequentialIndividualCompleterTest.java    From opt4j with MIT License 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void evaluateDifferentObjectivesSize() throws TerminationException {
	Injector injector = Guice.createInjector(new MockProblemModule());
	IndividualFactory factory = injector.getInstance(IndividualFactory.class);
	Individual i1 = factory.create();
	Individual i2 = factory.create();

	SequentialIndividualCompleter completer = injector.getInstance(SequentialIndividualCompleter.class);

	i1.setPhenotype("my phenotype");
	i2.setPhenotype("my other phenotype");
	completer.evaluate(i1);
	objectives.add(new Objective("y"), 4);
	completer.evaluate(i2);
}
 
Example #27
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Before
@BeforeEach
public void setup() {
  final Injector injector = Guice.createInjector(this.getServerModule());
  injector.injectMembers(this);
  final Object resourceServiceProvider = this.resourceServerProviderRegistry.getExtensionToFactoryMap().get(this.fileExtension);
  if ((resourceServiceProvider instanceof IResourceServiceProvider)) {
    this.languageInfo = ((IResourceServiceProvider)resourceServiceProvider).<LanguageInfo>get(LanguageInfo.class);
  }
  this.languageServer.connect(ServiceEndpoints.toServiceObject(this, this.getLanguageClientClass()));
  this.languageServer.supportedMethods();
  File _absoluteFile = new File("").getAbsoluteFile();
  File _file = new File(_absoluteFile, AbstractLanguageServerTest.TEST_PROJECT_PATH);
  this.root = _file;
}
 
Example #28
Source File: SimpleExpressionsStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Injector createInjectorAndDoEMFRegistration() {
	org.eclipse.xtext.common.TerminalsStandaloneSetup.doSetup();

	Injector injector = createInjector();
	register(injector);
	return injector;
}
 
Example #29
Source File: StatemachineStandaloneSetupGenerated.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.eclipse.org/xtext/example/fowlerdsl/Statemachine")) {
		EPackage.Registry.INSTANCE.put("http://www.eclipse.org/xtext/example/fowlerdsl/Statemachine", StatemachinePackage.eINSTANCE);
	}
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("statemachine", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("statemachine", serviceProvider);
}
 
Example #30
Source File: TransientValuesTestStandaloneSetupGenerated.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void register(Injector injector) {
	IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);
	IResourceServiceProvider serviceProvider = injector.getInstance(IResourceServiceProvider.class);
	
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("transientvaluestest", resourceFactory);
	IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("transientvaluestest", serviceProvider);
	if (!EPackage.Registry.INSTANCE.containsKey("http://simple/transientvaluestest")) {
		EPackage.Registry.INSTANCE.put("http://simple/transientvaluestest", TransientvaluestestPackage.eINSTANCE);
	}
}