001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.text.java;
011:
012: import java.util.Hashtable;
013: import java.util.List;
014:
015: import org.eclipse.core.runtime.IProgressMonitor;
016:
017: import org.eclipse.jface.text.ITextViewer;
018: import org.eclipse.jface.text.contentassist.ContentAssistant;
019: import org.eclipse.jface.text.contentassist.IContextInformationValidator;
020:
021: import org.eclipse.ui.IEditorPart;
022:
023: import org.eclipse.jdt.core.JavaCore;
024:
025: import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
026: import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
027:
028: /**
029: * Java completion processor.
030: */
031: public class JavaCompletionProcessor extends ContentAssistProcessor {
032:
033: private final static String VISIBILITY = JavaCore.CODEASSIST_VISIBILITY_CHECK;
034: private final static String ENABLED = "enabled"; //$NON-NLS-1$
035: private final static String DISABLED = "disabled"; //$NON-NLS-1$
036:
037: private IContextInformationValidator fValidator;
038: protected final IEditorPart fEditor;
039:
040: public JavaCompletionProcessor(IEditorPart editor,
041: ContentAssistant assistant, String partition) {
042: super (assistant, partition);
043: fEditor = editor;
044: }
045:
046: /**
047: * Tells this processor to restrict its proposal to those element
048: * visible in the actual invocation context.
049: *
050: * @param restrict <code>true</code> if proposals should be restricted
051: */
052: public void restrictProposalsToVisibility(boolean restrict) {
053: Hashtable options = JavaCore.getOptions();
054: Object value = options.get(VISIBILITY);
055: if (value instanceof String) {
056: String newValue = restrict ? ENABLED : DISABLED;
057: if (!newValue.equals(value)) {
058: options.put(VISIBILITY, newValue);
059: JavaCore.setOptions(options);
060: }
061: }
062: }
063:
064: /**
065: * Tells this processor to restrict is proposals to those
066: * starting with matching cases.
067: *
068: * @param restrict <code>true</code> if proposals should be restricted
069: */
070: public void restrictProposalsToMatchingCases(boolean restrict) {
071: // not yet supported
072: }
073:
074: /*
075: * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
076: */
077: public IContextInformationValidator getContextInformationValidator() {
078: if (fValidator == null)
079: fValidator = new JavaParameterListValidator();
080: return fValidator;
081: }
082:
083: /*
084: * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#filterAndSort(java.util.List, org.eclipse.core.runtime.IProgressMonitor)
085: */
086: protected List filterAndSortProposals(List proposals,
087: IProgressMonitor monitor,
088: ContentAssistInvocationContext context) {
089: ProposalSorterRegistry.getDefault().getCurrentSorter()
090: .sortProposals(context, proposals);
091: return proposals;
092: }
093:
094: /*
095: * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor#createContext(org.eclipse.jface.text.ITextViewer, int)
096: */
097: protected ContentAssistInvocationContext createContext(
098: ITextViewer viewer, int offset) {
099: return new JavaContentAssistInvocationContext(viewer, offset,
100: fEditor);
101: }
102: }
|