public static void fixServiceArgument(@NotNull YAMLKeyValue yamlKeyValue) { YAMLKeyValue argumentsKeyValue = YamlHelper.getYamlKeyValue(yamlKeyValue, "arguments"); List<String> yamlMissingArgumentTypes = ServiceActionUtil.getYamlMissingArgumentTypes( yamlKeyValue.getProject(), ServiceActionUtil.ServiceYamlContainer.create(yamlKeyValue), false, new ContainerCollectionResolver.LazyServiceCollector(yamlKeyValue.getProject()) ); if(yamlMissingArgumentTypes.size() == 0) { return; } InsertServicesCallback insertServicesCallback; if(argumentsKeyValue == null) { // there is no "arguments" key so provide one insertServicesCallback = new YamlCreateServiceArgumentsCallback(yamlKeyValue); } else { insertServicesCallback = new YamlUpdateArgumentServicesCallback( yamlKeyValue.getProject(), argumentsKeyValue, yamlKeyValue ); } ServiceActionUtil.fixServiceArgument(yamlKeyValue.getProject(), yamlMissingArgumentTypes, insertServicesCallback); }
/** * Bridge to allow YAMLKeyValue adding child key-values elements. * Yaml plugin provides key adding only on YAMLMapping * * ser<caret>vice: * foo: "aaa" * */ @Nullable public static YAMLKeyValue putKeyValue(@NotNull YAMLKeyValue yamlKeyValue, @NotNull String keyName, @NotNull String valueText) { // create "foo: foo" YAMLKeyValue newYamlKeyValue = YAMLElementGenerator.getInstance(yamlKeyValue.getProject()) .createYamlKeyValue(keyName, valueText); YAMLMapping childOfAnyType = PsiTreeUtil.findChildOfAnyType(yamlKeyValue, YAMLMapping.class); if(childOfAnyType == null) { return null; } childOfAnyType.putKeyValue(newYamlKeyValue); return newYamlKeyValue; }
@Override public void insert(List<String> items) { PsiDocumentManager manager = PsiDocumentManager.getInstance(serviceKeyValue.getProject()); Document document = manager.getDocument(serviceKeyValue.getContainingFile()); if (document == null) { return; } List<String> arrayList = new ArrayList<>(); for (String item : items) { arrayList.add("'@" + (StringUtils.isNotBlank(item) ? item : "?") + "'"); } YamlHelper.putKeyValue(serviceKeyValue, "arguments", "[" + StringUtils.join(arrayList, ", ") + "]"); manager.doPostponedOperationsAndUnblockDocument(document); manager.commitDocument(document); } }
yamlKeyValue.getProject(), ServiceUtil.ServiceLineMarker.DECORATE, lazyDecoratedServices.getDecoratedServices(), yamlKeyValue.getProject(), ServiceUtil.ServiceLineMarker.PARENT, lazyDecoratedServices.getDecoratedServices(),