org.jetbrains.yaml.psi.YAMLFile Java Examples

The following examples show how to use org.jetbrains.yaml.psi.YAMLFile. 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: ServiceDeprecatedClassesInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void visitFile(PsiFile psiFile) {

    ProblemRegistrar problemRegistrar = null;

    if(psiFile instanceof YAMLFile) {
        psiFile.acceptChildren(new YmlClassElementWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar()));
    } else if(psiFile instanceof XmlFile) {
        psiFile.acceptChildren(new XmlClassElementWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar()));
    } else if(psiFile instanceof PhpFile) {
        psiFile.acceptChildren(new PhpClassWalkingVisitor(holder, problemRegistrar = new ProblemRegistrar()));
    }

    if(problemRegistrar != null) {
        problemRegistrar.reset();
    }

    super.visitFile(psiFile);
}
 
Example #2
Source File: FileResourceVisitorUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * foo:
 *   resources: 'FOO'
 */
private static void visitYamlFile(@NotNull YAMLFile yamlFile, @NotNull Consumer<FileResourceConsumer> consumer) {
    for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues(yamlFile)) {
        YAMLKeyValue resourceKey = YamlHelper.getYamlKeyValue(yamlKeyValue, "resource", true);
        if(resourceKey == null) {
            continue;
        }

        String resource = PsiElementUtils.trimQuote(resourceKey.getValueText());
        if(StringUtils.isBlank(resource)) {
            continue;
        }

        consumer.consume(new FileResourceConsumer(resourceKey, yamlKeyValue, normalize(resource)));
    }
}
 
Example #3
Source File: YamlServiceArgumentInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void visitFile(PsiFile file) {
    if(!(file instanceof YAMLFile)) {
        return;
    }

    for (ServiceActionUtil.ServiceYamlContainer serviceYamlContainer : ServiceActionUtil.getYamlContainerServiceArguments((YAMLFile) file)) {

        // we dont support parent services for now
        if("_defaults".equalsIgnoreCase(serviceYamlContainer.getServiceKey().getKeyText()) || !isValidService(serviceYamlContainer)) {
            continue;
        }

        List<String> yamlMissingArgumentTypes = ServiceActionUtil.getYamlMissingArgumentTypes(problemsHolder.getProject(), serviceYamlContainer, false, getLazyServiceCollector(problemsHolder.getProject()));
        if(yamlMissingArgumentTypes.size() > 0) {
            problemsHolder.registerProblem(serviceYamlContainer.getServiceKey().getFirstChild(), "Missing argument", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new YamlArgumentQuickfix());
        }
    }

    this.lazyServiceCollector = null;
}
 
Example #4
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 #5
Source File: SymfonyContainerServiceBuilder.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void update(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);

    if (project == null || !Symfony2ProjectComponent.isEnabled(project)) {
        this.setStatus(event, false);
        return;
    }

    Pair<PsiFile, PhpClass> pair = findPhpClass(event);
    if(pair == null) {
        return;
    }

    PsiFile psiFile = pair.getFirst();
    if(!(psiFile instanceof YAMLFile) && !(psiFile instanceof XmlFile) && !(psiFile instanceof PhpFile)) {
        this.setStatus(event, false);
    }
}
 
Example #6
Source File: TranslatorKeyExtractorDialog.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void filterList(String domainName) {

        // clear list no all*() method?
        while(this.listTableModel.getRowCount() > 0) {
            this.listTableModel.removeRow(0);
        }

        // we only support yaml files right now
        // filter on PsiFile instance
        Collection<PsiFile> domainPsiFilesYaml = TranslationUtil.getDomainPsiFiles(this.project, domainName).stream()
            .filter(domainPsiFile -> domainPsiFile instanceof YAMLFile || TranslationUtil.isSupportedXlfFile(domainPsiFile))
            .collect(Collectors.toCollection(ArrayList::new));

        this.listTableModel.addRows(this.getFormattedFileModelList(domainPsiFilesYaml));

        // only one domain; fine preselect it
        if(this.listTableModel.getRowCount() == 1) {
            this.listTableModel.getItem(0).setEnabled(true);
        }

    }
 
