1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 import org.eclipse.jdt.core.IJavaProject; 14 import org.eclipse.jdt.core.IType; 15 import org.eclipse.jdt.core.JavaModelException; 16 import org.eclipse.jdt.internal.debug.ui.display.DisplayCompletionProcessor; 17 import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateEngine; 18 import org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateProposal; 19 import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; 20 import org.eclipse.jface.text.ITextSelection; 21 import org.eclipse.jface.text.ITextViewer; 22 import org.eclipse.jface.text.contentassist.ICompletionProposal; 23 24 public class CodeSnippetCompletionProcessor extends DisplayCompletionProcessor { 25 26 public interface ITypeProvider { 27 IType getType(); 28 } 29 30 33 private ITypeProvider fTypeProvider; 34 35 public CodeSnippetCompletionProcessor(ITypeProvider detailFormatDialog) { 36 fTypeProvider= detailFormatDialog; 37 } 38 39 42 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { 43 try { 44 setErrorMessage(null); 45 IType receivingType= fTypeProvider.getType(); 46 if (receivingType == null) { 47 setErrorMessage(DebugUIMessages.CodeSnippetCompletionProcessor_0); return new ICompletionProposal[0]; 49 } 50 51 IJavaProject project= receivingType.getJavaProject(); 52 try { 53 ITextSelection textSelection= (ITextSelection)viewer.getSelectionProvider().getSelection(); 55 configureResultCollector(project, textSelection); 56 receivingType.codeComplete(viewer.getDocument().get().toCharArray(), -1, documentOffset, 57 new char[0][], new char[0][], 58 new int[0], false, getCollector()); 59 60 IJavaCompletionProposal[] results= getCollector().getJavaCompletionProposals(); 61 62 TemplateEngine templateEngine= getTemplateEngine(); 64 if (templateEngine != null) { 65 templateEngine.reset(); 66 templateEngine.complete(viewer, documentOffset, null); 67 TemplateProposal[] templateResults= templateEngine.getResults(); 68 69 IJavaCompletionProposal[] total= new IJavaCompletionProposal[results.length + templateResults.length]; 71 System.arraycopy(templateResults, 0, total, 0, templateResults.length); 72 System.arraycopy(results, 0, total, templateResults.length, results.length); 73 results= total; 74 } 75 return order(results); 78 } catch (JavaModelException x) { 79 handle(viewer, x); 80 } 81 return null; 82 } finally { 83 releaseCollector(); 84 } 85 } 86 } 87 | Popular Tags |