1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. 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
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor.php;
14 import java.text.MessageFormat;
16 import org.eclipse.jface.text.ITextViewer;
17 import org.eclipse.jface.text.TextPresentation;
18 import org.eclipse.jface.text.contentassist.CompletionProposal;
19 import org.eclipse.jface.text.contentassist.ContextInformation;
20 import org.eclipse.jface.text.contentassist.ICompletionProposal;
21 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
22 import org.eclipse.jface.text.contentassist.IContextInformation;
23 import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
24 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
27 * Example PHP completion processor.
29 public class PHPCompletionProcessor implements IContentAssistProcessor {
32 * Simple content assist tip closer. The tip is valid in a range
33 * of 5 characters around its popup location.
35 protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
37 protected int fInstallOffset;
40 * @see IContextInformationValidator#isContextInformationValid(int)
42 public boolean isContextInformationValid(int offset) {
43 return Math.abs(fInstallOffset - offset) < 5;
47 * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
49 public void install(IContextInformation info, ITextViewer viewer, int offset) {
50 fInstallOffset = offset;
54 * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
56 public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
61 protected final static String[] fgProposals =
99 protected IContextInformationValidator fValidator = new Validator();
102 * Method declared on IContentAssistProcessor
104 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
105 ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
106 for (int i = 0; i < fgProposals.length; i++) {
107 IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
108 result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
114 * Method declared on IContentAssistProcessor
116 public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
117 IContextInformation[] result = new IContextInformation[5];
118 for (int i = 0; i < result.length; i++)
119 result[i] = new ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset)}), //$NON-NLS-1$
120 MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
125 * Method declared on IContentAssistProcessor
127 public char[] getCompletionProposalAutoActivationCharacters() {
128 return new char[] { '.', '(' };
132 * Method declared on IContentAssistProcessor
134 public char[] getContextInformationAutoActivationCharacters() {
135 return new char[] { '#' };
139 * Method declared on IContentAssistProcessor
141 public IContextInformationValidator getContextInformationValidator() {
146 * Method declared on IContentAssistProcessor
148 public String getErrorMessage() {