/** * Consumer for method parameter match * * service_name: * class: FOOBAR * calls: * - [onFoobar, [@fo<caret>o]] */ public static void visitServiceCallArgumentMethodIndex(@NotNull YAMLScalar yamlScalar, @NotNull Consumer<Parameter> consumer) { YamlHelper.visitServiceCallArgument(yamlScalar, new ParameterResolverConsumer(yamlScalar.getProject(), consumer)); }
@Override public boolean accepts(@NotNull YAMLScalar yamlScalar, ProcessingContext processingContext) { return StringUtils.startsWith(yamlScalar.getTextValue(), value); } }
PsiElement context = yamlScalar.getContext(); if(context instanceof YAMLSequenceItem) { YAMLValue methodNameElement = methodParameter.get(0).getValue(); if(methodNameElement instanceof YAMLScalar) { String methodName = ((YAMLScalar) methodNameElement).getTextValue(); if(StringUtils.isNotBlank(methodName)) { PsiElement callYamlKeyValue = callYamlSeq.getContext();
PsiElement context = yamlScalar.getContext(); if(context instanceof YAMLKeyValue) { String serviceId = getServiceClassFromServiceMapping(parentMapping); if(StringUtils.isNotBlank(serviceId)) { PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlScalar.getProject(), serviceId, lazyServiceCollector); if(serviceClass != null) { Method constructor = serviceClass.getConstructor(); String serviceId = getServiceClassFromServiceMapping(parentMapping); if(StringUtils.isNotBlank(serviceId)) { PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(yamlScalar.getProject(), serviceId, lazyServiceCollector); if(serviceClass != null) { Method constructor = serviceClass.getConstructor();
PsiElement yamlSeq = yamlScalar.getContext(); if(yamlSeq instanceof YAMLSequenceItem) { PsiElement context = yamlSeq.getContext();
/** * [ROLE_USER, FEATURE_ALPHA, ROLE_ALLOWED_TO_SWITCH] */ @NotNull static public Collection<String> getYamlArrayValuesAsList(@NotNull YAMLSequence yamlArray) { Collection<String> keys = new ArrayList<>(); for (YAMLSequenceItem yamlSequenceItem : yamlArray.getItems()) { YAMLValue value = yamlSequenceItem.getValue(); if(!(value instanceof YAMLScalar)) { continue; } String textValue = ((YAMLScalar) value).getTextValue(); if(StringUtils.isNotBlank(textValue)) { keys.add(textValue); } } return keys; }
@Override public void visitElement(PsiElement psiElement) { if(psiElement instanceof YAMLScalar) { String textValue = ((YAMLScalar) psiElement).getTextValue(); if(textValue.length() > 0 && textValue.startsWith("!php/const:")) { String constantName = textValue.substring(11); if(StringUtils.isNotBlank(constantName) && ServiceContainerUtil.getTargetsForConstant(psiElement.getProject(), constantName).size() == 0) { holder.registerProblem(psiElement, MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } } super.visitElement(psiElement); } });
/** * Get false or true value for given key or null if not found or invalid value was found */ @Nullable public static Boolean getYamlKeyValueAsBoolean(@NotNull YAMLKeyValue yamlKeyValue, @NotNull String key) { YAMLKeyValue autowire = YamlHelper.getYamlKeyValue(yamlKeyValue, key); if(autowire == null) { return null; } YAMLValue value = autowire.getValue(); if(!(value instanceof YAMLScalar)) { return null; } String textValue = ((YAMLScalar) value).getTextValue().toLowerCase(); switch (textValue) { case "false": return false; case "true": return true; default: return null; } }
public Map<String, String> getLocalParameterMap(PsiFile psiFile) { Map<String, String> map = new HashMap<>(); for(YAMLKeyValue yamlParameterArray: getQualifiedKeyValuesInFile((YAMLFile) psiFile, "parameters")) { String keyName = yamlParameterArray.getKeyText(); if(StringUtils.isBlank(keyName)) { continue; } // extract parameter value String textValue = null; PsiElement value = yamlParameterArray.getValue(); if(value instanceof YAMLScalar) { String myTextValue = ((YAMLScalar) value).getTextValue(); if(myTextValue.length() > 0 && myTextValue.length() < 150) { textValue = myTextValue; } } map.put(keyName.toLowerCase(), textValue); } return map; }
/** * environment: * - FOOBAR=0 */ private static void visitEnvironmentSquenceItems(@NotNull Consumer<Pair<String, PsiElement>> consumer, @NotNull YAMLKeyValue yamlKeyValue) { YAMLKeyValue environment = YamlHelper.getYamlKeyValue(yamlKeyValue, "environment"); if (environment != null) { for (YAMLSequenceItem yamlSequenceItem : YamlHelper.getSequenceItems(environment)) { YAMLValue value = yamlSequenceItem.getValue(); if (value instanceof YAMLScalar) { String textValue = ((YAMLScalar) value).getTextValue(); if (StringUtils.isNotBlank(textValue)) { String[] split = textValue.split("="); if (split.length > 1) { consumer.accept(Pair.create(split[0], value)); } } } } } } }
/** * Factory goto: "factory: 'foo:bar'" */ @NotNull private Collection<PsiElement> getFactoryStringGoto(@NotNull PsiElement psiElement) { PsiElement parent = psiElement.getParent(); if(!(parent instanceof YAMLScalar)) { return Collections.emptyList(); } String textValue = ((YAMLScalar) parent).getTextValue(); String[] split = textValue.split(":"); if(split.length != 2) { return Collections.emptyList(); } PhpClass phpClass = ServiceUtil.getServiceClass(psiElement.getProject(), split[0]); if(phpClass == null) { return Collections.emptyList(); } Collection<PsiElement> results = new ArrayList<>(); for (Method method : phpClass.getMethods()) { if(split[1].equals(method.getName())) { results.add(method); } } return results; }
String textValue = ((YAMLScalar) value).getTextValue(); if(StringUtils.isNotBlank(textValue)) { tags.add(textValue);
/** * Returns "@foo" value of ["@foo", "fo<caret>o"] */ @Nullable public static String getPreviousSequenceItemAsText(@NotNull PsiElement psiElement) { PsiElement yamlScalar = psiElement.getParent(); if(!(yamlScalar instanceof YAMLScalar)) { return null; } PsiElement yamlSequence = yamlScalar.getParent(); if(!(yamlSequence instanceof YAMLSequenceItem)) { return null; } // @TODO: catch new lexer error on empty item [<caret>,@foo] "PsiErrorElement:Sequence item expected" YAMLSequenceItem prevSequenceItem = PsiTreeUtil.getPrevSiblingOfType(yamlSequence, YAMLSequenceItem.class); if(prevSequenceItem == null) { return null; } YAMLValue value = prevSequenceItem.getValue(); if(!(value instanceof YAMLScalar)) { return null; } return ((YAMLScalar) value).getTextValue(); }
@Nullable public static String getTextValueForElement(@NotNull PsiElement psiElement) { PsiElement parent = psiElement.getParent(); String value = null; if(parent instanceof StringLiteralExpression) { value = ((StringLiteralExpression) parent).getContents(); } else if(parent instanceof XmlAttributeValue) { // <foo attr="FOO"/> value = ((XmlAttributeValue) parent).getValue(); } else if(parent instanceof XmlText) { // <foo>FOO</foo> value = ((XmlText) parent).getValue(); } else if(parent instanceof YAMLScalar) { // foo: foo, foo: 'foo', foo: "foo" value = ((YAMLScalar) parent).getTextValue(); } else if(psiElement.getNode().getElementType() == TwigTokenTypes.STRING_TEXT) { // twig: 'foobar' value = psiElement.getText(); } if(StringUtils.isBlank(value)) { return null; } return value; }
serviceClass = ((YAMLScalar) value).getTextValue();
String textValue = ((YAMLScalar) element).getTextValue(); if(StringUtils.isBlank(textValue)) { continue;
String textValue = ((YAMLScalar) value2).getTextValue();
String textValue = ((YAMLScalar) itemValue).getTextValue(); if(StringUtils.isNotBlank(textValue)) { visitor.visit(new YamlServiceTag(serviceId, textValue, new StaticAttributeResolver("name", textValue)));
PsiElement value = ((YAMLKeyValue) yamlKeyValue).getValue(); if(value instanceof YAMLScalar) { String valueText = ((YAMLScalar) value).getTextValue(); if(StringUtils.isNotBlank(valueText) && valueText.startsWith("@") && valueText.length() > 1) { services.add(
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { PsiElement position = parameters.getPosition(); if(!Symfony2ProjectComponent.isEnabled(position)) { return; } PsiElement parent = position.getParent(); if(!(parent instanceof YAMLScalar)) { return; } String textValue = ((YAMLScalar) parent).getTextValue(); String[] split = textValue.split(":"); if(split.length < 2) { new ServiceCompletionProvider().addCompletions(parameters, processingContext, completionResultSet); return; } PhpClass phpClass = ServiceUtil.getServiceClass(position.getProject(), split[0]); if(phpClass == null) { return; } for (Method method : phpClass.getMethods()) { if(method.getAccess().isPublic() && !(method.getName().startsWith("__"))) { completionResultSet.addElement( LookupElementBuilder.create(split[0] + ":" + method.getName()) .withIcon(method.getIcon()).withTypeText(phpClass.getName(), true) ); } } } }