<commit_before>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.documentation.render;

import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
import org.jetbrains.annotations.NotNull;

public class JavaDocRenderTest extends AbstractEditorTest {
  public void testDeleteLine() {
    configureAndRender("class C {\n" +
                       "<caret>\n" +
                       "  /** doc */\n" +
                       "  int a;\n" +
                       "}\n");
    verifyFoldingState("[FoldRegion +(10:23), placeholder='']");
    executeAction(IdeActions.ACTION_EDITOR_DELETE_LINE);
    checkResultByText("class C {\n" +
                      "<caret>  /** doc */\n" +
                      "  int a;\n" +
                      "}\n");
  }

  private void configureAndRender(@NotNull String text) {
    init(text, TestFileType.JAVA);
    DocRenderPassFactory.Items items = DocRenderPassFactory.calculateItemsToRender(getEditor().getDocument(), getFile());
    DocRenderPassFactory.applyItemsToRender(getEditor(), getProject(), items, true);
  }
}<commit_msg>IDEA-235938 Rendered representation is not updated after editing javadoc contents<commit_after>// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.documentation.render;

import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class JavaDocRenderTest extends AbstractEditorTest {
  private boolean myStoredSetting;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    myStoredSetting = EditorSettingsExternalizable.getInstance().isDocCommentRenderingEnabled();
  }

  @Override
  protected void tearDown() throws Exception {
    try {
      EditorSettingsExternalizable.getInstance().setDocCommentRenderingEnabled(myStoredSetting);
    }
    catch (Throwable e) {
      addSuppressedException(e);
    }
    finally {
      super.tearDown();
    }
  }

  public void testDeleteLine() {
    configure("class C {\n" +
              "<caret>\n" +
              "  /** doc */\n" +
              "  int a;\n" +
              "}\n", true);
    verifyFoldingState("[FoldRegion +(10:23), placeholder='']");
    executeAction(IdeActions.ACTION_EDITOR_DELETE_LINE);
    checkResultByText("class C {\n" +
                      "<caret>  /** doc */\n" +
                      "  int a;\n" +
                      "}\n");
  }

  public void testCommentModification() {
    configure("class C {\n" +
              "  /** doc */\n" +
              "  int a;<caret>\n" +
              "}\n", false);
    verifyFoldingState("[]");
    verifyItem(12, 22, null);
    toggleItem();
    verifyFoldingState("[FoldRegion +(9:22), placeholder='']");
    verifyItem(12, 22, "doc");
    toggleItem();
    verifyFoldingState("[]");
    verifyItem(12, 22, null);
    runWriteCommand(() -> getEditor().getDocument().setText(getEditor().getDocument().getText().replace("doc", "another")));
    toggleItem();
    verifyFoldingState("[FoldRegion +(9:26), placeholder='']");
    verifyItem(12, 26, "another");
  }

  private void configure(@NotNull String text, boolean enableRendering) {
    EditorSettingsExternalizable.getInstance().setDocCommentRenderingEnabled(enableRendering);
    init(text, TestFileType.JAVA);
    DocRenderPassFactory.Items items = DocRenderPassFactory.calculateItemsToRender(getEditor().getDocument(), getFile());
    DocRenderPassFactory.applyItemsToRender(getEditor(), getProject(), items, enableRendering);
  }

  private void toggleItem() {
    executeAction(IdeActions.ACTION_TOGGLE_RENDERED_DOC);
    NonBlockingReadActionImpl.waitForAsyncTaskCompletion();
  }

  private void verifyItem(int startOffset, int endOffset, @Nullable String textInContent) {
    DocRenderItem item = DocRenderItem.getItemAroundOffset(getEditor(), startOffset);
    assertNotNull("Item is not found at offset " + startOffset, item);
    assertEquals("Unexpected item start offset", startOffset, item.highlighter.getStartOffset());
    assertEquals("Unexpected item end offset", endOffset, item.highlighter.getEndOffset());
    if (textInContent == null) {
      assertNull("Unexpected inlay", item.inlay);
    }
    else {
      assertNotNull("Inlay doesn't exist", item.inlay);
      assertTrue("Unexpected rendered text: " + item.textToRender, item.textToRender != null && item.textToRender.contains(textInContent));
    }
  }
}
{'fraction_non_alphanumeric': 0.12414761331728841, 'fraction_numerical': 0.011231448054552748, 'mean_word_length': 3.4646374216651745, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4158912', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1403, 'n_words': 299}