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.PHPUnitContext;
11 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
12 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
13 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.jface.text.ITextViewer;
17 import org.eclipse.jface.text.Region;
18 //import org.eclipse.jdt.internal.ui.text.link.LinkedPositionManager;
20 public class BuiltInEngine {
22 /** The context type. */
23 private ContextType fContextType;
24 /** The result proposals. */
25 private ArrayList fProposals= new ArrayList();
28 * Creates the template engine for a particular context type.
29 * See <code>TemplateContext</code> for supported context types.
31 public BuiltInEngine(ContextType contextType) {
32 // Assert.isNotNull(contextType);
33 fContextType= contextType;
37 * Empties the collector.
39 * @param viewer the text viewer
40 * @param unit the compilation unit (may be <code>null</code>)
47 * Returns the array of matching templates.
49 public IPHPCompletionProposal[] getResults() {
50 return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
54 * Inspects the context of the compilation unit around <code>completionPosition</code>
55 * and feeds the collector with proposals.
56 * @param viewer the text viewer
57 * @param completionPosition the context position in the document of the text viewer
58 * @param compilationUnit the compilation unit (may be <code>null</code>)
60 public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers)
61 //,ICompilationUnit compilationUnit)
62 //hrows JavaModelException
64 IDocument document= viewer.getDocument();
67 // if (LinkedPositionManager.hasActiveManager(document))
70 if (!(fContextType instanceof CompilationUnitContextType))
73 ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition);//mpilationUnit);
74 PHPUnitContext context= (PHPUnitContext) fContextType.createContext();
75 int start= context.getStart();
76 int end= context.getEnd();
77 IRegion region= new Region(start, end - start);
79 // Template[] templates= Templates.getInstance().getTemplates();
80 String identifier = null;
81 for (int i= 0; i != identifiers.length; i++) {
82 identifier = (String) identifiers[i];
83 if (context.canEvaluate(identifier)) {
84 fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN)));