Skip to content

Commit 2299529

Browse files
committed
GROOVY-9059
1 parent 17ad59d commit 2299529

File tree

6 files changed

+10
-1100
lines changed

6 files changed

+10
-1100
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.builder/src/org/eclipse/jdt/core/groovy/tests/builder/BasicGroovyBuildTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -3230,7 +3230,7 @@ public void testTraitGenerics() throws Exception {
32303230
"package q\n" +
32313231
"class ServiceWrapper {\n" +
32323232
" Service service\n" +
3233-
" def logger\n" + // modify the body
3233+
" def thing\n" + //add
32343234
"}\n");
32353235
//@formatter:on
32363236

base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,18 @@ public ClassNode redirect() {
201201
return (redirect == null ? this : redirect.redirect());
202202
}
203203

204+
public boolean isRedirectNode() {
205+
return (redirect != null);
206+
}
207+
204208
/**
205209
* Sets this instance as proxy for the given {@code ClassNode}.
206210
*
207211
* @param node the class to redirect to; if {@code null} the redirect is removed
208212
*/
209213
public void setRedirect(ClassNode cn) {
210214
if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode ("+getName()+"->"+cn.getName()+").");
211-
if (cn != null) cn = cn.redirect();
215+
if (cn != null && !isGenericsPlaceHolder()) cn = cn.redirect();
212216
if (cn == this) return;
213217
redirect = cn;
214218
}
@@ -1550,10 +1554,6 @@ private Map<CompilePhase, Map<Class<? extends ASTTransformation>, Set<ASTNode>>>
15501554
return transformInstances;
15511555
}
15521556

