@Override
  public void apply(ICompletionReporter reporter) throws BadLocationException {

    ViewPathArgumentContext context = (ViewPathArgumentContext) getContext();
    CompletionRequestor req = context.getCompletionRequestor();

    if (req.getClass() == PHPCompletionProposalCollector.class) {
      return;
    }

    if (workaroundCount == 0) {
      workaroundCount++;

    } else {
      workaroundCount = 0;
      return;
    }

    SymfonyModelAccess model = SymfonyModelAccess.getDefault();
    ISourceModule module = context.getSourceModule();
    ViewPath viewPath = context.getViewPath();

    String bundle = viewPath.getBundle();
    String controller = viewPath.getController();
    String template = viewPath.getTemplate();
    SourceRange range = getReplacementRange(context);
    IDLTKSearchScope projectScope =
        SearchEngine.createSearchScope(context.getSourceModule().getScriptProject());

    String prefix = context.getPrefix();

    // complete the bundle part
    if (bundle == null && controller == null && template == null) {

      List<Bundle> bundles = model.findBundles(context.getSourceModule().getScriptProject());

      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, module.getScriptProject());

      if (controllers != null) {
        for (IType ctrl : controllers) {

          String name = ctrl.getElementName().replace("Controller", "");
          if (!name.endsWith("\\")) {
            Controller con = new Controller((ModelElement) ctrl, name);
            reporter.reportType(con, ":", range);
          }
        }
      }

      // complete template path: "Bundle:Controller:|
    } else if (bundle != null && controller != null && template == null) {

      IModelElement[] templates =
          model.findTemplates(bundle, controller, module.getScriptProject());

      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(module.getScriptProject());

      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, module.getScriptProject());

      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);
          }
        }
      }
    }
  }
  public void apply(ICompletionReporter reporter) throws BadLocationException, ModelException {
    ICompletionContext context = getContext();
    if (!(context instanceof GlobalMethodStatementContext)) {
      return;
    }

    GlobalMethodStatementContext concreteContext = (GlobalMethodStatementContext) context;
    CompletionRequestor requestor = concreteContext.getCompletionRequestor();
    String prefix = concreteContext.getPrefix();

    String suffix = getSuffix(concreteContext);
    ISourceRange replaceRange = null;
    if (suffix.equals("")) { // $NON-NLS-1$
      replaceRange = getReplacementRange(concreteContext);
    } else {
      replaceRange = getReplacementRangeWithBraces(concreteContext);
    }
    replaceRange = getReplacementRange(context);

    IMethod enclosingMethod = concreteContext.getEnclosingMethod();

    // complete class variable: $this
    if (!PHPFlags.isStatic(enclosingMethod.getFlags())) {
      IType declaringType = enclosingMethod.getDeclaringType();
      if (declaringType != null) {
        if (THIS.startsWith(prefix)) { // $NON-NLS-1$
          reporter.reportField(
              new FakeField((ModelElement) declaringType, THIS, 0, 0),
              suffix,
              replaceRange,
              false,
              ICompletionReporter.RELEVANCE_ADJUST); // NON-NLS-1 //$NON-NLS-2$
        }
      } else {
        if (enclosingMethod.getParent() instanceof IField
            && concreteContext.getPhpVersion().isGreaterThan(PHPVersion.PHP5_3)) {
          IMethod method = (IMethod) enclosingMethod.getParent().getAncestor(IModelElement.METHOD);
          if (method != null) {
            declaringType = method.getDeclaringType();
            if (declaringType != null && THIS.startsWith(prefix)) { // $NON-NLS-1$
              reporter.reportField(
                  new FakeField((ModelElement) declaringType, THIS, 0, 0),
                  suffix,
                  replaceRange,
                  false,
                  ICompletionReporter.RELEVANCE_ADJUST); // NON-NLS-1 //$NON-NLS-2$
            }
          }
        }
      }
    }

    for (IModelElement element :
        PHPModelUtils.getMethodFields(
            enclosingMethod, prefix, requestor.isContextInformationMode(), null)) {
      reporter.reportField(
          (IField) element,
          "",
          replaceRange,
          false, //$NON-NLS-1$
          ICompletionReporter.RELEVANCE_ADJUST);
    }

    PHPVersion phpVersion = concreteContext.getPhpVersion();
    for (String variable : PHPVariables.getVariables(phpVersion)) {
      if (variable.startsWith(prefix)) {
        if (!requestor.isContextInformationMode() || variable.length() == prefix.length()) {
          reporter.reportField(
              new FakeField((ModelElement) concreteContext.getSourceModule(), variable, 0, 0),
              "",
              replaceRange,
              false, //$NON-NLS-1$
              -ICompletionReporter.RELEVANCE_ADJUST); // NON-NLS-1
        }
      }
    }
  }