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();
299 beforeLastToken = ITerminalSymbols.TokenNamethis_PHP_COMPLETION;
303 // System.out.println(scanner.toStringAction(lastToken));
304 token = scanner.getNextToken();
306 } catch (InvalidInputException e1) {
309 case ITerminalSymbols.TokenNameMINUS_GREATER:
310 // dereferencing operator '->' found
311 lastSignificantToken = ITerminalSymbols.TokenNameMINUS_GREATER;
312 if (beforeLastToken == ITerminalSymbols.TokenNameVariable) {
313 lastSignificantToken = ITerminalSymbols.TokenNameVariable;
316 case ITerminalSymbols.TokenNamenew:
317 lastSignificantToken = ITerminalSymbols.TokenNamenew;
321 } catch (BadLocationException e) {
323 return lastSignificantToken;
326 String getSQLTableName(String sqlText, int start) {
327 int tableNameStart = -1;
328 int currentCharacterPosition = start + 1;
332 ch = sqlText.charAt(currentCharacterPosition++);
333 if (tableNameStart == -1 && Character.isJavaIdentifierStart(ch)) {
334 tableNameStart = currentCharacterPosition - 1;
336 if (!Character.isJavaIdentifierPart(ch)) {
337 return sqlText.substring(tableNameStart,
338 currentCharacterPosition - 1);
342 } catch (IndexOutOfBoundsException e) {
343 if (tableNameStart >= 0) {
344 return sqlText.substring(tableNameStart, currentCharacterPosition - 1);
350 private String getLastSQLTableName(String startText) {
352 // scan for sql identifiers
354 int currentSQLPosition = startText.length();
357 boolean whiteSpace = true;
360 ch = startText.charAt(--currentSQLPosition);
361 if (ch >= 'A' && ch <= 'Z') {
363 identEnd = currentSQLPosition + 1;
365 } else if (ch >= 'a' && ch <= 'z') {
367 identEnd = currentSQLPosition + 1;
369 } else if (identEnd >= 0) {
370 ident = startText.substring(currentSQLPosition + 1, identEnd);
371 // select -- from -- where --
372 // update -- set -- where --
373 // insert into -- ( -- ) values ( -- )
374 if (ident.length() >= 4 && ident.length() <= 6) {
375 ident = ident.toLowerCase();
376 switch (ident.length()) {
378 // if (ident.equals("set")) {
379 // // System.out.println("set");
380 // token = ITerminalSymbols.TokenNameSQLset;
385 if (ident.equals("from")) {
386 // System.out.println("from");
387 token = ITerminalSymbols.TokenNameSQLfrom;
388 return getSQLTableName(startText, identEnd);
389 } else if (ident.equals("into")) {
390 // System.out.println("into");
391 token = ITerminalSymbols.TokenNameSQLinto;
392 return getSQLTableName(startText, identEnd);
396 // if (ident.equals("where")) {
397 // // System.out.println("where");
398 // token = ITerminalSymbols.TokenNameSQLwhere;
403 // if (ident.equals("select")) {
404 // // System.out.println("select");
405 // token = ITerminalSymbols.TokenNameSQLselect;
407 // } else if (ident.equals("insert")) {
408 // // System.out.println("insert");
409 // token = ITerminalSymbols.TokenNameSQLinsert;
412 if (ident.equals("update")) {
413 // System.out.println("update");
414 token = ITerminalSymbols.TokenNameSQLupdate;
415 return getSQLTableName(startText, identEnd);
417 // else if (ident.equals("values")) {
418 // // System.out.println("values");
419 // token = ITerminalSymbols.TokenNameSQLvalues;
427 } else if (Character.isWhitespace(ch)) {
432 } catch (IndexOutOfBoundsException e) {
434 return "<!--no-table-->";
438 * Detect the last significant SQL token in the text before the completion
442 private int getLastSQLToken(String startText) {
444 // scan for sql identifiers
446 int currentSQLPosition = startText.length();
449 boolean whiteSpace = true;
452 ch = startText.charAt(--currentSQLPosition);
453 if (ch >= 'A' && ch <= 'Z') {
455 identEnd = currentSQLPosition + 1;
457 } else if (ch >= 'a' && ch <= 'z') {
459 identEnd = currentSQLPosition + 1;
461 } else if (identEnd >= 0) {
462 ident = startText.substring(currentSQLPosition + 1, identEnd);
463 // select -- from -- where --
464 // update -- set -- where --
465 // insert into -- ( -- ) values ( -- )
466 if (ident.length() >= 3 && ident.length() <= 6) {
467 ident = ident.toLowerCase();
468 switch (ident.length()) {
470 if (ident.equals("set")) {
471 // System.out.println("set");
472 token = ITerminalSymbols.TokenNameSQLset;
477 if (ident.equals("from")) {
478 // System.out.println("from");
479 token = ITerminalSymbols.TokenNameSQLfrom;
482 } else if (ident.equals("into")) {
483 // System.out.println("into");
484 token = ITerminalSymbols.TokenNameSQLinto;
489 if (ident.equals("where")) {
490 // System.out.println("where");
491 token = ITerminalSymbols.TokenNameSQLwhere;
496 if (ident.equals("select")) {
497 // System.out.println("select");
498 token = ITerminalSymbols.TokenNameSQLselect;
500 } else if (ident.equals("insert")) {
501 // System.out.println("insert");
502 token = ITerminalSymbols.TokenNameSQLinsert;
504 } else if (ident.equals("update")) {
505 // System.out.println("update");
506 token = ITerminalSymbols.TokenNameSQLupdate;
508 } else if (ident.equals("values")) {
509 // System.out.println("values");
510 token = ITerminalSymbols.TokenNameSQLvalues;
518 } else if (Character.isWhitespace(ch)) {
523 } catch (IndexOutOfBoundsException e) {
525 return ITerminalSymbols.TokenNameEOF;
528 private ICompletionProposal[] internalComputeCompletionProposals(
529 ITextViewer viewer, int offset, int contextOffset) {
531 IDocument document = viewer.getDocument();
532 Object[] identifiers = null;
534 IProject project = null;
536 PHPEditor editor = null;
537 if (fEditor != null && (fEditor instanceof PHPEditor)) {
538 editor = (PHPEditor) fEditor;
539 file = ((IFileEditorInput) editor.getEditorInput()).getFile();
540 project = file.getProject();
541 // outlinePage = editor.getfOutlinePage();
542 // TODO: get the identifiers from the new model
543 // if (outlinePage instanceof PHPContentOutlinePage) {
544 // identifiers = ((PHPContentOutlinePage) outlinePage).getVariables();
549 ContextType phpContextType = ContextTypeRegistry.getInstance()
550 .getContextType("php"); //$NON-NLS-1$
551 ((CompilationUnitContextType) phpContextType).setContextParameters(
552 document, offset, 0);
553 PHPUnitContext context = (PHPUnitContext) phpContextType.createContext();
554 String prefix = context.getKey();
555 TableName sqlTable = new TableName();
556 int lastSignificantToken = getLastToken(viewer, offset, context, sqlTable);
557 boolean useClassMembers = (lastSignificantToken == ITerminalSymbols.TokenNameMINUS_GREATER)
558 || (lastSignificantToken == ITerminalSymbols.TokenNameVariable)
559 || (lastSignificantToken == ITerminalSymbols.TokenNamenew)
560 || (lastSignificantToken == ITerminalSymbols.TokenNamethis_PHP_COMPLETION);
561 boolean emptyPrefix = prefix == null || prefix.equals("");
562 if (fTemplateEngine != null) {
563 IPHPCompletionProposal[] templateResults = new IPHPCompletionProposal[0];
564 ICompletionProposal[] results;
566 fTemplateEngine.reset();
567 fTemplateEngine.complete(viewer, offset); //, unit);
568 templateResults = fTemplateEngine.getResults();
570 IPHPCompletionProposal[] identifierResults = new IPHPCompletionProposal[0];
571 if ((!useClassMembers) && identifiers != null) {
572 IdentifierEngine identifierEngine;
573 ContextType contextType = ContextTypeRegistry.getInstance()
574 .getContextType("php"); //$NON-NLS-1$
575 if (contextType != null) {
576 identifierEngine = new IdentifierEngine(contextType);
577 identifierEngine.complete(viewer, offset, identifiers);
578 identifierResults = identifierEngine.getResults();
581 // declarations stored in file project.index on project level
582 IPHPCompletionProposal[] declarationResults = new IPHPCompletionProposal[0];
583 if (project != null) {
584 DeclarationEngine declarationEngine;
585 ContextType contextType = ContextTypeRegistry.getInstance()
586 .getContextType("php"); //$NON-NLS-1$
587 if (contextType != null) {
588 IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault()
589 .getIndexManager(project);
590 SortedMap sortedMap = indexManager.getIdentifierMap();
591 declarationEngine = new DeclarationEngine(contextType,
592 lastSignificantToken, file);
593 declarationEngine.complete(viewer, offset, sortedMap);
594 declarationResults = declarationEngine.getResults();
597 // built in function names from phpsyntax.xml
598 ArrayList syntaxbuffer = PHPSyntaxRdr.getSyntaxData();
599 IPHPCompletionProposal[] builtinResults = new IPHPCompletionProposal[0];
600 if ((!useClassMembers) && syntaxbuffer != null) {
601 BuiltInEngine builtinEngine;
603 ContextType contextType = ContextTypeRegistry.getInstance()
604 .getContextType("php"); //$NON-NLS-1$
605 if (contextType != null) {
606 builtinEngine = new BuiltInEngine(contextType);
607 builtinEngine.complete(viewer, offset, syntaxbuffer);
608 builtinResults = builtinEngine.getResults();
611 IPHPCompletionProposal[] sqlResults = new IPHPCompletionProposal[0];
612 if (project != null) {
613 // Get The Database bookmark from the Quantum SQL plugin:
614 BookmarkCollection sqlBookMarks = BookmarkCollection.getInstance();
615 if (sqlBookMarks != null) {
616 String bookmarkString = Util.getMiscProjectsPreferenceValue(project,
617 IPreferenceConstants.PHP_BOOKMARK_DEFAULT);
618 if (bookmarkString != null && !bookmarkString.equals("")) {
619 Bookmark bookmark = sqlBookMarks.find(bookmarkString);
620 ArrayList sqlList = new ArrayList();
621 if (bookmark != null && !bookmark.isConnected()) {
622 new ConnectionUtil().connect(bookmark, null);
624 if (bookmark != null && bookmark.isConnected()) {
626 Connection connection = bookmark.getConnection();
627 DatabaseMetaData metaData = connection.getMetaData();
629 if (metaData != null) {
630 int start = context.getStart();
631 int end = context.getEnd();
632 String foundSQLTableName = sqlTable.getTableName();
635 String prefixWithoutDollar = prefix;
636 boolean isDollarPrefix = false;
637 if (prefix.length() > 0 && prefix.charAt(0) == '$') {
638 prefixWithoutDollar = prefix.substring(1);
639 isDollarPrefix = true;
641 IRegion region = new Region(start, end - start);
643 if (!isDollarPrefix) {
644 set = metaData.getTables(null, null, prefixWithoutDollar
647 // String tempSchema = set.getString("TABLE_SCHEM");
648 // tempSchema = (tempSchema == null) ? "" :
649 // tempSchema.trim();
650 tableName = set.getString("TABLE_NAME");
651 tableName = (tableName == null) ? "" : tableName.trim();
652 if (tableName != null && tableName.length() > 0) {
653 sqlList.add(new SQLProposal(tableName, context, region,
654 viewer, PHPUiImages.get(PHPUiImages.IMG_TABLE)));
659 set = metaData.getColumns(null, null, "%",
660 prefixWithoutDollar + "%");
661 SQLProposal sqlProposal;
663 columnName = set.getString("COLUMN_NAME");
664 columnName = (columnName == null) ? "" : columnName.trim();
665 tableName = set.getString("TABLE_NAME");
666 tableName = (tableName == null) ? "" : tableName.trim();
667 if (tableName != null && tableName.length() > 0
668 && columnName != null && columnName.length() > 0) {
669 if (isDollarPrefix) {
670 sqlProposal = new SQLProposal(tableName, "$"
671 + columnName, context, region, viewer, PHPUiImages
672 .get(PHPUiImages.IMG_COLUMN));
674 sqlProposal = new SQLProposal(tableName, columnName,
675 context, region, viewer, PHPUiImages
676 .get(PHPUiImages.IMG_COLUMN));
678 if (tableName.equals(foundSQLTableName)) {
679 sqlProposal.setRelevance(90);
680 } else if (tableName.indexOf(foundSQLTableName) >= 0) {
681 sqlProposal.setRelevance(75);
683 sqlList.add(sqlProposal);
687 sqlResults = new IPHPCompletionProposal[sqlList.size()];
688 for (int i = 0; i < sqlList.size(); i++) {
689 sqlResults[i] = (SQLProposal) sqlList.get(i);
692 } catch (NotConnectedException e) {
693 // ignore this - not mission critical
694 } catch (SQLException e) {
701 // concatenate the result arrays
702 IPHPCompletionProposal[] total;
703 total = new IPHPCompletionProposal[templateResults.length
704 + identifierResults.length + builtinResults.length
705 + declarationResults.length + sqlResults.length];
706 System.arraycopy(templateResults, 0, total, 0, templateResults.length);
707 System.arraycopy(identifierResults, 0, total, templateResults.length,
708 identifierResults.length);
709 System.arraycopy(builtinResults, 0, total, templateResults.length
710 + identifierResults.length, builtinResults.length);
711 System.arraycopy(declarationResults, 0, total, templateResults.length
712 + identifierResults.length + builtinResults.length,
713 declarationResults.length);
714 System.arraycopy(sqlResults, 0, total, templateResults.length
715 + identifierResults.length + builtinResults.length
716 + declarationResults.length, sqlResults.length);
718 fNumberOfComputedResults = (results == null ? 0 : results.length);
720 * Order here and not in result collector to make sure that the order
721 * applies to all proposals and not just those of the compilation unit.
723 return order(results);
725 return new IPHPCompletionProposal[0];
728 private int guessContextInformationPosition(ITextViewer viewer, int offset) {
729 int contextPosition = offset;
730 IDocument document = viewer.getDocument();
733 // PHPCodeReader reader= new PHPCodeReader();
734 // reader.configureBackwardReader(document, offset, true, true);
736 // int nestingLevel= 0;
738 // int curr= reader.read();
739 // while (curr != PHPCodeReader.EOF) {
741 // if (')' == (char) curr)
744 // else if ('(' == (char) curr) {
747 // if (nestingLevel < 0) {
748 // int start= reader.getOffset();
749 // if (looksLikeMethod(reader))
754 // curr= reader.read();
756 // } catch (IOException e) {
758 return contextPosition;
762 * (non-Javadoc) Method declared on IContentAssistProcessor
764 // public IContextInformation[] computeContextInformation(ITextViewer viewer,
765 // int documentOffset) {
766 // IContextInformation[] result = new IContextInformation[5];
767 // for (int i = 0; i < result.length; i++)
769 // ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"),
770 // new Object[] { new Integer(i), new Integer(documentOffset)}),
772 // MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"),
773 // new Object[] { new Integer(i), new Integer(documentOffset - 5), new
774 // Integer(documentOffset + 5)})); //$NON-NLS-1$
778 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
780 public IContextInformation[] computeContextInformation(ITextViewer viewer,
782 int contextInformationPosition = guessContextInformationPosition(viewer,
784 List result = addContextInformations(viewer, contextInformationPosition);
785 return (IContextInformation[]) result
786 .toArray(new IContextInformation[result.size()]);
789 private List addContextInformations(ITextViewer viewer, int offset) {
790 ICompletionProposal[] proposals = internalComputeCompletionProposals(
792 List result = new ArrayList();
793 for (int i = 0; i < proposals.length; i++) {
794 IContextInformation contextInformation = proposals[i]
795 .getContextInformation();
796 if (contextInformation != null) {
797 ContextInformationWrapper wrapper = new ContextInformationWrapper(
799 wrapper.setContextInformationPosition(offset);
807 * Order the given proposals.
809 private ICompletionProposal[] order(ICompletionProposal[] proposals) {
810 Arrays.sort(proposals, fComparator);
815 * (non-Javadoc) Method declared on IContentAssistProcessor
817 public char[] getCompletionProposalAutoActivationCharacters() {
818 return fProposalAutoActivationSet;
819 // return null; // new char[] { '$' };
823 * (non-Javadoc) Method declared on IContentAssistProcessor
825 public char[] getContextInformationAutoActivationCharacters() {
826 return new char[] {};
830 * (non-Javadoc) Method declared on IContentAssistProcessor
832 public IContextInformationValidator getContextInformationValidator() {
837 * (non-Javadoc) Method declared on IContentAssistProcessor
839 public String getErrorMessage() {