1553-
public boolean isRedirectNode() {
1554-
return redirect != null;
1555-
}
1556-
15571557
@Override
15581558
public String getText() {
15591559
return getName();

base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/tools/GenericsUtils.java

-24
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,6 @@ public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> gene
407407
exclusions = plus(exclusions, name); // GROOVY-7722
408408
type = genericsSpec.get(name);
409409
if (type != null && type.isGenericsPlaceHolder()) {
410-
// GRECLIPSE add -- GROOVY-9059
411-
if (type.hasMultiRedirect()) {
412-
// convert "S -> T -> U" to "T -> U"
413-
type = type.asGenericsType().getUpperBounds()[0];
414-
// continue to resolve "T -> U" if "T" is a placeholder
415-
return correctToGenericsSpecRecurse(genericsSpec, type, exclusions);
416-
}
417-
// GRECLIPSE end
418410
if (type.getGenericsTypes() == null) {
419411
// correct "T -> U" (no generics)
420412
ClassNode placeholder = ClassHelper.makeWithoutCaching(type.getUnresolvedName());
@@ -486,12 +478,7 @@ public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpe
486478
String name = type.getGenericsTypes()[0].getName();
487479
type = genericsSpec.get(name);
488480
if (type != null && type.isGenericsPlaceHolder()
489-
/* GRECLIPSE edit -- GROOVY-9059
490481
&& !name.equals(type.getUnresolvedName())) {
491-
*/
492-
&& type.hasMultiRedirect()) {
493-
type = type.asGenericsType().getUpperBounds()[0];
494-
// GRECLIPSE end
495482
return correctToGenericsSpec(genericsSpec, type);
496483
}
497484
}
@@ -538,7 +525,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
538525
for (GenericsType gt : gts) {
539526
String name = gt.getName();
540527
ClassNode type = gt.getType();
541-
/* GRECLIPSE edit
542528
if (gt.isPlaceholder()) {
543529
ClassNode redirect;
544530
if (gt.getUpperBounds() != null) {
@@ -558,7 +544,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
558544
type.setRedirect(redirect);
559545
}
560546
}
561-
*/
562547
newSpec.put(name, type);
563548
}
564549
}
@@ -738,16 +723,7 @@ public static GenericsType[] applyGenericsContextToPlaceHolders(Map<String, Clas
738723
throw new GroovyBugError("Given generics type " + old + " must be a placeholder!");
739724
ClassNode fromSpec = genericsSpec.get(old.getName());
740725
if (fromSpec != null) {
741-
/* GRECLIPSE edit
742-
if (fromSpec.isGenericsPlaceHolder()) {
743-
ClassNode[] upper = new ClassNode[]{fromSpec.redirect()};
744-
newTypes[i] = new GenericsType(fromSpec, upper, null);
745-
} else {
746-
newTypes[i] = new GenericsType(fromSpec);
747-
}
748-
*/
749726
newTypes[i] = fromSpec.asGenericsType();
750-
// GRECLIPSE end
751727
} else {
752728
ClassNode[] upper = old.getUpperBounds();
753729
ClassNode[] newUpper = upper;

base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/tools/GenericsUtils.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,6 @@ public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> gene
382382
exclusions = plus(exclusions, name); // GROOVY-7722
383383
type = genericsSpec.get(name);
384384
if (type != null && type.isGenericsPlaceHolder()) {
385-
// GRECLIPSE add -- GROOVY-9059
386-
if (type.hasMultiRedirect()) {
387-
// convert "S -> T -> U" to "T -> U"
388-
type = type.asGenericsType().getUpperBounds()[0];
389-
// continue to resolve "T -> U" if "T" is a placeholder
390-
return correctToGenericsSpecRecurse(genericsSpec, type, exclusions);
391-
}
392-
// GRECLIPSE end
393385
if (type.getGenericsTypes() == null) {
394386
// correct "T -> U" (no generics)
395387
ClassNode placeholder = ClassHelper.makeWithoutCaching(type.getUnresolvedName());
@@ -463,12 +455,7 @@ public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpe
463455
String name = type.getGenericsTypes()[0].getName();
464456
type = genericsSpec.get(name);
465457
if (type != null && type.isGenericsPlaceHolder()
466-
/* GRECLIPSE edit -- GROOVY-9059
467458
&& !name.equals(type.getUnresolvedName())) {
468-
*/
469-
&& type.hasMultiRedirect()) {
470-
type = type.asGenericsType().getUpperBounds()[0];
471-
// GRECLIPSE end
472459
return correctToGenericsSpec(genericsSpec, type);
473460
}
474461
}
@@ -515,7 +502,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
515502
for (GenericsType gt : gts) {
516503
String name = gt.getName();
517504
ClassNode type = gt.getType();
518-
/* GRECLIPSE edit
519505
if (gt.isPlaceholder()) {
520506
ClassNode redirect;
521507
if (gt.getUpperBounds() != null) {
@@ -527,15 +513,14 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
527513
}
528514
if (redirect.isGenericsPlaceHolder()) {
529515
// "T extends U" or "T super U"
530-
type = redirect;
516+
type = redirect; // GROOVY-9059
531517
} else {
532-
// "T" or "T extends Thing" or "T super Thing"
518+
// "T" or "T extends Type" or "T super Type"
533519
type = ClassHelper.makeWithoutCaching(name);
534520
type.setGenericsPlaceHolder(true);
535521
type.setRedirect(redirect);
536522
}
537523
}
538-
*/
539524
newSpec.put(name, type);
540525
}
541526
}

base/org.codehaus.groovy40/.checkstyle

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<file-match-pattern match-pattern="groovy/ast/expr/ClassExpression.java" include-pattern="false" />
3434
<file-match-pattern match-pattern="groovy/ast/expr/ConstantExpression.java" include-pattern="false" />
3535
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
36-
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
36+
<file-match-pattern match-pattern="groovy/ast/tools/ExpressionUtils.java" include-pattern="false" />
3737
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum)Visitor.java" include-pattern="false" />
3838
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
3939
<file-match-pattern match-pattern="groovy/classgen/GeneratorContext.java" include-pattern="false" />

0 commit comments

Comments
 (0)