I have the code here:
public class TestOverride { int foo() { return -1; } } class B extends TestOverride { @Override int foo() {
As you can see, I mentioned the error. I am trying to create quickfix for this in eclipse jdt ui. But I cannot get the superclass of node class B, which 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(); } }
Here I got parentClass only as TestOverride. But when I checked, it is not a TypeDeclaration type, it is not a SimpleName type.
My request is how do I get the TestOverride node class?
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); }
source share