com.google.inject.spi.Element类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(345)

本文整理了Java中com.google.inject.spi.Element类的一些代码示例,展示了Element类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element类的具体详情如下:
包路径:com.google.inject.spi.Element
类名称:Element

Element介绍

[英]A core component of a module or injector.

The elements of a module can be inspected, validated and rewritten. Use Elements#getElements(com.google.inject.Module[]) to read the elements from a module, and Elements#getModule(Iterable) to rewrite them. This can be used for static analysis and generation of Guice modules.

The elements of an injector can be inspected and exercised. Use com.google.inject.Injector#getBindings to reflect on Guice injectors.
[中]模块或注入器的核心部件。
可以检查、验证和重写模块的元素。使用Elements#getElements(com.google.inject.Module[])从模块中读取元素,使用Elements#getModule(Iterable)重写它们。这可以用于静态分析和Guice模块的生成。
可以检查和使用喷油器的元件。使用com。谷歌。注射注射器#获取绑定以反映Guice注射器。

代码示例

代码示例来源:origin: com.google.inject/guice

  1. void writeAll(Iterable<? extends Element> elements) {
  2. for (Element element : elements) {
  3. element.acceptVisitor(this);
  4. }
  5. }
  6. }

代码示例来源:origin: com.google.inject/guice

  1. @Override
  2. public void configure(Binder binder) {
  3. for (Element element : elements) {
  4. element.applyTo(binder);
  5. }
  6. }
  7. }

代码示例来源:origin: com.google.inject/guice

  1. public void process(InjectorImpl injector, List<Element> elements) {
  2. Errors errorsAnyElement = this.errors;
  3. this.injector = injector;
  4. try {
  5. for (Iterator<Element> i = elements.iterator(); i.hasNext(); ) {
  6. Element element = i.next();
  7. this.errors = errorsAnyElement.withSource(element.getSource());
  8. Boolean allDone = element.acceptVisitor(this);
  9. if (allDone) {
  10. i.remove();
  11. }
  12. }
  13. } finally {
  14. this.errors = errorsAnyElement;
  15. this.injector = null;
  16. }
  17. }

代码示例来源:origin: org.atteo.moonshine/container

  1. element.applyTo(binder);
  2. element.acceptVisitor(new DefaultElementVisitor<Void>() {
  3. private <T> void bindKey(Key<T> key) {
  4. Key<T> sourceKey;

代码示例来源:origin: com.netflix.governator/governator-core

  1. /**
  2. * @param elements List of elements
  3. * @return List all Module classes that were involved in setting up bindings for the list of Elements
  4. */
  5. public static List<String> getAllSourceModules(List<Element> elements) {
  6. List<String> names = new ArrayList<>();
  7. for (Element element : elements) {
  8. if (element.getSource().getClass().isAssignableFrom(ElementSource.class)) {
  9. ElementSource source = (ElementSource)element.getSource();
  10. names.addAll(source.getModuleClassNames());
  11. }
  12. }
  13. return names;
  14. }

代码示例来源:origin: io.github.gwtplus.gin/gin

  1. /**
  2. * Create a {@code Context} storing the context of the given Guice
  3. * {@link Element}.
  4. */
  5. public static Context forElement(Element element) {
  6. return new Context("%s", element.getSource());
  7. }

代码示例来源:origin: com.google.inject/guice

  1. private static Module extractScanners(Iterable<Element> elements) {
  2. final List<ModuleAnnotatedMethodScannerBinding> scanners = Lists.newArrayList();
  3. ElementVisitor<Void> visitor =
  4. new DefaultElementVisitor<Void>() {
  5. @Override
  6. public Void visit(ModuleAnnotatedMethodScannerBinding binding) {
  7. scanners.add(binding);
  8. return null;
  9. }
  10. };
  11. for (Element element : elements) {
  12. element.acceptVisitor(visitor);
  13. }
  14. return new AbstractModule() {
  15. @Override
  16. protected void configure() {
  17. for (ModuleAnnotatedMethodScannerBinding scanner : scanners) {
  18. scanner.applyTo(binder());
  19. }
  20. }
  21. };
  22. }
  23. }

代码示例来源:origin: com.google/inject

  1. public void process(InjectorImpl injector, List<Element> elements) {
  2. Errors errorsAnyElement = this.errors;
  3. this.injector = injector;
  4. try {
  5. for (Iterator<Element> i = elements.iterator(); i.hasNext(); ) {
  6. Element element = i.next();
  7. this.errors = errorsAnyElement.withSource(element.getSource());
  8. Boolean allDone = element.acceptVisitor(this);
  9. if (allDone) {
  10. i.remove();
  11. }
  12. }
  13. } finally {
  14. this.errors = errorsAnyElement;
  15. this.injector = null;
  16. }
  17. }

代码示例来源:origin: com.google.inject/guice

  1. @Override
  2. protected Void visitOther(Element element) {
  3. element.applyTo(binder);
  4. return null;
  5. }

代码示例来源:origin: com.netflix.governator/governator-core

  1. @Override
  2. protected String visitOther(Element element) {
  3. Object source = element.getSource();
  4. ElementSource elementSource = null;
  5. while (source instanceof ElementSource) {
  6. elementSource = (ElementSource)source;
  7. source = elementSource.getOriginalElementSource();
  8. }
  9. if (elementSource != null) {
  10. return elementSource.getModuleClassNames().toString();
  11. }
  12. return null;
  13. }
  14. }

代码示例来源:origin: org.sonatype.sisu/sisu-guice

  1. void writeAll(Iterable<? extends Element> elements) {
  2. for (Element element : elements) {
  3. element.acceptVisitor(this);
  4. }
  5. }
  6. }

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.inject

  1. public void process(InjectorImpl injector, List<Element> elements) {
  2. Errors errorsAnyElement = this.errors;
  3. this.injector = injector;
  4. try {
  5. for (Iterator<Element> i = elements.iterator(); i.hasNext(); ) {
  6. Element element = i.next();
  7. this.errors = errorsAnyElement.withSource(element.getSource());
  8. Boolean allDone = element.acceptVisitor(this);
  9. if (allDone) {
  10. i.remove();
  11. }
  12. }
  13. } finally {
  14. this.errors = errorsAnyElement;
  15. this.injector = null;
  16. }
  17. }

