com.intellij.patterns.StringPattern Java Examples

The following examples show how to use com.intellij.patterns.StringPattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YiiContibutorHelper.java    From yiistorm with MIT License 6 votes vote down vote up
public static PsiElementPattern.Capture<PsiElement> methodParamsList(String methodName,
                                                                     StringPattern className) {
    return PlatformPatterns.psiElement().withElementType(PhpElementTypes.PARAMETER_LIST)
            .withParent(
                    PlatformPatterns.psiElement()
                            .withElementType(PhpElementTypes.METHOD_REFERENCE)
                            .referencing(
                                    PhpPatterns.psiElement().withElementType(
                                            PhpElementTypes.CLASS_METHOD
                                    ).withName(methodName)
                                            .withParent(
                                                    PhpPatterns.psiElement().withName(
                                                            className
                                                    ))
                            )

            );
}
 
Example #2
Source File: YiiContibutorHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static PsiElementPattern.Capture firstStringInMethod(String methodName, StringPattern className) {

        return PlatformPatterns.psiElement(PsiElement.class)
                .withParent(
                        YiiContibutorHelper.methodLiteralExpression(methodName, className)
                                .insideStarting(
                                        PlatformPatterns.psiElement().withElementType(PhpElementTypes.PARAMETER_LIST)
                                )
                )
                .withLanguage(PhpLanguage.INSTANCE);

    }
 
Example #3
Source File: YiiContibutorHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static PhpElementPattern.Capture<StringLiteralExpression> methodLiteralExpression(String methodName,
                                                                                         StringPattern className) {
    return PhpPatterns.phpLiteralExpression()
            .withParent(
                    methodParamsList(methodName, className)
            );
}
 
Example #4
Source File: IndexPatternSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static List<TextRange> findContinuation(int mainRangeStartOffset, CharSequence text, IndexPattern[] allIndexPatterns, List<? extends CommentRange> commentRanges, int commentNum) {
  CommentRange commentRange = commentRanges.get(commentNum);
  int lineStartOffset = CharArrayUtil.shiftBackwardUntil(text, mainRangeStartOffset - 1, "\n") + 1;
  int lineEndOffset = CharArrayUtil.shiftForwardUntil(text, mainRangeStartOffset, "\n");
  int offsetInLine = mainRangeStartOffset - lineStartOffset;
  int maxCommentStartOffsetInLine = Math.max(0, commentRange.startOffset - lineStartOffset);
  List<TextRange> result = new ArrayList<>();
  outer:
  while (lineEndOffset < text.length()) {
    lineStartOffset = lineEndOffset + 1;
    lineEndOffset = CharArrayUtil.shiftForwardUntil(text, lineStartOffset, "\n");
    int refOffset = lineStartOffset + offsetInLine;
    int continuationStartOffset = CharArrayUtil.shiftForward(text, refOffset, lineEndOffset, WHITESPACE);
    if (continuationStartOffset == refOffset || continuationStartOffset >= lineEndOffset) break;
    if (continuationStartOffset >= commentRange.endOffset) {
      commentNum++;
      if (commentNum >= commentRanges.size()) break;
      commentRange = commentRanges.get(commentNum);
      if (continuationStartOffset < commentRange.startOffset || continuationStartOffset >= commentRange.endOffset) break;
    }
    int commentStartOffset = Math.max(lineStartOffset, commentRange.startOffset);
    int continuationEndOffset = Math.min(lineEndOffset, commentRange.endOffset);
    if (refOffset < commentStartOffset || commentStartOffset > lineStartOffset + maxCommentStartOffsetInLine ||
        CharArrayUtil.shiftBackward(text, commentStartOffset, refOffset - 1, WHITESPACE + commentRange.allowedContinuationPrefixChars) + 1 != commentStartOffset) {
      break;
    }
    CharSequence commentText = StringPattern.newBombedCharSequence(text.subSequence(commentStartOffset, continuationEndOffset));
    for (IndexPattern pattern : allIndexPatterns) {
      Pattern p = pattern.getPattern();
      if (p != null && p.matcher(commentText).find()) break outer;
    }
    result.add(new TextRange(continuationStartOffset, continuationEndOffset));
  }
  return result.isEmpty() ? Collections.emptyList() : result;
}
 
