當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。