Added: PreferencePage; External Browser startup; extended syntax highlighting
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPCompletionProcessor.java
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
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor.php;
13
14 import java.text.MessageFormat;
15
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;
25
26 /**
27  * Example PHP completion processor.
28  */
29 public class PHPCompletionProcessor implements IContentAssistProcessor {
30
31         /**
32          * Simple content assist tip closer. The tip is valid in a range
33          * of 5 characters around its popup location.
34          */
35         protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
36
37                 protected int fInstallOffset;
38
39                 /*
40                  * @see IContextInformationValidator#isContextInformationValid(int)
41                  */
42                 public boolean isContextInformationValid(int offset) {
43                         return Math.abs(fInstallOffset - offset) < 5;
44                 }
45
46                 /*
47                  * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
48                  */
49                 public void install(IContextInformation info, ITextViewer viewer, int offset) {
50                         fInstallOffset = offset;
51                 }
52
53                 /*
54                  * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
55                  */
56                 public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
57                         return false;
58                 }
59         };
60
61         protected final static String[] fgProposals =
62         {
63                 
64                 "elseif",
65                 "else",
66                 "endif",
67     "endfor",
68                 "for",
69     "if",
70                 "while",
71                 "endwhile",
72                 "switch",
73                 "case",
74                 "endswitch",
75                 "break",
76                 "continue",
77                 "return",
78                 "define",
79                 "include",
80                 "include_once",
81                 "require",
82                 "require_once",
83                 "function",
84                 "class",
85                 "new",
86                 "do",
87                 "old_function",
88                 "default",
89                 "global",
90                 "static",
91                 "foreach",
92                 "endforeach",
93                 "extends",
94                 "empty",
95                 "array",
96                 "isset",
97                 "echo",
98                 "var" };
99         protected IContextInformationValidator fValidator = new Validator();
100
101         /* (non-Javadoc)
102          * Method declared on IContentAssistProcessor
103          */
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$
109                 }
110                 return result;
111         }
112
113         /* (non-Javadoc)
114          * Method declared on IContentAssistProcessor
115          */
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$
121                 return result;
122         }
123
124         /* (non-Javadoc)
125          * Method declared on IContentAssistProcessor
126          */
127         public char[] getCompletionProposalAutoActivationCharacters() {
128                 return new char[] { '.', '(' };
129         }
130
131         /* (non-Javadoc)
132          * Method declared on IContentAssistProcessor
133          */
134         public char[] getContextInformationAutoActivationCharacters() {
135                 return new char[] { '#' };
136         }
137
138         /* (non-Javadoc)
139          * Method declared on IContentAssistProcessor
140          */
141         public IContextInformationValidator getContextInformationValidator() {
142                 return fValidator;
143         }
144
145         /* (non-Javadoc)
146          * Method declared on IContentAssistProcessor
147          */
148         public String getErrorMessage() {
149                 return null;
150         }
151 }