Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#insertKeyIntoFile() . 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: TranslationInsertUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: SymfonyCreateService.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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();
}
 
Example 3
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @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()
    );
}
 
Example 4
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @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()
    );
}
 
Example 5
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @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()
    );
}
 
Example 6
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @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()
    );
}
 
Example 7
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @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");

    String text = yamlFile.getText();
    assertEquals("services:\n" +
            "   foo:\n" +
            "       car: test\n" +
            "   my_service:\n" +
            "     class: foo\n" +
            "     tag:\n" +
            "       - foo",
        text
    );
}