protected String processTypeName(IType type, String token) {
   return type.getElementName();
 }
  private void initRelativeNamespace(ISourceModule sourceModule, int offset, String lastWord) {
    String nsName = lastWord;
    String fullName = lastWord;
    nsPrefix = null;
    if (lastWord.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) {
      nsPrefix =
          lastWord.substring(0, lastWord.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR));
      nsName = nsName.substring(0, nsName.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR) + 1);

      try {
        namespaces = PHPModelUtils.getNamespaceOf(nsName, sourceModule, offset, null, null);
      } catch (ModelException e) {
        if (DLTKCore.DEBUG) {
          e.printStackTrace();
        }
      }
    } else {
      namespaces = PhpModelAccess.NULL_TYPES;
    }
    if (lastWord.startsWith(NamespaceReference.NAMESPACE_DELIMITER)) {
      nsPrefix = null;
    } else {

      currentNS = null;
      try {
        IModelElement enclosingElement = getEnclosingElement();
        if (enclosingElement != null) {
          IType type = (IType) enclosingElement.getAncestor(IModelElement.TYPE);
          if (type != null && type.getParent() instanceof IType) {
            type = (IType) type.getParent();
          }
          if (type != null && (PHPFlags.isNamespace(type.getFlags()))) {
            currentNS = type;
            fullName =
                NamespaceReference.NAMESPACE_SEPARATOR
                    + currentNS.getElementName()
                    + NamespaceReference.NAMESPACE_SEPARATOR
                    + lastWord;
          } else {

          }
        }
      } catch (ModelException e1) {
        e1.printStackTrace();
      }
      if (currentNS != null) {
        if (nsPrefix == null) {
          nsPrefix = currentNS.getElementName();
        } else {
          nsPrefix = currentNS.getElementName() + NamespaceReference.NAMESPACE_SEPARATOR + nsPrefix;
        }
      }
    }

    IDLTKSearchScope scope = SearchEngine.createSearchScope(sourceModule.getScriptProject());
    if (fullName.startsWith(NamespaceReference.NAMESPACE_DELIMITER)) {
      fullName = fullName.substring(1);
    }
    possibleNamespaces =
        PhpModelAccess.getDefault()
            .findNamespaces(null, fullName, MatchRule.PREFIX, 0, 0, scope, null);
  }
 public String getTypeName() {
   if (fClass != null) {
     return "class:" + fClass.getElementName(); // $NON-NLS-1$
   }
   return "class: !!unknown!!"; //$NON-NLS-1$
 }
 /**
  * Get Record type def from {@link ISourceModule} <br>
  * DLTK Model => AST
  */
 public static TypeDef getTypeDef(IType type) {
   LuaSourceRoot luaSourceRoot = getLuaSourceRoot(type.getSourceModule());
   LuaFileAPI fileapi = luaSourceRoot.getFileapi();
   return fileapi.getTypes().get(type.getElementName());
 }
  @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);
          }
        }
      }
    }
  }