Java Code Examples for com.intellij.codeInsight.CodeInsightSettings#getInstance()

The following examples show how to use com.intellij.codeInsight.CodeInsightSettings#getInstance() . 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: TabOutScopesTrackerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int checkOrRemoveScopeEndingAt(@Nonnull Editor editor, int offset, boolean removeScope) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  if (!CodeInsightSettings.getInstance().TAB_EXITS_BRACKETS_AND_QUOTES) return 0;

  if (editor instanceof EditorWindow) {
    DocumentWindow documentWindow = ((EditorWindow)editor).getDocument();
    offset = documentWindow.injectedToHost(offset);
    editor = ((EditorWindow)editor).getDelegate();
  }
  if (!(editor instanceof DesktopEditorImpl)) return 0;

  Tracker tracker = Tracker.forEditor((DesktopEditorImpl)editor, false);
  if (tracker == null) return 0;

  return tracker.getCaretShiftForScopeEndingAt(offset, removeScope);
}
 
Example 2
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MinusculeMatcher createMatcher(final boolean caseSensitive) {
  String prefix = applyMiddleMatching(myPrefix);

  NameUtil.MatcherBuilder builder = NameUtil.buildMatcher(prefix);
  if (caseSensitive) {
    int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
    if (setting == CodeInsightSettings.FIRST_LETTER) {
      builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
    }
    else if (setting == CodeInsightSettings.ALL) {
      builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.ALL);
    }
  }
  if (myTypoTolerant) {
    builder = builder.typoTolerant();
  }
  return builder.build();
}
 
Example 3
Source File: EditorSmartKeysConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void apply(@Nonnull Panel panel) throws ConfigurationException {
  EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  editorSettings.setSmartHome(panel.myCbSmartHome.getValue());
  codeInsightSettings.SMART_END_ACTION = panel.myCbSmartEnd.getValue();
  codeInsightSettings.SMART_INDENT_ON_ENTER = panel.myCbSmartIndentOnEnter.getValue();
  codeInsightSettings.INSERT_BRACE_ON_ENTER = panel.myCbInsertPairCurlyBraceOnEnter.getValue();
  codeInsightSettings.INDENT_TO_CARET_ON_PASTE = panel.mySmartIndentPastedLinesCheckBox.getValue();
  codeInsightSettings.JAVADOC_STUB_ON_ENTER = panel.myCbInsertJavadocStubOnEnter.getValue();
  codeInsightSettings.AUTOINSERT_PAIR_BRACKET = panel.myCbInsertPairBracket.getValue();
  codeInsightSettings.AUTOINSERT_PAIR_QUOTE = panel.myCbInsertPairQuote.getValue();
  codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE = panel.myCbReformatBlockOnTypingRBrace.getValue();
  codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED = panel.myCbSurroundSelectionOnTyping.getValue();
  editorSettings.setCamelWords(panel.myCbCamelWords.getValue());
  codeInsightSettings.REFORMAT_ON_PASTE = panel.myReformatOnPasteCombo.getValue();
  codeInsightSettings.setBackspaceMode(panel.myCbIndentingBackspace.getValue());
}
 
Example 4
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void apply() {

    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

    codeInsightSettings.COMPLETION_CASE_SENSITIVE = getCaseSensitiveValue();

    codeInsightSettings.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = myCbSelectByChars.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION = myCbOnCodeCompletion.isSelected();
    codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = myCbOnSmartTypeCompletion.isSelected();
    codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO = myCbShowFullParameterSignatures.isSelected();

    codeInsightSettings.AUTO_POPUP_PARAMETER_INFO = myCbParameterInfoPopup.isSelected();
    codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP = myCbAutocompletion.isSelected();
    codeInsightSettings.AUTO_POPUP_JAVADOC_INFO = myCbAutopopupJavaDoc.isSelected();

    codeInsightSettings.PARAMETER_INFO_DELAY = getIntegerValue(myParameterInfoDelayField.getText(), 0);
    codeInsightSettings.JAVADOC_INFO_DELAY = getIntegerValue(myAutopopupJavaDocField.getText(), 0);

    UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = myCbSorting.isSelected();

    final Project project = DataManager.getInstance().getDataContext(myPanel).getData(CommonDataKeys.PROJECT);
    if (project != null){
      DaemonCodeAnalyzer.getInstance(project).settingsChanged();
    }
  }
 
