mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
eslint: 1) config parsing: determine plugins/extends also inside package.json 2) optimize configs search, order configs properly (by the file tree position related to file)
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
package com.intellij.json;
|
||||
|
||||
import com.intellij.json.psi.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
@@ -34,4 +41,28 @@ public class JsonUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends JsonElement> T getPropertyValueOfType(@NotNull final JsonObject object, @NotNull final String name,
|
||||
@NotNull final Class<T> clazz) {
|
||||
final JsonProperty property = object.findProperty(name);
|
||||
if (property == null) return null;
|
||||
return ObjectUtils.tryCast(property.getValue(), clazz);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<String> getChildAsStringList(@NotNull final JsonObject object, @NotNull final String name) {
|
||||
final JsonArray array = getPropertyValueOfType(object, name, JsonArray.class);
|
||||
if (array != null) return array.getValueList().stream().filter(value -> value instanceof JsonStringLiteral)
|
||||
.map(value -> StringUtil.unquoteString(value.getText())).collect(Collectors.toList());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<String> getChildAsSingleStringOrList(@NotNull final JsonObject object, @NotNull final String name) {
|
||||
final List<String> list = getChildAsStringList(object, name);
|
||||
if (list != null) return list;
|
||||
final JsonStringLiteral literal = getPropertyValueOfType(object, name, JsonStringLiteral.class);
|
||||
return literal == null ? null : Collections.singletonList(StringUtil.unquoteString(literal.getText()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user