コード例 #1
0
    @Override
    protected void addCompletions(
        @NotNull CompletionParameters parameters,
        ProcessingContext context,
        @NotNull CompletionResultSet result) {

      for (String[] completion :
          RegExpLanguageHosts.getInstance().getPosixCharacterClasses(parameters.getPosition())) {
        result.addElement(
            LookupElementBuilder.create(completion[0])
                .withTypeText((completion.length > 1) ? completion[1] : null)
                .withIcon(emptyIcon)
                .withInsertHandler(
                    new InsertHandler<LookupElement>() {
                      @Override
                      public void handleInsert(InsertionContext context, LookupElement item) {
                        context.setAddCompletionChar(false);
                        final Editor editor = context.getEditor();
                        final Document document = editor.getDocument();
                        final int tailOffset = context.getTailOffset();
                        if (document.getTextLength() < tailOffset + 2
                            || !document
                                .getText(new TextRange(tailOffset, tailOffset + 2))
                                .equals(":]")) {
                          document.insertString(tailOffset, ":]");
                        }
                        editor.getCaretModel().moveCaretRelatively(2, 0, false, false, true);
                      }
                    }));
      }
    }
コード例 #2
0
    @Override
    public void addCompletions(
        @NotNull final CompletionParameters parameters,
        final ProcessingContext context,
        @NotNull final CompletionResultSet result) {
      for (final String[] completion :
          RegExpLanguageHosts.getInstance().getKnownCharacterClasses(parameters.getPosition())) {
        addLookupElement(result, completion[0], completion[1], emptyIcon);
      }

      for (String[] stringArray :
          RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) {
        addLookupElement(
            result,
            "p{" + stringArray[0] + "}",
            stringArray.length > 1 ? stringArray[1] : null,
            PlatformIcons.PROPERTY_ICON);
      }
    }
コード例 #3
0
 @Override
 public void addCompletions(
     @NotNull final CompletionParameters parameters,
     final ProcessingContext context,
     @NotNull final CompletionResultSet result) {
   for (String[] stringArray :
       RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) {
     result.addElement(
         TailTypeDecorator.withTail(
             createLookupElement(stringArray[0], null, emptyIcon),
             TailType.createSimpleTailType('}')));
   }
 }
コード例 #4
0
 @Nullable
 private static RegExpLanguageHost findRegExpHost(@Nullable final PsiElement element) {
   if (element == null) {
     return null;
   }
   PsiLanguageInjectionHost host =
       InjectedLanguageManager.getInstance(element.getProject()).getInjectionHost(element);
   if (host instanceof RegExpLanguageHost) {
     return (RegExpLanguageHost) host;
   }
   if (host != null) {
     return INSTANCE.forClass(host.getClass());
   }
   return null;
 }