2016-06-09 64 views
0

我目前正在處理的錯誤要求我在選擇關聯的快速修復程序時使用擴展替換實現器。無法用eclipse中的擴展JDT替換實現器JDT

例如:

public class R{ 

} 
class Q implements R{ //error here 

} 

速戰速決將是改變以延長機具(這就是我重點)。但要做到這一點,我需要TypeDeclaration.SUPERCLASS_TYPE作爲ChildListPropertyDiscriptor而現在它是ChildPropertyDiscriptor。這使得它無法作爲getListRewrite的參數提供。

我想知道是否有任何方法可以讓TypeDeclaration.SUPERCLASS_TYPE作爲ChildListPropertyDiscriptor。否則有其他方式可以做到這一點。

我完整的代碼片段如下:

TypeDeclaration typeDecl= (TypeDeclaration) selectedNode.getParent(); 
    { 
     ASTRewrite rewrite= ASTRewrite.create(root.getAST()); 
     ASTNode placeHolder= rewrite.createMoveTarget(selectedNode); 
     ListRewrite interfaces= rewrite.getListRewrite(typeDecl, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY); //problem here 
     interfaces.insertFirst(placeHolder, null); 

     String label= CorrectionMessages.LocalCorrectionsSubProcessor_implementstoextends_description; 
     Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); 
     ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.CHANGE_EXTENDS_TO_IMPLEMENTS, image); 
     proposals.add(proposal); 
    } 

回答

0

Java不支持多繼承所以僅支持一種類型的extends。這解釋了爲什麼TypeDeclaration.SUPERCLASS_TYPE沒有列表,因此沒有ChildListPropertyDescriptior(可能與ListRewrite一起使用)。

你想,而不是什麼是ASTRewrite.set()

rewrite.set(typeDecl, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY, placeHolder, null);