KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > java > JavaCompletionProcessor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.text.java;
12
13 import java.util.Hashtable JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.contentassist.ContentAssistant;
20 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
21
22 import org.eclipse.ui.IEditorPart;
23
24 import org.eclipse.jdt.core.JavaCore;
25
26 import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
27 import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
28
29 /**
30  * Java completion processor.
31  */

32 public class JavaCompletionProcessor extends ContentAssistProcessor {
33
34     private final static String JavaDoc VISIBILITY= JavaCore.CODEASSIST_VISIBILITY_CHECK;
35     private final static String JavaDoc ENABLED= "enabled"; //$NON-NLS-1$
36
private final static String JavaDoc DISABLED= "disabled"; //$NON-NLS-1$
37

38     private IContextInformationValidator fValidator;
39     protected final IEditorPart fEditor;
40
41     public JavaCompletionProcessor(IEditorPart editor, ContentAssistant assistant, String JavaDoc partition) {
42         super(assistant, partition);
43         fEditor= editor;
44     }
45
46     /**
47      * Tells this processor to restrict its proposal to those element
48      * visible in the actual invocation context.
49      *
50      * @param restrict <code>true</code> if proposals should be restricted
51      */

52     public void restrictProposalsToVisibility(boolean restrict) {
53         Hashtable JavaDoc options= JavaCore.getOptions();
54         Object JavaDoc value= options.get(VISIBILITY);
55         if (value instanceof String JavaDoc) {
56             String JavaDoc newValue= restrict ? ENABLED : DISABLED;
57             if ( !newValue.equals(value)) {
58                 options.put(VISIBILITY, newValue);
59                 JavaCore.setOptions(options);
60             }
61         }
62     }
63
64     /**
65      * Tells this processor to restrict is proposals to those
66      * starting with matching cases.
67      *
68      * @param restrict <code>true</code> if proposals should be restricted
69      */

70     public void restrictProposalsToMatchingCases(boolean restrict) {
71         // not yet supported
72
}
73
74     /*
75      * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
76      */

77     public IContextInformationValidator getContextInformationValidator() {
78         if (fValidator == null)
79             fValidator= new JavaParameterListValidator();
80         return fValidator;
81     }
82
83     /*
84      * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#filterAndSort(java.util.List, org.eclipse.core.runtime.IProgressMonitor)
85      */

86     protected List JavaDoc filterAndSortProposals(List JavaDoc proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
87         ProposalSorterRegistry.getDefault().getCurrentSorter().sortProposals(context, proposals);
88         return proposals;
89     }
90
91     /*
92      * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#createContext(org.eclipse.jface.text.ITextViewer, int)
93      */

94     protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
95         return new JavaContentAssistInvocationContext(viewer, offset, fEditor);
96     }
97 }
98
Popular Tags