本文整理了Java中fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper
类的一些代码示例,展示了YamlHelper
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlHelper
类的具体详情如下:
包路径:fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper
类名称:YamlHelper
暂无
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@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)) {
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 != null && strings.size() > 0) {
for (String s : strings) {
if(phpClassServiceTags.contains(s)) {
phpClassServiceTags.remove(s);
}
}
}
return Pair.create(resolvedClassDefinition, phpClassServiceTags);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) {
if(psiElement.getContainingFile().getFileType() != YAMLFileType.YML || !Symfony2ProjectComponent.isEnabled(psiElement.getProject())) {
return false;
}
return YamlHelper.findServiceInContext(psiElement) != null;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
indentSpaces = YamlHelper.getIndentSpaceForFile((YAMLFile) psiFile);
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* acme_demo.form.type.gender:
* class: espend\Form\TypeBundle\Form\FooType
* tags:
* - { name: form.type, alias: foo_type_alias }
* - { name: foo }
*/
@NotNull
public static Map<String, Set<String>> getTags(@NotNull YAMLFile yamlFile) {
Map<String, Set<String>> map = new HashMap<>();
for(YAMLKeyValue yamlServiceKeyValue : YamlHelper.getQualifiedKeyValuesInFile(yamlFile, "services")) {
String serviceName = yamlServiceKeyValue.getName();
Set<String> serviceTagMap = YamlHelper.collectServiceTags(yamlServiceKeyValue);
if(serviceTagMap != null && serviceTagMap.size() > 0) {
map.put(serviceName, serviceTagMap);
}
}
return map;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* 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;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private void visitYamlMethod(PsiElement psiElement, ProblemsHolder holder, ContainerCollectionResolver.LazyServiceCollector collector) {
if(YamlElementPatternHelper.getInsideKeyValue("calls").accepts(psiElement)) {
PsiElement parent = psiElement.getParent();
if ((parent instanceof YAMLScalar)) {
YamlHelper.visitServiceCall((YAMLScalar) parent, s ->
registerMethodProblem(psiElement, holder, YamlHelper.trimSpecialSyntaxServiceName(s), collector)
);
}
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Nullable
public String getAttribute(@NotNull String attr) {
return YamlHelper.getYamlKeyValueAsString(yamlMapping, attr);
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private static Map<String, Integer> getIdUsages(@NotNull YAMLFile yamlFile) {
Map<String, Integer> services = new HashMap<>();
for(YAMLKeyValue yamlKeyValue: YamlHelper.getQualifiedKeyValuesInFile(yamlFile, "services")) {
String keyName = yamlKeyValue.getKeyText();
if(StringUtils.isBlank(keyName)) {
YAMLKeyValue arguments = YamlHelper.getYamlKeyValue(yamlKeyValue, "arguments");
if(arguments != null) {
YAMLValue value = arguments.getValue();
if(value instanceof YAMLSequence) {
for (String id : YamlHelper.getYamlArrayValuesAsList((YAMLSequence) value)) {
String idClean = YamlHelper.trimSpecialSyntaxServiceName(id);
if(StringUtils.isNotBlank(idClean)) {
services.putIfAbsent(idClean, 0);
YAMLKeyValue calls = YamlHelper.getYamlKeyValue(yamlKeyValue, "calls");
if(calls != null) {
String textValue = ((YAMLScalar) value2).getTextValue();
String idClean = YamlHelper.trimSpecialSyntaxServiceName(textValue);
if(StringUtils.isNotBlank(idClean)) {
services.putIfAbsent(idClean, 0);
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, final @Nullable String value, @NotNull String... keys) {
return insertKeyIntoFile(yamlFile, (yamlMapping, chainedKey) -> " " + value, keys);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
/**
* Extract service class for class or id attribute on shortcut
*
* <service id="foo" class="Foobar"/> => Foobar
* <service class="Foobar"/> => Foobar
*/
@Nullable
public static String getClassFromServiceDefinition(@NotNull XmlTag xmlTag) {
String classAttribute = xmlTag.getAttributeValue("class");
if(StringUtils.isNotBlank(classAttribute)) {
return classAttribute;
}
String id = xmlTag.getAttributeValue("id");
if(id == null || StringUtils.isBlank(id) || !YamlHelper.isClassServiceId(id)) {
return null;
}
return id;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private static String getServiceName(PsiElement psiElement) {
return YamlHelper.trimSpecialSyntaxServiceName(PsiElementUtils.getText(psiElement));
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@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;
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Override
public void visitElement(PsiElement psiElement) {
// @TODO: support key itself
if (YamlElementPatternHelper.getServiceDefinition().accepts(psiElement) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(psiElement)) {
// @foo, @=foo, @?foo
String serviceText = PsiElementUtils.trimQuote(psiElement.getText());
if (isValidService(serviceText)) {
String serviceName = YamlHelper.trimSpecialSyntaxServiceName(serviceText);
// dont mark "@", "@?", "@@" escaping and expressions
if (StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase()) && !YamlHelper.isClassServiceId(serviceName)) {
holder.registerProblem(psiElement, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
}
}
}
super.visitElement(psiElement);
}
});
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
private void visitYamlMethodTagKey(@NotNull final PsiElement psiElement, @NotNull ProblemsHolder holder, ContainerCollectionResolver.LazyServiceCollector collector) {
String methodName = PsiElementUtils.trimQuote(psiElement.getText());
if(StringUtils.isBlank(methodName)) {
return;
}
String classValue = YamlHelper.getServiceDefinitionClassFromTagMethod(psiElement);
if(classValue == null) {
return;
}
registerMethodProblem(psiElement, holder, classValue, collector);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@NotNull
private Collection<PsiElement> parameterGoToDeclaration(@NotNull PsiElement psiElement, @NotNull String psiParameterName) {
Collection<PsiElement> targets = new ArrayList<>();
targets.addAll(
DotEnvUtil.getEnvironmentVariableTargetsForParameter(psiElement.getProject(), psiParameterName)
);
if(!YamlHelper.isValidParameterName(psiParameterName)) {
return targets;
}
targets.addAll(ServiceUtil.getServiceClassTargets(psiElement.getProject(), psiParameterName));
return targets;
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@Override
public void visitElement(PsiElement element) {
if(YamlElementPatternHelper.getSingleLineScalarKey("class").accepts(element)) {
// class: '\Foo'
String text = PsiElementUtils.trimQuote(element.getText());
if(StringUtils.isBlank(text)) {
super.visitElement(element);
return;
}
PsiElement yamlScalar = element.getParent();
if(!(yamlScalar instanceof YAMLScalar)) {
super.visitElement(element);
return;
}
PsiElement classKey = yamlScalar.getParent();
if(classKey instanceof YAMLKeyValue) {
PsiElement yamlCompoundValue = classKey.getParent();
if(yamlCompoundValue instanceof YAMLCompoundValue) {
PsiElement serviceKeyValue = yamlCompoundValue.getParent();
if(serviceKeyValue instanceof YAMLKeyValue) {
Set<String> tags = YamlHelper.collectServiceTags((YAMLKeyValue) serviceKeyValue);
if(tags != null && tags.size() > 0) {
registerTaggedProblems(element, tags, text, holder, this.lazyServiceCollector);
}
}
}
}
}
super.visitElement(element);
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
List<PsiElement> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
if(yamlArrayOnSequenceOrArrayElements != null) {
serviceArguments = yamlArrayOnSequenceOrArrayElements.size();
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
YamlHelper.processKeysAfterRoot(psiFile, yamlKeyValue -> {
String keyText = yamlKeyValue.getKeyText();
if(StringUtils.isNotBlank(keyText) && !keyText.equals(keyText.toLowerCase()) && !YamlHelper.isClassServiceId(keyText)) {
PsiElement firstChild = yamlKeyValue.getFirstChild();
if(firstChild != null) {
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
@NotNull
public static Collection<PhpClass> getPhpClassesInYamlFile(@NotNull YAMLFile yamlFile, @NotNull ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {
Collection<PhpClass> phpClasses = new HashSet<>();
for (YAMLKeyValue keyValue : YamlHelper.getQualifiedKeyValuesInFile(yamlFile, "services")) {
YAMLValue value = keyValue.getValue();
if (value instanceof YAMLMapping) {
// foo.bar:
// classes: ...
String serviceId = ServiceContainerUtil.getServiceClassFromServiceMapping((YAMLMapping) value);
if (StringUtils.isNotBlank(serviceId)) {
PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlFile.getProject(), serviceId, lazyServiceCollector);
if (serviceClass != null) {
phpClasses.add(serviceClass);
}
}
} else if(value instanceof YAMLPlainTextImpl) {
// Foo\Bar: ~
String text = keyValue.getKeyText();
if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text)) {
phpClasses.addAll(PhpElementsUtil.getClassesInterface(yamlFile.getProject(), text));
}
}
}
return phpClasses;
}
}
代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin
String repositoryClassValue = YamlHelper.getYamlKeyValueAsString(yamlKey, "repositoryClass");
Set<String> keySet = YamlHelper.getKeySet(yamlKey);
if(keySet == null) {
continue;
内容来源于网络,如有侵权,请联系作者删除!