private MethodBuilderAbstractOption<ClassStructureBuilderAbstractMethodOption> genMethod(final Scope scope, final MetaClass returnType, final String name, final DefParameters defParameters) { return new MethodBuilderAbstractOption<ClassStructureBuilderAbstractMethodOption>( new MethodBuildCallback<ClassStructureBuilderAbstractMethodOption>() { @Override public ClassStructureBuilderAbstractMethodOption callback(final BlockStatement statement, final DefParameters parameters, final DefModifiers modifiers, final ThrowsDeclaration throwsDeclaration, final List<Annotation> annotations, final String comment) { final BuildMetaMethod buildMetaMethod = new BuildMetaMethod(classDefinition, statement, scope, modifiers, name, returnType, defParameters, throwsDeclaration); if (annotations != null) { buildMetaMethod.addAnnotations(annotations); } buildMetaMethod.setMethodComment(comment); classDefinition.addMethod(buildMetaMethod); return ClassBuilderAbstractMethodOption.this; } }); } }
@SuppressWarnings("unchecked") @Test public void testDefineAbstractClassWithAbstractMethods2() { final String cls = ClassBuilder .define("org.foo.Foo") .publicScope() .abstractClass() .body() .publicConstructor() .finish() .publicAbstractMethod(MetaClassFactory.get(String.class), "someString").finish() .publicAbstractMethod(Integer.class, "someInteger", Parameter.finalOf(long.class, "aLong")).finish() .publicAbstractMethod(void.class, "foo", String.class, Integer.class).throws_(Throwable.class) .protectedAbstractMethod(void.class, "bar", Long.class, Double.class).throws_(UnsupportedOperationException.class) .protectedAbstractMethod(Long.class, "funTimes", Parameter.finalOf(String.class, "str")).finish() .packageAbstractMethod(void.class, "foobaz", Map.class) .throws_(MetaClassFactory.get(ClassNotFoundException.class)) .packageAbstractMethod(Float.class, "boringTimes", Parameter.of(byte[].class, "byteArr")).finish() .publicMethod(void.class, "baz") .finish() .toJavaString(); assertEquals(ABSTRACT_CLASS_WITH_ABSTRACT_METHODS_2, cls); }
@Test public void testDefineAbstractClassWithAbstractMethods() { final String cls = ClassBuilder .define("org.foo.Foo") .publicScope() .abstractClass() .body() .publicConstructor() .finish() .publicAbstractMethod(void.class, "foo") .finish() .protectedAbstractMethod(void.class, "bar") .finish() .publicMethod(void.class, "baz") .finish() .toJavaString(); assertEquals("failed to generate abstract class with abstract method", ABSTRACT_CLASS_WITH_ABSTRACT_METHODS, cls); }
private MethodBuilderAbstractOption<ClassStructureBuilderAbstractMethodOption> genMethod(final Scope scope, final MetaClass returnType, final String name, final DefParameters defParameters) { return new MethodBuilderAbstractOption<ClassStructureBuilderAbstractMethodOption>( new MethodBuildCallback<ClassStructureBuilderAbstractMethodOption>() { @Override public ClassStructureBuilderAbstractMethodOption callback(final BlockStatement statement, final DefParameters parameters, final DefModifiers modifiers, final ThrowsDeclaration throwsDeclaration, final List<Annotation> annotations, final String comment) { final BuildMetaMethod buildMetaMethod = new BuildMetaMethod(classDefinition, statement, scope, modifiers, name, returnType, defParameters, throwsDeclaration); if (annotations != null) { buildMetaMethod.addAnnotations(annotations); } buildMetaMethod.setMethodComment(comment); classDefinition.addMethod(buildMetaMethod); return ClassBuilderAbstractMethodOption.this; } }); } }