本文整理汇总了Java中org.jetbrains.yaml.YAMLUtil类的典型用法代码示例。如果您正苦于以下问题:Java YAMLUtil类的具体用法?Java YAMLUtil怎么用?Java YAMLUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
YAMLUtil类属于org.jetbrains.yaml包,在下文中一共展示了YAMLUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTableModel
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@Override
public TranslationTableModel createTableModel() {
detactLanguages();
Collection<String> availableKeys = new LinkedHashSet<>();//preserve order, no dups
ConcurrentHashMap<String, Collection<YAMLKeyValue>> dataMap = new ConcurrentHashMap<>();
VirtualFile virtualFile = fileMap.elements().nextElement();
YAMLFileImpl yamlFile = (YAMLFileImpl) PsiManager.getInstance(project).findFile(virtualFile);
if (yamlFile != null) {
Collection<YAMLKeyValue> topLevelKeys = YAMLUtil.getTopLevelKeys(yamlFile);
for (String eachLanguage : languages) {
dataMap.put(eachLanguage, new HashSet<>());
Collection<YAMLKeyValue> topLevelValuesLang = findChildValues(topLevelKeys, eachLanguage);
for (YAMLKeyValue keyValue : topLevelValuesLang) {
if (keyValue.getValue() instanceof YAMLCompoundValue) {
List<String> keysBuffer = new ArrayList<>();
getCompoundKeys0(keyValue, keyValue.getKeyText(), keysBuffer, dataMap, eachLanguage);
availableKeys.addAll(keysBuffer);
} else {
availableKeys.add(keyValue.getKeyText());
dataMap.get(eachLanguage).add(keyValue);
}
}
}
}
return new TranslationTableModel(availableKeys, dataMap).setPrefixKey(true);
}
示例2: getHelpersInFile
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
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());
NeosProjectComponent.getLogger().debug(keyValue.getKeyText() + ": " + keyValue.getValueText());
}
}
}
}
return result;
}
示例3: multiResolve
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
String nodeTypeNameToFindReferenceFor = yamlElement.getKeyText();
// files which contain the NodeType definition
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NodeTypesYamlFileIndex.KEY, nodeTypeNameToFindReferenceFor, GlobalSearchScope.allScope(yamlElement.getProject()));
return files
.stream()
// get the PSI for each file
.map(file -> PsiManager.getInstance(yamlElement.getProject()).findFile(file))
// ensure we only have YAML files
.filter(psiFile -> psiFile instanceof YAMLFile)
.map(psiFile -> (YAMLFile) psiFile)
// get all YAML keys in these files
.flatMap(yamlFile -> YAMLUtil.getTopLevelKeys(yamlFile).stream())
// get the correct YAML key
.filter(yamlKeyValue -> yamlKeyValue.getKeyText().equals(nodeTypeNameToFindReferenceFor))
// remove "current" element if it exists
.filter(yamlKeyValue -> yamlElement != yamlKeyValue)
// build up the result object
.map(yamlKeyValue -> new PsiElementResolveResult(yamlKeyValue, true))
.toArray(PsiElementResolveResult[]::new);
}
示例4: invokeTranslation
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
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;
}
示例5: insertKeyIntoFile
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@Nullable
public static PsiElement insertKeyIntoFile(final @NotNull YAMLFile yamlFile, final @NotNull YAMLKeyValue yamlKeyValue, @NotNull String... keys) {
String keyText = yamlKeyValue.getKeyText();
return insertKeyIntoFile(yamlFile, (yamlMapping, chainedKey) -> {
String text = yamlKeyValue.getText();
final String previousIndent = StringUtil.repeatSymbol(' ', YAMLUtil.getIndentInThisLine(yamlMapping));
// split content of array value object;
// drop first item as getValueText() removes our key indent
String[] remove = (String[]) ArrayUtils.remove(text.split("\\r?\\n"), 0);
List<String> map = ContainerUtil.map(remove, s -> previousIndent + s);
return "\n" + StringUtils.strip(StringUtils.join(map, "\n"), "\n");
}, (String[]) ArrayUtils.add(keys, keyText));
}
示例6: createFileMap
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@Override
public void createFileMap(@NotNull VirtualFile file) {
fileMap.clear();
YAMLFile yamlFile = (YAMLFile) PsiManager.getInstance(project).findFile(file);
if (yamlFile != null) {
Collection<YAMLKeyValue> topLevelKeys = YAMLUtil.getTopLevelKeys(yamlFile);
for (YAMLKeyValue each : topLevelKeys) {
fileMap.put(each.getKeyText(), file);
}
}
}
示例7: createTableModel
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@Override
public TranslationTableModel createTableModel() {
detactLanguages();
ConcurrentHashMap<String, Collection<YAMLKeyValue>> dataMap = new ConcurrentHashMap<>();
Collection<String> availableKeys = new LinkedHashSet<>();//preserve order, no dups
Collection<VirtualFile> removeFiles = new ArrayList<>();
Set<Map.Entry<String, VirtualFile>> set = fileMap.entrySet();
for (Map.Entry<String, VirtualFile> each : set) {
//this should never be accessed if VirtualFileListener works correctly
if (each.getValue() == null || !each.getValue().exists()) {
fileMap.remove(each.getKey());
continue;
}
YAMLFileImpl yamlFile = (YAMLFileImpl) PsiManager.getInstance(project).findFile(each.getValue());
if (yamlFile != null) {
String lang = each.getValue().getNameWithoutExtension();
dataMap.put(lang, new HashSet<>());
for (YAMLKeyValue keyValue : YAMLUtil.getTopLevelKeys(yamlFile)) {
if (keyValue.getValue() instanceof YAMLCompoundValue) {
List<String> keysBuffer = new ArrayList<>();
getCompoundKeys0(keyValue, keyValue.getKeyText(), keysBuffer, dataMap, lang);
availableKeys.addAll(keysBuffer);
} else {
availableKeys.add(keyValue.getKeyText());
dataMap.get(lang).add(keyValue);
}
}
}
}
return new TranslationTableModel(availableKeys, dataMap);
}
示例8: doIndex
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@NotNull
private Map<String, Void> doIndex(FileContent fileContent) {
Map<String, Void> result = new HashMap<>();
YAMLUtil.getTopLevelKeys((YAMLFile)fileContent.getPsiFile())
.forEach(yamlKeyValue -> result.put(yamlKeyValue.getKeyText(), null));
return result;
}
示例9: getNodeTypeDefinitions
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
public static Collection<PsiElement> getNodeTypeDefinitions(Project project, String name, @Nullable String namespace) {
String fqn = "Neos.Neos" + ":" + name;
if (namespace != null) {
String aliasNamespace = findNamespaceByAlias(project, namespace);
if (aliasNamespace != null) {
fqn = aliasNamespace + ":" + name;
} else {
fqn = namespace + ":" + name;
}
}
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NodeTypesYamlFileIndex.KEY, fqn, GlobalSearchScope.allScope(project));
// Check for legacy namespace
if (files.isEmpty() && namespace == null) {
return getNodeTypeDefinitions(project, name, "TYPO3.Neos");
}
final String finalFqn = fqn;
return files
.stream()
// get the PSI for each file
.map(file -> PsiManager.getInstance(project).findFile(file))
// ensure we only have YAML files
.filter(psiFile -> psiFile instanceof YAMLFile)
.map(psiFile -> (YAMLFile) psiFile)
// get all YAML keys in these files
.flatMap(yamlFile -> YAMLUtil.getTopLevelKeys(yamlFile).stream())
// get the correct YAML key
.filter(yamlKeyValue -> yamlKeyValue.getKeyText().equals(finalFqn))
.collect(Collectors.toList());
}
示例10: invoke
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException {
final YAMLElementGenerator elementGenerator = YAMLElementGenerator.getInstance(project);
for (final String missingKey : missingKeys) {
final YAMLKeyValue newKeyValue = elementGenerator.createYamlKeyValue(missingKey, "");
mapping.add(elementGenerator.createEol());
mapping.add(elementGenerator.createIndent(YAMLUtil.getIndentToThisElement(mapping)));
mapping.add(newKeyValue);
}
}
示例11: isKubernetesFile
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
/**
* Determines whether the element is within a Kubernetes YAML file. This is done by checking for the presence of "apiVersion" or "kind" as top-level keys within the first document of the file.
*
* @param element an element within the file to check.
* @return true if the element is within A Kubernetes YAML file, otherwise, false.
*/
public static boolean isKubernetesFile(final PsiElement element) {
final PsiFile file = element.getContainingFile();
if (file instanceof YAMLFile) {
final Collection<YAMLKeyValue> keys = YAMLUtil.getTopLevelKeys((YAMLFile) file);
return keys.stream().map(YAMLKeyValue::getKeyText).anyMatch(s -> "apiVersion".equals(s) || "kind".equals(s));
}
return false;
}
示例12: createDefaults
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
@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;
}
示例13: getTwigGlobalsFromYamlConfig
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
/**
* 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;
}
示例14: visitRoot
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
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);
}
}
示例15: processKeysAfterRoot
import org.jetbrains.yaml.YAMLUtil; //导入依赖的package包/类
/**
* 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);
}
}
}
}
}