/**
* Report the different parts of a ViewPath (Bundle:Controller(/Subpath):template) to the completion engine
*/
public static void reportViewpath(ICompletionReporter reporter, ViewPath viewPath, String prefix, SourceRange range, IScriptProject project)
{
SymfonyModelAccess model = SymfonyModelAccess.getDefault();
String bundle = viewPath.getBundle();
String controller = viewPath.getController();
String template = viewPath.getTemplate();
IDLTKSearchScope projectScope = SearchEngine.createSearchScope(project);
// complete the bundle part
if (bundle == null && controller == null && template == null) {
List<Bundle> bundles = model.findBundles(project);
for (Bundle b : bundles) {
IType[] bundleTypes = PhpModelAccess.getDefault().findTypes(b.getElementName(), MatchRule.EXACT, 0, 0, projectScope, null);
if (bundleTypes.length == 1) {
ModelElement bType = (ModelElement) bundleTypes[0];
if (CodeAssistUtils.startsWithIgnoreCase(bType.getElementName(), prefix)) {
Bundle bundleType = new Bundle(bType, b.getElementName());
reporter.reportType(bundleType, ":", range);
}
}
}
// complete the controller part: "Bundle:|
} else if (controller == null && template == null) {
IType[] controllers = model.findBundleControllers(bundle, project);
for (IPath path : model.findBundleViewPaths(bundle, project)) {
IType t = null;
for (IType type : controllers) {
String pathString = path.removeLastSegments(path.segmentCount()-1).toString();
if (type.getElementName().contains(pathString)) {
t = type;
break;
}
}
if (t == null) {
continue;
}
Controller ctrl = new Controller((ModelElement)t, path.toString());
reporter.reportType(ctrl, ":", range);
}
// complete template path: "Bundle:Controller:|
} else if (bundle != null && controller != null) {
IModelElement[] templates = model.findTemplates(bundle, controller, project);
if (templates != null) {
for (IModelElement tpl : templates) {
if (CodeAssistUtils.startsWithIgnoreCase(tpl.getElementName(), prefix)) {
Template t = new Template((ModelElement) tpl, tpl.getElementName());
reporter.reportType(t, "", range);
}
}
}
// project root: "::|
} else if (bundle == null && controller == null && template != null) {
IModelElement[] templates = model.findRootTemplates(project);
if (templates != null) {
for (IModelElement tpl : templates) {
if (CodeAssistUtils.startsWithIgnoreCase(tpl.getElementName(), prefix)) {
Template t = new Template((ModelElement) tpl, tpl.getElementName());
reporter.reportType(t, "", range);
}
}
}
// bundle root: "AcmeDemoBundle::|
} else if (bundle != null && controller == null && template != null) {
IModelElement[] templates = model.findBundleRootTemplates(bundle, project);
if (templates != null) {
for (IModelElement tpl : templates) {
if (CodeAssistUtils.startsWithIgnoreCase(tpl.getElementName(), prefix)) {