private Class<?> assertIsPage(final InjectionSite injectionSite) { final Class<?> candidate = injectionSite.getAnnotation(TransitionTo.class).value(); if (!candidate.isAnnotationPresent(Page.class)) { throw new IllegalArgumentException(String.format("They type %s is not a valid value for @%s. A @%s is required.", candidate.getName(), TransitionTo.class.getSimpleName(), Page.class.getSimpleName())); } else { return candidate; } }
private Class<?> assertTargetType(final InjectionSite injectionSite, final InjectionContext injectionContext) { if (injectionSite.isAnnotationPresent(TransitionTo.class)) { return assertIsPage(injectionSite); } else if (injectionSite.isAnnotationPresent(TransitionToRole.class)) { return assertRoleExistsAndIsValid(injectionSite, injectionContext); } else { throw new IllegalStateException( String.format("This extension provider should only be called for anchors with %s or %s.", TransitionTo.class.getSimpleName(), TransitionToRole.class.getSimpleName())); } }
/** * @return A unique name for this injection site. */ public String getUniqueName() { return enclosingType.getName() + "_" + annotatedName(); }
@Override public CustomFactoryInjectable getInjectable(final InjectionSite injectionSite, final FactoryNameGenerator nameGenerator) { final String loggerName; if (injectionSite.isAnnotationPresent(NamedLogger.class)) { loggerName = injectionSite.getAnnotation(NamedLogger.class).value(); } else { loggerName = injectionSite.getEnclosingType().getFullyQualifiedName(); } if (!injectablesByLoggerName.containsKey(loggerName)) { final Statement loggerValue = invokeStatic(LoggerFactory.class, "getLogger", loggerName); final FactoryBodyGenerator generator = new AbstractBodyGenerator() { @Override protected List<Statement> generateCreateInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { return Collections.singletonList(Stmt.nestedCall(loggerValue).returnValue()); } }; final MetaClass type = MetaClassFactory.get(Logger.class); final Qualifier qualifier = injectionContext.getQualifierFactory().forUniversallyQualified(); injectablesByLoggerName.put(loggerName, new DefaultCustomFactoryInjectable(type, qualifier, nameGenerator.generateFor(type, qualifier, InjectableType.ExtensionProvided), Dependent.class, Collections.singletonList(WiringElementType.DependentBean), generator)); } return injectablesByLoggerName.get(loggerName); } });
private Injectable maybeProcessAsExtension(final BaseDependency dep, final Injectable depOwner, final Map<String, Injectable> customProvidedInjectables, final Multimap<ResolutionPriority, InjectableImpl> resolvedByPriority, final Collection<InjectableImpl> resolved) { Injectable injectable = resolved.iterator().next(); if (injectable.isExtension()) { final ExtensionInjectable providedInjectable = (ExtensionInjectable) injectable; final Collection<Injectable> otherResolvedInjectables = new ArrayList<>(resolvedByPriority.values()); otherResolvedInjectables.remove(injectable); final InjectionSite site = new InjectionSite(depOwner.getInjectedType(), dep, otherResolvedInjectables); injectable = providedInjectable.provider.getInjectable(site, nameGenerator); customProvidedInjectables.put(injectable.getFactoryName(), injectable); dep.injectable = GraphUtil.copyInjectableReference(dep.injectable); } return injectable; }
private Class<?> assertIsPage(final InjectionSite injectionSite) { final Class<?> candidate = injectionSite.getAnnotation(TransitionTo.class).value(); if (!candidate.isAnnotationPresent(Page.class)) { throw new IllegalArgumentException(String.format("They type %s is not a valid value for @%s. A @%s is required.", candidate.getName(), TransitionTo.class.getSimpleName(), Page.class.getSimpleName())); } else { return candidate; } }
private Class<?> assertTargetType(final InjectionSite injectionSite, final InjectionContext injectionContext) { if (injectionSite.isAnnotationPresent(TransitionTo.class)) { return assertIsPage(injectionSite); } else if (injectionSite.isAnnotationPresent(TransitionToRole.class)) { return assertRoleExistsAndIsValid(injectionSite, injectionContext); } else { throw new IllegalStateException( String.format("This extension provider should only be called for anchors with %s or %s.", TransitionTo.class.getSimpleName(), TransitionToRole.class.getSimpleName())); } }
private Class<? extends UniquePageRole> assertRoleExistsAndIsValid(final InjectionSite injectionSite, final InjectionContext injectionContext) { final Class<? extends UniquePageRole> candidateRole = injectionSite.getAnnotation(TransitionToRole.class).value(); if (pagesByRole.get(candidateRole).size() == 1) { return candidateRole; } else if (pagesByRole.get(candidateRole).isEmpty()) { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but no @%s exists with that role.", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName())); } else { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but multiple @%ss pages exist with that role: %s", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName(), pagesByRole.get(candidateRole).toString())); } }
@Override public CustomFactoryInjectable getInjectable(final InjectionSite injectionSite, final FactoryNameGenerator nameGenerator) { if (injectionSite.isAnnotationPresent(Model.class)) { if (provided == null) { final FactoryBodyGenerator generator = new AbstractBodyGenerator() {
private Class<? extends UniquePageRole> assertRoleExistsAndIsValid(final InjectionSite injectionSite, final InjectionContext injectionContext) { final Class<? extends UniquePageRole> candidateRole = injectionSite.getAnnotation(TransitionToRole.class).value(); if (pagesByRole.get(candidateRole).size() == 1) { return candidateRole; } else if (pagesByRole.get(candidateRole).isEmpty()) { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but no @%s exists with that role.", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName())); } else { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but multiple @%ss pages exist with that role: %s", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName(), pagesByRole.get(candidateRole).toString())); } }
@Override public CustomFactoryInjectable getInjectable(final InjectionSite injectionSite, final FactoryNameGenerator nameGenerator) { if (injectionSite.isAnnotationPresent(Model.class)) { if (provided == null) { final FactoryBodyGenerator generator = new AbstractBodyGenerator() {
private FactoryBodyGenerator getGenerator(final InjectionSite injectionSite) { final AnnoWithNonBindingAttribute anno = injectionSite.getAnnotation(AnnoWithNonBindingAttribute.class); final String value = anno.value(); return new AbstractBodyGenerator() { @Override protected List<Statement> generateCreateInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { return Arrays.asList(Stmt.loadLiteral(value).returnValue()); } }; }