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 DetailFormatterCompletionProcessor extends DisplayCompletionProcessor { 25 26 29 private DetailFormatterDialog fDetailFormatDialog; 30 31 public DetailFormatterCompletionProcessor(DetailFormatterDialog detailFormatDialog) { 32 fDetailFormatDialog= detailFormatDialog; 33 } 34 35 38 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { 39 40 IType receivingType= fDetailFormatDialog.getType(); 41 if (receivingType == null) { 42 return new ICompletionProposal[0]; 43 } 44 45 IJavaProject project= receivingType.getJavaProject(); 46 try { 47 ITextSelection textSelection= (ITextSelection)viewer.getSelectionProvider().getSelection(); 49 configureResultCollector(project, textSelection); 50 receivingType.codeComplete(viewer.getDocument().get().toCharArray(), -1, documentOffset, 51 new char[0][], new char[0][], 52 new int[0], false, getCollector()); 53 54 IJavaCompletionProposal[] results= getCollector().getResults(); 55 56 TemplateEngine templateEngine= getTemplateEngine(); 58 if (templateEngine != null) { 59 templateEngine.reset(); 60 templateEngine.complete(viewer, documentOffset, null); 61 TemplateProposal[] templateResults= templateEngine.getResults(); 62 63 IJavaCompletionProposal[] total= new IJavaCompletionProposal[results.length + templateResults.length]; 65 System.arraycopy(templateResults, 0, total, 0, templateResults.length); 66 System.arraycopy(results, 0, total, templateResults.length, results.length); 67 results= total; 68 } 69 return order(results); 72 } catch (JavaModelException x) { 73 handle(viewer, x); 74 } 75 return null; 76 } 77 } 78 | Popular Tags |