Example 5
Source File: LiveTemplateCharFilter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Result acceptChar(char c, int prefixLength, Lookup lookup) {
  LookupElement item = lookup.getCurrentItem();
  if (item instanceof LiveTemplateLookupElement && lookup.isCompletion()) {
    if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX;

    if (c == ((LiveTemplateLookupElement)item).getTemplateShortcut()) {
      return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
    }
    return Result.HIDE_LOOKUP;
  }
  if (item instanceof TemplateExpressionLookupElement) {
    if (Character.isJavaIdentifierPart(c)) return Result.ADD_TO_PREFIX;
    if (CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS) {
      return null;
    }
    return Result.HIDE_LOOKUP;
  }

  return null;
}
 
Example 6
Source File: HaxeTypedHandler.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public Result beforeCharTyped(char c,
                              Project project,
                              Editor editor,
                              PsiFile file,
                              FileType fileType) {
  if (c == '<') {
    myAfterTypeOrComponentName = checkAfterTypeOrComponentName(file, editor.getCaretModel().getOffset());
  }
  if (c == '{') {
    myAfterDollar = checkAfterDollarInString(file, editor.getCaretModel().getOffset());
  }
  if (c == '>') {
    if (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET &&
        JavaTypedHandler.handleJavaGT(editor, HaxeTokenTypes.OLESS, HaxeTokenTypes.OGREATER, INVALID_INSIDE_REFERENCE)) {
      return Result.STOP;
    }
  }
  return super.beforeCharTyped(c, project, editor, file, fileType);
}
 
Example 7
Source File: EditorSmartKeysConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void reset(@Nonnull Panel panel) {
  EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  panel.myReformatOnPasteCombo.setValue(codeInsightSettings.REFORMAT_ON_PASTE);

  panel.myCbSmartHome.setValue(editorSettings.isSmartHome());
  panel.myCbSmartEnd.setValue(codeInsightSettings.SMART_END_ACTION);

  panel.myCbSmartIndentOnEnter.setValue(codeInsightSettings.SMART_INDENT_ON_ENTER);
  panel.myCbInsertPairCurlyBraceOnEnter.setValue(codeInsightSettings.INSERT_BRACE_ON_ENTER);
  panel.myCbInsertJavadocStubOnEnter.setValue(codeInsightSettings.JAVADOC_STUB_ON_ENTER);

  panel.myCbInsertPairBracket.setValue(codeInsightSettings.AUTOINSERT_PAIR_BRACKET);
  panel.mySmartIndentPastedLinesCheckBox.setValue(codeInsightSettings.INDENT_TO_CARET_ON_PASTE);
  panel.myCbInsertPairQuote.setValue(codeInsightSettings.AUTOINSERT_PAIR_QUOTE);
  panel.myCbReformatBlockOnTypingRBrace.setValue(codeInsightSettings.REFORMAT_BLOCK_ON_RBRACE);
  panel.myCbCamelWords.setValue(editorSettings.isCamelWords());

  panel.myCbSurroundSelectionOnTyping.setValue(codeInsightSettings.SURROUND_SELECTION_ON_QUOTE_TYPED);

  panel.myCbIndentingBackspace.setValue(codeInsightSettings.getBackspaceMode());
}
 
