Search in sources :

Example 1 with JsonElementGenerator

use of com.intellij.json.psi.JsonElementGenerator in project intellij-community by JetBrains.

the class JsonPsiUtilTest method checkAddProperty.

private void checkAddProperty(@NotNull String before, @NotNull String after, final boolean first) {
    getCustomCodeStyleSettings().OBJECT_WRAPPING = CommonCodeStyleSettings.DO_NOT_WRAP;
    myFixture.configureByText(JsonFileType.INSTANCE, before);
    final PsiElement atCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    final JsonObject jsonObject = PsiTreeUtil.getParentOfType(atCaret, JsonObject.class);
    assertNotNull(jsonObject);
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        JsonPsiUtil.addProperty(jsonObject, new JsonElementGenerator(getProject()).createProperty("foo", "null"), first);
    });
    myFixture.checkResult(after);
}
Also used : JsonElementGenerator(com.intellij.json.psi.JsonElementGenerator) JsonObject(com.intellij.json.psi.JsonObject) PsiElement(com.intellij.psi.PsiElement)

Example 2 with JsonElementGenerator

use of com.intellij.json.psi.JsonElementGenerator in project intellij-community by JetBrains.

the class JsonPropertyMixin method setName.

@Override
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
    final JsonElementGenerator generator = new JsonElementGenerator(getProject());
    // Strip only both quotes in case user wants some exotic name like key'
    getNameElement().replace(generator.createStringLiteral(StringUtil.unquoteString(name)));
    return this;
}
Also used : JsonElementGenerator(com.intellij.json.psi.JsonElementGenerator)

Aggregations

JsonElementGenerator (com.intellij.json.psi.JsonElementGenerator)2 JsonObject (com.intellij.json.psi.JsonObject)1 PsiElement (com.intellij.psi.PsiElement)1