Example #7
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 #8
Source File: ContainerParameterStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, String, FileContent> getIndexer() {
    return inputData -> {
        Map<String, String> map = new HashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!Symfony2ProjectComponent.isEnabledForIndex(psiFile.getProject())) {
            return map;
        }

        if(!ServicesDefinitionStubIndex.isValidForIndex(inputData, psiFile)) {
            return map;
        }

        if(psiFile instanceof YAMLFile) {
            attachTHashMapNullable(YamlHelper.getLocalParameterMap(psiFile), map);
        } else if(psiFile instanceof XmlFile) {
            attachTHashMapNullable(XmlHelper.getFileParameterMap((XmlFile) psiFile), map);
        }

        return map;
    };
}
 
Example #9
Source File: ServiceIndexUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static List<PsiElement> findParameterDefinitions(@NotNull PsiFile psiFile, @NotNull String parameterName) {

        List<PsiElement> items = new ArrayList<>();

        if(psiFile instanceof YAMLFile) {
            PsiElement servicePsiElement = YamlHelper.getLocalParameterMap(psiFile, parameterName);
            if(servicePsiElement != null) {
                items.add(servicePsiElement);
            }
        }

        if(psiFile instanceof XmlFile) {
            PsiElement localParameterName = XmlHelper.getLocalParameterName(psiFile, parameterName);
            if(localParameterName != null) {
                items.add(localParameterName);
            }
        }

        return items;
    }
 
Example #10
Source File: TwigUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see TwigUtil#getTwigGlobalsFromYamlConfig
 */
public void testGetTwigGlobalsFromYamlConfig() {
    String content = "twig:\n" +
        "    globals:\n" +
        "       ga_tracking: '%ga_tracking%'\n" +
        "       user_management: '@AppBundle\\Service\\UserManagement'\n"
        ;

    YAMLFile yamlFile = (YAMLFile) PsiFileFactory.getInstance(getProject())
        .createFileFromText("DUMMY__." + YAMLFileType.YML.getDefaultExtension(), YAMLFileType.YML, content, System.currentTimeMillis(), false);

    Map<String, String> globals = TwigUtil.getTwigGlobalsFromYamlConfig(yamlFile);

    assertEquals("%ga_tracking%", globals.get("ga_tracking"));
    assertEquals("@AppBundle\\Service\\UserManagement", globals.get("user_management"));
}
 
Example #11
Source File: ControllerMethodInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile psiFile) {
            if(psiFile instanceof YAMLFile) {
                visitYaml(holder, psiFile);
            }

            if(psiFile instanceof XmlFile) {
                visitXml(holder, psiFile);
            }

            super.visitFile(psiFile);
        }
    };
}
 
Example #12
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 #13
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 #14
Source File: DoctrineYamlMappingDriver.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments args) {

    PsiFile psiFile = args.getPsiFile();
    if(!(psiFile instanceof YAMLFile)) {
        return null;
    }

    Collection<DoctrineModelField> fields = new ArrayList<>();
    DoctrineMetadataModel model = new DoctrineMetadataModel(fields);

    for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
        // first line is class name; check of we are right
        if(args.isEqualClass(YamlHelper.getYamlKeyName(yamlKeyValue))) {
            model.setTable(YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "table"));
            fields.addAll(EntityHelper.getModelFieldsSet(yamlKeyValue));
        }
    }

    if(model.isEmpty()) {
        return null;
    }

    return model;
}
 
