import com.intellij.json.JsonBundle;
import com.intellij.json.JsonElementTypes;
import com.intellij.json.psi.*;
+import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
final PsiElement element = descriptor.getPsiElement();
if (element instanceof JsonLiteral || element instanceof JsonReferenceExpression) {
final String content = StringUtil.stripQuotesAroundValue(element.getText());
- element.replace(new JsonElementGenerator(project).createStringLiteral(content));
+ // TODO: find out better way to replace element and skip reformatting step afterwards
+ final ASTNode replacement = new JsonElementGenerator(project).createStringLiteral(content).getNode();
+ element.getParent().getNode().replaceChild(element.getNode(), replacement);
}
else if (element != null) {
LOG.error("Quick fix was applied to unexpected element", element.getText(), element.getParent().getText());
import com.intellij.psi.TokenType;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
-import com.intellij.psi.formatter.FormatterUtil;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
}
else if (!hasElementType(childNode, JSON_ALL_BRACES)) {
assert myChildWrap != null;
- if (!FormatterUtil.isPrecededBy(childNode, JSON_OPEN_BRACES)) {
- wrap = myChildWrap;
- }
+ wrap = myChildWrap;
indent = Indent.getNormalIndent();
}
else if (hasElementType(childNode, JSON_OPEN_BRACES)) {
});
}
+ // IDEA-138902
+ public void testObjectsWithSingleProperty() throws Exception {
+ withPreservedSettings(new ThrowableRunnable<Exception>() {
+ @Override
+ public void run() throws Exception {
+ doTest();
+ }
+ });
+ }
+
// Moved from JavaScript
public void testWeb3830() throws Exception {
--- /dev/null
+{"level0": {"level1": {"level2": "someValue"}}}
\ No newline at end of file
--- /dev/null
+{
+ "level0": {
+ "level1": {
+ "level2": "someValue"
+ }
+ }
+}
\ No newline at end of file
5,
6,
7,
- ["this line is long too"]
+ [
+ "this line is long too"
+ ]
]
\ No newline at end of file
{
- "<selection>property</selection>": [null]
+ "<selection>property</selection>": [
+ null
+ ]
}
\ No newline at end of file