Skip to content

Commit 9ef1b74

Browse files
committed
Merge branch 'master', future 0.7.
2 parents e956f50 + 34d900e commit 9ef1b74

128 files changed

Lines changed: 1487 additions & 361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTORS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following individuals and organizations have given their time and energy to help
22
with the creation and maintenance of Flapi.
33

4-
* Jiri Jetmar - FLAPI-126
5-
* Chris Wensel ([@cwensel](https://github.com/cwensel)) - [#5, #8, FLAPI-114]
4+
* Jiri Jetmar - [#159]
5+
* Chris Wensel ([@cwensel](https://github.com/cwensel)) - [#5, #8, #12, #197]

Documentation.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,27 @@
107107
.setReturnType(String class)
108108

109109
// Generate class names which are condensed at the expense of
110-
// being mangled and not as readable by a human. This is
110+
// being mangled and not as readable by humans. This is
111111
// useful if you have a complicated descriptor which creates
112-
// class names too long to be compiled. (optional, disabled by default)
112+
// class names too long to be compiled. (disabled by default)
113113
.enableCondensedClassNames()
114114

115+
// Provide a custom name generator instance, to be consulted
116+
// when creating the generated source code.
117+
//
118+
// The `DefaultNameGenerator` implementation will leave names
119+
// as they are. A more compact form can be achieved by using
120+
// the `TinyNameGenerator`, which will try to shorten names
121+
// as much as possible. For more consistent naming the
122+
// `HashedNameGenerator` can be used, which makes use of the
123+
// MD5 hashing algorithm.
124+
.useCustomNameGenerator(NameGenerator generator)
125+
126+
// Disable the printing of timestamps in the generated source
127+
// code. This will eliminate changes between successive executions
128+
// so long as the same version of the tool is used each time.
129+
.disableTimestamps()
130+
115131
// Complete the finished descriptor, returning a new
116132
// `Descriptor` object. (**required**)
117133
.build()
@@ -546,8 +562,7 @@ public interface MyHelper {
546562
*
547563
* A method may specify a block chain by annotating any number
548564
* 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.
565+
* type `AtomicReference`.
551566
*
552567
* The helper will be introspected like the current type, and the
553568
* chain will be constructed moving from the leftmost parameter
@@ -569,15 +584,14 @@ interface MyHelper {
569584

570585
@Last
571586
String startBlock(
572-
int paramA, @BlockChain(Alpha.class) AtomicReference<Alpha> helperA,
573-
int paramB, @BlockChain(Beta.class) AtomicReference<Beta> helperB
587+
int paramA, @BlockChain AtomicReference<Alpha> helperA,
588+
int paramB, @BlockChain AtomicReference<Beta> helperB
574589
);
575590
}
576591

577592
// Marks a method parameter as a container for another block's helper.
578-
// The types must match the generic signature of the `AtomicReference` object,
579-
// or else an error will be thrown at runtime.
580-
@BlockChain(Class<?> type)
593+
// The parameter **must** be of type `AtomicReference`.
594+
@BlockChain
581595

582596

583597

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ composeEmail()
5656

5757
### [Getting Started](https://github.com/UnquietCode/Flapi/wiki/Getting-Started)
5858
If you are using Maven (or Gradle, or Ivy) you can download and install to your local repo, or include the following
59-
repository and dependency in your POM file:
60-
```
59+
repository and dependency in your build script:
60+
61+
#### Maven
62+
```xml
6163
<repository>
6264
<id>uqc</id>
6365
<name>UnquietCode Repository</name>
@@ -73,13 +75,31 @@ repository and dependency in your POM file:
7375
<scope>test</scope>
7476
</dependency>
7577
```
76-
In a test, define your `Descriptor` object and output the generated source code. (The
78+
79+
#### Gradle
80+
```groovy
81+
repositories {
82+
maven {
83+
url 'http://www.unquietcode.com/maven/releases'
84+
}
85+
}
86+
87+
...
88+
89+
dependencies {
90+
testCompile 'unquietcode.tools.flapi:flapi:0.6.1'
91+
}
92+
```
93+
94+
In a test define your `Descriptor` object and output the generated source code. (The
7795
[Pizza Builder](https://github.com/UnquietCode/Flapi/wiki/Pizza-Builder-Example)
7896
example is a simple descriptor you can start with.) You can also make use of the
7997
[maven plugin](https://github.com/UnquietCode/Flapi/wiki/Maven-Build-Plugin) to
8098
perform the code generation.
8199

82-
At the time of writing, the project builds fine in JDK 6 and 7. However, please note that the automated builds are no longer being run against JDK 6.
100+
At the time of writing, the project builds fine in JDK 6 and 7. However, please note that
101+
the automated builds are no longer being run against JDK 6.
102+
83103

84104
### Additional Resources
85105

flapi-build-project/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<plugin>
126126
<groupId>org.codehaus.mojo</groupId>
127127
<artifactId>build-helper-maven-plugin</artifactId>
128-
<version>1.7</version>
128+
<version>1.9.1</version>
129129
<executions>
130130
<execution>
131131
<id>add-sources</id>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*********************************************************************
2+
Copyright 2015 the Flapi authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
********************************************************************/
16+
17+
package unquietcode.tools.flapi;
18+
19+
/**
20+
* Simple little ditty to provide things.
21+
*
22+
* This is meant to be replaced by the real type
23+
* contained within Java 8, whenever JDK 7 support
24+
* is discontinued.
25+
*
26+
* TODO delete after propagation
27+
*
28+
* @author Ben Fagin
29+
* @version 2015-01-16
30+
*/
31+
public interface Supplier<T> {
32+
T get();
33+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*********************************************************************
2+
Copyright 2015 the Flapi authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
********************************************************************/
16+
17+
package unquietcode.tools.flapi.generator.naming;
18+
19+
/**
20+
* Interface which defines a contract for managing the
21+
* generated names of the various state classes.
22+
*
23+
* TODO delete after propagation
24+
*
25+
* @author Ben Fagin
26+
* @version 2015-01-14
27+
*/
28+
public interface NameGenerator {
29+
30+
/**
31+
* Using the provided method name, return a
32+
* suitable string to use as a replacement.
33+
*
34+
* This name is incorporated into the complete class
35+
* name, which can then be further altered.
36+
*
37+
* @param methodKey the unique method key
38+
* @return a new method name, or the same, but not null
39+
*/
40+
String methodName(String methodKey);
41+
42+
/**
43+
* Using the provided state name, return a
44+
* suitable string to use as a replacement.
45+
*
46+
* @param stateKey the unique state key
47+
* @return a new state name, or the same, but not null
48+
*/
49+
String className(String stateKey);
50+
51+
52+
// *Generator
53+
String generatorName(String stateName);
54+
55+
// *Factory
56+
String factoryName(String stateName);
57+
58+
// *Helper
59+
String helperName(String stateName);
60+
61+
// *Builder
62+
String builderName(String stateName);
63+
64+
// Start
65+
String wrapperName(String stateName);
66+
}

flapi-descriptor/src/test/java/unquietcode/tools/flapi/builder/DescriptorConfigurator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* @version 08-03-2014
1313
*/
1414
public class DescriptorConfigurator implements DescriptorMaker {
15+
private static final int NAME_GROUP = 3;
1516

1617
@Override
1718
public Descriptor descriptor() {
18-
1919
Descriptor builder = Flapi.builder()
2020
.setPackage("unquietcode.tools.flapi.configurator")
2121
.setDescriptorName("DescriptorConfigurator")
@@ -37,6 +37,20 @@ public Descriptor descriptor() {
3737
.addContent("humanly readable. If your generated class names are too long to be\n")
3838
.addContent("compiled, you will have to use this.")
3939
.finish()
40+
.atMost(1, NAME_GROUP)
41+
42+
.addMethod("useCustomNameGenerator(unquietcode.tools.flapi.generator.naming.NameGenerator generator)")
43+
.withDocumentation()
44+
.addContent("Provide a custom NameGenerator.")
45+
.finish()
46+
.atMost(1, NAME_GROUP)
47+
48+
.addMethod("disableTimestamps()")
49+
.withDocumentation()
50+
.addContent("Disable the use of timestamps in the generated source code.\n")
51+
.addContent("This will eliminate changes between successive executions so long\n")
52+
.addContent("as the same version of the tool is used each time.")
53+
.finish()
4054
.atMost(1)
4155

4256
.addMethod("build()").last(Descriptor.class)

flapi-descriptor/src/test/java/unquietcode/tools/flapi/builder/MainDescriptor.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class MainDescriptor implements DescriptorMaker {
1414
private static final int DOC_GROUP = 1;
1515
private static final int RETURN_TYPE_GROUP = 2;
16+
private static final int NAME_GROUP = 3;
1617

1718
@Override
1819
public Descriptor descriptor() {
@@ -25,37 +26,53 @@ public Descriptor descriptor() {
2526
.enableCondensedClassNames()
2627

2728
// descriptor methods
29+
2830
.addMethod("setPackage(String packageName)")
2931
.withDocumentation("set the root package name to use for the generated classes")
30-
.exactly(1)
31-
32-
.addMethod("setDescriptorName(String descriptorName)")
33-
.withDocumentation("set the name of the top level descriptor")
34-
.exactly(1)
32+
.atMost(1)
3533

3634
.addMethod("setStartingMethodName(String methodName)")
3735
.withDocumentation("set the name of the generator's starting method (default is 'create')")
3836
.atMost(1)
3937

40-
.addMethod("setReturnType(Class returnType)")
41-
.withDocumentation("set the return type for the top level descriptor (default is void)")
42-
.atMost(1, RETURN_TYPE_GROUP)
43-
44-
.addMethod("setReturnType(String returnType)")
45-
.withDocumentation("set the return type for the top level descriptor (default is void)")
46-
.atMost(1, RETURN_TYPE_GROUP)
47-
4838
.addMethod("enableCondensedClassNames()")
4939
.withDocumentation()
5040
.addContent("Allow class names to be condensed, at the cost of no longer being\n")
5141
.addContent("humanly readable. If your generated class names are too long to be\n")
5242
.addContent("compiled, you will have to use this.")
5343
.finish()
44+
.atMost(1, NAME_GROUP)
45+
46+
.addMethod("useCustomNameGenerator(unquietcode.tools.flapi.generator.naming.NameGenerator generator)")
47+
.withDocumentation()
48+
.addContent("Provide a custom NameGenerator.")
49+
.finish()
50+
.atMost(1, NAME_GROUP)
51+
52+
.addMethod("disableTimestamps()")
53+
.withDocumentation()
54+
.addContent("Disable the use of timestamps in the generated source code.\n")
55+
.addContent("This will eliminate changes between successive executions so long\n")
56+
.addContent("as the same version of the tool is used each time.")
57+
.finish()
5458
.atMost(1)
5559

56-
.addMethod("build()")
57-
.withDocumentation("Finish work and build the descriptor. This should only be called once.")
58-
.last(Descriptor.class)
60+
.addMethod("build()").last(Descriptor.class)
61+
62+
// descriptor methods
63+
64+
.addMethod("setDescriptorName(String descriptorName)")
65+
.withDocumentation("set the name of the top level descriptor")
66+
.exactly(1)
67+
68+
.addMethod("setReturnType(Class returnType)")
69+
.withDocumentation("set the return type for the top level descriptor (default is void)")
70+
.atMost(1, RETURN_TYPE_GROUP)
71+
72+
.addMethod("setReturnType(String returnType)")
73+
.withDocumentation("set the return type for the top level descriptor (default is void)")
74+
.atMost(1, RETURN_TYPE_GROUP)
75+
5976

6077
// Method
6178
.startBlock("Method", "addMethod(String methodSignature)")

flapi-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<plugin>
119119
<groupId>org.codehaus.mojo</groupId>
120120
<artifactId>build-helper-maven-plugin</artifactId>
121-
<version>1.7</version>
121+
<version>1.9.1</version>
122122
<executions>
123123
<execution>
124124
<phase>initialize</phase>

flapi-runtime/src/main/java/unquietcode/tools/flapi/runtime/BlockInvocationHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public final Object invoke(Object proxy, Method method, Object[] args) throws Th
8383

8484
// handles legacy concerns before the chainInfo() array existed by
8585
// synthesizing a new array from the older values
86+
@SuppressWarnings("deprecation")
8687
private Object invokeAndReturn(Method method, Object[] originalArgs, Object proxy, MethodInfo info) {
8788
final ChainInfo[] chain;
8889

@@ -105,7 +106,7 @@ private Object invokeAndReturn(Method method, Object[] originalArgs, Object prox
105106

106107
private Object invokeAndReturn(Method method, Object[] originalArgs, Object proxy, MethodInfo info, ChainInfo[] chain) {
107108
// Don't use info.chainInfo() directly, since they might not match due
108-
// to legacy considerations (will be removed in 1.0).
109+
// to legacy considerations (will be removed in 1.0). TODO remove in 1.0
109110

110111
final int depth = chain.length;
111112

0 commit comments

Comments
 (0)