public BuildMetaClass(Context context, String name) { super(null); this.className = name; this.context = Context.create(context); this.context.addVariable(Variable.create("this", this)); context.attachClass(this); }
/** * Tests that it is safe to call ensureMemberExposed() on any type of InjectionPoint. (This was an * actual bug that was not caught by the existing integration tests). */ public void testEnsureMemberExposedWithConstructorInjectionPoint() throws Exception { final ClassStructureBuilder<? extends ClassStructureBuilder<?>> structureBuilder = ClassBuilder.define("my.FakeBootstrapper").publicScope().body(); IOCProcessingContext processingContext = IOCProcessingContext.Builder.create() .logger( new TreeLogger() { @Override public TreeLogger branch( Type type, String msg, Throwable caught, HelpInfo helpInfo) { return null; } @Override public boolean isLoggable(Type type) { return false; } @Override public void log(Type type, String msg, Throwable caught, HelpInfo helpInfo) { System.out.println(type.getLabel() + ": " + msg); if (caught != null) { caught.printStackTrace(); } } }) .sourceWriter(new StringSourceWriter()) .context(Context.create()) .bootstrapClassInstance(structureBuilder.getClassDefinition()) .bootstrapBuilder(structureBuilder) .blockBuilder(Stmt.do_()) .packages(Collections.singleton(ConstructorInjectedBean.class.getPackage().getName())) .build(); InjectionContext ctx = InjectionContext.Builder.create().processingContext(processingContext).build(); MetaConstructor constructor = MetaClassFactory.get(ConstructorInjectedBean.class).getConstructor(FooService.class); InjectionPoint<Inject> injectionPoint = new InjectionPoint<Inject>( new Inject() { @Override public Class<? extends Annotation> annotationType() { return Inject.class; } }, TaskType.Parameter, constructor, null, null, null, constructor.getParameters()[0], null, ctx); // holy crap that was a lot of setup. Here comes the actual test: injectionPoint.ensureMemberExposed(); }
public static void assertIsIterable(final Statement statement) { final Class<?> cls = statement.getType().asClass(); if (!cls.isArray() && !Iterable.class.isAssignableFrom(cls)) throw new TypeNotIterableException(statement.generate(Context.create())); }