@Override
 protected void configure() {
   AnnotatedBindingBuilder<Resource.Factory> _bind =
       this.<Resource.Factory>bind(Resource.Factory.class);
   _bind.to(JavaResource.Factory.class);
   AnnotatedBindingBuilder<IResourceValidator> _bind_1 =
       this.<IResourceValidator>bind(IResourceValidator.class);
   _bind_1.toInstance(IResourceValidator.NULL);
   AnnotatedBindingBuilder<IGenerator> _bind_2 = this.<IGenerator>bind(IGenerator.class);
   _bind_2.to(IGenerator.NullGenerator.class);
   AnnotatedBindingBuilder<IEncodingProvider> _bind_3 =
       this.<IEncodingProvider>bind(IEncodingProvider.class);
   _bind_3.to(IEncodingProvider.Runtime.class);
   AnnotatedBindingBuilder<IResourceServiceProvider> _bind_4 =
       this.<IResourceServiceProvider>bind(IResourceServiceProvider.class);
   _bind_4.to(JavaResourceServiceProvider.class);
   AnnotatedBindingBuilder<IContainer.Manager> _bind_5 =
       this.<IContainer.Manager>bind(IContainer.Manager.class);
   _bind_5.to(SimpleResourceDescriptionsBasedContainerManager.class);
   AnnotatedBindingBuilder<IResourceDescription.Manager> _bind_6 =
       this.<IResourceDescription.Manager>bind(IResourceDescription.Manager.class);
   _bind_6.to(JavaResourceDescriptionManager.class);
   AnnotatedBindingBuilder<IQualifiedNameProvider> _bind_7 =
       this.<IQualifiedNameProvider>bind(IQualifiedNameProvider.class);
   _bind_7.to(JvmIdentifiableQualifiedNameProvider.class);
   AnnotatedBindingBuilder<String> _bind_8 = this.<String>bind(String.class);
   Named _named = Names.named(Constants.FILE_EXTENSIONS);
   LinkedBindingBuilder<String> _annotatedWith = _bind_8.annotatedWith(_named);
   _annotatedWith.toInstance("java");
   AnnotatedBindingBuilder<String> _bind_9 = this.<String>bind(String.class);
   Named _named_1 = Names.named(Constants.LANGUAGE_NAME);
   LinkedBindingBuilder<String> _annotatedWith_1 = _bind_9.annotatedWith(_named_1);
   _annotatedWith_1.toInstance("org.eclipse.xtext.java.Java");
   AnnotatedBindingBuilder<IJvmTypeProvider.Factory> _bind_10 =
       this.<IJvmTypeProvider.Factory>bind(IJvmTypeProvider.Factory.class);
   _bind_10.to(ClasspathTypeProviderFactory.class);
   AnnotatedBindingBuilder<ClassLoader> _bind_11 = this.<ClassLoader>bind(ClassLoader.class);
   ClassLoader _classLoader = JavaSourceLanguageRuntimeModule.class.getClassLoader();
   _bind_11.toInstance(_classLoader);
   AnnotatedBindingBuilder<IReferableElementsUnloader> _bind_12 =
       this.<IReferableElementsUnloader>bind(IReferableElementsUnloader.class);
   _bind_12.to(IReferableElementsUnloader.GenericUnloader.class);
   AnnotatedBindingBuilder<IResourceDescriptionsProvider> _bind_13 =
       this.<IResourceDescriptionsProvider>bind(IResourceDescriptionsProvider.class);
   final IResourceDescriptionsProvider _function =
       new IResourceDescriptionsProvider() {
         @Override
         public IResourceDescriptions getResourceDescriptions(final ResourceSet it) {
           return ChunkedResourceDescriptions.findInEmfObject(it);
         }
       };
   _bind_13.toInstance(_function);
 }
 @Override
 @SuppressWarnings("unchecked")
 protected void configure() {
   // Bind mock controllet to this instance, to automatically replay/verify all mocks created by
   // runner.
   bind(MockController.class).toInstance(this);
   // map field values by type
   for (Field field : fields.keySet()) {
     TypeLiteral literal = TypeLiteral.get(field.getGenericType());
     AnnotatedBindingBuilder builder = bind(literal);
     // Check field annotations.
     Annotation[] fieldAnnotations = field.getAnnotations();
     for (Annotation annotation : fieldAnnotations) {
       Class<? extends Annotation> annotationType = annotation.annotationType();
       if (
       /* annotationType.isAnnotationPresent(Qualifier.class)|| */ annotationType
           .isAnnotationPresent(BindingAnnotation.class)) {
         builder.annotatedWith(annotation);
       }
       if (annotationType.isAnnotationPresent(ScopeAnnotation.class)) {
         builder.in(annotationType);
       }
     }
     Binding binding = fields.get(field);
     if (null != binding.getValue()) {
       builder.toInstance(binding.getValue());
     } else if (null != binding.getImplementation()) {
       builder.to(binding.getImplementation());
     } else if (null != binding.getProvider()) {
       builder.toProvider(binding.getProvider());
     }
   }
 }
