import java.util.ArrayList;
-import net.sourceforge.phpdt.internal.corext.template.ContextType;
+import net.sourceforge.phpdt.core.ICompilationUnit;
import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
-import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
-import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import net.sourceforge.phpdt.internal.corext.template.php.JavaContext;
+import net.sourceforge.phpdt.internal.corext.template.php.JavaContextType;
import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPElement;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPFunction;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
public class BuiltInEngine {
/** The context type. */
- private ContextType fContextType;
+ private JavaContextType fContextType;
/** The result proposals. */
private ArrayList fProposals = new ArrayList();
* Creates the template engine for a particular context type.
* See <code>TemplateContext</code> for supported context types.
*/
- public BuiltInEngine(ContextType contextType) {
+ public BuiltInEngine(JavaContextType contextType) {
// Assert.isNotNull(contextType);
fContextType = contextType;
}
* @param completionPosition the context position in the document of the text viewer
* @param compilationUnit the compilation unit (may be <code>null</code>)
*/
- public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers)
- //,ICompilationUnit compilationUnit)
+ public void complete(ITextViewer viewer, int completionPosition, ArrayList identifiers,ICompilationUnit compilationUnit)
//hrows JavaModelException
{
IDocument document = viewer.getDocument();
}
}
- ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
-
- PHPUnitContext context = (PHPUnitContext) fContextType.createContext();
+// ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
+// JavaContext context = (JavaContext) fContextType.createContext();
+ JavaContext context = (JavaContext) fContextType.createContext(document, completionPosition,selection.y,compilationUnit);
+ context.setVariable("selection", selectedText); //$NON-NLS-1$
int start = context.getStart();
int end = context.getEnd();
IRegion region = new Region(start, end - start);
// Template[] templates= Templates.getInstance().getTemplates();
String identifier = null;
int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
- for (int i = 0; i != identifiers.length; i++) {
- identifier = (String) identifiers[i];
- if (context.canEvaluate(identifier)) {
- if (maxProposals-- < 0) {
- return;
+ PHPElement element = null;
+ for (int i = 0; i != identifiers.size(); i++) {
+ element = (PHPElement) identifiers.get(i);
+ if (element instanceof PHPFunction) {
+ identifier = ((PHPFunction) element).getName();
+ if (context.canEvaluate(identifier)) {
+ if (maxProposals-- < 0) {
+ return;
+ }
+ fProposals.add(new BuiltInProposal(identifier, (PHPFunction) element, context, region, viewer));
}
- fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN)));
}
}
}