Ejemplo n.º 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);
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Runs the query to retrieve all global types
   *
   * @param context
   * @return
   * @throws BadLocationException
   */
  protected IType[] getTypes(AbstractCompletionContext context) throws BadLocationException {

    String prefix = context.getPrefix();
    if (prefix.startsWith("$")) {
      return EMPTY;
    }

    IDLTKSearchScope scope = createSearchScope();
    if (context.getCompletionRequestor().isContextInformationMode()) {
      return PhpModelAccess.getDefault()
          .findTypes(prefix, MatchRule.EXACT, trueFlag, falseFlag, scope, null);
    }

    List<IType> result = new LinkedList<IType>();
    if (prefix.length() > 1 && prefix.toUpperCase().equals(prefix)) {
      // Search by camel-case
      IType[] types =
          PhpModelAccess.getDefault()
              .findTypes(prefix, MatchRule.CAMEL_CASE, trueFlag, falseFlag, scope, null);
      result.addAll(Arrays.asList(types));
    }
    IType[] types =
        PhpModelAccess.getDefault()
            .findTypes(null, prefix, MatchRule.PREFIX, trueFlag, falseFlag, scope, null);
    if (context instanceof NamespaceMemberContext) {
      for (IType type : types) {
        if (PHPModelUtils.getFullName(type).startsWith(prefix)) {
          result.add(type);
        }
      }
    } else {
      result.addAll(Arrays.asList(types));
    }

    return (IType[]) result.toArray(new IType[result.size()]);
  }
Ejemplo n.º 3
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);
          }
        }
      }
    }
  }