Beispiel #1
0
  protected void addAlias(ICompletionReporter reporter, String suffix) throws BadLocationException {
    if (aliasAdded) {
      return;
    }
    aliasAdded = true;
    ICompletionContext context = getContext();
    AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
    if (!abstractContext.getCompletionRequestor().isContextInformationMode()) {
      // get types for alias
      String prefix = abstractContext.getPrefixWithoutProcessing();
      boolean exactMatch = false;
      if (prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) == 0) {
        return;
      } else if (prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) {
        prefix = prefix.substring(0, prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR));
        exactMatch = true;
      } else {

      }

      if (prefix.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) < 0) {
        IModuleSource module = reporter.getModule();
        org.eclipse.dltk.core.ISourceModule sourceModule =
            (org.eclipse.dltk.core.ISourceModule) module.getModelElement();
        ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
        final int offset = abstractContext.getOffset();
        IType namespace = PHPModelUtils.getCurrentNamespace(sourceModule, offset);

        final Map<String, UsePart> result =
            PHPModelUtils.getAliasToNSMap(prefix, moduleDeclaration, offset, namespace, exactMatch);
        reportAlias(reporter, suffix, abstractContext, module, result);
      }
    }
  }
Beispiel #2
0
  /**
   * Adds the self function with the relevant data to the proposals array
   *
   * @param context
   * @param reporter
   * @throws BadLocationException
   */
  protected void addSelf(AbstractCompletionContext context, ICompletionReporter reporter)
      throws BadLocationException {

    String prefix = context.getPrefix();
    SourceRange replaceRange = getReplacementRange(context);

    if (CodeAssistUtils.startsWithIgnoreCase("self", prefix)) {
      if (!context.getCompletionRequestor().isContextInformationMode()
          || prefix.length() == 4) { // "self".length()

        String suffix = getSuffix(context);

        // get the class data for "self". In case of null, the self
        // function will not be added
        IType selfClassData =
            CodeAssistUtils.getSelfClassData(context.getSourceModule(), context.getOffset());
        if (selfClassData != null) {
          try {
            IMethod ctor = null;
            for (IMethod method : selfClassData.getMethods()) {
              if (method.isConstructor()) {
                ctor = method;
                break;
              }
            }
            if (ctor != null) {
              ISourceRange sourceRange = selfClassData.getSourceRange();
              FakeMethod ctorMethod =
                  new FakeMethod(
                      (ModelElement) selfClassData,
                      "self",
                      sourceRange.getOffset(),
                      sourceRange.getLength(),
                      sourceRange.getOffset(),
                      sourceRange.getLength()) {
                    public boolean isConstructor() throws ModelException {
                      return true;
                    }
                  };
              ctorMethod.setParameters(ctor.getParameters());
              reporter.reportMethod(ctorMethod, suffix, replaceRange);
            } else {
              ISourceRange sourceRange = selfClassData.getSourceRange();
              reporter.reportMethod(
                  new FakeMethod(
                      (ModelElement) selfClassData,
                      "self",
                      sourceRange.getOffset(),
                      sourceRange.getLength(),
                      sourceRange.getOffset(),
                      sourceRange.getLength()),
                  "()",
                  replaceRange);
            }
          } catch (ModelException e) {
            PHPCorePlugin.log(e);
          }
        }
      }
    }
  }