当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中com.google.gwt.inject.rebind.binding.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于com.google.gwt.inject.rebind.binding包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createImplementedByBinding

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private BindClassBinding createImplementedByBinding(Key<?> key, ImplementedBy implementedBy)
    throws BindingCreationException {
  Class<?> rawType = key.getTypeLiteral().getRawType();
  Class<?> implementationType = implementedBy.value();

  if (implementationType == rawType) {
    throw new BindingCreationException(
        "@ImplementedBy points to the same class it annotates: %s", rawType);
  }

  if (!rawType.isAssignableFrom(implementationType)) {
    throw new BindingCreationException("%s doesn't extend %s (while resolving @ImplementedBy)",
        implementationType, rawType);
  }

  return bindingFactory.getBindClassBinding(Key.get(implementationType), key,
      Context.forText("@ImplementedBy annotation"));
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:19,代码来源:ImplicitBindingCreator.java

示例2: visit

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
public Void visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) {
  // Detect provider methods and handle them
  // TODO(bstoler): Update this when the SPI explicitly has a case for
  // provider methods
  Provider<? extends T> provider = providerInstanceBinding.getProviderInstance();
  if (provider instanceof ProviderMethod) {
    Context context = Context.forElement(providerInstanceBinding);
    bindingsCollection.addBinding(targetKey,
        bindingFactory.getProviderMethodBinding((ProviderMethod<?>) provider, context));
    return null;
  }

  if (provider instanceof GwtDotCreateProvider) {
    addImplicitBinding(providerInstanceBinding);
    return null;
  }

  // OTt, use the normal default handler (and error)
  return super.visit(providerInstanceBinding);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:21,代码来源:GuiceBindingVisitor.java

示例3: createBindingsForFactories

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void createBindingsForFactories(GinjectorBindings bindings) {
  for (final FactoryModule<?> factoryModule : bindings.getFactoryModules()) {
    FactoryBinding binding;
    try {
      binding = bindingFactory.getFactoryBinding(
          factoryModule.getBindings(),
          factoryModule.getFactoryType(),
          Context.forText(factoryModule.getSource()));
    } catch (ConfigurationException e) {
      errorManager.logError("Factory %s could not be created", e, factoryModule.getFactoryType());
      continue;
    }

    bindings.addBinding(factoryModule.getFactoryType(), binding);
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:17,代码来源:BindingsProcessor.java

示例4: writeBindingContext

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
/**
 * Writes out a binding context, followed by a newline.
 *
 * <p>Binding contexts may contain newlines; this routine translates those for
 * the SourceWriter to ensure that indents, Javadoc comments, etc are handled
 * properly.
 */
public void writeBindingContext(SourceWriter writer, Context context) {
  // Avoid a trailing \n -- the GWT class source file composer will output an
  // ugly extra newline if we do that.
  String text = context.toString();
  boolean first = true;
  for (String line : text.split("\n")) {
    if (first) {
      first = false;
    } else {
      writer.println();
    }
    // Indent the line relative to its current location.  writer.indent()
    // won't work, since it does the wrong thing in Javadoc.
    writer.print("  ");
    writer.print(line);
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:25,代码来源:SourceWriteUtil.java

示例5: expectExposedBindingsExist

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
/**
 * For each binding exposed from a child, expect it to be represented
 * in the parent by an {@link ExposedChildBinding}.
 */
private void expectExposedBindingsExist() {
  for (Map.Entry<GinjectorBindings, Map<Key<?>, GinjectorBindings>> entry :
      exposedTo.entrySet()) {
    GinjectorBindings parent = entry.getKey();
    Map<Key<?>, GinjectorBindings> keyToChildMap = entry.getValue();

    for (Map.Entry<Key<?>, GinjectorBindings> keyAndChild : keyToChildMap.entrySet()) {
      Key<?> key = keyAndChild.getKey();
      GinjectorBindings child = keyAndChild.getValue();

      expect(parent.getBinding(key))
          .andReturn(new ExposedChildBinding(errorManager, Key.get(Long.class), child,
              Context.forText("")))
          .anyTimes();
    }
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:22,代码来源:BindingPositionerTest.java

示例6: ensureAccessible

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
/**
 * Ensure that the binding for key which exists in the parent Ginjector is also available to the
 * child Ginjector.
 */
private void ensureAccessible(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
  // Parent will be null if it is was an optional dependency and it couldn't be created.
  if (parent != null && !child.equals(parent) && !child.isBound(key)) {
    PrettyPrinter.log(logger, TreeLogger.DEBUG,
        "In %s: inheriting binding for %s from the parent %s", child, key, parent);
    Context context = Context.format("Inheriting %s from parent", key);

    // We don't strictly need all the extra checks in addBinding, but it can't hurt.  We know, for
    // example, that there will not be any unresolved bindings for this key.
    child.addBinding(key, bindingFactory.getParentBinding(key, parent, context));
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:17,代码来源:BindingInstaller.java

示例7: createProvidedByBinding

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private BindProviderBinding createProvidedByBinding(Key<?> key, ProvidedBy providedBy)
    throws BindingCreationException {
  Class<?> rawType = key.getTypeLiteral().getRawType();
  Class<? extends Provider<?>> providerType = providedBy.value();

  if (providerType == rawType) {
    throw new BindingCreationException(
        "@ProvidedBy points to the same class it annotates: %s", rawType);
  }

  return bindingFactory.getBindProviderBinding(Key.get(providerType), key,
      Context.forText("@ProvidedBy annotation"));
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:14,代码来源:ImplicitBindingCreator.java

示例8: testInstallImplicitBindings

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
public void testInstallImplicitBindings() throws Exception {
  // Tests that implicit bindings that are not already available in the origin are made accessible
  // foo and bar both had implicit bindings created (with no dependencies).  Foo is installed in
  // the child, and bar is installed in root.  We should add a binding to make bar accessible in
  // the child.
  expect(positions.getInstallPosition(foo())).andStubReturn(child);
  expect(positions.getInstallPosition(bar())).andStubReturn(root);
  
  Map<Key<?>, Binding> implicitBindingMap = new HashMap<Key<?>, Binding>();
  
  // Parent Binding to make bar available to child
  ParentBinding barBinding = control.createMock("barBinding", ParentBinding.class);
  expect(child.isBound(bar())).andReturn(false);
  expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class)))
      .andReturn(barBinding);
  
  // Implicit binding for Foo
  Binding fooBinding = control.createMock("fooBinding", Binding.class);
  expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList());
  implicitBindingMap.put(foo(), fooBinding);
  
  expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
  expect(child.getDependencies()).andReturn(TestUtils.dependencyList(
      new Dependency(Dependency.GINJECTOR, foo(), SOURCE),
      new Dependency(Dependency.GINJECTOR, bar(), SOURCE)));
  
  child.addBinding(bar(), barBinding);
  child.addBinding(foo(), fooBinding);
  control.replay();
  installer.installBindings(output);
  control.verify();
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:33,代码来源:BindingInstallerTest.java

示例9: testInheritDependencies

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
public void testInheritDependencies() throws Exception {
  // Tests that when we install an implicit binding (for foo), we install bindings to "inherit"
  // the dependencies (bar and baz) from the appropriate injectors.  In this case, bar must be
  // inherited from the root, but we don't need to do anything with baz, since it is already
  // available.
  expect(positions.getInstallPosition(foo())).andStubReturn(child);
  expect(positions.getInstallPosition(bar())).andStubReturn(root);
  expect(positions.getInstallPosition(baz())).andStubReturn(child);
  
  Map<Key<?>, Binding> implicitBindingMap = new HashMap<Key<?>, Binding>();
  
  // Parent Binding to make bar available to child
  ParentBinding barBinding = control.createMock("barBinding", ParentBinding.class);
  expect(child.isBound(bar())).andReturn(false);
  expect(bindingFactory.getParentBinding(eq(bar()), eq(root), isA(Context.class)))
      .andReturn(barBinding);

  // Implicit binding for Bar
  Binding bazBinding = control.createMock("bazBinding", Binding.class);
  expect(graph.getDependenciesOf(baz())).andReturn(TestUtils.dependencyList());
  implicitBindingMap.put(baz(), bazBinding);
  
  // Implicit binding for Foo
  Binding fooBinding = control.createMock("fooBinding", Binding.class);
  expect(graph.getDependenciesOf(foo())).andReturn(TestUtils.dependencyList(
      new Dependency(foo(), bar(), SOURCE),
      new Dependency(foo(), baz(), SOURCE)));
  implicitBindingMap.put(foo(), fooBinding);
  
  expect(output.getImplicitBindings()).andReturn(implicitBindingMap.entrySet());
  expect(child.getDependencies()).andReturn(TestUtils.dependencyList(
      new Dependency(Dependency.GINJECTOR, foo(), SOURCE)));
  
  child.addBinding(baz(), bazBinding);
  child.addBinding(bar(), barBinding);
  child.addBinding(foo(), fooBinding);
  control.replay();
  installer.installBindings(output);
  control.verify();
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:41,代码来源:BindingInstallerTest.java

示例10: bind

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void bind(Key<?> key, GinjectorBindings in) {
  Binding binding = control.createMock(Binding.class);
  expect(binding.getContext()).andReturn(Context.forText("")).anyTimes();
  expect(in.isBound(key)).andReturn(true).anyTimes();
  expect(in.getBinding(key)).andReturn(binding).anyTimes();
  bindings.add(binding);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:8,代码来源:BindingResolverTest.java

示例11: bindChild

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void bindChild(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
  ExposedChildBinding binding = control.createMock(ExposedChildBinding.class);
  expect(binding.getContext()).andReturn(Context.forText("")).anyTimes();
  expect(parent.isBound(key)).andReturn(true).anyTimes();
  expect(parent.getBinding(key)).andReturn(binding).anyTimes();
  expect(child.isPinned(key)).andReturn(true).anyTimes();
  expect(binding.getChildBindings()).andReturn(child).anyTimes();
  bindings.add(binding);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:10,代码来源:BindingResolverTest.java

示例12: bindParent

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void bindParent(Key<?> key, GinjectorBindings parent, GinjectorBindings child) {
  ParentBinding binding = control.createMock(ParentBinding.class);
  expect(binding.getContext()).andReturn(Context.forText("")).anyTimes();
  expect(binding.getParentBindings()).andReturn(parent).anyTimes();
  expect(child.isBound(key)).andReturn(true).anyTimes();
  expect(child.getBinding(key)).andReturn(binding).anyTimes();
  bindings.add(binding);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:9,代码来源:BindingResolverTest.java

示例13: writeBindingGetter

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
/**
 * Writes a method describing the getter for the given key, along with any other code necessary to support it. Produces a list of helper methods that still
 * need to be written.
 */
void writeBindingGetter(Key<?> key, Binding binding, GinScope scope, List<InjectorMethod> helperMethodsOutput) {
    Context bindingContext = binding.getContext();

    SourceSnippetBuilder getterBuilder = new SourceSnippetBuilder();
    SourceSnippet creationStatements;
    String getter = nameGenerator.getGetterMethodName(key);

    String typeName;
    try {
        typeName = ReflectUtil.getSourceName(key.getTypeLiteral());

        creationStatements = binding.getCreationStatements(nameGenerator, helperMethodsOutput);
    } catch (NoSourceNameException e) {
        errorManager.logError("Error trying to write getter for [%s] -> [%s];" + " binding declaration: %s", e, key, binding, bindingContext);
        return;
    }
    // Name of the field that we might need.
    String field = nameGenerator.getSingletonFieldName(key);

    switch (scope) {
        case EAGER_SINGLETON:
            initializeEagerSingletonsBody.append("// Eager singleton bound at:\n");
            appendBindingContextCommentToMethod(bindingContext, initializeEagerSingletonsBody);
            initializeEagerSingletonsBody.append(getter).append("();\n");
            // $FALL-THROUGH$
        case SINGLETON:
            writer.println("private " + typeName + " " + field + " = null;");
            writer.println();
            getterBuilder.append(String.format("\nif (%s == null) {\n", field)).append(creationStatements).append("\n")
                    .append(String.format("    %s = result;\n", field)).append(postConstruct(key)).append("}\n").append(String.format("return %s;\n", field));
            break;

        case NO_SCOPE:
            sourceWriteUtil.writeBindingContextJavadoc(writer, bindingContext, key);

            getterBuilder.append(creationStatements).append("\n").append(postConstruct(key)).append("return result;\n");
            break;

        default:
            throw new IllegalStateException();
    }

    outputMethod(SourceSnippets.asMethod(false, String.format("public %s %s()", typeName, getter), fragmentPackageName.toString(), getterBuilder.build()));
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:49,代码来源:GinjectorFragmentOutputter.java

示例14: appendBindingContextCommentToMethod

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void appendBindingContextCommentToMethod(Context bindingContext, StringBuilder methodBody) {
    for (String line : bindingContext.toString().split("\n")) {
        methodBody.append("//   ").append(line).append("\n");
    }
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:6,代码来源:GinjectorFragmentOutputter.java

示例15: addImplicitBinding

import com.google.gwt.inject.rebind.binding.Context; //导入依赖的package包/类
private void addImplicitBinding(Element sourceElement) {
  bindingsCollection.addDependency(new Dependency(Dependency.GINJECTOR, targetKey,
      Context.forElement(sourceElement).toString()));
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:5,代码来源:GuiceBindingVisitor.java


注:本文中的com.google.gwt.inject.rebind.binding.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。