Skip to content

Commit 3853350

Browse files
author
Emil Forslund
committed
Update to 2.3 of Speedment
1 parent 3e0d406 commit 3853350

File tree

186 files changed

+5623
-4113
lines changed

Some content is hidden

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

186 files changed

+5623
-4113
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
*
3+
* Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at:
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package com.speedment.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Marks a Method, Type or Constructor as an API. An API marked entity with a
26+
* certain API version will remain "Compatible" across new software releases
27+
* indefinitely , for that particular API version.
28+
* <p>
29+
* "Compatible" is defined as follows:
30+
* <p>
31+
* Method: Its signature (i.e. name and parameters), and return type will
32+
* remain.
33+
* <p>
34+
* Interface: Its name and all its declared methods with its return type and
35+
* signature and static fields will remain. New methods and static field might
36+
* be added.
37+
* <p>
38+
* Enum: Its elements will remain and their individual order will remain. New
39+
* elements might be added.
40+
*
41+
* @author pemi
42+
*/
43+
@Api(version = "2.3", snapshot = false)
44+
@Retention(value = RetentionPolicy.RUNTIME)
45+
@Target({ElementType.METHOD, ElementType.TYPE, ElementType.CONSTRUCTOR})
46+
public @interface Api {
47+
48+
/**
49+
* Returns the current API version.
50+
*
51+
* @return the current API version.
52+
*/
53+
String version();
54+
55+
/**
56+
* Returns if this API version is a snapshot, i.e. it is not yet "frozen"
57+
* and may change within the given API version.
58+
*
59+
* @return true if this API version is a snapshot, false otherwise.
60+
*/
61+
boolean snapshot() default false;
62+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Annotations used in generated code is located in this package.
3+
* <p>
4+
* This package is part of the API. Modifications to classes here should only
5+
* (if ever) be done in major releases.
6+
*/
7+
package com.speedment.annotation;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
*
3+
* Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at:
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package com.speedment.codegen;
18+
19+
import com.speedment.annotation.Api;
20+
import java.util.Optional;
21+
22+
/**
23+
* Keeps track of which dependencies have been imported and which is not
24+
* included. This is useful for solving the issue of when to write the full name
25+
* of a class and when to only include the short name.
26+
*
27+
* @author Emil Forslund
28+
* @since 2.0
29+
*/
30+
@Api(version = "2.3")
31+
public interface DependencyManager {
32+
33+
/**
34+
* Attempts to add the specified resource to the dependency list. If the
35+
* name is already taken it will return {@code false}.
36+
*
37+
* @param fullname the full name of the resource.
38+
* @return {@code true} if it was added, else <code>false</code>
39+
*/
40+
boolean load(String fullname);
41+
42+
/**
43+
* Returns <code>true</code> if the specified fullname is either:
44+
*
45+
* <pre>
46+
* (A) loaded into the dependency list;
47+
* (B) on the ignore list.
48+
* </pre>
49+
*
50+
* Else it returns <code>false</code>.
51+
*
52+
* @param fullname the full name of the resource.
53+
* @return {@code true} if it don't have to be loaded.
54+
*/
55+
boolean isLoaded(String fullname);
56+
57+
/**
58+
* Returns true if the specified class belongs to a package that is on the
59+
* ignore list.
60+
*
61+
* @param fullname the full name of a package or a class
62+
* @return {@code true} if it should be ignored as a dependency
63+
*/
64+
boolean isIgnored(String fullname);
65+
66+
/**
67+
* Clear all dependencies.
68+
*/
69+
void clearDependencies();
70+
71+
/**
72+
* Attempts to set the package that is currently being rendered. If a
73+
* package is already set, the operation will fail and {@code false} will be
74+
* returned. If the operation succeeded, {@code true} is returned and the
75+
* {@code DependencyManager} will expect
76+
* {@link #unsetCurrentPackage(java.lang.String)} to be called later before
77+
* the generation is finished.
78+
*
79+
* @param pack the new current package
80+
* @return {@code true} if the operation succeeded, else {@code false}
81+
*/
82+
boolean setCurrentPackage(String pack);
83+
84+
/**
85+
* Attempts to unset the currently rendered package. If the specified
86+
* package is the one that is currently being rendered, it will be unset and
87+
* {@code true} will be returned. If the package specified is not correct,
88+
* the current package will <b>not</b> be unset and {@code false} will be
89+
* returned. If no package was set the operation will throw an
90+
* {@link IllegalStateException}.
91+
*
92+
* @param pack the current package to unset
93+
* @return {@code true} if the operation succeeded, else {@code false}
94+
*/
95+
boolean unsetCurrentPackage(String pack);
96+
97+
/**
98+
* Returns the current package if one is set, or else {@code empty}.
99+
* @return the package
100+
*/
101+
Optional<String> getCurrentPackage();
102+
}

src/main/java/com/speedment/codegen/base/Generator.java renamed to src/main/java/com/speedment/codegen/Generator.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright (c) 2006-2015, Speedment, Inc. All Rights Reserved.
3+
* Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
66
* use this file except in compliance with the License. You may obtain a copy of
@@ -14,8 +14,9 @@
1414
* License for the specific language governing permissions and limitations under
1515
* the License.
1616
*/
17-
package com.speedment.codegen.base;
17+
package com.speedment.codegen;
1818

19+
import com.speedment.annotation.Api;
1920
import java.util.Collection;
2021
import java.util.Optional;
2122
import java.util.stream.Stream;
@@ -24,8 +25,10 @@
2425
* A hook to the generator that can be passed to various stages in the pipeline.
2526
* Contains multiple methods for generating model-to-model or model-to-text.
2627
*
27-
* @author Emil Forslund
28+
* @author Emil Forslund
29+
* @since 2.0
2830
*/
31+
@Api(version = "2.3")
2932
public interface Generator {
3033

3134
/**
@@ -112,7 +115,7 @@ default <M> Stream<Meta<M, String>> metaOn(M model) {
112115
* @see Meta
113116
*/
114117
default <A> Stream<Meta<A, String>> metaOn(Collection<A> models) {
115-
return models.stream().map(model -> metaOn(model)).flatMap(m -> m);
118+
return models.stream().map(this::metaOn).flatMap(m -> m);
116119
}
117120

118121
/**
@@ -171,7 +174,7 @@ default Optional<String> on(Object model) {
171174
}
172175
}
173176

174-
return metaOn(model).map(c -> c.getResult()).findAny();
177+
return metaOn(model).map(Meta::getResult).findAny();
175178
}
176179

177180
/**
@@ -182,7 +185,7 @@ default Optional<String> on(Object model) {
182185
* @return a stream of meta objects
183186
*/
184187
default <M> Stream<String> onEach(Collection<M> models) {
185-
return metaOn(models).map(c -> c.getResult());
188+
return metaOn(models).map(Meta::getResult);
186189
}
187190

188191
/**
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
*
3+
* Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at:
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package com.speedment.codegen;
18+
19+
import com.speedment.annotation.Api;
20+
21+
/**
22+
* Meta information about the generation process.
23+
*
24+
* @param <A> the model type
25+
* @param <B> the result type
26+
* @author Emil Forslund
27+
* @since 2.0
28+
*/
29+
@Api(version = "2.3")
30+
public interface Meta<A, B> {
31+
32+
/**
33+
* The model that was sent to the generator.
34+
* @return the model
35+
*/
36+
A getModel();
37+
38+
/**
39+
* The result that was produced by the generator.
40+
* @return the model
41+
*/
42+
B getResult();
43+
44+
/**
45+
* The transform that was used to produce the result.
46+
* @return the transform
47+
*/
48+
Transform<A, B> getTransform();
49+
50+
/**
51+
* The factory that created the transform.
52+
* @return the factory
53+
*/
54+
TransformFactory getFactory();
55+
56+
/**
57+
* The render stack that represents which generation processes is waiting
58+
* for this result.
59+
*
60+
* @return the current render stack
61+
*/
62+
RenderStack getRenderStack();
63+
64+
// /**
65+
// * Meta implementation.
66+
// *
67+
// * @param <A> the model type
68+
// * @param <B> the result type
69+
// */
70+
// class Impl<A, B> implements Meta<A, B> {
71+
//
72+
// private A model;
73+
// private B result;
74+
// private Transform<A, B> transform;
75+
// private TransformFactory factory;
76+
// private RenderStack stack;
77+
//
78+
// Impl() {}
79+
//
80+
// @Override
81+
// public B getResult() {
82+
// return result;
83+
// }
84+
//
85+
// protected Impl<A, B> setResult(B result) {
86+
// this.result = result;
87+
// return this;
88+
// }
89+
//
90+
// @Override
91+
// public Transform<A, B> getTransform() {
92+
// return transform;
93+
// }
94+
//
95+
// protected Impl<A, B> setTransform(Transform<A, B> view) {
96+
// this.transform = view;
97+
// return this;
98+
// }
99+
//
100+
// @Override
101+
// public TransformFactory getFactory() {
102+
// return factory;
103+
// }
104+
//
105+
// protected Impl<A, B> setFactory(TransformFactory factory) {
106+
// this.factory = factory;
107+
// return this;
108+
// }
109+
//
110+
// @Override
111+
// public A getModel() {
112+
// return model;
113+
// }
114+
//
115+
// public Impl<A, B> setModel(A model) {
116+
// this.model = model;
117+
// return this;
118+
// }
119+
//
120+
// @Override
121+
// public RenderStack getRenderStack() {
122+
// return stack;
123+
// }
124+
//
125+
// public Impl<A, B> setRenderStack(RenderStack stack) {
126+
// this.stack = stack;
127+
// return this;
128+
// }
129+
//
130+
// @Override
131+
// public String toString() {
132+
// return "Impl{" + "model=" + model + ", result=" + result + ", transform=" + transform + ", factory=" + factory + ", stack=" + stack + '}';
133+
// }
134+
// }
135+
}

0 commit comments

Comments
 (0)