示例#3
0
 public void configureResourceBaseProvider(final Binder binder) {
   AnnotatedBindingBuilder<IResourceBaseProvider> _bind =
       binder.<IResourceBaseProvider>bind(IResourceBaseProvider.class);
   String _resourceBase = this.getResourceBase();
   ResourceBaseProviderImpl _resourceBaseProviderImpl =
       new ResourceBaseProviderImpl(_resourceBase);
   _bind.toInstance(_resourceBaseProviderImpl);
 }
  @SuppressWarnings("unchecked")
  @Test
  public void configure() {
    Binder binder = createNiceMock(Binder.class);
    AnnotatedBindingBuilder<LangFactory> bindLangFactory =
        createMock(AnnotatedBindingBuilder.class);
    AnnotatedBindingBuilder<ILinkingDiagnosticMessageProvider.Extended> bindLinkingDMP =
        createMock(AnnotatedBindingBuilder.class);
    AnnotatedBindingBuilder<ILaunchManager> bindLaunchManager =
        createMock(AnnotatedBindingBuilder.class);
    final ILaunchManager launchManager = createMock(ILaunchManager.class);
    final AnnotatedBindingBuilder<Console> bindConsole = createMock(AnnotatedBindingBuilder.class);
    final Console console = createMock(Console.class);

    expect(binder.bind(LangFactory.class)).andReturn(bindLangFactory);
    expect(binder.bind(ILinkingDiagnosticMessageProvider.Extended.class)).andReturn(bindLinkingDMP);
    expect(binder.bind(ILaunchManager.class)).andReturn(bindLaunchManager);
    expect(binder.bind(Console.class)).andReturn(bindConsole);

    bindLangFactory.toInstance(LangFactory.eINSTANCE);

    expect(bindLinkingDMP.to(Antlr4MissingReferenceMessageProvider.class)).andReturn(null);

    bindLaunchManager.toInstance(launchManager);
    bindConsole.toInstance(console);

    Object[] mocks = {binder, bindLangFactory, bindLinkingDMP, launchManager, console};

    replay(mocks);

    new Antlr4RuntimeModule() {
      @Override
      protected ILaunchManager getLaunchManager() {
        return launchManager;
      }

      @Override
      protected Console getConsole() {
        return console;
      }
    }.configure(binder);

    verify(mocks);
  }
 public void configureLineSeparatorInformation(final Binder binder) {
   AnnotatedBindingBuilder<ILineSeparatorInformation> _bind =
       binder.<ILineSeparatorInformation>bind(ILineSeparatorInformation.class);
   final ILineSeparatorInformation _function =
       new ILineSeparatorInformation() {
         @Override
         public String getLineSeparator() {
           return DefaultGeneratorModule.this.code.getLineDelimiter();
         }
       };
   _bind.toInstance(_function);
 }
 public void configureIEncodingProvider(final Binder binder) {
   AnnotatedBindingBuilder<IEncodingProvider> _bind =
       binder.<IEncodingProvider>bind(IEncodingProvider.class);
   IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
   final Procedure1<IEncodingProvider.Runtime> _function =
       new Procedure1<IEncodingProvider.Runtime>() {
         @Override
         public void apply(final IEncodingProvider.Runtime it) {
           String _encoding = DefaultGeneratorModule.this.code.getEncoding();
           it.setDefaultEncoding(_encoding);
         }
       };
   IEncodingProvider.Runtime _doubleArrow =
       ObjectExtensions.<IEncodingProvider.Runtime>operator_doubleArrow(_runtime, _function);
   _bind.toInstance(_doubleArrow);
 }
 public void configureCodeConfig(final Binder binder) {
   AnnotatedBindingBuilder<CodeConfig> _bind = binder.<CodeConfig>bind(CodeConfig.class);
   _bind.toInstance(this.code);
 }
 public void configureXtextProjectConfig(final Binder binder) {
   AnnotatedBindingBuilder<IXtextProjectConfig> _bind =
       binder.<IXtextProjectConfig>bind(IXtextProjectConfig.class);
   _bind.toInstance(this.project);
 }