Example #5
Source File: YiiContibutorHelper.java    From yiistorm with MIT License 4 votes vote down vote up
public static PsiElementPattern.Capture stringInMethod(String methodName, StringPattern className) {
    return PlatformPatterns.psiElement(PsiElement.class)
            .withParent(YiiContibutorHelper.methodLiteralExpression(methodName, className))
            .withLanguage(PhpLanguage.INSTANCE);
}
 
Example #6
Source File: IndexPatternSearcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean collectPatternMatches(IndexPattern[] allIndexPatterns,
                                             IndexPattern indexPattern,
                                             CharSequence chars,
                                             List<? extends CommentRange> commentRanges,
                                             int commentNum,
                                             PsiFile file,
                                             TextRange range,
                                             Processor<? super IndexPatternOccurrence> consumer,
                                             TIntArrayList matches,
                                             boolean multiLine) {
  CommentRange commentRange = commentRanges.get(commentNum);
  int commentStart = commentRange.startOffset;
  int commentEnd = commentRange.endOffset;
  int commentPrefixLength = commentRange.prefixLength;
  int commentSuffixLength = commentRange.suffixLength;
  Pattern pattern = indexPattern.getPattern();
  if (pattern != null) {
    ProgressManager.checkCanceled();

    CharSequence input = StringPattern.newBombedCharSequence(new CharSequenceSubSequence(chars, commentStart - commentPrefixLength, commentEnd + commentSuffixLength));
    Matcher matcher = pattern.matcher(input);
    while (true) {
      //long time1 = System.currentTimeMillis();
      boolean found = matcher.find();
      //long time2 = System.currentTimeMillis();
      //System.out.println("scanned text of length " + (lexer.getTokenEnd() - lexer.getTokenStart() + " in " + (time2 - time1) + " ms"));

      if (!found) break;
      int suffixStartOffset = input.length() - commentSuffixLength;
      int start = fitToRange(matcher.start(), commentPrefixLength, suffixStartOffset) + commentStart - commentPrefixLength;
      int end = fitToRange(matcher.end(), commentPrefixLength, suffixStartOffset) + commentStart - commentPrefixLength;
      if (start != end) {
        if ((range == null || range.getStartOffset() <= start && end <= range.getEndOffset()) && matches.indexOf(start) == -1) {
          List<TextRange> additionalRanges = multiLine ? findContinuation(start, chars, allIndexPatterns, commentRanges, commentNum) : Collections.emptyList();
          if (range != null && !additionalRanges.isEmpty() && additionalRanges.get(additionalRanges.size() - 1).getEndOffset() > range.getEndOffset()) {
            continue;
          }
          matches.add(start);
          IndexPatternOccurrenceImpl occurrence = new IndexPatternOccurrenceImpl(file, start, end, indexPattern, additionalRanges);
          if (!consumer.process(occurrence)) {
            return false;
          }
        }
      }

      ProgressManager.checkCanceled();
    }
  }
  return true;
}
 
Example #7
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Matcher compileRegExp(FindModel model, CharSequence text) {
  Pattern pattern = model.compileRegExp();
  return pattern == null ? null : pattern.matcher(StringPattern.newBombedCharSequence(text));
}
 
Example #8
Source File: YiiReferenceContributor.java    From yiistorm with MIT License 2 votes vote down vote up
/**
 * Check file name
 *
 * @param namePattern
 * @return
 */
private PsiElementPattern.Capture<PsiElement> inFile(StringPattern namePattern) {
    return PlatformPatterns.psiElement(PsiElement.class).inFile(PlatformPatterns.psiFile().withName(namePattern));
}