Example #15
Source File: TaggedExtendsInterfaceClassInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitFile(PsiFile psiFile) {
            if(psiFile instanceof YAMLFile) {
                psiFile.acceptChildren(new YmlClassElementWalkingVisitor(holder, new ContainerCollectionResolver.LazyServiceCollector(holder.getProject())));
            } else if(psiFile instanceof XmlFile) {
                psiFile.acceptChildren(new XmlClassElementWalkingVisitor(holder, new ContainerCollectionResolver.LazyServiceCollector(holder.getProject())));
            }
        }
    };
}
 
Example #16
Source File: YamlUpdateArgumentServicesCallbackTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void invokeInsert(YAMLFile yamlFile) {
    Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.collectElementsOfType(yamlFile, YAMLKeyValue.class);

    final YamlUpdateArgumentServicesCallback callback = new YamlUpdateArgumentServicesCallback(
        getProject(),
        ContainerUtil.find(yamlKeyValues, new YAMLKeyValueCondition("arguments")),
        ContainerUtil.find(yamlKeyValues, new YAMLKeyValueCondition("foo"))
    );

    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                @Override
                public void run() {
                    callback.insert(Arrays.asList("foo", "bar"));
                }
            });

        }
    }, null, null);
}
 
Example #17
Source File: PermissionIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {

    return inputData -> {

        Map<String, Void> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!(psiFile instanceof YAMLFile) || !psiFile.getName().endsWith(".permissions.yml")) {
            return map;
        }

        for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
            String keyText = yamlKeyValue.getKeyText();
            if(StringUtils.isBlank(keyText)) {
                continue;
            }

            map.put(keyText, null);
        }

        return map;
    };
}
 
Example #18
Source File: MenuIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {

    return inputData -> {

        Map<String, Void> map = new THashMap<>();

        PsiFile psiFile = inputData.getPsiFile();
        if(!(psiFile instanceof YAMLFile) || !psiFile.getName().endsWith(".menu.yml")) {
            return map;
        }

        for (YAMLKeyValue yamlKeyValue : YamlHelper.getTopLevelKeyValues((YAMLFile) psiFile)) {
            String keyText = yamlKeyValue.getKeyText();
            if(StringUtils.isBlank(keyText)) {
                continue;
            }

            map.put(keyText, null);
        }

        return map;
    };
}
 
Example #19
Source File: EelHelperUtil.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
public static HashMap<String, String> getHelpersInFile(@NotNull PsiFile psiFile) {
    YAMLKeyValue defaultContext = YAMLUtil.getQualifiedKeyInFile((YAMLFile) psiFile, "Neos", "Fusion", "defaultContext");

    if (defaultContext == null) {
        defaultContext = YAMLUtil.getQualifiedKeyInFile((YAMLFile) psiFile, "TYPO3", "TypoScript", "defaultContext");
    }

    HashMap<String, String> result = new HashMap<>();
    if (defaultContext != null) {
        PsiElement mapping = defaultContext.getLastChild();
        if (mapping instanceof YAMLMapping) {
            for (PsiElement mappingElement : mapping.getChildren()) {
                if (mappingElement instanceof YAMLKeyValue) {
                    YAMLKeyValue keyValue = (YAMLKeyValue) mappingElement;
                    result.put(keyValue.getKeyText(), keyValue.getValueText());
                    NeosProjectService.getLogger().debug(keyValue.getKeyText() + ": " + keyValue.getValueText());
                }
            }
        }
    }

    return result;
}
 
Example #20
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 #21
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void testGetTaggedServices() {
    PsiFile psiFile = myFixture.configureByText(YAMLFileType.YML, "" +
        "services:\n" +
        "   foobar:\n" +
        "       class: ClassName\\Foo\n" +
        "       tags:\n" +
        "           - { name: crossHint.test_222 }\n" +
        "   foobar2:\n" +
        "       class: ClassName\\Foo\n" +
        "       tags: [ 'test.11' ]\n"
    );

    Collection<YAMLKeyValue> taggedServices1 = YamlHelper.getTaggedServices((YAMLFile) psiFile, "crossHint.test_222");
    assertTrue(taggedServices1.stream().anyMatch(yamlKeyValue -> "foobar".equals(yamlKeyValue.getKey().getText())));

    Collection<YAMLKeyValue> taggedServices2 = YamlHelper.getTaggedServices((YAMLFile) psiFile, "test.11");
    assertTrue(taggedServices2.stream().anyMatch(yamlKeyValue -> "foobar2".equals(yamlKeyValue.getKey().getText())));
}
 