Example 8
Source File: CodeCompletionPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void reset() {
  CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();

  final String value;
  switch(codeInsightSettings.COMPLETION_CASE_SENSITIVE){
    case CodeInsightSettings.ALL:
      value = CASE_SENSITIVE_ALL;
      break;

    case CodeInsightSettings.NONE:
      value = CASE_SENSITIVE_NONE;
      break;

    default:
      value = CASE_SENSITIVE_FIRST_LETTER;
      break;
  }
  myCaseSensitiveCombo.setSelectedItem(value);

  myCbSelectByChars.setSelected(codeInsightSettings.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS);

  myCbOnCodeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_CODE_COMPLETION);
  myCbOnSmartTypeCompletion.setSelected(codeInsightSettings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION);

  myCbAutocompletion.setSelected(codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP);

  myCbAutopopupJavaDoc.setSelected(codeInsightSettings.AUTO_POPUP_JAVADOC_INFO);
  myAutopopupJavaDocField.setEnabled(codeInsightSettings.AUTO_POPUP_JAVADOC_INFO);
  myAutopopupJavaDocField.setText(String.valueOf(codeInsightSettings.JAVADOC_INFO_DELAY));

  myCbParameterInfoPopup.setSelected(codeInsightSettings.AUTO_POPUP_PARAMETER_INFO);
  myParameterInfoDelayField.setEnabled(codeInsightSettings.AUTO_POPUP_PARAMETER_INFO);
  myParameterInfoDelayField.setText(String.valueOf(codeInsightSettings.PARAMETER_INFO_DELAY));
  myCbShowFullParameterSignatures.setSelected(codeInsightSettings.SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO);

  myCbAutocompletion.setSelected(codeInsightSettings.AUTO_POPUP_COMPLETION_LOOKUP);
  myCbSorting.setSelected(UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY);

  myCbAutocompletion.setText("Autopopup code completion" + (PowerSaveMode.isEnabled() ? " (not available in Power Save mode)" : ""));
}
 
Example 9
Source File: BashUnmatchedBraceEnterProcessorTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyFile() throws Exception {
    boolean previous = CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER;
    CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER = true;

    try {
        myFixture.configureByText(BashFileType.BASH_FILE_TYPE, "abc");
        myFixture.type("\n");
    } finally {
        CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER = previous;
    }
}
 
Example 10
Source File: AbstractCompletionTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = oldBasic;
    CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = oldSmart;

    super.tearDown();
}
 
Example 11
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void moveToParameterAtOffset(int offset) {
  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
  PsiElement argsList = findArgumentList(file, offset, -1);
  if (argsList == null && !CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION) return;

  if (!myHint.isVisible()) AutoPopupController.getInstance(myProject).autoPopupParameterInfo(myEditor, null);

 offset = adjustOffsetToInlay(offset);
  myEditor.getCaretModel().moveToOffset(offset);
  myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  myEditor.getSelectionModel().removeSelection();
  if (argsList != null) {
    executeUpdateParameterInfo(argsList, new MyUpdateParameterInfoContext(offset, file), null);
  }
}
 
Example 12
Source File: CamelHumpMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean prefixMatches(@Nonnull final String name) {
  if (name.startsWith("_") && CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE == CodeInsightSettings.FIRST_LETTER && firstLetterCaseDiffers(name)) {
    return false;
  }

  return myMatcher.matches(name);
}
 
Example 13
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private BraceHighlightingHandler(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Alarm alarm, PsiFile psiFile) {
  myProject = project;

  myEditor = editor;
  myAlarm = alarm;
  myDocument = (DocumentEx)myEditor.getDocument();

  myPsiFile = psiFile;
  myCodeInsightSettings = CodeInsightSettings.getInstance();
}
 
Example 14
Source File: CSharpParametersInfo.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static ParameterPresentationBuilder<CSharpSimpleParameterInfo> build(@Nonnull CSharpSimpleLikeMethod callable, @Nonnull PsiElement scope)
{
	CSharpSimpleParameterInfo[] parameters = callable.getParameterInfos();
	DotNetTypeRef returnType = callable.getReturnTypeRef();

	char[] bounds = getOpenAndCloseTokens(callable);

	ParameterPresentationBuilder<CSharpSimpleParameterInfo> builder = new ParameterPresentationBuilder<>();

	if(CodeInsightSettings.getInstance().SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO)
	{
		if(callable instanceof CSharpConstructorDeclaration)
		{
			builder.add(((CSharpConstructorDeclaration) callable).getName());
		}
		else if(callable instanceof PsiNamedElement)
		{
			builder.add(CSharpTypeRefPresentationUtil.buildShortText(returnType, scope));

			builder.addSpace();

			builder.add(((PsiNamedElement) callable).getName());
		}

		builder.addEscaped(String.valueOf(bounds[0]));
	}

	if(parameters.length > 0)
	{
		for(int i = 0; i < parameters.length; i++)
		{
			if(i != 0)
			{
				builder.add(", ");
			}

			CSharpSimpleParameterInfo parameter = parameters[i];
			try (AccessToken ignored = builder.beginParameter(i))
			{
				buildParameter(builder, parameter, scope);
			}
		}
	}
	else
	{
		try (AccessToken ignored = builder.beginParameter(0))
		{
			builder.add("<no parameters>");
		}
	}

	if(CodeInsightSettings.getInstance().SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO)
	{
		builder.addEscaped(String.valueOf(bounds[1]));
	}

	return builder;
}
 
