Skip to content

Commit ce16c49

Browse files
authored
Applied open rewrite recipes (#513)
* Applied open rewrite recipes * Upgrade do Java 11
1 parent a63b946 commit ce16c49

File tree

70 files changed

+608
-365
lines changed

Some content is hidden

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

70 files changed

+608
-365
lines changed

.github/workflows/receive-pr.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ jobs:
4242

4343
# Execute recipes
4444
- name: Apply OpenRewrite recipes
45-
run: ./mvnw -Dtoolchain.skip=true -Dlicense.skip=true -DskipTests=true -P openrewrite clean install
46-
45+
run: ./mvnw -Dtoolchain.skip=true -P examples,quickbuild,openrewrite,dev clean install
4746
# Capture the diff
4847
- name: Create patch
4948
run: |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@
10441044
<configuration>
10451045
<exportDatatables>true</exportDatatables>
10461046
<activeRecipes>
1047-
<recipe>org.openrewrite.java.migrate.UpgradeToJava8</recipe>
1047+
<recipe>org.openrewrite.java.migrate.Java8toJava11</recipe>
10481048
</activeRecipes>
10491049
</configuration>
10501050
</execution>

querydsl-examples/querydsl-example-r2dbc-sql-codegen/src/test/java/com/querydsl/example/config/TestDataService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ public void removeTestData() {
149149
// Idem for sequences
150150
s =
151151
c.createStatement(
152-
"SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES WHERE"
153-
+ " SEQUENCE_SCHEMA='PUBLIC'");
152+
"""
153+
SELECT SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES WHERE\
154+
SEQUENCE_SCHEMA='PUBLIC'\
155+
""");
154156
List<String> sequences =
155157
Flux.from(s.execute())
156158
.flatMap(result -> result.map((row, meta) -> row.get(0, String.class)))

querydsl-examples/querydsl-example-sql-guice/src/test/java/com/querydsl/example/sql/repository/TweetRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void save_with_mentions() {
5656
tweet.setPosterId(posterId);
5757
Long tweetId = repository.save(tweet, otherId);
5858

59-
assertThat(repository.findWithMentioned(otherId).get(0).getId()).isEqualTo(tweetId);
59+
assertThat(repository.findWithMentioned(otherId).getFirst().getId()).isEqualTo(tweetId);
6060
}
6161

6262
@Test

querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/AliasTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void alias3() {
8383

8484
// 4
8585
from(c, cats)
86-
.where($(c.getKittens().get(0).getBodyWeight()).gt(12))
86+
.where($(c.getKittens().getFirst().getBodyWeight()).gt(12))
8787
.select($(c.getName()))
8888
.iterate();
8989

querydsl-libraries/querydsl-collections/src/test/java/com/querydsl/collections/CollQueryStandardTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected Fetchable<?> createQuery(Predicate filter) {
7373

7474
@Test
7575
public void test() {
76-
Cat kitten = data.getFirst().getKittens().get(0);
76+
Cat kitten = data.getFirst().getKittens().getFirst();
7777
standardTest.runArrayTests(cat.kittenArray, otherCat.kittenArray, kitten, new Cat());
7878
standardTest.runBooleanTests(cat.name.isNull(), otherCat.kittens.isEmpty());
7979
standardTest.runCollectionTests(cat.kittens, otherCat.kittens, kitten, new Cat());

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/MethodType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public enum MethodType {
3030
/** __mappedPath invocation */
3131
GET_MAPPED_PATH("__mappedPath", Path.class, ManagedObject.class),
3232
/** getter invocation */
33+
LIST_GET_FIRST("getFirst", Object.class, List.class),
34+
/** getter invocation */
3335
GETTER("(get|is).+", Object.class, Object.class),
3436
/** hashCode invocation */
3537
HASH_CODE("hashCode", int.class, Object.class),

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/alias/PropertyAccessInvocationHandler.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,27 @@ public Object intercept(
8484
MethodType methodType = MethodType.get(method);
8585

8686
if (methodType == MethodType.GETTER) {
87-
String ptyName = propertyNameForGetter(method);
87+
var ptyName = propertyNameForGetter(method);
8888
Class<?> ptyClass = method.getReturnType();
89-
Type genericType = method.getGenericReturnType();
89+
var genericType = method.getGenericReturnType();
9090

9191
if (propToObj.containsKey(ptyName)) {
9292
rv = propToObj.get(ptyName);
9393
} else {
94-
PathMetadata pm = createPropertyPath((Path<?>) hostExpression, ptyName);
94+
var pm = createPropertyPath((Path<?>) hostExpression, ptyName);
9595
rv = newInstance(ptyClass, genericType, proxy, ptyName, pm);
9696
}
9797
aliasFactory.setCurrent(propToExpr.get(ptyName));
9898

9999
} else if (methodType == MethodType.SCALA_GETTER) {
100-
String ptyName = method.getName();
100+
var ptyName = method.getName();
101101
Class<?> ptyClass = method.getReturnType();
102-
Type genericType = method.getGenericReturnType();
102+
var genericType = method.getGenericReturnType();
103103

104104
if (propToObj.containsKey(ptyName)) {
105105
rv = propToObj.get(ptyName);
106106
} else {
107-
PathMetadata pm = createPropertyPath((Path<?>) hostExpression, ptyName);
107+
var pm = createPropertyPath((Path<?>) hostExpression, ptyName);
108108
rv = newInstance(ptyClass, genericType, proxy, ptyName, pm);
109109
}
110110
aliasFactory.setCurrent(propToExpr.get(ptyName));
@@ -115,7 +115,18 @@ public Object intercept(
115115
if (propToObj.containsKey(propKey)) {
116116
rv = propToObj.get(propKey);
117117
} else {
118-
PathMetadata pm = createListAccessPath((Path<?>) hostExpression, (Integer) args[0]);
118+
var pm = createListAccessPath((Path<?>) hostExpression, (Integer) args[0]);
119+
Class<?> elementType = ((ParameterizedExpression<?>) hostExpression).getParameter(0);
120+
rv = newInstance(elementType, elementType, proxy, propKey, pm);
121+
}
122+
aliasFactory.setCurrent(propToExpr.get(propKey));
123+
} else if (methodType == MethodType.LIST_GET_FIRST) {
124+
// TODO : manage cases where the argument is based on a property invocation
125+
Object propKey = Arrays.asList(MethodType.LIST_GET_FIRST);
126+
if (propToObj.containsKey(propKey)) {
127+
rv = propToObj.get(propKey);
128+
} else {
129+
var pm = PathMetadataFactory.forListFirst((Path<?>) hostExpression);
119130
Class<?> elementType = ((ParameterizedExpression<?>) hostExpression).getParameter(0);
120131
rv = newInstance(elementType, elementType, proxy, propKey, pm);
121132
}
@@ -126,7 +137,7 @@ public Object intercept(
126137
if (propToObj.containsKey(propKey)) {
127138
rv = propToObj.get(propKey);
128139
} else {
129-
PathMetadata pm = createMapAccessPath((Path<?>) hostExpression, args[0]);
140+
var pm = createMapAccessPath((Path<?>) hostExpression, args[0]);
130141
Class<?> valueType = ((ParameterizedExpression<?>) hostExpression).getParameter(1);
131142
rv = newInstance(valueType, valueType, proxy, propKey, pm);
132143
}
@@ -270,7 +281,7 @@ protected <T> T newInstance(
270281
}
271282

272283
protected String propertyNameForGetter(Method method) {
273-
String name = method.getName();
284+
var name = method.getName();
274285
name = name.startsWith("is") ? name.substring(2) : name.substring(3);
275286
return BeanUtils.uncapitalize(name);
276287
}

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadataFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public static PathMetadata forCollectionAny(Path<?> parent) {
5555
return new PathMetadata(parent, "", PathType.COLLECTION_ANY);
5656
}
5757

58+
/**
59+
* Create a new PathMetadata instance for list first element
60+
*
61+
* @param parent parent path
62+
* @return collection any path
63+
*/
64+
public static PathMetadata forListFirst(Path<?> parent) {
65+
return new PathMetadata(parent, "", PathType.LIST_FIRST);
66+
}
67+
5868
/**
5969
* Create a new PathMetadata instance for delegate access
6070
*

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/PathType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public enum PathType implements Operator {
4646
VARIABLE,
4747

4848
/** Treated path */
49-
TREATED_PATH;
49+
TREATED_PATH,
50+
51+
/** List first element (list.getFirst) */
52+
LIST_FIRST;
5053

5154
@Override
5255
public Class<?> getType() {

0 commit comments

Comments
 (0)