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.sql.Connection;
15 import java.sql.DatabaseMetaData;
16 import java.sql.ResultSet;
17 import java.sql.SQLException;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
22 import java.util.SortedMap;
24 import net.sourceforge.phpdt.core.IBuffer;
25 import net.sourceforge.phpdt.core.ICompilationUnit;
26 import net.sourceforge.phpdt.core.IJavaProject;
27 import net.sourceforge.phpdt.core.JavaModelException;
28 import net.sourceforge.phpdt.core.ToolFactory;
29 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
30 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
31 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
32 import net.sourceforge.phpdt.internal.compiler.SourceElementParser;
33 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
34 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
35 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
36 import net.sourceforge.phpdt.internal.core.CompilationUnit;
37 import net.sourceforge.phpdt.internal.core.CompilationUnitStructureRequestor;
38 import net.sourceforge.phpdt.internal.core.JavaModelManager;
39 import net.sourceforge.phpdt.internal.core.JavaProject;
40 import net.sourceforge.phpdt.internal.corext.template.ContextType;
41 import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
42 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
43 import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
44 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
45 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
46 import net.sourceforge.phpdt.internal.ui.text.java.PHPCompletionProposalComparator;
47 import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine;
48 import net.sourceforge.phpdt.internal.ui.text.template.DeclarationEngine;
49 import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine;
50 import net.sourceforge.phpdt.internal.ui.text.template.SQLProposal;
51 import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine;
52 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
53 import net.sourceforge.phpeclipse.IPreferenceConstants;
54 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
55 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
56 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
57 import net.sourceforge.phpeclipse.overlaypages.Util;
58 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
59 import net.sourceforge.phpeclipse.phpeditor.PHPSyntaxRdr;
61 import org.eclipse.core.resources.IFile;
62 import org.eclipse.core.resources.IProject;
63 import org.eclipse.jface.text.BadLocationException;
64 import org.eclipse.jface.text.IDocument;
65 import org.eclipse.jface.text.IRegion;
66 import org.eclipse.jface.text.ITextViewer;
67 import org.eclipse.jface.text.Region;
68 import org.eclipse.jface.text.TextPresentation;
69 import org.eclipse.jface.text.contentassist.ICompletionProposal;
70 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
71 import org.eclipse.jface.text.contentassist.IContextInformation;
72 import org.eclipse.jface.text.contentassist.IContextInformationExtension;
73 import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
74 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
75 import org.eclipse.swt.graphics.Image;
76 import org.eclipse.ui.IEditorPart;
77 import org.eclipse.ui.IFileEditorInput;
79 import com.quantum.model.Bookmark;
80 import com.quantum.model.BookmarkCollection;
81 import com.quantum.model.NotConnectedException;
82 import com.quantum.util.connection.ConnectionUtil;
85 * Example PHP completion processor.
87 public class PHPCompletionProcessor implements IContentAssistProcessor {
89 * Simple content assist tip closer. The tip is valid in a range of 5
90 * characters around its popup location.
92 protected static class Validator implements IContextInformationValidator,
93 IContextInformationPresenter {
94 protected int fInstallOffset;
97 * @see IContextInformationValidator#isContextInformationValid(int)
99 public boolean isContextInformationValid(int offset) {
100 return Math.abs(fInstallOffset - offset) < 5;
104 * @see IContextInformationValidator#install(IContextInformation,
107 public void install(IContextInformation info, ITextViewer viewer, int offset) {
108 fInstallOffset = offset;
112 * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int,
115 public boolean updatePresentation(int documentPosition,
116 TextPresentation presentation) {
121 private static class ContextInformationWrapper implements
122 IContextInformation, IContextInformationExtension {
123 private final IContextInformation fContextInformation;
125 private int fPosition;
127 public ContextInformationWrapper(IContextInformation contextInformation) {
128 fContextInformation = contextInformation;
132 * @see IContextInformation#getContextDisplayString()
134 public String getContextDisplayString() {
135 return fContextInformation.getContextDisplayString();
139 * @see IContextInformation#getImage()
141 public Image getImage() {
142 return fContextInformation.getImage();
146 * @see IContextInformation#getInformationDisplayString()
148 public String getInformationDisplayString() {
149 return fContextInformation.getInformationDisplayString();
153 * @see IContextInformationExtension#getContextInformationPosition()
155 public int getContextInformationPosition() {
159 public void setContextInformationPosition(int position) {
160 fPosition = position;
164 private class TableName {
172 * @return Returns the tableName.
174 public String getTableName() {
175 if (fTableName == null) {
176 return "<!--no-table-->";
183 * The tableName to set.
185 public void setTableName(String tableName) {
186 fTableName = tableName;
190 private char[] fProposalAutoActivationSet;
192 protected IContextInformationValidator fValidator = new Validator();
194 private TemplateEngine fTemplateEngine;
196 private PHPCompletionProposalComparator fComparator;
198 private int fNumberOfComputedResults = 0;
200 private IEditorPart fEditor;
202 protected IWorkingCopyManager fManager;
204 public PHPCompletionProcessor(IEditorPart editor) {
206 fManager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
207 ContextType contextType = ContextTypeRegistry.getInstance().getContextType(
208 "php"); //$NON-NLS-1$
209 if (contextType != null)
210 fTemplateEngine = new TemplateEngine(contextType);
211 fComparator = new PHPCompletionProposalComparator();
215 * Tells this processor to order the proposals alphabetically.
218 * <code>true</code> if proposals should be ordered.
220 public void orderProposalsAlphabetically(boolean order) {
221 fComparator.setOrderAlphabetically(order);
225 * Sets this processor's set of characters triggering the activation of the
226 * completion proposal computation.
228 * @param activationSet
231 public void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
232 fProposalAutoActivationSet = activationSet;
236 * (non-Javadoc) Method declared on IContentAssistProcessor
238 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
239 int documentOffset) {
240 int contextInformationPosition = guessContextInformationPosition(viewer,
242 return internalComputeCompletionProposals(viewer, documentOffset,
243 contextInformationPosition);
246 private int getLastToken(ITextViewer viewer, int completionPosition,
247 PHPUnitContext context, TableName tableName) {
248 IDocument document = viewer.getDocument();
249 int start = context.getStart();
250 int end = context.getEnd();
252 int lastSignificantToken = ITerminalSymbols.TokenNameEOF;
254 // begin search 2 lines behind of this
259 ch = document.getChar(j);
265 ch = document.getChar(j);
272 // scan the line for the dereferencing operator '->'
273 startText = document.get(j, start - j);
275 System.out.println(startText);
277 int token = ITerminalSymbols.TokenNameEOF;
278 // token = getLastSQLToken(startText);
279 tableName.setTableName(getLastSQLTableName(startText));
280 Scanner scanner = ToolFactory.createScanner(false, false, false);
281 scanner.setSource(startText.toCharArray());
282 scanner.setPHPMode(true);
283 int beforeLastToken = ITerminalSymbols.TokenNameEOF;
284 int lastToken = ITerminalSymbols.TokenNameEOF;
287 token = scanner.getNextToken();
289 while (token != ITerminalSymbols.TokenNameERROR
290 && token != ITerminalSymbols.TokenNameEOF) {
291 beforeLastToken = lastToken;
292 if (lastToken==ITerminalSymbols.TokenNameVariable) {
293 ident = scanner.getCurrentTokenSource();
294 if (ident.length==5 &&
300 beforeLastToken = ITerminalSymbols.TokenNamethis_PHP_COMPLETION;
304 // System.out.println(scanner.toStringAction(lastToken));
305 token = scanner.getNextToken();
307 } catch (InvalidInputException e1) {
310 case ITerminalSymbols.TokenNameMINUS_GREATER:
311 // dereferencing operator '->' found
312 lastSignificantToken = ITerminalSymbols.TokenNameMINUS_GREATER;
313 if (beforeLastToken == ITerminalSymbols.TokenNameVariable) {
314 lastSignificantToken = ITerminalSymbols.TokenNameVariable;
317 case ITerminalSymbols.TokenNamenew:
318 lastSignificantToken = ITerminalSymbols.TokenNamenew;
322 } catch (BadLocationException e) {
324 return lastSignificantToken;
327 String getSQLTableName(String sqlText, int start) {
328 int tableNameStart = -1;
329 int currentCharacterPosition = start + 1;
333 ch = sqlText.charAt(currentCharacterPosition++);
334 if (tableNameStart == -1 && Character.isJavaIdentifierStart(ch)) {
335 tableNameStart = currentCharacterPosition - 1;
337 if (!Character.isJavaIdentifierPart(ch)) {
338 return sqlText.substring(tableNameStart,
339 currentCharacterPosition - 1);
343 } catch (IndexOutOfBoundsException e) {
344 if (tableNameStart >= 0) {
345 return sqlText.substring(tableNameStart, currentCharacterPosition - 1);
351 private String getLastSQLTableName(String startText) {
353 // scan for sql identifiers
355 int currentSQLPosition = startText.length();
358 boolean whiteSpace = true;
361 ch = startText.charAt(--currentSQLPosition);
362 if (ch >= 'A' && ch <= 'Z') {
364 identEnd = currentSQLPosition + 1;
366 } else if (ch >= 'a' && ch <= 'z') {
368 identEnd = currentSQLPosition + 1;
370 } else if (identEnd >= 0) {
371 ident = startText.substring(currentSQLPosition + 1, identEnd);
372 // select -- from -- where --
373 // update -- set -- where --
374 // insert into -- ( -- ) values ( -- )
375 if (ident.length() >= 4 && ident.length() <= 6) {
376 ident = ident.toLowerCase();
377 switch (ident.length()) {
379 // if (ident.equals("set")) {
380 // // System.out.println("set");
381 // token = ITerminalSymbols.TokenNameSQLset;
386 if (ident.equals("from")) {
387 // System.out.println("from");
388 token = ITerminalSymbols.TokenNameSQLfrom;
389 return getSQLTableName(startText, identEnd);
390 } else if (ident.equals("into")) {
391 // System.out.println("into");
392 token = ITerminalSymbols.TokenNameSQLinto;
393 return getSQLTableName(startText, identEnd);
397 // if (ident.equals("where")) {
398 // // System.out.println("where");
399 // token = ITerminalSymbols.TokenNameSQLwhere;
404 // if (ident.equals("select")) {
405 // // System.out.println("select");
406 // token = ITerminalSymbols.TokenNameSQLselect;
408 // } else if (ident.equals("insert")) {
409 // // System.out.println("insert");
410 // token = ITerminalSymbols.TokenNameSQLinsert;
413 if (ident.equals("update")) {
414 // System.out.println("update");
415 token = ITerminalSymbols.TokenNameSQLupdate;
416 return getSQLTableName(startText, identEnd);
418 // else if (ident.equals("values")) {
419 // // System.out.println("values");
420 // token = ITerminalSymbols.TokenNameSQLvalues;
428 } else if (Character.isWhitespace(ch)) {
433 } catch (IndexOutOfBoundsException e) {
435 return "<!--no-table-->";
439 * Detect the last significant SQL token in the text before the completion
443 private int getLastSQLToken(String startText) {
445 // scan for sql identifiers
447 int currentSQLPosition = startText.length();
450 boolean whiteSpace = true;
453 ch = startText.charAt(--currentSQLPosition);
454 if (ch >= 'A' && ch <= 'Z') {
456 identEnd = currentSQLPosition + 1;
458 } else if (ch >= 'a' && ch <= 'z') {
460 identEnd = currentSQLPosition + 1;
462 } else if (identEnd >= 0) {
463 ident = startText.substring(currentSQLPosition + 1, identEnd);
464 // select -- from -- where --
465 // update -- set -- where --
466 // insert into -- ( -- ) values ( -- )
467 if (ident.length() >= 3 && ident.length() <= 6) {
468 ident = ident.toLowerCase();
469 switch (ident.length()) {
471 if (ident.equals("set")) {
472 // System.out.println("set");
473 token = ITerminalSymbols.TokenNameSQLset;
478 if (ident.equals("from")) {
479 // System.out.println("from");
480 token = ITerminalSymbols.TokenNameSQLfrom;
483 } else if (ident.equals("into")) {
484 // System.out.println("into");
485 token = ITerminalSymbols.TokenNameSQLinto;
490 if (ident.equals("where")) {
491 // System.out.println("where");
492 token = ITerminalSymbols.TokenNameSQLwhere;
497 if (ident.equals("select")) {
498 // System.out.println("select");
499 token = ITerminalSymbols.TokenNameSQLselect;
501 } else if (ident.equals("insert")) {
502 // System.out.println("insert");
503 token = ITerminalSymbols.TokenNameSQLinsert;
505 } else if (ident.equals("update")) {
506 // System.out.println("update");
507 token = ITerminalSymbols.TokenNameSQLupdate;
509 } else if (ident.equals("values")) {
510 // System.out.println("values");
511 token = ITerminalSymbols.TokenNameSQLvalues;
519 } else if (Character.isWhitespace(ch)) {
524 } catch (IndexOutOfBoundsException e) {
526 return ITerminalSymbols.TokenNameEOF;
529 private ICompletionProposal[] internalComputeCompletionProposals(
530 ITextViewer viewer, int offset, int contextOffset) {
532 IDocument document = viewer.getDocument();
533 Object[] identifiers = null;
535 IProject project = null;
537 PHPEditor editor = null;
538 if (fEditor != null && (fEditor instanceof PHPEditor)) {
539 editor = (PHPEditor) fEditor;
540 file = ((IFileEditorInput) editor.getEditorInput()).getFile();
541 project = file.getProject();
542 // outlinePage = editor.getfOutlinePage();
543 // TODO: get the identifiers from the new model
544 // if (outlinePage instanceof PHPContentOutlinePage) {
545 // identifiers = ((PHPContentOutlinePage) outlinePage).getVariables();
550 ContextType phpContextType = ContextTypeRegistry.getInstance()
551 .getContextType("php"); //$NON-NLS-1$
552 ((CompilationUnitContextType) phpContextType).setContextParameters(
553 document, offset, 0);
554 PHPUnitContext context = (PHPUnitContext) phpContextType.createContext();
555 String prefix = context.getKey();
556 TableName sqlTable = new TableName();
557 int lastSignificantToken = getLastToken(viewer, offset, context, sqlTable);
558 boolean useClassMembers = (lastSignificantToken == ITerminalSymbols.TokenNameMINUS_GREATER)
559 || (lastSignificantToken == ITerminalSymbols.TokenNameVariable)
560 || (lastSignificantToken == ITerminalSymbols.TokenNamenew)
561 || (lastSignificantToken == ITerminalSymbols.TokenNamethis_PHP_COMPLETION);
562 boolean emptyPrefix = prefix == null || prefix.equals("");
563 if (fTemplateEngine != null) {
564 IPHPCompletionProposal[] templateResults = new IPHPCompletionProposal[0];
565 ICompletionProposal[] results;
567 fTemplateEngine.reset();
568 fTemplateEngine.complete(viewer, offset); //, unit);
569 templateResults = fTemplateEngine.getResults();
571 IPHPCompletionProposal[] identifierResults = new IPHPCompletionProposal[0];
572 if ((!useClassMembers) && identifiers != null) {
573 IdentifierEngine identifierEngine;
574 ContextType contextType = ContextTypeRegistry.getInstance()
575 .getContextType("php"); //$NON-NLS-1$
576 if (contextType != null) {
577 identifierEngine = new IdentifierEngine(contextType);
578 identifierEngine.complete(viewer, offset, identifiers);
579 identifierResults = identifierEngine.getResults();
582 // declarations stored in file project.index on project level
583 IPHPCompletionProposal[] declarationResults = new IPHPCompletionProposal[0];
584 if (project != null) {
585 DeclarationEngine declarationEngine;
586 ContextType contextType = ContextTypeRegistry.getInstance()
587 .getContextType("php"); //$NON-NLS-1$
588 if (contextType != null) {
589 IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault()
590 .getIndexManager(project);
591 SortedMap sortedMap = indexManager.getIdentifierMap();
592 declarationEngine = new DeclarationEngine(contextType,
593 lastSignificantToken, file);
594 declarationEngine.complete(viewer, offset, sortedMap);
595 declarationResults = declarationEngine.getResults();
598 // built in function names from phpsyntax.xml
599 ArrayList syntaxbuffer = PHPSyntaxRdr.getSyntaxData();
600 IPHPCompletionProposal[] builtinResults = new IPHPCompletionProposal[0];
601 if ((!useClassMembers) && syntaxbuffer != null) {
602 BuiltInEngine builtinEngine;
604 ContextType contextType = ContextTypeRegistry.getInstance()
605 .getContextType("php"); //$NON-NLS-1$
606 if (contextType != null) {
607 builtinEngine = new BuiltInEngine(contextType);
608 builtinEngine.complete(viewer, offset, syntaxbuffer);
609 builtinResults = builtinEngine.getResults();
612 IPHPCompletionProposal[] sqlResults = new IPHPCompletionProposal[0];
613 if (project != null) {
614 // Get The Database bookmark from the Quantum SQL plugin:
615 BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance();
616 if (sqlBookMarks != null) {
617 String bookmarkString = Util.getMiscProjectsPreferenceValue(project,
618 IPreferenceConstants.PHP_BOOKMARK_DEFAULT);
619 if (bookmarkString != null && !bookmarkString.equals("")) {
620 Bookmark bookmark = sqlBookMarks.find(bookmarkString);
621 ArrayList sqlList = new ArrayList();
622 if (bookmark != null && !bookmark.isConnected()) {
623 new ConnectionUtil().connect(bookmark, null);
625 if (bookmark != null && bookmark.isConnected()) {
627 Connection connection = bookmark.getConnection();
628 DatabaseMetaData metaData = connection.getMetaData();
630 if (metaData != null) {
631 int start = context.getStart();
632 int end = context.getEnd();
633 String foundSQLTableName = sqlTable.getTableName();
636 String prefixWithoutDollar = prefix;
637 boolean isDollarPrefix = false;
638 if (prefix.length() > 0 && prefix.charAt(0) == '$') {
639 prefixWithoutDollar = prefix.substring(1);
640 isDollarPrefix = true;
642 IRegion region = new Region(start, end - start);
644 if (!isDollarPrefix) {
645 set = metaData.getTables(null, null, prefixWithoutDollar
648 // String tempSchema = set.getString("TABLE_SCHEM");
649 // tempSchema = (tempSchema == null) ? "" :
650 // tempSchema.trim();
651 tableName = set.getString("TABLE_NAME");
652 tableName = (tableName == null) ? "" : tableName.trim();
653 if (tableName != null && tableName.length() > 0) {
654 sqlList.add(new SQLProposal(tableName, context, region,
655 viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE)));
660 set = metaData.getColumns(null, null, "%",
661 prefixWithoutDollar + "%");
662 SQLProposal sqlProposal;
664 columnName = set.getString("COLUMN_NAME");
665 columnName = (columnName == null) ? "" : columnName.trim();
666 tableName = set.getString("TABLE_NAME");
667 tableName = (tableName == null) ? "" : tableName.trim();
668 if (tableName != null && tableName.length() > 0
669 && columnName != null && columnName.length() > 0) {
670 if (isDollarPrefix) {
671 sqlProposal = new SQLProposal(tableName, "$"
672 + columnName, context, region, viewer, PHPUiImages
673 .get(PHPUiImages.IMG_COLUMN));
675 sqlProposal = new SQLProposal(tableName, columnName,
676 context, region, viewer, PHPUiImages
677 .get(PHPUiImages.IMG_COLUMN));
679 if (tableName.equals(foundSQLTableName)) {
680 sqlProposal.setRelevance(90);
681 } else if (tableName.indexOf(foundSQLTableName) >= 0) {
682 sqlProposal.setRelevance(75);
684 sqlList.add(sqlProposal);
688 sqlResults = new IPHPCompletionProposal[sqlList.size()];
689 for (int i = 0; i < sqlList.size(); i++) {
690 sqlResults[i] = (SQLProposal) sqlList.get(i);
693 } catch (NotConnectedException e) {
694 // ignore this - not mission critical
695 } catch (SQLException e) {
702 // concatenate the result arrays
703 IPHPCompletionProposal[] total;
704 total = new IPHPCompletionProposal[templateResults.length
705 + identifierResults.length + builtinResults.length
706 + declarationResults.length + sqlResults.length];
707 System.arraycopy(templateResults, 0, total, 0, templateResults.length);
708 System.arraycopy(identifierResults, 0, total, templateResults.length,
709 identifierResults.length);
710 System.arraycopy(builtinResults, 0, total, templateResults.length
711 + identifierResults.length, builtinResults.length);
712 System.arraycopy(declarationResults, 0, total, templateResults.length
713 + identifierResults.length + builtinResults.length,
714 declarationResults.length);
715 System.arraycopy(sqlResults, 0, total, templateResults.length
716 + identifierResults.length + builtinResults.length
717 + declarationResults.length, sqlResults.length);
719 fNumberOfComputedResults = (results == null ? 0 : results.length);
721 * Order here and not in result collector to make sure that the order
722 * applies to all proposals and not just those of the compilation unit.
724 return order(results);
726 return new IPHPCompletionProposal[0];
729 private int guessContextInformationPosition(ITextViewer viewer, int offset) {
730 int contextPosition = offset;
731 IDocument document = viewer.getDocument();
734 // PHPCodeReader reader= new PHPCodeReader();
735 // reader.configureBackwardReader(document, offset, true, true);
737 // int nestingLevel= 0;
739 // int curr= reader.read();
740 // while (curr != PHPCodeReader.EOF) {
742 // if (')' == (char) curr)
745 // else if ('(' == (char) curr) {
748 // if (nestingLevel < 0) {
749 // int start= reader.getOffset();
750 // if (looksLikeMethod(reader))
755 // curr= reader.read();
757 // } catch (IOException e) {
759 return contextPosition;
763 * (non-Javadoc) Method declared on IContentAssistProcessor
765 // public IContextInformation[] computeContextInformation(ITextViewer viewer,
766 // int documentOffset) {
767 // IContextInformation[] result = new IContextInformation[5];
768 // for (int i = 0; i < result.length; i++)
770 // ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"),
771 // new Object[] { new Integer(i), new Integer(documentOffset)}),
773 // MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"),
774 // new Object[] { new Integer(i), new Integer(documentOffset - 5), new
775 // Integer(documentOffset + 5)})); //$NON-NLS-1$
779 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
781 public IContextInformation[] computeContextInformation(ITextViewer viewer,
783 int contextInformationPosition = guessContextInformationPosition(viewer,
785 List result = addContextInformations(viewer, contextInformationPosition);
786 return (IContextInformation[]) result
787 .toArray(new IContextInformation[result.size()]);
790 private List addContextInformations(ITextViewer viewer, int offset) {
791 ICompletionProposal[] proposals = internalComputeCompletionProposals(
793 List result = new ArrayList();
794 for (int i = 0; i < proposals.length; i++) {
795 IContextInformation contextInformation = proposals[i]
796 .getContextInformation();
797 if (contextInformation != null) {
798 ContextInformationWrapper wrapper = new ContextInformationWrapper(
800 wrapper.setContextInformationPosition(offset);
808 * Order the given proposals.
810 private ICompletionProposal[] order(ICompletionProposal[] proposals) {
811 Arrays.sort(proposals, fComparator);
816 * (non-Javadoc) Method declared on IContentAssistProcessor
818 public char[] getCompletionProposalAutoActivationCharacters() {
819 return fProposalAutoActivationSet;
820 // return null; // new char[] { '$' };
824 * (non-Javadoc) Method declared on IContentAssistProcessor
826 public char[] getContextInformationAutoActivationCharacters() {
827 return new char[] {};
831 * (non-Javadoc) Method declared on IContentAssistProcessor
833 public IContextInformationValidator getContextInformationValidator() {
838 * (non-Javadoc) Method declared on IContentAssistProcessor
840 public String getErrorMessage() {