1 11 12 package org.eclipse.jdt.internal.ui.text.correction; 13 14 import org.eclipse.core.runtime.CoreException; 15 16 import org.eclipse.jdt.core.ICompilationUnit; 17 import org.eclipse.jdt.core.dom.AST; 18 import org.eclipse.jdt.core.dom.ASTNode; 19 import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; 20 import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; 21 import org.eclipse.jdt.core.dom.CompilationUnit; 22 import org.eclipse.jdt.core.dom.IMethodBinding; 23 import org.eclipse.jdt.core.dom.ITypeBinding; 24 import org.eclipse.jdt.core.dom.MethodDeclaration; 25 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; 26 import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; 27 import org.eclipse.jdt.core.dom.rewrite.ListRewrite; 28 import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; 29 30 import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; 31 import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; 32 import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2; 33 import org.eclipse.jdt.internal.corext.util.Messages; 34 35 import org.eclipse.jdt.ui.JavaElementLabels; 36 37 import org.eclipse.jdt.internal.ui.JavaPlugin; 38 import org.eclipse.jdt.internal.ui.JavaPluginImages; 39 import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; 40 import org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider; 41 42 public class UnimplementedMethodsCompletionProposal extends ASTRewriteCorrectionProposal { 43 44 private ASTNode fTypeNode; 45 private IMethodBinding[] fMethodsToOverride; 46 47 public UnimplementedMethodsCompletionProposal(ICompilationUnit cu, ASTNode typeNode, int relevance) { 48 super("", cu, null, relevance, null); setDisplayName(CorrectionMessages.UnimplementedMethodsCompletionProposal_description); 50 setImage(JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)); 51 52 fTypeNode= typeNode; 53 fMethodsToOverride= null; 54 } 55 56 57 60 protected ASTRewrite getRewrite() throws CoreException { 61 ITypeBinding binding; 62 AST ast= fTypeNode.getAST(); 63 64 ASTRewrite rewrite= ASTRewrite.create(ast); 65 ListRewrite listRewrite; 66 if (fTypeNode instanceof AnonymousClassDeclaration) { 67 AnonymousClassDeclaration decl= (AnonymousClassDeclaration) fTypeNode; 68 binding= decl.resolveBinding(); 69 listRewrite= rewrite.getListRewrite(decl, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY); 70 } else { 71 AbstractTypeDeclaration decl= (AbstractTypeDeclaration) fTypeNode; 72 binding= decl.resolveBinding(); 73 listRewrite= rewrite.getListRewrite(decl, decl.getBodyDeclarationsProperty()); 74 } 75 IMethodBinding[] methods= StubUtility2.getUnimplementedMethods(binding); 76 fMethodsToOverride= methods; 77 78 CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(getCompilationUnit().getJavaProject()); 79 if (binding.isAnonymous()) { 80 settings.createComments= false; 81 } 82 ImportRewrite imports= createImportRewrite((CompilationUnit) fTypeNode.getRoot()); 83 ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fTypeNode.getRoot(), fTypeNode.getStartPosition(), imports); 84 for (int i= 0; i < methods.length; i++) { 85 MethodDeclaration newMethodDecl= StubUtility2.createImplementationStub(getCompilationUnit(), rewrite, imports, ast, methods[i], binding.getName(), settings, binding.isInterface(), context); 86 listRewrite.insertLast(newMethodDecl, null); 87 } 88 return rewrite; 89 } 90 91 94 public String getAdditionalProposalInfo() { 95 try { 96 getChange(); StringBuffer buf= new StringBuffer (); 98 buf.append("<b>"); buf.append(Messages.format(CorrectionMessages.UnimplementedMethodsCompletionProposal_info, String.valueOf(fMethodsToOverride.length))); 100 buf.append("</b><ul>"); for (int i= 0; i < fMethodsToOverride.length; i++) { 102 buf.append("<li>"); buf.append(BindingLabelProvider.getBindingLabel(fMethodsToOverride[i], JavaElementLabels.ALL_FULLY_QUALIFIED)); 104 buf.append("</li>"); } 106 buf.append("</ul>"); return buf.toString(); 108 } catch (CoreException e) { 109 JavaPlugin.log(e); 110 } 111 return null; 112 } 113 } 114 | Popular Tags |