Package org.eclipse.php.internal.core.codeassist.contexts

Examples of org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext


   *            Completion context
   * @return right hand type(s) for the expression that encloses current
   *         offset
   */
  public IType[] getLeftHandType(ICompletionContext context) {
    AbstractCompletionContext aContext = (AbstractCompletionContext) context;
    int offset = aContext.getOffset();
    if (!rhTypesCache.containsKey(offset)) {

      TextSequence statementText = aContext.getStatementText();
      int triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
          statementText, statementText.length());
      triggerEnd = PHPTextSequenceUtilities.readIdentifierStartIndex(
          statementText, triggerEnd, true);
      triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
          statementText, triggerEnd);

      rhTypesCache.put(offset, CodeAssistUtils.getTypesFor(
          aContext.getSourceModule(), statementText, triggerEnd,
          offset));
    }
    return rhTypesCache.get(offset);
  }
View Full Code Here


    }
    return rhTypesCache.get(offset);
  }

  public IType[] getLeftHandType(ICompletionContext context, boolean isType) {
    AbstractCompletionContext aContext = (AbstractCompletionContext) context;
    int offset = aContext.getOffset();
    if (!rhTypesCache.containsKey(offset)) {

      TextSequence statementText = aContext.getStatementText();
      int triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
          statementText, statementText.length());
      triggerEnd = PHPTextSequenceUtilities.readIdentifierStartIndex(
          statementText, triggerEnd, true);
      triggerEnd = PHPTextSequenceUtilities.readBackwardSpaces(
          statementText, triggerEnd);

      if (isType) {
        rhTypesCache.put(offset, CodeAssistUtils.getTypesFor(
            aContext.getSourceModule(), statementText, triggerEnd,
            offset));
      } else {
        rhTypesCache.put(offset, CodeAssistUtils.getTraitsFor(
            aContext.getSourceModule(), statementText, triggerEnd,
            offset));
      }
    }
    return rhTypesCache.get(offset);
  }
View Full Code Here

    super(context);
  }

  @Override
  public void apply(ICompletionReporter reporter) throws BadLocationException {
    AbstractCompletionContext completionContext = (AbstractCompletionContext) getContext();
    if (completionContext.getPrefix() != null
        && completionContext.getPrefix().indexOf(
            NamespaceReference.NAMESPACE_SEPARATOR) >= 0) {
      return;
    }
    super.apply(reporter);
  }
