@Override
  public boolean endvisit(ModuleDeclaration s) throws Exception {
    for (Test test : tests) {
      for (MethodDeclaration method : methods) {
        if (method.getName().equals(test.getInternalFunction())) {

          PHPMethodDeclaration phpMethod = (PHPMethodDeclaration) method;
          PHPDocBlock doc = phpMethod.getPHPDoc();

          if (doc != null) {
            test.addDoc(doc);
          }

          Logger.debugMSG(
              "indexing test tag: "
                  + test.getElementName()
                  + " with metadata: "
                  + test.getMetadata());

          ReferenceInfo info =
              new ReferenceInfo(
                  ITwigModelElement.TEST, 0, 0, test.getElementName(), test.getMetadata(), null);
          addReferenceInfo(info);
        }
      }
    }

    for (Function function : functions) {

      for (MethodDeclaration method : methods) {

        if (method.getName().equals(function.getInternalFunction())) {

          PHPMethodDeclaration phpMethod = (PHPMethodDeclaration) method;
          PHPDocBlock doc = phpMethod.getPHPDoc();

          if (doc != null) {
            function.addDoc(doc);
          }

          function.addArgs(method.getArguments());

          Logger.debugMSG(
              "indexing function: "
                  + function.getElementName()
                  + " with metadata: "
                  + function.getMetadata());
          ReferenceInfo info =
              new ReferenceInfo(
                  ITwigModelElement.FUNCTION,
                  0,
                  0,
                  function.getElementName(),
                  function.getMetadata(),
                  null);
          addReferenceInfo(info);
        }
      }
    }

    for (Filter filter : filters) {

      for (MethodDeclaration method : methods) {

        if (method.getName().equals(filter.getInternalFunction())) {

          PHPMethodDeclaration phpMethod = (PHPMethodDeclaration) method;
          PHPDocBlock doc = phpMethod.getPHPDoc();

          if (doc != null) {
            filter.addDoc(doc);
          }

          filter.addArgs(method.getArguments());

          Logger.debugMSG(
              "indexing filter: "
                  + filter.getElementName()
                  + " with metadata: "
                  + filter.getMetadata());
          ReferenceInfo info =
              new ReferenceInfo(
                  ITwigModelElement.FILTER,
                  0,
                  0,
                  filter.getElementName(),
                  filter.getMetadata(),
                  null);
          addReferenceInfo(info);
        }
      }
    }

    return true;
  }
  @SuppressWarnings("unchecked")
  @Override
  public boolean endvisit(TypeDeclaration s) throws Exception {
    if (s instanceof ClassDeclaration) {
      if (tag != null) {
        if (tag.getStartTag() != null) {

          int length = currentClass.sourceEnd() - currentClass.sourceStart();
          PHPDocBlock block = currentClass.getPHPDoc();
          String desc = "";
          if (block != null) {
            String shortDesc =
                block.getShortDescription() != null ? block.getShortDescription() : "";
            String longDesc = block.getLongDescription() != null ? block.getLongDescription() : "";
            desc = shortDesc + longDesc;
          }

          String endTag = tag.getEndTag();

          JSONObject metadata = new JSONObject();
          metadata.put(TwigType.PHPCLASS, currentClass.getName());
          metadata.put(TwigType.DOC, desc);
          metadata.put(TwigType.IS_OPEN_CLOSE, endTag != null);

          Logger.debugMSG(
              "indexing twig tag: "
                  + tag.getStartTag()
                  + " : "
                  + tag.getEndTag()
                  + " with metadata: "
                  + metadata.toString());

          ReferenceInfo info =
              new ReferenceInfo(
                  ITwigModelElement.START_TAG,
                  currentClass.sourceStart(),
                  length,
                  tag.getStartTag(),
                  metadata.toString(),
                  null);
          addReferenceInfo(info);

          if (endTag != null) {
            ReferenceInfo endIinfo =
                new ReferenceInfo(
                    ITwigModelElement.END_TAG,
                    currentClass.sourceStart(),
                    length,
                    tag.getEndTag(),
                    metadata.toString(),
                    null);
            addReferenceInfo(endIinfo);
          }
        }
        tag = null;
      }

      inTwigExtension = false;
      inTokenParser = false;
      currentClass = null;
    }

    return false;
  }