Java Code Examples for org.jetbrains.yaml.YAMLUtil#getQualifiedKeyInFile()
The following examples show how to use
org.jetbrains.yaml.YAMLUtil#getQualifiedKeyInFile() .
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: EelHelperUtil.java From intellij-neos with GNU General Public License v3.0 | 6 votes |
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 2
Source File: TranslationInsertUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
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 3
Source File: ServiceContainerUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull private static ServiceFileDefaults createDefaults(@NotNull YAMLFile psiFile) { YAMLKeyValue yamlKeyValueDefaults = YAMLUtil.getQualifiedKeyInFile(psiFile, "services", "_defaults"); if(yamlKeyValueDefaults != null) { return new ServiceFileDefaults( YamlHelper.getYamlKeyValueAsBoolean(yamlKeyValueDefaults, "public"), YamlHelper.getYamlKeyValueAsBoolean(yamlKeyValueDefaults, "autowire") ); } return ServiceFileDefaults.EMPTY; }
Example 4
Source File: TwigUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Collects Twig globals in given yaml configuration * * twig: * globals: * ga_tracking: '%ga_tracking%' * user_management: '@AppBundle\Service\UserManagement' */ @NotNull public static Map<String, String> getTwigGlobalsFromYamlConfig(@NotNull YAMLFile yamlFile) { YAMLKeyValue yamlKeyValue = YAMLUtil.getQualifiedKeyInFile(yamlFile, "twig", "globals"); if(yamlKeyValue == null) { return Collections.emptyMap(); } YAMLValue value = yamlKeyValue.getValue(); if(!(value instanceof YAMLMapping)) { return Collections.emptyMap(); } Map<String, String> pair = new HashMap<>(); for (YAMLPsiElement element : value.getYAMLElements()) { if(!(element instanceof YAMLKeyValue)) { continue; } String keyText = ((YAMLKeyValue) element).getKeyText(); if(StringUtils.isBlank(keyText)) { continue; } String valueText = ((YAMLKeyValue) element).getValueText(); if(StringUtils.isBlank(valueText)) { continue; } pair.put(keyText, valueText); } return pair; }
Example 5
Source File: YamlDuplicateServiceKeyInspection.java From idea-php-symfony2-plugin with MIT License | 5 votes |
protected void visitRoot(PsiFile psiFile, String rootName, @NotNull ProblemsHolder holder) { if(!(psiFile instanceof YAMLFile)) { return; } YAMLKeyValue yamlKeyValue = YAMLUtil.getQualifiedKeyInFile((YAMLFile) psiFile, rootName); if(yamlKeyValue == null) { return; } YAMLCompoundValue yaml = PsiTreeUtil.findChildOfType(yamlKeyValue, YAMLMapping.class); if(yaml != null) { YamlHelper.attachDuplicateKeyInspection(yaml, holder); } }
Example 6
Source File: YamlHelper.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Process yaml key in second level filtered by a root: * File > roots -> "Item" * TODO: visitQualifiedKeyValuesInFile */ public static void processKeysAfterRoot(@NotNull PsiFile psiFile, @NotNull Processor<YAMLKeyValue> yamlKeyValueProcessor, @NotNull String... roots) { for (String root : roots) { YAMLKeyValue yamlKeyValue = YAMLUtil.getQualifiedKeyInFile((YAMLFile) psiFile, root); if(yamlKeyValue != null) { YAMLCompoundValue yaml = PsiTreeUtil.findChildOfType(yamlKeyValue, YAMLCompoundValue.class); if(yaml != null) { for(YAMLKeyValue yamlKeyValueVisit: PsiTreeUtil.getChildrenOfTypeAsList(yaml, YAMLKeyValue.class)) { yamlKeyValueProcessor.process(yamlKeyValueVisit); } } } } }
Example 7
Source File: YamlHelper.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Get all key values in first level key visit * * parameters: * foo: "foo" */ @NotNull public static Collection<YAMLKeyValue> getQualifiedKeyValuesInFile(@NotNull YAMLFile yamlFile, @NotNull String firstLevelKeyToVisit) { YAMLKeyValue parameters = YAMLUtil.getQualifiedKeyInFile(yamlFile, firstLevelKeyToVisit); if(parameters == null) { return Collections.emptyList(); } return getNextKeyValues(parameters); }
Example 8
Source File: YamlHelper.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Visit all key values in first level key * * parameters: * foo: "foo" */ public static void visitQualifiedKeyValuesInFile(@NotNull YAMLFile yamlFile, @NotNull String firstLevelKeyToVisit, @NotNull Consumer<YAMLKeyValue> consumer) { YAMLKeyValue parameters = YAMLUtil.getQualifiedKeyInFile(yamlFile, firstLevelKeyToVisit); if(parameters == null) { return; } visitNextKeyValues(parameters, consumer); }
Example 9
Source File: ServiceGenerateAction.java From idea-php-symfony2-plugin with MIT License | 5 votes |
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 10
Source File: RouteHelper.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Find every possible route name declaration inside yaml, xml or @Route annotation */ @Nullable public static PsiElement getRouteNameTarget(@NotNull Project project, @NotNull String routeName) { for(VirtualFile virtualFile: RouteHelper.getRouteDefinitionInsideFile(project, routeName)) { PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if(psiFile instanceof YAMLFile) { return YAMLUtil.getQualifiedKeyInFile((YAMLFile) psiFile, routeName); } else if(psiFile instanceof XmlFile) { PsiElement target = RouteHelper.getXmlRouteNameTarget((XmlFile) psiFile, routeName); if(target != null) { return target; } } else if(psiFile instanceof PhpFile) { // find on @Route annotation for (PhpClass phpClass : PhpPsiUtil.findAllClasses((PhpFile) psiFile)) { // get prefix by PhpClass String prefix = getRouteNamePrefix(phpClass); for (Method method : phpClass.getOwnMethods()) { PhpDocComment docComment = method.getDocComment(); if(docComment == null) { continue; } PhpDocCommentAnnotation container = AnnotationUtil.getPhpDocCommentAnnotationContainer(docComment); if(container == null) { continue; } // multiple @Route annotation in bundles are allowed for (String routeClass : ROUTE_CLASSES) { PhpDocTagAnnotation phpDocTagAnnotation = container.getPhpDocBlock(routeClass); if(phpDocTagAnnotation != null) { String annotationRouteName = phpDocTagAnnotation.getPropertyValue("name"); if(annotationRouteName != null) { // name provided @Route(name="foobar") if(routeName.equals(prefix + annotationRouteName)) { return phpDocTagAnnotation.getPropertyValuePsi("name"); } } else { // just @Route() without name provided String routeByMethod = AnnotationBackportUtil.getRouteByMethod(phpDocTagAnnotation.getPhpDocTag()); if(routeName.equals(prefix + routeByMethod)) { return phpDocTagAnnotation.getPhpDocTag(); } } } } } } } } return null; }
Example 11
Source File: TwigUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Collects Twig path in given yaml configuration * * twig: * paths: * "%kernel.root_dir%/../src/vendor/bundle/Resources/views": core */ @NotNull public static Collection<Pair<String, String>> getTwigPathFromYamlConfig(@NotNull YAMLFile yamlFile) { YAMLKeyValue yamlKeyValue = YAMLUtil.getQualifiedKeyInFile(yamlFile, "twig", "paths"); if(yamlKeyValue == null) { return Collections.emptyList(); } YAMLValue value = yamlKeyValue.getValue(); if(!(value instanceof YAMLMapping)) { return Collections.emptyList(); } Collection<Pair<String, String>> pair = new ArrayList<>(); for (YAMLPsiElement element : value.getYAMLElements()) { if(!(element instanceof YAMLKeyValue)) { continue; } String keyText = ((YAMLKeyValue) element).getKeyText(); if(StringUtils.isBlank(keyText)) { continue; } keyText = keyText.replace("\\", "/").replaceAll("/+", "/"); // empty value is empty string on out side: // "foo: " String valueText = ""; YAMLValue yamlValue = ((YAMLKeyValue) element).getValue(); if (yamlValue != null) { valueText = ((YAMLKeyValue) element).getValueText(); } else { // workaround for foo: !foobar // as we got tag element PsiElement key = ((YAMLKeyValue) element).getKey(); if(key != null) { PsiElement nextSiblingOfType = PsiElementUtils.getNextSiblingOfType(key, PlatformPatterns.psiElement(YAMLTokenTypes.TAG)); if(nextSiblingOfType != null) { String text = nextSiblingOfType.getText(); if(text.startsWith("!")) { valueText = StringUtils.stripStart(text, "!"); } } } } // Symfony 3.4 / 4.0: namespace overwrite: "@!Foo" => "@Foo" valueText = StringUtils.stripStart(valueText, "!"); // normalize null value if(valueText.equals("~")) { valueText = ""; } pair.add(Pair.create(valueText, keyText)); } return pair; }