View Full Code Here

  }

  public void apply(ICompletionReporter reporter) throws BadLocationException {

    ICompletionContext context = getContext();
    AbstractCompletionContext concreteContext = (AbstractCompletionContext) context;

    enclosingClass = null;
    try {
      IModelElement enclosingElement = concreteContext.getSourceModule()
          .getElementAt(concreteContext.getOffset());
      while (enclosingElement instanceof IField) {
        enclosingElement = enclosingElement.getParent();
      }
      if (enclosingElement instanceof IMethod) {
        IModelElement parent = ((IMethod) enclosingElement).getParent();
        if (parent instanceof IType) {
          enclosingClass = (IType) parent;
        }
      }
    } catch (ModelException e) {
      PHPCorePlugin.log(e);
    }

    SourceRange replaceRange = getReplacementRange(context);
    String suffix = getSuffix(concreteContext);

    IType[] types = getTypes(concreteContext);
    for (IType type : types) {
      if (!concreteContext.getCompletionRequestor()
          .isContextInformationMode()) {
        // here we use fake method,and do the real work in class
        // ParameterGuessingProposal
        IMethod ctorMethod = FakeConstructor.createFakeConstructor(
            null, type, type.equals(enclosingClass));
View Full Code Here

  }

  public void apply(ICompletionReporter reporter) throws BadLocationException {

    ICompletionContext context = getContext();
    AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
    if (abstractContext.getCompletionRequestor() instanceof IPHPCompletionRequestor) {
      IPHPCompletionRequestor phpCompletionRequestor = (IPHPCompletionRequestor) abstractContext
          .getCompletionRequestor();
      if (phpCompletionRequestor.filter(CompletionFlag.STOP_REPORT_TYPE)) {
        return;
      }
    }
    if (abstractContext.getPrefixWithoutProcessing().trim().length() == 0) {
      return;
    }
    boolean isUseContext = context instanceof UseNameContext
        && !((UseNameContext) context).isUseTrait();
    SourceRange replacementRange = getReplacementRange(abstractContext);

    IType[] types = getTypes(abstractContext);
    // now we compute type suffix in PHPCompletionProposalCollector
    String suffix = "";//$NON-NLS-1$
    String nsSuffix = getNSSuffix(abstractContext);
    int extraInfo = getExtraInfo();
    if ((abstractContext.getOffset() - abstractContext.getPrefix().length()
        - 1 >= 0)
        && (abstractContext.getDocument().getChar(
            abstractContext.getOffset()
                - abstractContext.getPrefix().length() - 1) == '\'' || abstractContext
            .getDocument().getChar(
                abstractContext.getOffset()
                    - abstractContext.getPrefix().length()
                    - 1) == '\"')) {
      extraInfo = extraInfo | ProposalExtraInfo.NO_INSERT_NAMESPACE;
    }
    if ("namespace".equals(abstractContext.getPreviousWord(1)) //$NON-NLS-1$
        || isUseContext) {
      extraInfo = extraInfo | ProposalExtraInfo.NO_INSERT_NAMESPACE;
    }

    for (IType type : types) {
View Full Code Here

    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,
View Full Code Here

  }

  public void apply(ICompletionReporter reporter) throws BadLocationException {

    ICompletionContext context = getContext();
    AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
    String prefix = abstractContext.getPrefix();

    if (prefix.length() > 0 && !prefix.startsWith("$")) { //$NON-NLS-1$
      return;
    }
    CompletionRequestor requestor = abstractContext
        .getCompletionRequestor();

    MatchRule matchRule = MatchRule.PREFIX;
    if (requestor.isContextInformationMode()) {
      matchRule = MatchRule.EXACT;
    }

    IField[] fields = null;
    if (showVarsFromOtherFiles(PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES)) {
      IDLTKSearchScope scope = createSearchScope();
      fields = PhpModelAccess.getDefault().findFields(prefix, matchRule,
          Modifiers.AccGlobal, Modifiers.AccConstant, scope, null);
    } else if (showVarsFromOtherFiles(PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES)) {
      // FIXME why we can't get $myGlobalVar from php
      // code:list($myGlobalVar) = 0;
      IDLTKSearchScope scope = createSearchScopeWithReferencedFiles(abstractContext
          .getSourceModule());
      fields = PhpModelAccess.getDefault().findFields(prefix, matchRule,
          Modifiers.AccGlobal, Modifiers.AccConstant, scope, null);
    }

    List<IField> result = new LinkedList<IField>();
    if (fields != null) {
      result.addAll(Arrays.asList(fields));
    }

    fields = PHPModelUtils.getFileFields(abstractContext.getSourceModule(),
        prefix, false, null);
    if (fields != null) {
      result.addAll(Arrays.asList(fields));
    }
    fields = result.toArray(new IField[result.size()]);

    SourceRange replaceRange = getReplacementRange(context);
    for (IModelElement var : fields) {
      reporter.reportField((IField) var, "", replaceRange, false); //$NON-NLS-1$
    }

    if (showPhpVariables) {
      PHPVersion phpVersion = abstractContext.getPhpVersion();
      for (String variable : PHPVariables.getVariables(phpVersion)) {
        if (variable.startsWith(prefix)) {
          if (!requestor.isContextInformationMode()
              || variable.length() == prefix.length()) {
            reporter.reportField(
                new FakeField((ModelElement) abstractContext
                    .getSourceModule(), variable, 0, 0),
                "", replaceRange, false); // NON-NLS-1 //$NON-NLS-1$
          }
        }
      }
View Full Code Here

  }

  @Override
  protected IDLTKSearchScope createSearchScope() {
    ICompletionContext context = getContext();
    AbstractCompletionContext abstractContext = (AbstractCompletionContext) context;
    if (abstractContext.getPrefixWithoutProcessing().trim().length() == 0) {
      ISourceModule sourceModule = ((AbstractCompletionContext) context)
          .getSourceModule();
      return SearchEngine.createSearchScope(sourceModule);
    }
    return super.createSearchScope();
View Full Code Here

    super(context);
  }

  @Override
  public void apply(ICompletionReporter reporter) throws BadLocationException {
    AbstractCompletionContext completionContext = (AbstractCompletionContext) getContext();
    if (completionContext.getPrefix() != null
        && completionContext.getPrefix().indexOf(
            NamespaceReference.NAMESPACE_SEPARATOR) >= 0) {
      return;
    }
    super.apply(reporter);
  }
View Full Code Here

  }

  @Override
  public void apply(ICompletionReporter reporter) throws BadLocationException {
    // let NamespaceNonFinalClassesStrategy to deal with namespace prefix
    AbstractCompletionContext completionContext = (AbstractCompletionContext) getContext();
    if (completionContext.getPrefix() != null
        && completionContext.getPrefix().indexOf(
            NamespaceReference.NAMESPACE_SEPARATOR) >= 0) {
      return;
    }
    super.apply(reporter);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.