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<?> 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<? 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())); } }
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())); } }
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()); } }; }
@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); } });