mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 17:53:25 +07:00
IDEA-226522 Sort properties alphabetically breaks indentation in JSON
GitOrigin-RevId: 2f7299bfb9ccfd2f14e9b6ec15078c8b41c38dba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a9285da09f
commit
d8df42bfc8
@@ -8,9 +8,7 @@ import com.intellij.json.psi.JsonObject;
|
||||
import com.intellij.json.psi.JsonProperty;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
@@ -20,6 +18,7 @@ import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -68,9 +67,12 @@ public class JsonSortPropertiesIntention implements IntentionAction, LowPriority
|
||||
assert parentObject instanceof JsonObject;
|
||||
// cycle-sort performs the minimal amount of modifications, and we want to patch the tree as little as possible
|
||||
cycleSortProperties(((JsonObject)parentObject).getPropertyList());
|
||||
SmartPsiElementPointer<PsiElement> pointer = SmartPointerManager.createPointer(parentObject);
|
||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
|
||||
PsiElement element = pointer.getElement();
|
||||
if (element == null) return;
|
||||
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
|
||||
codeStyleManager.reformat(parentObject);
|
||||
codeStyleManager.reformatText(element.getContainingFile(), Collections.singleton(element.getTextRange()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,4 +16,8 @@ public class JsonIntentionActionTest extends JsonTestCase {
|
||||
public void testSortMalformedJson() {
|
||||
doTest("json.intention.sort.properties");
|
||||
}
|
||||
|
||||
public void testSortPropertiesShouldReformat() {
|
||||
doTest("json.intention.sort.properties");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,40 +32,40 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
",<caret>,
|
||||
".*credentials.*",
|
||||
": ",
|
||||
Keys
|
||||
Keys
|
||||
be
|
||||
be
|
||||
can
|
||||
"defaultValue": [
|
||||
,
|
||||
"description": ""
|
||||
ends
|
||||
expressions.
|
||||
"key"
|
||||
"name": "endpoints.env.keys-to-sanitize"
|
||||
or
|
||||
property
|
||||
ption
|
||||
regex
|
||||
sanitized.
|
||||
"secret"
|
||||
should
|
||||
simple
|
||||
"sourceType": "org.springframework.boot.actuate.endpoint.EnvironmentEndpoint"
|
||||
strings
|
||||
that
|
||||
that
|
||||
the,
|
||||
"token",
|
||||
"type": "java.lang.String[]",
|
||||
"vcap_services",
|
||||
with
|
||||
]
|
||||
},
|
||||
",<caret>,
|
||||
".*credentials.*",
|
||||
": ",
|
||||
Keys
|
||||
Keys
|
||||
be
|
||||
be
|
||||
can
|
||||
"defaultValue": [
|
||||
,
|
||||
"description": ""
|
||||
ends
|
||||
expressions.
|
||||
"key"
|
||||
"name": "endpoints.env.keys-to-sanitize"
|
||||
or
|
||||
property
|
||||
ption
|
||||
regex
|
||||
sanitized.
|
||||
"secret"
|
||||
should
|
||||
simple
|
||||
"sourceType": "org.springframework.boot.actuate.endpoint.EnvironmentEndpoint"
|
||||
strings
|
||||
that
|
||||
that
|
||||
the,
|
||||
"token",
|
||||
"type": "java.lang.String[]",
|
||||
"vcap_services",
|
||||
with
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "endpoints.metrics.filter.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"description": "The Laravel Framework.",
|
||||
"keywords": [
|
||||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "laravel/laravel",
|
||||
"require": {
|
||||
"p<caret>hp": ">=5.6.4",
|
||||
"twbs/bootstrap": "^3.3",
|
||||
"laravel/framework": "5.4.",
|
||||
"laravel/tinker": "~1.0",
|
||||
"laravelcollective/html": "^5.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"description": "The Laravel Framework.",
|
||||
"keywords": [
|
||||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "laravel/laravel",
|
||||
"require": {
|
||||
"laravel/framework": "5.4.",
|
||||
"laravel/tinker": "~1.0",
|
||||
"laravelcollective/html": "^5.4",
|
||||
"php": ">=5.6.4",
|
||||
"twbs/bootstrap": "^3.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user