代码示例来源:origin: com.google.inject/guice

  1. @Override
  2. public void applyTo(Binder binder) {
  3. PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();
  4. for (Element element : getElements()) {
  5. element.applyTo(privateBinder);
  6. }
  7. getExposedKeys(); // ensure exposedKeysToSources is populated
  8. for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
  9. privateBinder.withSource(entry.getValue()).expose(entry.getKey());
  10. }
  11. }

代码示例来源:origin: io.github.gwtplus.gin/gin

  1. protected Void visitOther(Element element) {
  2. visit(new Message(element.getSource(), "Ignoring unsupported Module element: " + element));
  3. return null;
  4. }

代码示例来源:origin: ArcBees/Jukito

  1. private void visitElements(List<Element> elements) {
  2. for (Element element : elements) {
  3. element.acceptVisitor(this);
  4. }
  5. }

代码示例来源:origin: Nextdoor/bender

  1. public void process(InjectorImpl injector, List<Element> elements) {
  2. Errors errorsAnyElement = this.errors;
  3. this.injector = injector;
  4. try {
  5. for (Iterator<Element> i = elements.iterator(); i.hasNext(); ) {
  6. Element element = i.next();
  7. this.errors = errorsAnyElement.withSource(element.getSource());
  8. Boolean allDone = element.acceptVisitor(this);
  9. if (allDone) {
  10. i.remove();
  11. }
  12. }
  13. } finally {
  14. this.errors = errorsAnyElement;
  15. this.injector = null;
  16. }
  17. }

代码示例来源:origin: com.google.inject/guice

  1. void rewrite(Binder binder, PrivateElements privateElements, Set<Key<?>> keysToSkip) {
  2. PrivateBinder privateBinder =
  3. binder.withSource(privateElements.getSource()).newPrivateBinder();
  4. Set<Key<?>> skippedExposes = Sets.newHashSet();
  5. for (Key<?> key : privateElements.getExposedKeys()) {
  6. if (keysToSkip.remove(key)) {
  7. skippedExposes.add(key);
  8. } else {
  9. privateBinder.withSource(privateElements.getExposedSource(key)).expose(key);
  10. }
  11. }
  12. for (Element element : privateElements.getElements()) {
  13. if (element instanceof Binding && skippedExposes.remove(((Binding) element).getKey())) {
  14. continue;
  15. }
  16. if (element instanceof PrivateElements) {
  17. rewrite(privateBinder, (PrivateElements) element, skippedExposes);
  18. continue;
  19. }
  20. element.applyTo(privateBinder);
  21. }
  22. }

代码示例来源:origin: org.atteo.moonshine/container

  1. private <T> void bindKey(Key<T> key) {
  2. Key<T> sourceKey;
  3. Class<? extends Annotation> annotation = dependency.getAnnotation();
  4. if (annotation == ImportService.NoAnnotation.class) {
  5. sourceKey = Key.get(key.getTypeLiteral());
  6. } else {
  7. sourceKey = Key.get(key.getTypeLiteral(), annotation);
  8. }
  9. if (!sourceKey.equals(key)) {
  10. binder.withSource(element.getSource()).bind(sourceKey).to(key);
  11. }
  12. }

代码示例来源:origin: org.jukito/jukito

  1. private void visitElements(List<Element> elements) {
  2. for (Element element : elements) {
  3. element.acceptVisitor(this);
  4. }
  5. }

代码示例来源:origin: org.sonatype.sisu/sisu-guice

  1. public void process(InjectorImpl injector, List<Element> elements) {
  2. Errors errorsAnyElement = this.errors;
  3. this.injector = injector;
  4. try {
  5. for (Iterator<Element> i = elements.iterator(); i.hasNext(); ) {
  6. Element element = i.next();
  7. this.errors = errorsAnyElement.withSource(element.getSource());
  8. Boolean allDone = element.acceptVisitor(this);
  9. if (allDone) {
  10. i.remove();
  11. }
  12. }
  13. } finally {
  14. this.errors = errorsAnyElement;
  15. this.injector = null;
  16. }
  17. }

相关文章