I have a code here:
public class TestOverride {
int foo() {
return -1;
}
}
class B extends TestOverride {
@Override
int foo() {
// error - quick fix to add "return super.foo();"
}
}
As you can see I have mentioned the error. I'm trying to create a quickfix for this in eclipse jdt ui. But i'm unable to get the superclass node of the class B that is Class TestOverride.
I tried the following code
if(selectedNode instanceof MethodDeclaration) {
ASTNode type = selectedNode.getParent();
if(type instanceof TypeDeclaration) {
ASTNode parentClass = ((TypeDeclaration) type).getSuperclassType();
}
}
In here I got parentClass as TestOverride only. But when I checked this is not of the type TypeDeclaration it's not of type SimpleName either.
My query is how I get the class TestOverride node?
EDIT
for (IMethodBinding parentMethodBinding :superClassBinding.getDeclaredMethods()){
if (methodBinding.overrides(parentMethodBinding)){
ReturnStatement rs = ast.newReturnStatement();
SuperMethodInvocation smi = ast.newSuperMethodInvocation();
rs.setExpression(smi);
Block oldBody = methodDecl.getBody();
ListRewrite listRewrite = rewriter.getListRewrite(oldBody, Block.STATEMENTS_PROPERTY);
listRewrite.insertFirst(rs, null);
}
TestOverride
node if you just insert thereturn super.foo();
call? – Improvised