Search in sources :

Example 1 with YAMLMapping

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);
}
Also used : YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) YAMLMapping(org.jetbrains.yaml.psi.YAMLMapping) PsiElement(com.intellij.psi.PsiElement)

Example 2 with YAMLMapping

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();
}
Also used : YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) YAMLValue(org.jetbrains.yaml.psi.YAMLValue) YAMLMapping(org.jetbrains.yaml.psi.YAMLMapping) DocumentFragment(com.intellij.openapi.editor.DocumentFragment) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

YAMLKeyValue (org.jetbrains.yaml.psi.YAMLKeyValue)2 YAMLMapping (org.jetbrains.yaml.psi.YAMLMapping)2 DocumentFragment (com.intellij.openapi.editor.DocumentFragment)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 Nullable (org.jetbrains.annotations.Nullable)1 YAMLValue (org.jetbrains.yaml.psi.YAMLValue)1