WEB-25334 JSON Schema: completion doesn't suggest null

This commit is contained in:
irengrig
2017-02-08 12:31:39 +01:00
parent b6f61aa16c
commit eb30eab77d
3 changed files with 51 additions and 9 deletions
@@ -152,20 +152,26 @@ class JsonBySchemaObjectCompletionContributor extends CompletionContributor {
}
else {
final JsonSchemaType type = schema.getType();
if (JsonSchemaType._boolean.equals(type)) {
addPossibleBooleanValue(type);
final List<JsonSchemaType> variants = schema.getTypeVariants();
if (variants != null) {
for (JsonSchemaType variant : variants) {
addPossibleBooleanValue(variant);
}
if (type != null) {
suggestByType(schema, type);
} else if (schema.getTypeVariants() != null) {
for (JsonSchemaType schemaType : schema.getTypeVariants()) {
suggestByType(schema, schemaType);
}
} else if (JsonSchemaType._string.equals(type)) {
addPossibleStringValue(schema);
}
}
}
private void suggestByType(JsonSchemaObject schema, JsonSchemaType type) {
if (JsonSchemaType._boolean.equals(type)) {
addPossibleBooleanValue(type);
} else if (JsonSchemaType._string.equals(type)) {
addPossibleStringValue(schema);
} else if (JsonSchemaType._null.equals(type)) {
addValueVariant("null", null);
}
}
private void addPossibleStringValue(JsonSchemaObject schema) {
Object defaultValue = schema.getDefault();
String defaultValueString = defaultValue == null ? null : defaultValue.toString();
@@ -185,6 +185,8 @@ public class ReadJsonSchemaFromPsi {
}
} else if (value instanceof JsonBooleanLiteral) {
objects.add(((JsonBooleanLiteral)value).getValue());
} else if (value instanceof JsonNullLiteral) {
objects.add("null");
}
}
object.setEnum(objects);
@@ -132,6 +132,40 @@ public class JsonBySchemaCompletionTest extends CompletionTestCase {
"\"r1\"", "\"r2\"");
}
public void testSimpleNullCompletion() throws Exception {
final String schema = "{\n" +
" \"properties\": {\n" +
" \"null\": {\n" +
" \"type\": \"null\"\n" +
" }\n" +
" }\n" +
"}";
testImpl(schema, "{\"null\": <caret>}", "null");
}
public void testNullCompletionInEnum() throws Exception {
final String schema = "{\n" +
" \"properties\": {\n" +
" \"null\": {\n" +
" \"type\": [\"null\", \"integer\"],\n" +
" \"enum\": [null, 1, 2]\n" +
" }\n" +
" }\n" +
"}";
testImpl(schema, "{\"null\": <caret>}", "1", "2", "null");
}
public void testNullCompletionInTypeVariants() throws Exception {
final String schema = "{\n" +
" \"properties\": {\n" +
" \"null\": {\n" +
" \"type\": [\"null\", \"boolean\"]\n" +
" }\n" +
" }\n" +
"}";
testImpl(schema, "{\"null\": <caret>}", "false", "null", "true");
}
@NotNull
private static String parcelShopSchema() {
return "{\n" +