Example 15
Source File: EndHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void doExecute(@Nonnull final Editor editor, Caret caret, DataContext dataContext) {
  CodeInsightSettings settings = CodeInsightSettings.getInstance();
  if (!settings.SMART_END_ACTION) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, caret, dataContext);
    }
    return;
  }

  final Project project = DataManager.getInstance().getDataContext(editor.getComponent()).getData(CommonDataKeys.PROJECT);
  if (project == null) {
    if (myOriginalHandler != null) {
      myOriginalHandler.execute(editor, caret, dataContext);
    }
    return;
  }
  final Document document = editor.getDocument();
  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);

  if (file == null) {
    if (myOriginalHandler != null){
      myOriginalHandler.execute(editor, caret, dataContext);
    }
    return;
  }

  final EditorNavigationDelegate[] extensions = EditorNavigationDelegate.EP_NAME.getExtensions();
  for (EditorNavigationDelegate delegate : extensions) {
    if (delegate.navigateToLineEnd(editor, dataContext) == EditorNavigationDelegate.Result.STOP) {
      return;
    }
  }

  final CaretModel caretModel = editor.getCaretModel();
  final int caretOffset = caretModel.getOffset();
  CharSequence chars = editor.getDocument().getCharsSequence();
  int length = editor.getDocument().getTextLength();

  if (caretOffset < length) {
    final int offset1 = CharArrayUtil.shiftBackward(chars, caretOffset - 1, " \t");
    if (offset1 < 0 || chars.charAt(offset1) == '\n' || chars.charAt(offset1) == '\r') {
      final int offset2 = CharArrayUtil.shiftForward(chars, offset1 + 1, " \t");
      boolean isEmptyLine = offset2 >= length || chars.charAt(offset2) == '\n' || chars.charAt(offset2) == '\r';
      if (isEmptyLine) {

        // There is a possible case that indent string is not calculated for particular document (that is true at least for plain text
        // documents). Hence, we check that and don't finish processing in case we have such a situation.
        boolean stopProcessing = true;
        PsiDocumentManager.getInstance(project).commitAllDocuments();
        CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
        final String lineIndent = styleManager.getLineIndent(file, caretOffset);
        if (lineIndent != null) {
          int col = calcColumnNumber(lineIndent, editor.getSettings().getTabSize(project));
          int line = caretModel.getVisualPosition().line;
          caretModel.moveToVisualPosition(new VisualPosition(line, col));

          if (caretModel.getLogicalPosition().column != col){
            if (!ApplicationManager.getApplication().isWriteAccessAllowed() &&
                !FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
              return;
            }
            editor.getSelectionModel().removeSelection();
            WriteAction.run(() -> document.replaceString(offset1 + 1, offset2, lineIndent));
          }
        }
        else {
          stopProcessing = false;
        }

        editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        editor.getSelectionModel().removeSelection();
        if (stopProcessing) {
          return;
        }
      }
    }
  }

  if (myOriginalHandler != null){
    myOriginalHandler.execute(editor, caret, dataContext);
  }
}
 
Example 16
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean areParameterTemplatesEnabledOnCompletion() {
  return Registry.is("java.completion.argument.live.template") && !CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION;
}
 
