Skip to content

Commit

Permalink
Update the Groovy plugin to 4.0.0-rc-1
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 27, 2021
1 parent 2228742 commit 0c684dd
Show file tree
Hide file tree
Showing 49 changed files with 1,133 additions and 5,874 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ public static String printTypeName(ClassNode type) {
if (type.isGenericsPlaceHolder()) {
return type.getUnresolvedName() + arraySuffix;
}
return type.getText() + printGenerics(type) + arraySuffix;
String name = type.getText();
if (name.charAt(0) == '(') // Groovy 4.0.0-rc-1+
name = name.substring(1, name.length() - 1);
return name + (name.contains(" or ") ? "" : printGenerics(type)) + arraySuffix;
}

public static String printGenerics(ClassNode type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ public void testLocalVar20() {
assertType(contents, offset, offset + 1, "java.lang.StringBuffer");

offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, Float.parseFloat(System.getProperty("java.specification.version")) < 11
? "java.io.Serializable or java.lang.CharSequence" : "java.io.Serializable or java.lang.CharSequence or " +
"java.lang.Comparable<? extends java.io.Serializable or java.lang.CharSequence or java.lang.Comparable<java.lang.String>>");
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.CharSequence" +
(Float.parseFloat(System.getProperty("java.specification.version")) < 11 ? "" : " or java.lang.Comparable"));
}

@Test
Expand All @@ -341,9 +340,8 @@ public void testLocalVar21() {
assertType(contents, offset, offset + 1, "java.lang.StringBuffer");

offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, Float.parseFloat(System.getProperty("java.specification.version")) < 11
? "java.io.Serializable or java.lang.CharSequence" : "java.io.Serializable or java.lang.CharSequence or " +
"java.lang.Comparable<? extends java.io.Serializable or java.lang.CharSequence or java.lang.Comparable<java.lang.String>>");
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.CharSequence" +
(Float.parseFloat(System.getProperty("java.specification.version")) < 11 ? "" : " or java.lang.Comparable"));
}

@Test
Expand All @@ -370,7 +368,7 @@ public void testLocalVar22() {
assertType(contents, offset, offset + 1, "java.math.BigDecimal");

offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable<? extends java.lang.Object>");
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable");
}

@Test
Expand All @@ -396,7 +394,7 @@ public void testLocalVar23() {
assertType(contents, offset, offset + 1, "java.math.BigDecimal");

offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable<? extends java.lang.Object>");
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable");
}

@Test
Expand Down Expand Up @@ -425,7 +423,7 @@ public void testLocalVar24() {
assertType(contents, offset, offset + 1, "java.math.BigDecimal");

offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable<? extends java.lang.Object>");
assertType(contents, offset, offset + 1, "java.io.Serializable or java.lang.Comparable");
}

@Test
Expand Down Expand Up @@ -492,7 +490,7 @@ public void testLocalVar26() {

// line 11
offset = contents.indexOf("x", offset + 1);
assertType(contents, offset, offset + 1, "java.lang.Number or java.lang.Comparable<? extends java.lang.Number or java.lang.Comparable<java.lang.Integer>>");
assertType(contents, offset, offset + 1, "java.lang.Number or java.lang.Comparable");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ public void testTypeChecked10002() {
"\tList<String> list = ['a','b',3]\n" +
"\t ^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - Incompatible generic argument types." +
" Cannot assign java.util.ArrayList<java.io.Serializable<? extends java.lang.Object>> to: java.util.List<java.lang.String>\n" +
" Cannot assign java.util.ArrayList<java.io.Serializable<? extends " + (isAtLeastGroovy(40) ? "java.io.Serializable<java.lang.String>" : "java.lang.Object") + ">> to: java.util.List<java.lang.String>\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 4)\n" +
"\tDeque<String> deque = ['x','y']\n" +
Expand Down Expand Up @@ -4772,12 +4772,22 @@ public void testTypeChecked10339() {
};
//@formatter:on

String type = "java.io.Serializable";
if (isAtLeastGroovy(40)) {
type += " or java.lang.Comparable";
if (Float.parseFloat(System.getProperty("java.specification.version")) > 11) {
type += " or java.lang.constant.Constable or java.lang.constant.ConstantDesc";
}
type = "(" + type + ")";
} else {
type += "<? extends java.io.Serializable<java.lang.String>>";
}
runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 7)\n" +
"\tInteger i = bar(foo(), 1)\n" +
"\t ^^^^^^^^^^^^^\n" +
"Groovy:[Static type checking] - Cannot assign value of type java.io.Serializable<? extends java.io.Serializable<java.lang.String>> to variable of type java.lang.Integer\n" +
"Groovy:[Static type checking] - Cannot assign value of type " + type + " to variable of type java.lang.Integer\n" +
"----------\n");
}

Expand Down
1 change: 1 addition & 0 deletions base/org.codehaus.groovy25/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<file-match-pattern match-pattern="groovy/transform/FieldASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LazyASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/LogASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/NamedVariantASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/NewifyASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/TupleConstructorASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/StaticCompilationVisitor.java" include-pattern="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ contribute(enclosingClass(annotatedBy(AutoExternalize))) {
contribute(isScript() & currentType(subType(Script) & bind(fields: fields(not(isFinal()))))) {
provider = '{@link groovy.transform.Field Field} AST transform'
for (FieldNode field : fields) {
if (field.getEnd() > 0) {
if (field.end > 0) {
method name: getSetterName(field.name), type: void, params: [(field.name): field.type], isStatic: field.isStatic()
}
}
Expand Down Expand Up @@ -215,11 +215,11 @@ contribute(currentType(meths: methods(hasArgument(annotatedBy(NamedParam))) | ha
provider = '{@link groovy.transform.NamedVariant NamedVariant} AST transform'
for (MethodNode meth : meths) {
Parameter parm = meth.parameters[0]
if (!ClassHelper.MAP_TYPE.equals(parm.type)) {
if (parm.type != ClassHelper.MAP_TYPE) {
continue
}

Map<String, ?> namedParams = [:], optionalParams = [:]
Map<String, ?> requiredParams = [:], optionalParams = [:]
for (AnnotationNode anno : parm.getAnnotations(NAMED_PARAM_TYPE) ?:
parm.getAnnotations(NAMED_PARAMS_TYPE).collectMany { it.getMember('value').expressions*.value }) {
String name = anno.getMember('value').value
Expand All @@ -228,12 +228,12 @@ contribute(currentType(meths: methods(hasArgument(annotatedBy(NamedParam))) | ha
Boolean r = anno.getMember('required')?.value
if (r == null) r = NamedParam.getMethod('required').defaultValue

(r ? namedParams : optionalParams).put(name, type)
(r ? requiredParams : optionalParams).put(name, type)
}

method name: meth.name,
params: params(meth),
namedParams: namedParams,
namedParams: requiredParams,
optionalParams: optionalParams,
declaringType: meth.declaringClass,
type: meth.returnType, isStatic: meth.isStatic(),
Expand Down
Loading

0 comments on commit 0c684dd

Please sign in to comment.