Example #22
Source File: NodeTypeReference.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    String nodeTypeNameToFindReferenceFor = yamlElement.getKeyText();

    // files which contain the NodeType definition
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NodeTypesYamlFileIndex.KEY, nodeTypeNameToFindReferenceFor, GlobalSearchScope.allScope(yamlElement.getProject()));

    return files
            .stream()
            // get the PSI for each file
            .map(file -> PsiManager.getInstance(yamlElement.getProject()).findFile(file))
            // ensure we only have YAML files
            .filter(psiFile -> psiFile instanceof YAMLFile)
            .map(psiFile -> (YAMLFile) psiFile)
            // get all YAML keys in these files
            .flatMap(yamlFile -> YAMLUtil.getTopLevelKeys(yamlFile).stream())
            // get the correct YAML key
            .filter(yamlKeyValue -> yamlKeyValue.getKeyText().equals(nodeTypeNameToFindReferenceFor))
            // remove "current" element if it exists
            .filter(yamlKeyValue -> yamlElement != yamlKeyValue)
            // build up the result object
            .map(yamlKeyValue -> new PsiElementResolveResult(yamlKeyValue, true))
            .toArray(PsiElementResolveResult[]::new);
}
 
Example #23
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 #24
Source File: YamlUpdateArgumentServicesCallbackTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see YamlUpdateArgumentServicesCallback#insert(java.util.List)
 */
public void testArgumentInsertOfArrayArguments() {

    YAMLFile yamlFile = YAMLElementGenerator.getInstance(getProject()).createDummyYamlWithText("" +
        "services:\n" +
        "    foo:\n" +
        "        class: Foo\\Foo\n" +
        "        arguments: [ @service_container ]"
    );

    invokeInsert(yamlFile);

    assertEquals("" +
            "services:\n" +
            "    foo:\n" +
            "        class: Foo\\Foo\n" +
            "        arguments: [ @service_container, '@foo', '@bar' ]",
        yamlFile.getText()
    );
}
 
Example #25
Source File: SpecIconProvider.java    From intellij-swagger with MIT License 6 votes vote down vote up
@Nullable
@Override
public Icon getIcon(@NotNull PsiElement element, int flags) {
  if (element instanceof YAMLFile || element instanceof JsonFile) {

    final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    final Project project = element.getProject();

    if (indexService.isMainSpecFile(virtualFile, project)
        || indexService.isPartialSpecFile(virtualFile, project)) {
      return getIcon();
    }
  }

  return null;
}
 
Example #26
Source File: YamlUpdateArgumentServicesCallbackTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see YamlUpdateArgumentServicesCallback#insert(java.util.List)
 */
public void testArgumentInsertOfSequenceArrayArguments() {

    YAMLFile yamlFile = YAMLElementGenerator.getInstance(getProject()).createDummyYamlWithText("" +
        "services:\n" +
        "    foo:\n" +
        "        class: Foo\\Foo\n" +
        "        arguments:\n" +
        "           - @service_container"
    );

    invokeInsert(yamlFile);

    assertEquals("" +
            "services:\n" +
            "    foo:\n" +
            "        class: Foo\\Foo\n" +
            "        arguments:\n" +
            "           - @service_container\n" +
            "           - '@foo'\n" +
            "           - '@bar'",
        yamlFile.getText()
    );
}
 
Example #27
Source File: TwigUtilTempTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see TwigUtil#getTwigPathFromYamlConfigResolved
 */
