InsertHandler<LookupElement> (@NotNull JsonSchemaObject jsonSchemaObject, final boolean hasValue, boolean insertComma) { JsonSchemaType type = jsonSchemaObject.guessType(); List<Object> values = jsonSchemaObject.getEnum(); if (type == null && values != null && !values.isEmpty()) type = detectType(values); final Object defaultValue = jsonSchemaObject.getDefault(); final String defaultValueAsString = defaultValue == null || defaultValue instanceof JsonSchemaObject ? null : (defaultValue instanceof String ? "\"" + defaultValue + "\"" : String.valueOf(defaultValue)); JsonSchemaType finalType = type; return new InsertHandler<>() { @Override public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement item) { ApplicationManager.getApplication().assertWriteAccessAllowed(); Editor editor = context.getEditor(); Project project = context.getProject(); String stringToInsert = null; final String comma = insertComma ? "," : ""; if (handleInsideQuotesInsertion(context, editor, hasValue)) return; PsiElement element = context.getFile().findElementAt(editor.getCaretModel().getOffset()); boolean insertColon = element == null || !":".equals(element.getText()); if (!insertColon) { editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() + 1); } if (finalType != null) { boolean hadEnter; switch (finalType) { case _object -> { EditorModificationUtil.insertStringAtCaret(editor, insertColon ? ": " : " ", false, true, insertColon ? 2 : 1); hadEnter = false; boolean invokeEnter = myWalker.hasWhitespaceDelimitedCodeBlocks(); if (insertColon && invokeEnter) { invokeEnterHandler(editor); hadEnter = true; } if (insertColon) { stringToInsert = myWalker.getDefaultObjectValue() + comma; EditorModificationUtil.insertStringAtCaret(editor, stringToInsert, false, true, hadEnter ? 0 : 1); } if (hadEnter || !insertColon) { EditorActionUtil.moveCaretToLineEnd(editor, false, false); } PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); if (!hadEnter && stringToInsert != null) { formatInsertedString(context, stringToInsert.length()); } if (stringToInsert != null && !invokeEnter) { invokeEnterHandler(editor); } } case _boolean -> { String value = String.valueOf(Boolean.TRUE.toString().equals(defaultValueAsString)); stringToInsert = (insertColon ? ": " : " ") + value + comma; SelectionModel model = editor.getSelectionModel(); EditorModificationUtil.insertStringAtCaret(editor, stringToInsert, false, true, stringToInsert.length() - comma.length()); formatInsertedString(context, stringToInsert.length()); int start = editor.getSelectionModel().getSelectionStart(); model.setSelection(start - value.length(), start); AutoPopupController.getInstance(context.getProject()).autoPopupMemberLookup(context.getEditor(), null); } case _array -> { EditorModificationUtilEx.insertStringAtCaret(editor, insertColon ? ":" : " ", false, true, 1); hadEnter = false; if (insertColon && myWalker.hasWhitespaceDelimitedCodeBlocks()) { invokeEnterHandler(editor); hadEnter = true; } else { EditorModificationUtilEx.insertStringAtCaret(editor, " ", false, true, 1); } if (insertColon) { stringToInsert = myWalker.getDefaultArrayValue() + comma; EditorModificationUtil.insertStringAtCaret(editor, stringToInsert, false, true, hadEnter ? 0 : 1); } if (hadEnter) { EditorActionUtil.moveCaretToLineEnd(editor, false, false); } PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); if (stringToInsert != null && myWalker.requiresReformatAfterArrayInsertion()) { formatInsertedString(context, stringToInsert.length()); } } case _string, _integer, _number -> insertPropertyWithEnum(context, editor, defaultValueAsString, values, finalType, comma, myWalker, insertColon); default -> { } } } else { insertPropertyWithEnum(context, editor, defaultValueAsString, values, null, comma, myWalker, insertColon); } } }; }