com.intellij.json.psi.JsonObject Java Examples

The following examples show how to use com.intellij.json.psi.JsonObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtraModulesUtil.java    From weex-language-support with MIT License 6 votes vote down vote up
private static String getHomePage(PsiDirectory directory) {
    PsiFile pkg = directory.findFile("package.json");
    if (pkg != null && pkg instanceof JsonFile) {
        if (((JsonFile) pkg).getTopLevelValue() instanceof JsonObject) {
            JsonObject object = (JsonObject) ((JsonFile) pkg).getTopLevelValue();
            if (object != null) {
                JsonProperty homePage = object.findProperty("homepage");
                if (homePage != null && homePage.getValue() != null && homePage.getValue() instanceof JsonStringLiteral) {
                    JsonStringLiteral propValue = (JsonStringLiteral) homePage.getValue();
                    return propValue.getValue();
                }
            }
        }
    }
    return null;
}
 
Example #2
Source File: ExtraModulesUtil.java    From weex-language-support with MIT License 6 votes vote down vote up
private static PsiFile getMain(PsiDirectory moduleRoot) {
    PsiFile pkg = moduleRoot.findFile("package.json");
    if (pkg != null && pkg instanceof JsonFile) {
        if (((JsonFile) pkg).getTopLevelValue() instanceof JsonObject) {
            JsonObject object = (JsonObject) ((JsonFile) pkg).getTopLevelValue();
            if (object != null) {
                JsonProperty property = object.findProperty("main");
                if (property != null && property.getValue() != null && property.getValue() instanceof JsonStringLiteral) {
                    JsonStringLiteral propValue = (JsonStringLiteral) property.getValue();
                    String value = propValue.getValue();
                    PsiFile psiFile = moduleRoot.findFile(value.replace("./", ""));
                    return psiFile;
                }
            }
        }
    }
    return null;
}
 
Example #3
Source File: ExtraModulesUtil.java    From weex-language-support with MIT License 6 votes vote down vote up
public static String getModuleName(PsiDirectory dir) {
    PsiFile pkg = dir.findFile("package.json");
    String name = dir.getName();
    if (pkg != null && pkg instanceof JsonFile) {
        if (((JsonFile) pkg).getTopLevelValue() instanceof JsonObject) {
            JsonObject object = (JsonObject) ((JsonFile) pkg).getTopLevelValue();
            if (object != null) {
                JsonProperty property = object.findProperty("name");
                JsonProperty property1 = object.findProperty("version");
                if (property != null && property.getValue() != null && property.getValue() instanceof JsonStringLiteral) {
                    JsonStringLiteral propValue = (JsonStringLiteral) property.getValue();
                    name = propValue.getValue();
                    if (property1 != null && property1.getValue() != null && property1.getValue() instanceof JsonStringLiteral) {
                        JsonStringLiteral propValue1 = (JsonStringLiteral) property1.getValue();
                        name = name + ":" + propValue1.getValue();
                    }
                }
            }
        }
    }
    return name;
}
 
Example #4
Source File: GraphQLIntrospectEndpointUrlLineMarkerProvider.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
private String getSchemaPath(JsonProperty urlElement, boolean showNotificationOnMissingPath) {
    JsonObject jsonObject = PsiTreeUtil.getParentOfType(urlElement, JsonObject.class);
    while (jsonObject != null) {
        JsonProperty schemaPathElement = jsonObject.findProperty("schemaPath");
        if (schemaPathElement != null) {
            if (schemaPathElement.getValue() instanceof JsonStringLiteral) {
                String schemaPath = ((JsonStringLiteral) schemaPathElement.getValue()).getValue();
                if (schemaPath.trim().isEmpty()) {
                    Notifications.Bus.notify(new Notification("GraphQL", "Unable to perform introspection", "Please set a non-empty 'schemaPath' field", NotificationType.WARNING), urlElement.getProject());
                }
                return schemaPath;
            } else {
                break;
            }
        }
        jsonObject = PsiTreeUtil.getParentOfType(jsonObject, JsonObject.class);
    }
    if (showNotificationOnMissingPath) {
        Notifications.Bus.notify(new Notification("GraphQL", "Unable to perform introspection", "Please set a non-empty 'schemaPath' field. The introspection result will be written to that file.", NotificationType.WARNING), urlElement.getProject());
    }
    return null;
}
 
Example #5
Source File: PathFinder.java    From intellij-swagger with MIT License 5 votes vote down vote up
private PsiElement getNextObjectParent(final PsiElement psiElement) {
  if (psiElement == null) {
    return null;
  }

  if (psiElement instanceof JsonObject
      || (psiElement instanceof YAMLKeyValue || psiElement instanceof YAMLMapping)
          && !(psiElement instanceof JsonStringLiteral)) {
    return psiElement;
  }

  return getNextObjectParent(psiElement.getParent());
}