use of org.jetbrains.yaml.psi.YAMLMapping in project intellij-community by JetBrains.
the class YAMLMappingModificationTest method doMappingTest.
private void doMappingTest(final String key, final String content) {
myFixture.configureByFile(getTestName(true) + ".yml");
final int offset = myFixture.getCaretOffset();
final PsiElement elementAtCaret = myFixture.getFile().findElementAt(offset);
final YAMLMapping mapping = PsiTreeUtil.getParentOfType(elementAtCaret, YAMLMapping.class, false);
if (mapping == null) {
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
YAMLUtil.createI18nRecord((YAMLFile) myFixture.getFile(), new String[] { key }, content);
});
} else {
assertNotNull(mapping);
//final int indent = YAMLUtil.getIndentInThisLine(mapping);
//final String indentString = StringUtil.repeatSymbol(' ', indent);
final YAMLKeyValue dummyKeyValue = YAMLElementGenerator.getInstance(myFixture.getProject()).createYamlKeyValue(key, content);
assertNotNull(dummyKeyValue);
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> mapping.putKeyValue(dummyKeyValue));
}
assertSameLinesWithFile(getTestDataPath() + getTestName(true) + ".txt", myFixture.getFile().getText(), false);
}
use of org.jetbrains.yaml.psi.YAMLMapping in project intellij-plugins by JetBrains.
the class BasePathInfo method extractBasePathPair.
@Nullable
private static Pair<YAMLKeyValue, DocumentFragment> extractBasePathPair(@NotNull YAMLDocument yamlDocument) {
final Ref<Pair<YAMLKeyValue, DocumentFragment>> result = Ref.create(null);
final YAMLValue value = yamlDocument.getTopLevelValue();
if (value instanceof YAMLMapping) {
for (YAMLKeyValue keyValue : ((YAMLMapping) value).getKeyValues()) {
if (keyValue != null && isBasePathKey(keyValue) && result.isNull()) {
DocumentFragment valueFragment = JstdConfigFileUtils.extractValueAsDocumentFragment(keyValue);
result.set(Pair.create(keyValue, valueFragment));
}
}
}
return result.get();
}
Aggregations