KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-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 BreakpointConditionCompletionProcessor extends DisplayCompletionProcessor {
25
26     private IType fType;
27     
28     private int fPosition;
29         
30     public BreakpointConditionCompletionProcessor(IType type) {
31         fType= type;
32     }
33
34     /**
35      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
36      */

37     public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
38         try {
39             setErrorMessage(null);
40             if (fType == null) {
41                 setErrorMessage(DebugUIMessages.BreakpointConditionCompletionProcessor_0); //$NON-NLS-1$
42
return new ICompletionProposal[0];
43             }
44             
45             IJavaProject project= fType.getJavaProject();
46             try {
47                 // Generate selections from the compilation unit
48
ITextSelection textSelection= (ITextSelection)viewer.getSelectionProvider().getSelection();
49                 configureResultCollector(project, textSelection);
50                 fType.codeComplete(viewer.getDocument().get().toCharArray(), fPosition, documentOffset,
51                      new char[0][], new char[0][],
52                      new int[0], false, getCollector());
53                      
54                 IJavaCompletionProposal[] results= getCollector().getJavaCompletionProposals();
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         } finally {
77             releaseCollector();
78         }
79     }
80     /**
81      * Sets the type.
82      * @param type The type to set
83      */

84     public void setType(IType type) {
85         fType= type;
86     }
87
88     /**
89      * Sets the line number.
90      * @param lineNb The line number to set
91      */

92     public void setPosition(int position) {
93         fPosition= position;
94     }
95
96 }
97
Popular Tags