Examples of TextSequence


Examples of org.eclipse.php.internal.core.util.text.TextSequence

          break;
        }
      }
    } catch (BadLocationException e) {
    }
    TextSequence textSequence = PHPTextSequenceUtilities
        .getStatement(lineStart,
            document.getRegionAtCharacterOffset(lineStart), true);
    if (textSequence == null) {
      return false;
    }
    String regionType = FormatterUtils.getRegionType(document,
        textSequence.getOriginalOffset(0));
    if (IndentationUtils.isRegionTypeAllowedMultiline(regionType)) {
      int statementStart = textSequence.getOriginalOffset(0);
      // we only search for opening pear in textSequence
      int bound = statementStart;
      int parenPeer = scanner.findOpeningPeer(offset - 1, bound,
          PHPHeuristicScanner.LPAREN, PHPHeuristicScanner.RPAREN);
      bound = parenPeer != -1 ? Math.max(parenPeer, bound) : bound;
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

            if (tRegion != null) {
              // Determine element name:
              int elementStart = container.getStartOffset()
                  + phpScriptRegion.getStart()
                  + tRegion.getStart();
              TextSequence statement = PHPTextSequenceUtilities
                  .getStatement(
                      elementStart + tRegion.getLength(),
                      sRegion, true);
              if (statement != null) {
                int endPosition = PHPTextSequenceUtilities
                    .readBackwardSpaces(statement,
                        statement.length());
                int startPosition = PHPTextSequenceUtilities
                    .readIdentifierStartIndex(phpVersion,
                        statement, endPosition, true);
                String elementName = statement.subSequence(
                    startPosition, endPosition).toString();
                List<IModelElement> result = new LinkedList<IModelElement>();
                for (Iterator<IModelElement> iterator = filtered
                    .iterator(); iterator.hasNext();) {
                  IModelElement modelElement = (IModelElement) iterator
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

            return EMPTY;
          }
          // Determine element name:
          int elementStart = container.getStartOffset()
              + phpScriptRegion.getStart() + tRegion.getStart();
          TextSequence statement = PHPTextSequenceUtilities
              .getStatement(elementStart + tRegion.getLength(),
                  sRegion, true);
          if (statement == null) {
            return EMPTY;
          }
          int endPosition = PHPTextSequenceUtilities
              .readBackwardSpaces(statement, statement.length());
          int startPosition = PHPTextSequenceUtilities
              .readIdentifierStartIndex(phpVersion, statement,
                  endPosition, true);
          String elementName = statement.subSequence(startPosition,
              endPosition).toString();

          // Determine previous word:
          int prevWordEnd = PHPTextSequenceUtilities
              .readBackwardSpaces(statement, startPosition);
          int prevWordStart = PHPTextSequenceUtilities
              .readIdentifierStartIndex(phpVersion, statement,
                  prevWordEnd, false);
          String prevWord = statement.subSequence(prevWordStart,
              prevWordEnd).toString();

          // Determine next word:
          ITextRegion nextRegion = tRegion;
          do {
            nextRegion = phpScriptRegion.getPhpToken(nextRegion
                .getEnd());
            if (!PHPPartitionTypes.isPHPCommentState(nextRegion
                .getType())
                && nextRegion.getType() != PHPRegionTypes.WHITESPACE) {
              break;
            }
          } while (nextRegion.getEnd() < phpScriptRegion.getLength());

          String nextWord = sDoc.get(
              container.getStartOffset()
                  + phpScriptRegion.getStart()
                  + nextRegion.getStart(),
              nextRegion.getTextLength());

          if (elementName.length() > 0) {
            IType containerType = PHPModelUtils.getCurrentType(
                sourceModule, offset);
            if (containerType == null) {
              containerType = PHPModelUtils.getCurrentNamespace(
                  sourceModule, offset);
            }

            // If we are in function declaration:
            if (FUNCTION.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$
              if (containerType != null) {
                return PHPModelUtils.getTypeMethod(
                    containerType, elementName, true);
              }
              return getFunction(sourceModule, elementName);
            }

            // If we are in class declaration:
            if (CLASS.equalsIgnoreCase(prevWord)
                || INTERFACE.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$ //$NON-NLS-2$
              if (containerType != null) {
                if (containerType.getElementName()
                    .equalsIgnoreCase(elementName)) {
                  containerType = PHPModelUtils
                      .getCurrentNamespace(sourceModule,
                          offset);
                }
                if (containerType != null) {
                  return PHPModelUtils.getTypeType(
                      containerType, elementName, true);
                }
              }
              return getClass(sourceModule, elementName);
            }

            // Class instantiation:
            if (NEW.equalsIgnoreCase(prevWord)) { //$NON-NLS-1$
              return getConstructorsIfAny(extractClasses(PHPModelUtils
                  .getTypes(elementName, sourceModule,
                      offset, cache, null)));
            }

            // Handle extends and implements:
            // Check that the statement suites the condition. If
            // class or interface keywords don't appear in the
            // beginning of the statement or they are alone there.
            boolean isClassDeclaration = false;
            if (statement.length() > 6
                && (CLASS.equals(statement.subSequence(0, 5)
                    .toString())
                    && (isClassDeclaration = true) || statement
                    .length() > 10
                    && INTERFACE.equals(statement
                        .subSequence(0, 9).toString()))) { //$NON-NLS-1$ //$NON-NLS-2$

              IModelElement[] generalizationTypes = getGeneralizationTypes(
                  sourceModule, isClassDeclaration, prevWord,
                  elementName, offset);
              if (generalizationTypes != null) {
                return generalizationTypes;
              }

              // Multiple extensions and implementations:
              int listStartPosition = PHPTextSequenceUtilities
                  .readIdentifierListStartIndex(statement,
                      endPosition);

              // Determine pre-list word:
              int preListWordEnd = PHPTextSequenceUtilities
                  .readBackwardSpaces(statement,
                      listStartPosition);
              int preListWordStart = PHPTextSequenceUtilities
                  .readIdentifierStartIndex(statement,
                      preListWordEnd, false);
              String preListWord = statement.subSequence(
                  preListWordStart, preListWordEnd)
                  .toString();

              generalizationTypes = getGeneralizationTypes(
                  sourceModule, isClassDeclaration,
                  preListWord, elementName, offset);
              if (generalizationTypes != null) {
                return generalizationTypes;
              }
            }

            // Previous trigger:
            String trigger = null;
            if (startPosition > 2) {
              trigger = statement.subSequence(startPosition - 2,
                  startPosition).toString();
            }

            // If this is variable:
            if (elementName.charAt(0) == '$'
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

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

Examples of org.eclipse.php.internal.core.util.text.TextSequence

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

Examples of org.eclipse.php.internal.core.util.text.TextSequence

   *
   * @return <code>true</code> if there are whitespace characters before the
   *         cursor
   */
  public boolean hasWhitespaceBeforeCursor() {
    TextSequence statementText = getStatementText();

    // determine whether there are whitespaces before the cursor
    int statementLength = statementText.length();
    int statementEnd = PHPTextSequenceUtilities.readBackwardSpaces(
        statementText, statementLength);
    return statementLength != statementEnd;
  }
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

   * Returns previous word before the cursor position
   *
   * @throws BadLocationException
   */
  public String getPreviousWord() throws BadLocationException {
    TextSequence statementText = getStatementText();

    int statementLength = statementText.length();
    int wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
        statementText, statementLength); // read whitespace
    int wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, wordEnd, true);
    if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
      return ""; //$NON-NLS-1$
    }
    String previousWord = statementText.subSequence(wordStart, wordEnd)
        .toString();

    if (hasWhitespaceBeforeCursor()) {
      return previousWord;
    }

    wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(statementText,
        wordStart - 1); // read whitespace
    wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, wordEnd, true);
    if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
      return ""; //$NON-NLS-1$
    }
    previousWord = statementText.subSequence(wordStart, wordEnd).toString();

    return previousWord;
  }
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

   * Returns previous word before the cursor position
   *
   * @throws BadLocationException
   */
  public String getPreviousWord(int times) throws BadLocationException {
    TextSequence statementText = getStatementText();

    int statementLength = statementText.length();
    int wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
        statementText, statementLength); // read whitespace
    int wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, wordEnd, true);

    for (int i = 0; i < times - 1; i++) {
      statementLength = wordStart;
      wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
          statementText, statementLength); // read whitespace
      wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
          phpVersion, statementText, wordEnd, true);

    }
    if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
      return ""; //$NON-NLS-1$
    }
    String previousWord = statementText.subSequence(wordStart, wordEnd)
        .toString();

    if (hasWhitespaceBeforeCursor()) {
      return previousWord;
    }

    wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(statementText,
        wordStart - 1); // read whitespace
    wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, wordEnd, true);
    if (wordStart < 0 || wordEnd < 0 || wordStart > wordEnd) {
      return ""; //$NON-NLS-1$
    }
    previousWord = statementText.subSequence(wordStart, wordEnd).toString();

    return previousWord;
  }
View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

   * Returns previous word before the cursor position
   *
   * @throws BadLocationException
   */
  public int getPreviousWordOffset(int times) throws BadLocationException {
    TextSequence statementText = getStatementText();

    int statementLength = statementText.length();
    int wordEnd = PHPTextSequenceUtilities.readBackwardSpaces(
        statementText, statementLength); // read whitespace
    int wordStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, wordEnd, true);

View Full Code Here

Examples of org.eclipse.php.internal.core.util.text.TextSequence

  public String getPrefixWithoutProcessing() {
    if (hasWhitespaceBeforeCursor()) {
      return ""; //$NON-NLS-1$
    }
    TextSequence statementText = getStatementText();
    int statementLength = statementText.length();
    int prefixEnd = PHPTextSequenceUtilities.readBackwardSpaces(
        statementText, statementLength); // read whitespace
    int prefixStart = PHPTextSequenceUtilities.readIdentifierStartIndex(
        phpVersion, statementText, prefixEnd, true);
    return statementText.subSequence(prefixStart, prefixEnd).toString();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.