Пример #1
0
    private void doVisitElement(PsiElement element) {
      CompiledPattern pattern = myGlobalVisitor.getContext().getPattern();

      if (myGlobalVisitor.getCodeBlockLevel() == 0) {
        initTopLevelElement(element);
        return;
      }

      if (canBePatternVariable(element) && pattern.isRealTypedVar(element)) {
        myGlobalVisitor.handle(element);
        final MatchingHandler handler = pattern.getHandler(element);
        handler.setFilter(
            new NodeFilter() {
              public boolean accepts(PsiElement other) {
                return canBePatternVariableValue(other);
              }
            });

        super.visitElement(element);

        return;
      }

      super.visitElement(element);

      if (myGlobalVisitor.getContext().getSearchHelper().doOptimizing()
          && element instanceof LeafElement) {
        ParserDefinition parserDefinition =
            LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
        if (parserDefinition != null) {
          String text = element.getText();

          // todo: support variables inside comments
          boolean flag = true;
          if (StringUtil.isJavaIdentifier(text) && flag) {
            myGlobalVisitor.processTokenizedName(
                text, true, GlobalCompilingVisitor.OccurenceKind.CODE);
          }
        }
      }
    }
Пример #2
0
    public void visitLiteral(PsiElement literal) {
      final PsiElement l2 = myGlobalVisitor.getElement();

      MatchingHandler handler = (MatchingHandler) literal.getUserData(CompiledPattern.HANDLER_KEY);

      if (handler instanceof SubstitutionHandler) {
        int offset = 0;
        int length = l2.getTextLength();
        final String text = l2.getText();

        if (length > 2 && (text.charAt(0) == '"' && text.charAt(length - 1) == '"')
            || (text.charAt(0) == '\'' && text.charAt(length - 1) == '\'')) {
          length--;
          offset++;
        }
        myGlobalVisitor.setResult(
            ((SubstitutionHandler) handler)
                .handle(l2, offset, length, myGlobalVisitor.getMatchContext()));
      } else if (handler != null) {
        myGlobalVisitor.setResult(handler.match(literal, l2, myGlobalVisitor.getMatchContext()));
      } else {
        myGlobalVisitor.setResult(literal.textMatches(l2));
      }
    }