Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#getYamlKeyValueAsString()
The following examples show how to use
fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper#getYamlKeyValueAsString() .
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: RouteHelper.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Find controller definition in yaml structure * * foo: * defaults: { _controller: "Bundle:Foo:Bar" } * defaults: * _controller: "Bundle:Foo:Bar" * controller: "Bundle:Foo:Bar" */ @Nullable public static String getYamlController(@NotNull YAMLKeyValue psiElement) { YAMLKeyValue yamlKeyValue = YamlHelper.getYamlKeyValue(psiElement, "defaults"); if(yamlKeyValue != null) { final YAMLValue container = yamlKeyValue.getValue(); if(container instanceof YAMLMapping) { YAMLKeyValue yamlKeyValueController = YamlHelper.getYamlKeyValue(container, "_controller", true); if(yamlKeyValueController != null) { String valueText = yamlKeyValueController.getValueText(); if(StringUtils.isNotBlank(valueText)) { return valueText; } } } } String controller = YamlHelper.getYamlKeyValueAsString(psiElement, "controller"); if(controller != null && StringUtils.isNotBlank(controller)) { return controller; } return null; }
Example 2
Source File: YamlCompletionContributor.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { YAMLKeyValue yamlKeyValue = PsiTreeUtil.getParentOfType(completionParameters.getOriginalPosition(), YAMLKeyValue.class); if(yamlKeyValue != null) { PsiElement compoundValue = yamlKeyValue.getParent(); if(compoundValue instanceof YAMLCompoundValue) { // path and pattern are valid String pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "path", false); if(pattern == null) { pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "pattern", false); } if(pattern != null) { Matcher matcher = Pattern.compile("\\{(\\w+)}").matcher(pattern); while(matcher.find()){ completionResultSet.addElement(LookupElementBuilder.create(matcher.group(1))); } } } } }
Example 3
Source File: YamlKeyValueAttributeValue.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public String getString(@NotNull String key) { String value = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, key); if(StringUtils.isBlank(value)) { return null; } return value; }
Example 4
Source File: YamlGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public String findClassForElement(@NotNull PsiElement psiElement) { YAMLMapping parentOfType = PsiTreeUtil.getParentOfType(psiElement, YAMLMapping.class); if(parentOfType == null) { return null; } return YamlHelper.getYamlKeyValueAsString(parentOfType, "class"); }
Example 5
Source File: YamlGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable @Override public String findIdForElement(@NotNull PsiElement psiElement) { YAMLMapping parentOfType = PsiTreeUtil.getParentOfType(psiElement, YAMLMapping.class); if(parentOfType == null) { return null; } return YamlHelper.getYamlKeyValueAsString(parentOfType, "id"); }
Example 6
Source File: YamlCompletionContributor.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { if(!Symfony2ProjectComponent.isEnabled(completionParameters.getPosition())) { return; } PsiElement psiElement = completionParameters.getPosition(); YAMLCompoundValue yamlCompoundValue = PsiTreeUtil.getParentOfType(psiElement, YAMLCompoundValue.class); if(yamlCompoundValue == null) { return; } yamlCompoundValue = PsiTreeUtil.getParentOfType(yamlCompoundValue, YAMLCompoundValue.class); if(yamlCompoundValue == null) { return; } String value = YamlHelper.getYamlKeyValueAsString(yamlCompoundValue, "class", true); if(value != null) { PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), value); if(phpClass != null) { FormUtil.attachFormAliasesCompletions(phpClass, completionResultSet); } } }
Example 7
Source File: YamlCompletionContributor.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = completionParameters.getPosition(); if(!Symfony2ProjectComponent.isEnabled(position)) { return; } YAMLCompoundValue yamlCompoundValue = PsiTreeUtil.getParentOfType(position, YAMLCompoundValue.class); if(yamlCompoundValue == null) { return; } String className = YamlHelper.getYamlKeyValueAsString(yamlCompoundValue, "targetEntity", false); if(className == null) { return; } PhpClass phpClass = PhpElementsUtil.getClass(position.getProject(), className); if(phpClass == null) { return; } for(DoctrineModelField field: EntityHelper.getModelFields(phpClass)) { if(field.getRelation() != null) { completionResultSet.addElement(new DoctrineModelFieldLookupElement(field)); } } }
Example 8
Source File: YamlGoToDeclarationHandler.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * services: * My<caret>Class: ~ */ private Collection<PsiElement> getClassesForServiceKey(@NotNull PsiElement psiElement) { PsiElement parent = psiElement.getParent(); if(parent instanceof YAMLKeyValue) { String valueText = ((YAMLKeyValue) parent).getKeyText(); if (StringUtils.isNotBlank(valueText)) { Collection<PsiElement> targets = new HashSet<>(); // My<caret>Class\: // resource: '....' // exclude: '....' if (valueText.endsWith("\\")) { String resource = YamlHelper.getYamlKeyValueAsString((YAMLKeyValue) parent, "resource"); if (resource != null) { String exclude = YamlHelper.getYamlKeyValueAsString((YAMLKeyValue) parent, "exclude"); targets.addAll(getPhpClassFromResources(psiElement.getProject(), valueText, psiElement.getContainingFile().getVirtualFile(), resource, exclude)); } } targets.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), valueText)); return targets; } } return Collections.emptyList(); }
Example 9
Source File: YamlServiceTagIntention.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable private static Pair<PhpClass, Set<String>> invoke(@NotNull Project project, @NotNull YAMLKeyValue serviceKeyValue) { String aClass = YamlHelper.getYamlKeyValueAsString(serviceKeyValue, "class"); if(aClass == null || StringUtils.isBlank(aClass)) { PsiElement key = serviceKeyValue.getKey(); if (key != null) { String text = key.getText(); if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text)) { aClass = text; } } } if(aClass == null) { return null; } PhpClass resolvedClassDefinition = ServiceUtil.getResolvedClassDefinition(project, aClass, new ContainerCollectionResolver.LazyServiceCollector(project)); if(resolvedClassDefinition == null) { return null; } Set<String> phpClassServiceTags = ServiceUtil.getPhpClassServiceTags(resolvedClassDefinition); Set<String> strings = YamlHelper.collectServiceTags(serviceKeyValue); if(strings.size() > 0) { for (String s : strings) { if(phpClassServiceTags.contains(s)) { phpClassServiceTags.remove(s); } } } return Pair.create(resolvedClassDefinition, phpClassServiceTags); }
Example 10
Source File: DoctrineUtil.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * Extract class and repository from all yaml files * We need to filter on some condition, so we dont index files which not holds meta for doctrine * * Note: index context method, so file validity in each statement */ @Nullable private static Collection<Pair<String, String>> getClassRepositoryPair(@NotNull YAMLFile yamlFile) { // we are indexing all yaml files for prefilter on path, // if false if check on parse String name = yamlFile.getName().toLowerCase(); boolean iAmMetadataFile = name.contains(".odm.") || name.contains(".orm.") || name.contains(".mongodb.") || name.contains(".couchdb."); YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(yamlFile, YAMLDocument.class); if(yamlDocument == null) { return null; } YAMLValue topLevelValue = yamlDocument.getTopLevelValue(); if(!(topLevelValue instanceof YAMLMapping)) { return null; } Collection<Pair<String, String>> pairs = new ArrayList<>(); for (YAMLKeyValue yamlKey : ((YAMLMapping) topLevelValue).getKeyValues()) { String keyText = yamlKey.getKeyText(); if(StringUtils.isBlank(keyText)) { continue; } String repositoryClassValue = YamlHelper.getYamlKeyValueAsString(yamlKey, "repositoryClass"); // check blank condition String repositoryClass = null; if(StringUtils.isNotBlank(repositoryClassValue)) { repositoryClass = repositoryClassValue; } // fine repositoryClass exists a valid metadata file if(!iAmMetadataFile && repositoryClass != null) { iAmMetadataFile = true; } // currently not valid metadata file find valid keys // else we are not allowed to store values if(!iAmMetadataFile) { Set<String> keySet = YamlHelper.getKeySet(yamlKey); if(keySet == null) { continue; } if(!(keySet.contains("fields") || keySet.contains("id") || keySet.contains("collection") || keySet.contains("db") || keySet.contains("indexes"))) { continue; } iAmMetadataFile = true; } pairs.add(Pair.create(keyText, repositoryClass)); } if(pairs.size() == 0) { return null; } return pairs; }
Example 11
Source File: YamlMappingAttributeResolver.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Nullable public String getAttribute(@NotNull String attr) { return YamlHelper.getYamlKeyValueAsString(yamlMapping, attr); }
Example 12
Source File: YamlLineMarkerProvider.java From idea-php-symfony2-plugin with MIT License | 4 votes |
private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull YAMLKeyValue yamlKeyValue, @NotNull Collection<LineMarkerInfo> result, @NotNull LazyDecoratedParentServiceValues lazyDecoratedServices) { String id = yamlKeyValue.getKeyText(); if(StringUtils.isBlank(id)) { return; } // decorates: foobar String decorates = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "decorates"); if(decorates != null && StringUtils.isNotBlank(decorates)) { result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(leafTarget, ServiceUtil.ServiceLineMarker.DECORATE, decorates)); } // parent: foobar String parent = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "parent"); if(parent != null && StringUtils.isNotBlank(parent)) { result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(leafTarget, ServiceUtil.ServiceLineMarker.PARENT, parent)); } // foreign "decorates" linemarker NavigationGutterIconBuilder<PsiElement> decorateLineMarker = ServiceUtil.getLineMarkerForDecoratedServiceId( yamlKeyValue.getProject(), ServiceUtil.ServiceLineMarker.DECORATE, lazyDecoratedServices.getDecoratedServices(), id ); if(decorateLineMarker != null) { result.add(decorateLineMarker.createLineMarkerInfo(leafTarget)); } // foreign "parent" linemarker NavigationGutterIconBuilder<PsiElement> parentLineMarker = ServiceUtil.getLineMarkerForDecoratedServiceId( yamlKeyValue.getProject(), ServiceUtil.ServiceLineMarker.PARENT, lazyDecoratedServices.getDecoratedServices(), id ); if(parentLineMarker != null) { result.add(parentLineMarker.createLineMarkerInfo(leafTarget)); } }
Example 13
Source File: YamlCompletionContributor.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = completionParameters.getPosition(); if(!Symfony2ProjectComponent.isEnabled(position)) { return; } PsiElement psiElement = PsiTreeUtil.findFirstParent(position, psiElement1 -> { if (psiElement1 instanceof YAMLKeyValue) { String s = ((YAMLKeyValue) psiElement1).getKeyText().toLowerCase(); if ("joinTable".equalsIgnoreCase(s)) { return true; } } return false; }); if(psiElement == null) { return; } PsiElement yamlCompoundValue = psiElement.getParent(); if(!(yamlCompoundValue instanceof YAMLCompoundValue)) { return; } String className = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) yamlCompoundValue, "targetEntity", false); if(className == null) { return; } PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), className); if(phpClass == null) { return; } for(DoctrineModelField field: EntityHelper.getModelFields(phpClass)) { if(field.getRelation() == null) { String columnName = field.getColumn(); if(columnName == null) { completionResultSet.addElement(LookupElementBuilder.create(field.getName()).withIcon(Symfony2Icons.DOCTRINE)); } else { completionResultSet.addElement(LookupElementBuilder.create(columnName).withTypeText(field.getName(), false).withIcon(Symfony2Icons.DOCTRINE)); } } } }