本文整理了Java中fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper.insertKeyIntoFile()
方法的一些代码示例,展示了YamlHelper.insertKeyIntoFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlHelper.insertKeyIntoFile()
方法的具体详情如下:
包路径:fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper
类名称:YamlHelper
方法名:insertKeyIntoFile
[英]Adds a yaml key on path. This implemention merge values and support nested key values foo:\n bar: car -> foo.car.foo.bar
[中]在路径上添加yaml键。此实现合并值并支持嵌套键值foo:\n bar:car->foo。汽车福。酒吧
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, final @Nullable String value, @NotNull String... keys) {
return insertKeyIntoFile(yamlFile, (yamlMapping, chainedKey) -> " " + value, keys);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private static PsiElement invokeTranslation(@NotNull final YAMLFile yamlFile, @NotNull final String keyName, @NotNull final String translation) {
String[] split = keyName.split("\\.");
PsiElement psiElement = YamlHelper.insertKeyIntoFile(yamlFile, "'" + translation + "'", split);
if(psiElement == null) {
return null;
}
// resolve target to get value
YAMLKeyValue target = YAMLUtil.getQualifiedKeyInFile(yamlFile, split);
if(target != null && target.getValue() != null) {
return target.getValue();
} else if(target != null) {
return target;
}
return yamlFile;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, final @NotNull YAMLKeyValue yamlKeyValue, @NotNull String... keys) {
String keyText = yamlKeyValue.getKeyText();
return insertKeyIntoFile(yamlFile, (yamlMapping, chainedKey) -> {
String text = yamlKeyValue.getText();
final String previousIndent = StringUtil.repeatSymbol(' ', YAMLUtil.getIndentInThisLine(yamlMapping));
// split content of array value object;
// drop first item as getValueText() removes our key indent
String[] remove = (String[]) ArrayUtils.remove(text.split("\\r?\\n"), 0);
List<String> map = ContainerUtil.map(remove, s -> previousIndent + s);
return "\n" + StringUtils.strip(StringUtils.join(map, "\n"), "\n");
}, (String[]) ArrayUtils.add(keys, keyText));
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private void insertYamlServiceTag() {
if(!(this.psiFile instanceof YAMLFile)) {
return;
}
String text = createServiceAsText(ServiceBuilder.OutputType.Yaml, this.psiFile);
YAMLKeyValue fromText = YamlPsiElementFactory.createFromText(project, YAMLKeyValue.class, text);
if(fromText == null) {
return;
}
PsiElement psiElement = YamlHelper.insertKeyIntoFile((YAMLFile) psiFile, fromText, "services");
if(psiElement != null) {
navigateToElement(new TextRange[] {psiElement.getTextRange()});
}
dispose();
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile
* TODO empty file
*/
public void skipTestInsertKeyIntoEmptyFile() {
YAMLFile yamlFile = (YAMLFile) myFixture.configureByText(YAMLFileType.YML, "");
YamlHelper.insertKeyIntoFile(yamlFile, "value", "car", "bar", "apple");
assertEquals("" +
"foo:\n" +
" bar:\n" +
" car: test\n" +
"car:\n" +
" bar:\n" +
" apple: value",
yamlFile.getText()
);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile
*/
public void testInsertKeyIntoFile() {
YAMLFile yamlFile = (YAMLFile) myFixture.configureByText(YAMLFileType.YML, "" +
"foo:\n" +
" bar:\n" +
" car: test"
);
YamlHelper.insertKeyIntoFile(yamlFile, "value", "foo", "bar", "apple");
assertEquals("" +
"foo:\n" +
" bar:\n" +
" car: test\n" +
" apple: value",
yamlFile.getText()
);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile
*/
public void testInsertKeyIntoFileOnRoot() {
YAMLFile yamlFile = (YAMLFile) myFixture.configureByText(YAMLFileType.YML, "" +
"foo:\n" +
" bar:\n" +
" car: test"
);
YamlHelper.insertKeyIntoFile(yamlFile, "value", "car", "bar", "apple");
assertEquals("" +
"foo:\n" +
" bar:\n" +
" car: test\n" +
"car:\n" +
" bar:\n" +
" apple: value",
yamlFile.getText()
);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile
*/
public void testInsertKeyValueWithMissingMainKeyInRoot() {
YAMLFile yamlFile = (YAMLFile) myFixture.configureByText(YAMLFileType.YML, "foo: foo");
YAMLKeyValue yamlKeyValue = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
"my_service:\n" +
" class: foo\n" +
" tag: foo"
);
assertNotNull(yamlKeyValue);
YamlHelper.insertKeyIntoFile(yamlFile, yamlKeyValue, "services");
assertEquals("" +
"foo: foo\n" +
"services:\n" +
" my_service:\n" +
" class: foo\n" +
" tag: foo",
yamlFile.getText()
);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* @see fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile
*/
public void testInsertKeyWithArrayValue() {
YAMLFile yamlFile = (YAMLFile) myFixture.configureByText(YAMLFileType.YML, "" +
"services:\n" +
" foo:\n" +
" car: test"
);
YAMLKeyValue yamlKeyValue = YamlPsiElementFactory.createFromText(getProject(), YAMLKeyValue.class, "" +
"my_service:\n" +
" class: foo\n" +
" tag:\n" +
" - foo\n"
);
assertNotNull(yamlKeyValue);
YamlHelper.insertKeyIntoFile(yamlFile, yamlKeyValue, "services");
assertEquals("" +
"services:\n" +
" foo:\n" +
" car: test\n" +
" my_service:\n" +
" class: foo\n" +
" tag:\n" +
" - foo",
yamlFile.getText()
);
}
内容来源于网络,如有侵权,请联系作者删除!