@Nullable public static YAMLKeyValue getYamlKeyValue(@Nullable YAMLKeyValue yamlKeyValue, String keyName, boolean ignoreCase) { if(yamlKeyValue == null) { return null; } PsiElement yamlCompoundValue = yamlKeyValue.getValue(); if(!(yamlCompoundValue instanceof YAMLCompoundValue)) { return null; } return getYamlKeyValue(yamlCompoundValue, keyName, ignoreCase); }
@Override public void visitElement(final PsiElement element) { if (element instanceof YAMLKeyValue) { final YAMLKeyValue yamlKeyValue = (YAMLKeyValue) element; if (SwaggerConstants.REF_KEY.equals(yamlKeyValue.getKeyText())) { final String refValue = StringUtils.removeAllQuotes(yamlKeyValue.getValueText()); if (isYamlFile(refValue)) { result.add( extractFileNameFromFileRefValue(refValue) + DELIMITER + getSwaggerFileType(yamlKeyValue.getValue(), refValue)); } } } super.visitElement(element); }
@Nullable public static String getYamlKeyValueAsString(@NotNull YAMLKeyValue yamlKeyValue, @NotNull String keyName, boolean ignoreCase) { PsiElement yamlCompoundValue = yamlKeyValue.getValue(); if(!(yamlCompoundValue instanceof YAMLCompoundValue)) { return null; } return getYamlKeyValueAsString((YAMLCompoundValue) yamlCompoundValue, keyName, ignoreCase); }
@Override public void visitElement(final PsiElement element) { if (element instanceof YAMLKeyValue) { final YAMLKeyValue yamlKeyValue = (YAMLKeyValue) element; if (OpenApiConstants.REF_KEY.equals(yamlKeyValue.getKeyText())) { final String refValue = StringUtils.removeAllQuotes(yamlKeyValue.getValueText()); if (isYamlFile(refValue)) { result.add( extractFileNameFromFileRefValue(refValue) + DELIMITER + getOpenApiFileTypeFromRefElement(yamlKeyValue.getValue(), refValue)); } } } super.visitElement(element); }
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; }
/** * 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; }
@Nullable public static String getStringValueOfKeyInProbablyMapping(@Nullable YAMLValue node, @NotNull String keyText) { YAMLKeyValue mapping = YAMLUtil.findKeyInProbablyMapping(node, keyText); if(mapping == null) { return null; } YAMLValue value = mapping.getValue(); if(value == null) { return null; } return value.getText(); }
YAMLValue value = yamlKeyValue.getValue(); if(!(value instanceof YAMLMapping)) { return Collections.emptyMap();
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement psiElement1 = descriptor.getPsiElement(); YAMLKeyValue replacement = YamlPsiElementFactory.createFromText( project, YAMLKeyValue.class, "class: " + replacementFQN ); if (replacement != null && replacement.getValue() != null) { psiElement1.replace(replacement.getValue()); } } }
@Override public boolean isValue(final PsiElement psiElement) { return !(org.apache.commons.lang.StringUtils.isBlank(psiElement.getText()) || psiElement instanceof YAMLKeyValue) && Optional.ofNullable(psiElement.getParent()) .map(PsiElement::getParent) .filter(el -> el instanceof YAMLKeyValue) .map(YAMLKeyValue.class::cast) .filter(el -> el.getValue() == psiElement.getParent()) .isPresent(); }
@Nullable public static Set<String> getKeySet(@Nullable YAMLKeyValue yamlKeyValue) { if(yamlKeyValue == null) { return null; } PsiElement yamlCompoundValue = yamlKeyValue.getValue(); if(yamlCompoundValue == null) { return null; } Set<String> keySet = new HashSet<>(); for(YAMLKeyValue yamlKey: PsiTreeUtil.getChildrenOfTypeAsList(yamlCompoundValue, YAMLKeyValue.class)) { String fieldName = getYamlKeyName(yamlKey); if(fieldName != null) { keySet.add(fieldName); } } return keySet; }
@Override public List<String> getSecurityScopesIfOAuth2(final PsiElement securityDefinitionItem) { final List<YAMLKeyValue> properties = getChildProperties(securityDefinitionItem); final boolean isOAuth2 = properties .stream() .anyMatch( prop -> { final Optional<String> value = Optional.ofNullable(prop.getValue()) .map(YAMLValue::getText) .map(StringUtils::removeAllQuotes); return "type".equals(prop.getName()) && Optional.of("oauth2").equals(value); }); if (isOAuth2) { return properties .stream() .filter(prop -> "scopes".equals(prop.getName())) .map(this::getChildProperties) .flatMap(Collection::stream) .map(YAMLKeyValue::getName) .collect(Collectors.toList()); } return ImmutableList.of(); }
/** * 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; }
@Nullable public static List<DoctrineModelField> getYamlDoctrineFields(String keyName, @Nullable YAMLKeyValue yamlKeyValue) { if(yamlKeyValue == null) { return null; } PsiElement yamlCompoundValue = yamlKeyValue.getValue(); if(yamlCompoundValue == null) { return null; } List<DoctrineModelField> modelFields = new ArrayList<>(); for(YAMLKeyValue yamlKey: PsiTreeUtil.getChildrenOfTypeAsList(yamlCompoundValue, YAMLKeyValue.class)) { String fieldName = YamlHelper.getYamlKeyName(yamlKey); if(fieldName != null) { DoctrineModelField modelField = new DoctrineModelField(fieldName); modelField.addTarget(yamlKey); attachYamlFieldTypeName(keyName, modelField, yamlKey); modelFields.add(modelField); } } return modelFields; }
PsiElement tagsCompound = tagsKeyValue.getValue(); if(!(tagsCompound instanceof YAMLSequence)) { return null;
@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; } }
/** * Find last known KeyValue of key path, so that we can merge new incoming keys */ @NotNull private static Pair<YAMLKeyValue, String[]> findLastKnownKeyInFile(@NotNull YAMLFile file, @NotNull String... keys) { YAMLKeyValue last = null; YAMLMapping mapping = ObjectUtils.tryCast(file.getDocuments().get(0).getTopLevelValue(), YAMLMapping.class); for (int i = 0; i < keys.length; i++) { String s = keys[i]; if (mapping == null) { return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length)); } YAMLKeyValue keyValue = mapping.getKeyValueByKey(s); if (keyValue == null) { return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length)); } last = keyValue; mapping = ObjectUtils.tryCast(keyValue.getValue(), YAMLMapping.class); } return Pair.create(last, new String[]{}); }
YAMLValue value = aClass.getValue(); if(value instanceof YAMLScalar) { serviceClass = ((YAMLScalar) value).getTextValue();
final YAMLValue tagsValue = tagTag.getValue(); if(!(tagsValue instanceof YAMLSequence)) { return;