public void testGetTwigPathFromYamlConfigResolved() {
    createFile("app/test/foo.html.twig");
    createFile("app/template/foo.html.twig");

    PsiFile dummyFile = YamlPsiElementFactory.createDummyFile(getProject(), "" +
        "twig:\n" +
        "   paths:\n" +
        "       '%kernel.root_dir%/test': foo\n" +
        "       '%kernel.project_dir%/app/test': project\n" +
        "       '%kernel.root_dir%/../app': app\n" +
        "       'app/template': MY_PREFIX\n" +
        "       'app///\\\\\\template': MY_PREFIX_1\n"
    );

    Collection<Pair<String, String>> paths = TwigUtil.getTwigPathFromYamlConfigResolved((YAMLFile) dummyFile);

    assertNotNull(
        paths.stream().filter(pair -> "foo".equals(pair.getFirst()) && "app/test".equals(pair.getSecond())).findFirst().get()
    );

    assertNotNull(
        paths.stream().filter(pair -> "project".equals(pair.getFirst()) && "app/test".equals(pair.getSecond())).findFirst().get()
    );

    assertNotNull(
        paths.stream().filter(pair -> "app".equals(pair.getFirst()) && "app".equals(pair.getSecond())).findFirst().get()
    );

    assertNotNull(
        paths.stream().filter(pair -> "MY_PREFIX".equals(pair.getFirst()) && "app/template".equals(pair.getSecond())).findFirst().get()
    );

    Pair<String, String> myPrefix1 = paths.stream().filter(pair -> "MY_PREFIX_1".equals(pair.getFirst())).findAny().get();

    assertEquals("MY_PREFIX_1", myPrefix1.getFirst());
    assertEquals("app/template", myPrefix1.getSecond());
}
 
Example #28
Source File: ServiceGenerateAction.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private boolean isValidForFile(@NotNull PsiFile file) {

        if(file instanceof XmlFile) {
            XmlTag rootTag = ((XmlFile) file).getRootTag();
            return !(rootTag == null || !"container".equals(rootTag.getName()));
        } else if(file instanceof YAMLFile) {
            return
                YAMLUtil.getQualifiedKeyInFile((YAMLFile) file, "parameters") != null ||
                YAMLUtil.getQualifiedKeyInFile((YAMLFile) file, "services") != null;
        }

        return false;
    }
 
Example #29
Source File: YamlCreateServiceArgumentsCallbackTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testYamlServiceArgumentCreation() {
    YAMLFile yamlFile = YAMLElementGenerator.getInstance(getProject()).createDummyYamlWithText("" +
        "services:\n" +
        "    foo:\n" +
        "        class: Foo\\Foo\n"
    );

    Collection<YAMLKeyValue> yamlKeyValues = PsiTreeUtil.collectElementsOfType(yamlFile, YAMLKeyValue.class);

    YAMLKeyValue services = ContainerUtil.find(yamlKeyValues, new YamlUpdateArgumentServicesCallbackTest.YAMLKeyValueCondition("foo"));
    assertNotNull(services);

    final YamlCreateServiceArgumentsCallback callback = new YamlCreateServiceArgumentsCallback(services);

    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                @Override
                public void run() {
                    callback.insert(Arrays.asList("foo", null, ""));
                }
            });

        }
    }, null, null);

    assertEquals("" +
                    "services:\n" +
                    "    foo:\n" +
                    "        class: Foo\\Foo\n" +
                    "        arguments:\n" +
                    "          ['@foo', '@?', '@?']\n",
            yamlFile.getText()
    );
}
 
Example #30
Source File: YamlHelperLightTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private int getIndentForTextContent(@NotNull String content) {
    return YamlHelper.getIndentSpaceForFile((YAMLFile) YamlPsiElementFactory.createDummyFile(
        getProject(),
        "foo.yml",
        content
    ));
}