@Nullable
  public static <E extends PsiElement> E findArgumentList(
      PsiFile file, int offset, int lbraceOffset) {
    if (file == null) return null;
    ParameterInfoHandler[] handlers =
        ShowParameterInfoHandler.getHandlers(
            file.getProject(),
            PsiUtilCore.getLanguageAtOffset(file, offset),
            file.getViewProvider().getBaseLanguage());

    if (handlers != null) {
      for (ParameterInfoHandler handler : handlers) {
        if (handler instanceof ParameterInfoHandlerWithTabActionSupport) {
          final ParameterInfoHandlerWithTabActionSupport parameterInfoHandler2 =
              (ParameterInfoHandlerWithTabActionSupport) handler;

          // please don't remove typecast in the following line; it's required to compile the code
          // under old JDK 6 versions
          final E e =
              (E)
                  ParameterInfoUtils.findArgumentList(
                      file, offset, lbraceOffset, parameterInfoHandler2);
          if (e != null) return e;
        }
      }
    }

    return null;
  }
 @Override
 public boolean isInContext(@NotNull PsiFile file, int offset) {
   if (!PsiUtilCore.getLanguageAtOffset(file, offset).isKindOf(ErlangLanguage.INSTANCE))
     return false;
   PsiElement element = file.findElementAt(offset);
   if (element instanceof PsiWhiteSpace) {
     return false;
   }
   return element != null && isInContext(element);
 }
示例#3
0
 @Override
 public boolean isApplicable(PsiFile file, int offset, boolean wrapping) {
   PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
   if (wrapping
       || file == null
       || settings == null
       || !settings.isPostfixTemplatesEnabled()
       || PsiUtilCore.getLanguageAtOffset(file, offset) != JavaLanguage.INSTANCE) {
     return false;
   }
   return StringUtil.isNotEmpty(
       computeTemplateKeyWithoutContextChecking(file.getText(), offset + 1));
 }
  public static Set<TemplateContextType> getApplicableContextTypes(PsiFile file, int offset) {
    Set<TemplateContextType> result = getDirectlyApplicableContextTypes(file, offset);

    Language baseLanguage = file.getViewProvider().getBaseLanguage();
    if (baseLanguage != file.getLanguage()) {
      PsiFile basePsi = file.getViewProvider().getPsi(baseLanguage);
      if (basePsi != null) {
        result.addAll(getDirectlyApplicableContextTypes(basePsi, offset));
      }
    }

    // if we have, for example, a Ruby fragment in RHTML selected with its exact bounds, the file
    // language and the base
    // language will be ERb, so we won't match HTML templates for it. but they're actually valid
    Language languageAtOffset = PsiUtilCore.getLanguageAtOffset(file, offset);
    if (languageAtOffset != file.getLanguage() && languageAtOffset != baseLanguage) {
      PsiFile basePsi = file.getViewProvider().getPsi(languageAtOffset);
      if (basePsi != null) {
        result.addAll(getDirectlyApplicableContextTypes(basePsi, offset));
      }
    }

    return result;
  }
  private static void process(
      @NotNull final PsiFile file,
      @NotNull final Editor editor,
      @NotNull final Project project,
      int offset) {
    PsiElement elementAtOffset = file.findElementAt(offset);
    if (elementAtOffset == null) {
      return;
    }

    Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
    final CodeDocumentationProvider docProvider;
    final DocumentationProvider langDocumentationProvider =
        LanguageDocumentation.INSTANCE.forLanguage(language);
    if (langDocumentationProvider instanceof CompositeDocumentationProvider) {
      docProvider =
          ((CompositeDocumentationProvider) langDocumentationProvider)
              .getFirstCodeDocumentationProvider();
    } else if (langDocumentationProvider instanceof CodeDocumentationProvider) {
      docProvider = (CodeDocumentationProvider) langDocumentationProvider;
    } else {
      docProvider = null;
    }
    if (docProvider == null) {
      return;
    }

    final Pair<PsiElement, PsiComment> pair = docProvider.parseContext(elementAtOffset);
    if (pair == null) {
      return;
    }

    Commenter c = LanguageCommenters.INSTANCE.forLanguage(language);
    if (!(c instanceof CodeDocumentationAwareCommenter)) {
      return;
    }
    final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter) c;
    final Runnable task;
    if (pair.second == null || pair.second.getTextRange().isEmpty()) {
      task =
          new Runnable() {
            @Override
            public void run() {
              generateComment(pair.first, editor, docProvider, commenter, project);
            }
          };
    } else {
      final DocCommentFixer fixer = DocCommentFixer.EXTENSION.forLanguage(language);
      if (fixer == null) {
        return;
      } else {
        task =
            new Runnable() {
              @Override
              public void run() {
                fixer.fixComment(project, editor, pair.second);
              }
            };
      }
    }
    final Runnable command =
        new Runnable() {
          @Override
          public void run() {
            ApplicationManager.getApplication().runWriteAction(task);
          }
        };
    CommandProcessor.getInstance().executeCommand(project, command, "Fix documentation", null);
  }