Skip to content

Commit ae8c8e8

Browse files
committed
doc updates
1 parent 3e984b6 commit ae8c8e8

5 files changed

Lines changed: 116 additions & 31 deletions

File tree

Documentation.java

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -470,54 +470,116 @@ public enum TestEnum {
470470
/**
471471
* ## Annotations
472472
*
473-
* Yes, you can!
473+
* Starting in version 0.6 it is possible to describe a
474+
* descriptor based on a given interface or class, in addition
475+
* to the existing fluent builder. This method essentially replaces
476+
* the generated helpers with helpers that you provide, using
477+
* annotations to describe the intended flow of execution
478+
* through your methods.
474479
*/
480+
@Block(name="CustomizedName")
481+
public interface MyHelper {
475482

483+
@AtLeast(2)
484+
void doSomething();
476485

477-
// marks the method as occurring any number of times
478-
@Any
486+
@Between(minInc=1, maxInc=2)
487+
void doSomethingElse();
479488

480-
// marks the method as occurring any tim
481-
// copy these from the stuff above
482-
@Any(int group)
489+
@Last
490+
@Documented("the last method you'll ever need")
491+
String end();
483492

484-
//
485-
@AtLeast(int value)
486-
void x()
493+
void skipped();
494+
}
495+
496+
Descriptor descriptor = Flapi.create(MyHelper.class).build();
497+
498+
// Create a new descriptor by introspecting the class,
499+
// first for Flapi annotations, and then as a generic bean.
500+
Descriptor descriptor = Flapi.create(Class class)
487501

502+
// Specifies that the method can be called at most _x_ times.
503+
// After that amount, the method will no longer be available
504+
// to be called.
488505
@AtMost(int value)
489506

507+
// Members of the same group will become invisible
508+
// as soon as this method does so.
490509
@AtMost(int value, int group)
491510

511+
// The method must be called at least _x_ times.
512+
@AtLeast(int value)
513+
514+
// The method must be called between _x_ and _y_ times.
492515
@Between(int minin, int maxInc)
493516

517+
// The method must be called exactly _x_ times.
494518
@Exactly(int value)
495519

520+
// The method can be called any number of times.
521+
@Any()
496522

523+
// Members of the same group will become invisible
524+
// after this method is called for the first time.
525+
@Any(int group)
497526

498-
// marks the method as last
499-
@Last
500-
501-
// last with return value
527+
// The method can be called once, and will return
528+
// the method's return type after being called.
529+
@Last()
502530

531+
// The method will only become visible after at
532+
// least one member of the group has been called.
503533
@After(int group)
504534

535+
// Provide documentation for the method.
536+
@Documented(String[] value)
537+
538+
// Provide an alternate name to use for the interface
539+
// or class's corresponding generated name, instead of
540+
// the default (`XyzBuilder`).
541+
@Block(String name)
542+
543+
544+
/**
545+
* ### @BlockChain Parameters
546+
*
547+
* A method may specify a block chain by annotating any number
548+
* of parameters with `@BlockChain`. The parameter **must** be of
549+
* type `AtomicReference`, and the annotation must include the
550+
* type of the block, matching the generic signature of the reference.
551+
*
552+
* The helper will be introspected like the current type, and the
553+
* chain will be constructed moving from the leftmost parameter
554+
* towards the rightmost.
555+
*/
556+
interface Alpha {
505557

506-
// mark a method parameter as a container for another block
507-
// helper. The chain is constructed by looking at the last parameters
508-
// marked with the chain info. In the current implementation, the
509-
// parameters **must** be placed as the last parameters to the method.
510-
//
558+
@Last
559+
void alpha();
560+
}
561+
562+
interface Beta {
563+
564+
@Last
565+
void beta();
566+
}
567+
568+
interface MyHelper {
569+
570+
@Last
571+
String startBlock(
572+
int paramA, @BlockChain(Alpha.class) AtomicReference<Alpha> helperA,
573+
int paramB, @BlockChain(Beta.class) AtomicReference<Beta> helperB
574+
);
575+
}
576+
577+
// Marks a method parameter as a container for another block's helper.
511578
// The types must match the generic signature of the `AtomicReference` object,
512579
// or else an error will be thrown at runtime.
513-
@BlockChain(Class<?>[] types)
580+
@BlockChain(Class<?> type)
514581

515-
// provide documentation for the method
516-
@Documented(String[] value)
517582

518-
// create a new descriptor by introspecting the class,
519-
// first for Flapi annotations, and then as a generic bean
520-
Descriptor descriptor = Flapi.create(Class class)
521583

522584

523585

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ Descriptor builder = Flapi.builder()
2424
```
2525
##### ...or this:
2626
```java
27-
annotation example
27+
interface EmailHelper {
28+
29+
@AtMost(1) void subject(String subject);
30+
@AtLeast(1) void addRecipient(String emailAddress);
31+
@Exactly(1) void sender(String emailAddress);
32+
@Any void addCC(String emailAddress);
33+
@Any void addBCC(String emailAddress);
34+
@AtMost(1) void body(String text);
35+
@Any void addAttachment(File file);
36+
@Last EmailMessage send();
37+
}
38+
39+
Flapi.create(EmailHelper.class)
40+
.setPackage("unquietcode.tools.flapi.examples.email.builder")
41+
.setStartingMethodName("compose")
42+
.build();
2843
```
2944

3045
##### ...into this:
@@ -54,7 +69,7 @@ repository and dependency in your POM file:
5469
<dependency>
5570
<groupId>unquietcode.tools.flapi</groupId>
5671
<artifactId>flapi</artifactId>
57-
<version>0.5.2</version>
72+
<version>0.6</version>
5873
<scope>test</scope>
5974
</dependency>
6075
```
@@ -86,10 +101,7 @@ The original blog post describing Flapi.
86101
Google Group for asking questions and connecting with other developers using Flapi in their projects.
87102

88103
### What's the project's status?
89-
Version 0.5 has been released, and includes a few new features and bug fixes.
90-
See the [Release Notes](https://github.com/UnquietCode/Flapi/wiki/Version-0.5) for the full details.
91-
92-
The latest patch version is `0.5.2`.
104+
Version 0.6 has been released, and includes support for creating descriptors using annotations. See the [Release Notes](https://github.com/UnquietCode/Flapi/wiki/Version-0.6) for the full details.
93105

94106
### Problems?
95107
Use the [issue tracker](https://github.com/UnquietCode/Flapi/issues) to report problems encountered or new

VERSION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ of descriptors.
55
### Annotations
66
You can now create descriptors from annotated helper classes and interfaces. See the documentation section on [annotations]() for more details.
77

8+
### Bean Builders
9+
Similar to annotations, you can provide a class with `setXYZ(..)` and `withXYZ(..)` methods, and these will be turned into a simple builder where each method can only be called at most one time, and where a bean will be returned at the end of the chain.
10+
811
## Resolved Issues
912
Issues are now handled through GitHub, and historical issues have been migrated from JIRA.
1013

src/test/java/unquietcode/tools/flapi/examples/email/EmailBuilderExample.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public Descriptor descriptor() {
3939
.build();
4040
}
4141

42+
@Test
43+
public void annot() {
44+
Flapi.create(AnnotatedEmailHelper.class)
45+
.setPackage("unquietcode.tools.flapi.examples.email.builder")
46+
.setStartingMethodName("compose")
47+
.build();
48+
}
49+
4250
@Test
4351
public void usage() {
4452
EmailMessage message = EmailGenerator.compose(new EmailHelperImpl())

src/test/java/unquietcode/tools/flapi/examples/email/EmailHelperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @author Ben Fagin
1616
* @version 04-29-2012
1717
*/
18-
public class EmailHelperImpl implements EmailHelper {
18+
public class EmailHelperImpl implements EmailHelper, AnnotatedEmailHelper {
1919
private final EmailMessage email;
2020

2121
public EmailHelperImpl() {

0 commit comments

Comments
 (0)