Skip to content

Commit

Permalink
GROOVY-9059
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 7, 2023
1 parent 17ad59d commit 2299529
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1,100 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -3230,7 +3230,7 @@ public void testTraitGenerics() throws Exception {
"package q\n" +
"class ServiceWrapper {\n" +
" Service service\n" +
" def logger\n" + // modify the body
" def thing\n" + //add
"}\n");
//@formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,18 @@ public ClassNode redirect() {
return (redirect == null ? this : redirect.redirect());
}

public boolean isRedirectNode() {
return (redirect != null);
}

/**
* Sets this instance as proxy for the given {@code ClassNode}.
*
* @param node the class to redirect to; if {@code null} the redirect is removed
*/
public void setRedirect(ClassNode cn) {
if (isPrimaryNode) throw new GroovyBugError("tried to set a redirect for a primary ClassNode ("+getName()+"->"+cn.getName()+").");
if (cn != null) cn = cn.redirect();
if (cn != null && !isGenericsPlaceHolder()) cn = cn.redirect();
if (cn == this) return;
redirect = cn;
}
Expand Down Expand Up @@ -1550,10 +1554,6 @@ private Map<CompilePhase, Map<Class<? extends ASTTransformation>, Set<ASTNode>>>
return transformInstances;
}

public boolean isRedirectNode() {
return redirect != null;
}

@Override
public String getText() {
return getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,6 @@ public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> gene
exclusions = plus(exclusions, name); // GROOVY-7722
type = genericsSpec.get(name);
if (type != null && type.isGenericsPlaceHolder()) {
// GRECLIPSE add -- GROOVY-9059
if (type.hasMultiRedirect()) {
// convert "S -> T -> U" to "T -> U"
type = type.asGenericsType().getUpperBounds()[0];
// continue to resolve "T -> U" if "T" is a placeholder
return correctToGenericsSpecRecurse(genericsSpec, type, exclusions);
}
// GRECLIPSE end
if (type.getGenericsTypes() == null) {
// correct "T -> U" (no generics)
ClassNode placeholder = ClassHelper.makeWithoutCaching(type.getUnresolvedName());
Expand Down Expand Up @@ -486,12 +478,7 @@ public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpe
String name = type.getGenericsTypes()[0].getName();
type = genericsSpec.get(name);
if (type != null && type.isGenericsPlaceHolder()
/* GRECLIPSE edit -- GROOVY-9059
&& !name.equals(type.getUnresolvedName())) {
*/
&& type.hasMultiRedirect()) {
type = type.asGenericsType().getUpperBounds()[0];
// GRECLIPSE end
return correctToGenericsSpec(genericsSpec, type);
}
}
Expand Down Expand Up @@ -538,7 +525,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
for (GenericsType gt : gts) {
String name = gt.getName();
ClassNode type = gt.getType();
/* GRECLIPSE edit
if (gt.isPlaceholder()) {
ClassNode redirect;
if (gt.getUpperBounds() != null) {
Expand All @@ -558,7 +544,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
type.setRedirect(redirect);
}
}
*/
newSpec.put(name, type);
}
}
Expand Down Expand Up @@ -738,16 +723,7 @@ public static GenericsType[] applyGenericsContextToPlaceHolders(Map<String, Clas
throw new GroovyBugError("Given generics type " + old + " must be a placeholder!");
ClassNode fromSpec = genericsSpec.get(old.getName());
if (fromSpec != null) {
/* GRECLIPSE edit
if (fromSpec.isGenericsPlaceHolder()) {
ClassNode[] upper = new ClassNode[]{fromSpec.redirect()};
newTypes[i] = new GenericsType(fromSpec, upper, null);
} else {
newTypes[i] = new GenericsType(fromSpec);
}
*/
newTypes[i] = fromSpec.asGenericsType();
// GRECLIPSE end
} else {
ClassNode[] upper = old.getUpperBounds();
ClassNode[] newUpper = upper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,6 @@ public static ClassNode correctToGenericsSpecRecurse(Map<String, ClassNode> gene
exclusions = plus(exclusions, name); // GROOVY-7722
type = genericsSpec.get(name);
if (type != null && type.isGenericsPlaceHolder()) {
// GRECLIPSE add -- GROOVY-9059
if (type.hasMultiRedirect()) {
// convert "S -> T -> U" to "T -> U"
type = type.asGenericsType().getUpperBounds()[0];
// continue to resolve "T -> U" if "T" is a placeholder
return correctToGenericsSpecRecurse(genericsSpec, type, exclusions);
}
// GRECLIPSE end
if (type.getGenericsTypes() == null) {
// correct "T -> U" (no generics)
ClassNode placeholder = ClassHelper.makeWithoutCaching(type.getUnresolvedName());
Expand Down Expand Up @@ -463,12 +455,7 @@ public static ClassNode correctToGenericsSpec(Map<String, ClassNode> genericsSpe
String name = type.getGenericsTypes()[0].getName();
type = genericsSpec.get(name);
if (type != null && type.isGenericsPlaceHolder()
/* GRECLIPSE edit -- GROOVY-9059
&& !name.equals(type.getUnresolvedName())) {
*/
&& type.hasMultiRedirect()) {
type = type.asGenericsType().getUpperBounds()[0];
// GRECLIPSE end
return correctToGenericsSpec(genericsSpec, type);
}
}
Expand Down Expand Up @@ -515,7 +502,6 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
for (GenericsType gt : gts) {
String name = gt.getName();
ClassNode type = gt.getType();
/* GRECLIPSE edit
if (gt.isPlaceholder()) {
ClassNode redirect;
if (gt.getUpperBounds() != null) {
Expand All @@ -527,15 +513,14 @@ public static Map<String, ClassNode> addMethodGenerics(MethodNode current, Map<S
}
if (redirect.isGenericsPlaceHolder()) {
// "T extends U" or "T super U"
type = redirect;
type = redirect; // GROOVY-9059
} else {
// "T" or "T extends Thing" or "T super Thing"
// "T" or "T extends Type" or "T super Type"
type = ClassHelper.makeWithoutCaching(name);
type.setGenericsPlaceHolder(true);
type.setRedirect(redirect);
}
}
*/
newSpec.put(name, type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion base/org.codehaus.groovy40/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<file-match-pattern match-pattern="groovy/ast/expr/ClassExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/expr/ConstantExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/ast/tools/ExpressionUtils.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum)Visitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/classgen/GeneratorContext.java" include-pattern="false" />
Expand Down
Loading

0 comments on commit 2299529

Please sign in to comment.