2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.ui.text.template;
7 import java.util.ArrayList;
9 import net.sourceforge.phpdt.internal.corext.template.ContextType;
10 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
11 import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
12 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
13 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.IRegion;
17 import org.eclipse.jface.text.ITextViewer;
18 import org.eclipse.jface.text.Region;
19 //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager;
21 public class BuiltInEngine {
23 /** The context type. */
24 private ContextType fContextType;
25 /** The result proposals. */
26 private ArrayList fProposals= new ArrayList();
29 * Creates the template engine for a particular context type.
30 * See <code>TemplateContext</code> for supported context types.
32 public BuiltInEngine(ContextType contextType) {
33 // Assert.isNotNull(contextType);
34 fContextType= contextType;
38 * Empties the collector.
40 * @param viewer the text viewer
41 * @param unit the compilation unit (may be <code>null</code>)
48 * Returns the array of matching templates.
50 public IPHPCompletionProposal[] getResults() {
51 return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
55 * Inspects the context of the compilation unit around <code>completionPosition</code>
56 * and feeds the collector with proposals.
57 * @param viewer the text viewer
58 * @param completionPosition the context position in the document of the text viewer
59 * @param compilationUnit the compilation unit (may be <code>null</code>)
61 public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers)
62 //,ICompilationUnit compilationUnit)
63 //hrows JavaModelException
65 IDocument document= viewer.getDocument();
68 // if (LinkedPositionManager.hasActiveManager(document))
71 if (!(fContextType instanceof CompilationUnitContextType))
74 ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit);
75 PHPUnitContext context= (PHPUnitContext) fContextType.createContext();
76 int start= context.getStart();
77 int end= context.getEnd();
78 IRegion region= new Region(start, end - start);
80 // Template[] templates= Templates.getInstance().getTemplates();
81 String identifier = null;
82 for (int i= 0; i != identifiers.length; i++) {
83 identifier = (String) identifiers[i];
84 if (context.canEvaluate(identifier)) {
85 fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN)));