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

    try {

      FilterContext ctx = (FilterContext) getContext();
      TwigModelAccess model = TwigModelAccess.getDefault();

      String prefix = ctx.getPrefix();
      SourceRange range = getReplacementRange(getContext());

      Filter[] filters = model.getFilters(ctx.getSourceModule().getScriptProject());

      for (Filter filter : filters) {
        if (CodeAssistUtils.startsWithIgnoreCase(filter.getElementName(), prefix)) {

          filter.setScriptProject(ctx.getSourceModule().getScriptProject());
          reporter.reportType(filter, "", range);
        }
      }

    } catch (Exception e) {
      Logger.logException(e);
    }
  }
 protected void addReferenceInfo(ReferenceInfo info) {
   try {
     requestor.addReference(info);
   } catch (Exception e) {
     Logger.logException(e);
   }
 }
 protected void findOccurrences() {
   try {
     if (astRoot != null) {
       astRoot.traverse(this);
     }
   } catch (Exception e) {
     Logger.logException(e);
   }
 }
  @Override
  public void setSourceModule(IModuleSource sourceModule) {
    try {

      super.setSourceModule(sourceModule);

      if (TwigModelUtils.isTwigTemplate(sourceModule.getFileName()) == false) return;

      String source = sourceModule.getSourceContents();
      fRequestor.enterModule();

      final ModuleDeclaration decl = SourceParserUtil.parseSourceModule(new StringReader(source));

      decl.traverse(
          new TwigASTVisitor() {
            @Override
            public boolean visit(BlockStatement block) throws Exception {
              if (TwigCoreConstants.START_BLOCK.equals(block.getName().getValue())) {

                Variable name = block.getBlockName();

                if (name == null) {
                  return false;
                }

                List<?> statements = block.getChilds();

                MethodInfo info = new MethodInfo();
                info.nameSourceStart = name.sourceStart();
                info.nameSourceEnd = name.sourceEnd() - 1;
                info.declarationStart = block.sourceStart();

                info.name = name.getValue();
                fRequestor.enterMethod(info);

                if (statements.size() > 1) {
                  fRequestor.exitMethod(block.sourceEnd());
                }

              } else if (TwigCoreConstants.EXTENDS.equals(block.getName().getValue())) {

                Statement first = block.getFirstChild();

                if (first instanceof StringLiteral) {
                  StringLiteral parent = (StringLiteral) first;
                  String display = TwigCoreConstants.EXTENDS + " " + parent.getValue();
                  fRequestor.acceptPackage(block.sourceStart(), block.sourceEnd(), display);
                }
              }
              return false;
            }
            /*

            @Override
            public boolean visit(PrintStatement print) throws Exception
            {
                System.err.println("request print element");
                MethodInfo info = new MethodInfo();
                info.nameSourceStart = print.sourceStart();
                info.nameSourceEnd = print.sourceEnd();
                info.name = "var";
                info.declarationStart = print.sourceStart();

                fRequestor.enterMethod(info);



                return true;
            }

            @Override
            public boolean endvisit(PrintStatement s) throws Exception
            {
                fRequestor.exitMethod(s.sourceEnd());
                return true;
            }
            */

            @Override
            public boolean endvisit(BlockStatement block) throws Exception {
              if (TwigCoreConstants.END_BLOCK.equals(block.getName().getValue())) {
                fRequestor.exitMethod(block.sourceEnd());
              }
              return false;
            }

            @Override
            public boolean endvisit(Variable s) throws Exception {

              FieldInfo info = new FieldInfo();

              info.declarationStart = s.sourceStart();
              info.nameSourceStart = s.sourceStart();
              info.nameSourceEnd = s.sourceEnd();
              info.name = s.getValue();
              info.modifiers = Modifiers.AccPublic;

              fRequestor.enterField(info);

              fRequestor.exitField(s.sourceEnd());
              return false;
            }
          });

      fRequestor.exitModule(decl.sourceEnd());

    } catch (Exception e) {
      Logger.logException(e);
    }
  }