KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > DetailFormatterCompletionProcessor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /**
27      * The dialog with which this processor is associated.
28      */

29     private DetailFormatterDialog fDetailFormatDialog;
30         
31     public DetailFormatterCompletionProcessor(DetailFormatterDialog detailFormatDialog) {
32         fDetailFormatDialog= detailFormatDialog;
33     }
34
35     /**
36      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
37      */

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             // Generate selections from the compilation unit
48
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             // Generate selections from the template engine
57
TemplateEngine templateEngine= getTemplateEngine();
58             if (templateEngine != null) {
59                 templateEngine.reset();
60                 templateEngine.complete(viewer, documentOffset, null);
61                 TemplateProposal[] templateResults= templateEngine.getResults();
62
63                 // concatenate arrays
64
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              //Order here and not in result collector to make sure that the order
70
//applies to all proposals and not just those of the compilation unit.
71
return order(results);
72         } catch (JavaModelException x) {
73             handle(viewer, x);
74         }
75         return null;
76     }
77 }
78
Popular Tags