Example 17
Source File: EnterBetweenBracesHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Result preprocessEnter(@Nonnull final PsiFile file, @Nonnull final Editor editor, @Nonnull final Ref<Integer> caretOffsetRef, @Nonnull final Ref<Integer> caretAdvance,
                              @Nonnull final DataContext dataContext, final EditorActionHandler originalHandler) {
  Document document = editor.getDocument();
  CharSequence text = document.getCharsSequence();
  int caretOffset = caretOffsetRef.get().intValue();
  if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
    return Result.Continue;
  }

  int prevCharOffset = CharArrayUtil.shiftBackward(text, caretOffset - 1, " \t");
  int nextCharOffset = CharArrayUtil.shiftForward(text, caretOffset, " \t");

  if (!isValidOffset(prevCharOffset, text) || !isValidOffset(nextCharOffset, text) ||
      !isBracePair(text.charAt(prevCharOffset), text.charAt(nextCharOffset))) {
    return Result.Continue;
  }

  PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
  if (file.findElementAt(prevCharOffset) == file.findElementAt(nextCharOffset)) {
    return Result.Continue;
  }

  final int line = document.getLineNumber(caretOffset);
  final int start = document.getLineStartOffset(line);
  final CodeDocumentationUtil.CommentContext commentContext =
          CodeDocumentationUtil.tryParseCommentContext(file, text, caretOffset, start);

  // special case: enter inside "()" or "{}"
  String indentInsideJavadoc = isInComment(caretOffset, file) && commentContext.docAsterisk
                               ? CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset)
                               : null;

  originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);

  Project project = editor.getProject();
  if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
    document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc);
  }

  PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
  try {
    CodeStyleManager.getInstance(file.getProject()).adjustLineIndent(file, editor.getCaretModel().getOffset());
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
  return indentInsideJavadoc == null ? Result.Continue : Result.DefaultForceIndent;
}
 
Example 18
Source File: BuildLookupElement.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean insertClosingQuotes() {
  return CodeInsightSettings.getInstance().AUTOINSERT_PAIR_QUOTE;
}
 
Example 19
Source File: EnterAfterJavadocTagHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Result preprocessEnter(@Nonnull PsiFile file,
                              @Nonnull Editor editor,
                              @Nonnull Ref<Integer> caretOffset,
                              @Nonnull Ref<Integer> caretAdvance,
                              @Nonnull DataContext dataContext,
                              EditorActionHandler originalHandler) {
  if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
    return Result.Continue;
  }

  Document document = editor.getDocument();
  CharSequence text = document.getCharsSequence();
  int line = document.getLineNumber(caretOffset.get());
  int start = document.getLineStartOffset(line);
  int end = document.getLineEndOffset(line);

  CodeDocumentationUtil.CommentContext commentContext = CodeDocumentationUtil.tryParseCommentContext(file, text, caretOffset.get(), start);
  if (!commentContext.docAsterisk) {
    return Result.Continue;
  }

  Context context = parse(text, start, end, caretOffset.get());
  if (!context.shouldGenerateLine()) {
    return context.shouldIndent() ? Result.DefaultForceIndent : Result.Continue;
  }

  String indentInsideJavadoc = CodeDocumentationUtil.getIndentInsideJavadoc(document, caretOffset.get());

  boolean restoreCaret = false;
  if (caretOffset.get() != context.endTagStartOffset) {
    editor.getCaretModel().moveToOffset(context.endTagStartOffset);
    restoreCaret = true;
  }

  originalHandler.execute(editor, dataContext);
  Project project = editor.getProject();
  if (indentInsideJavadoc != null && project != null && CodeStyleSettingsManager.getSettings(project).JD_LEADING_ASTERISKS_ARE_ENABLED) {
    document.insertString(editor.getCaretModel().getOffset(), "*" + indentInsideJavadoc);
  }

  if (restoreCaret) {
    editor.getCaretModel().moveToOffset(caretOffset.get());
  }

  return Result.DefaultForceIndent;
}
 
Example 20
Source File: EnterAfterUnmatchedBraceHandler.java    From consulo with Apache License 2.0 3 votes vote down vote up
/**
 * Calculates the maximum number of '}' that can be inserted by handler.
 * Can return {@code 0} or less in custom implementation to skip '}' insertion in the {@code preprocessEnter} call
 * and switch to default implementation.
 *
 * @param file        target PSI file
 * @param editor      target editor
 * @param caretOffset target caret offset
 * @return maximum number of '}' that can be inserted by handler, {@code 0} or less to switch to default implementation
 */
protected int getMaxRBraceCount(@Nonnull final PsiFile file, @Nonnull final Editor editor, int caretOffset) {
  if (!CodeInsightSettings.getInstance().INSERT_BRACE_ON_ENTER) {
    return 0;
  }
  return Math.max(0, getUnmatchedLBracesNumberBefore(editor, caretOffset, file.getFileType()));
}