Skip to content

Commit 680a4c8

Browse files
committed
FIX: Added the checking of method type parameter bounds to the self reference fix. Self references of method type parameter bounds are now replaced by origin code referenced (xyz.Type instead of Type which implicitly is ecore.xyz.Type).
1 parent b874a92 commit 680a4c8

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/main/java/jce/codemanipulation/ecore/TypeManipulationVisitor.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.eclipse.jdt.core.dom.MethodDeclaration;
88
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
99
import org.eclipse.jdt.core.dom.Type;
10+
import org.eclipse.jdt.core.dom.TypeParameter;
1011

1112
import jce.util.PathHelper;
1213
import jce.util.RawTypeUtil;
@@ -25,8 +26,7 @@ public class TypeManipulationVisitor extends ASTVisitor {
2526

2627
/**
2728
* Basic constructor. Sets the name of the origin type.
28-
* @param originType is the fully qualified name of the correlating origin type of the Ecore interface which is
29-
* visited.
29+
* @param originType is the fully qualified name of the correlating origin type of the Ecore interface which is visited.
3030
*/
3131
public TypeManipulationVisitor(String originType) {
3232
super();
@@ -36,19 +36,19 @@ public TypeManipulationVisitor(String originType) {
3636

3737
@Override
3838
public boolean visit(MethodDeclaration node) {
39-
AST ast = node.getAST();
40-
checkParameters(node, ast);
41-
checkReturnType(node, ast);
39+
checkParameters(node);
40+
checkReturnType(node);
41+
checkTypeParameters(node);
4242
return super.visit(node);
4343
}
4444

4545
/**
4646
* Checks if parameters are self references and replaces them if they are.
4747
*/
48-
private void checkParameters(MethodDeclaration method, AST ast) {
48+
private void checkParameters(MethodDeclaration method) {
4949
for (SingleVariableDeclaration parameter : RawTypeUtil.castList(SingleVariableDeclaration.class, method.parameters())) {
5050
if (isSelfReference(parameter.getType())) {
51-
parameter.setType(createOriginType(ast));
51+
parameter.setType(createOriginType(method.getAST()));
5252
logger.info("Manually changed type of parameter " + parameter.getName() + " to " + originType);
5353
}
5454
}
@@ -57,13 +57,29 @@ private void checkParameters(MethodDeclaration method, AST ast) {
5757
/**
5858
* Checks if the method return type is a self references and replaces it if it is.
5959
*/
60-
private void checkReturnType(MethodDeclaration method, AST ast) {
60+
private void checkReturnType(MethodDeclaration method) {
6161
if (isSelfReference(method.getReturnType2())) {
62-
method.setReturnType2(createOriginType(ast));
62+
method.setReturnType2(createOriginType(method.getAST()));
6363
logger.info("Manually changed return type of method " + method.getName() + " to " + originType);
6464
}
6565
}
6666

67+
/**
68+
* Checks if bounds of method type parameters are self references and replaces them if they are.
69+
*/
70+
@SuppressWarnings("unchecked")
71+
private void checkTypeParameters(MethodDeclaration method) {
72+
for (TypeParameter parameter : RawTypeUtil.castList(TypeParameter.class, method.typeParameters())) {
73+
for (Type bound : RawTypeUtil.castList(Type.class, parameter.typeBounds())) {
74+
if (isSelfReference(bound)) {
75+
bound.delete();
76+
parameter.typeBounds().add(createOriginType(method.getAST()));
77+
logger.info("Manually changed bound of typ parameter " + parameter.getName() + " to " + originType);
78+
}
79+
}
80+
}
81+
}
82+
6783
/**
6884
* Creates a new {@link Type} which referenced the correlating origin code type of the visited Ecore interface.
6985
*/

0 commit comments

Comments
 (0)