use of org.jetbrains.yaml.psi.YAMLKeyValue in project intellij-plugins by JetBrains.
the class JstdConfigFileReferenceContributor method createBasePathRef.
@Nullable
private static PsiReference createBasePathRef(@NotNull BasePathInfo basePathInfo) {
DocumentFragment documentFragment = basePathInfo.getValueAsDocumentFragment();
YAMLKeyValue keyValue = basePathInfo.getKeyValue();
if (documentFragment != null && keyValue != null) {
PsiElementFragment<YAMLKeyValue> keyValueFragment = PsiElementFragment.create(keyValue, documentFragment);
if (keyValueFragment != null) {
return new MyPsiReference(keyValueFragment, basePathInfo, ".");
}
}
return null;
}
use of org.jetbrains.yaml.psi.YAMLKeyValue in project intellij-swagger by zalando.
the class OpenApiDataIndexer method getPartialYamlOpenApiFileNames.
private Set<String> getPartialYamlOpenApiFileNames(final PsiFile file) {
final Set<String> result = new HashSet<>();
file.accept(new PsiRecursiveElementVisitor() {
@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 boolean isYamlFile(String refValue) {
return refValue.contains(FileConstants.YAML_FILE_NAME_SUFFIX) || refValue.contains(FileConstants.YML_FILE_NAME_SUFFIX);
}
});
return result;
}
use of org.jetbrains.yaml.psi.YAMLKeyValue in project intellij-swagger by zalando.
the class SwaggerDataIndexer method getPartialYamlSwaggerFileNames.
private Set<String> getPartialYamlSwaggerFileNames(final PsiFile file) {
final Set<String> result = new HashSet<>();
file.accept(new PsiRecursiveElementVisitor() {
@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);
}
private boolean isYamlFile(String refValue) {
return refValue.contains(FileConstants.YAML_FILE_NAME_SUFFIX) || refValue.contains(FileConstants.YML_FILE_NAME_SUFFIX);
}
});
return result;
}
use of org.jetbrains.yaml.psi.YAMLKeyValue in project intellij-plugins by JetBrains.
the class DartPathPackageReferenceInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!PubspecYamlUtil.PUBSPEC_YAML.equals(holder.getFile().getName()))
return super.buildVisitor(holder, isOnTheFly);
final Module module = ModuleUtilCore.findModuleForPsiElement(holder.getFile());
final DartSdk sdk = DartSdk.getDartSdk(holder.getProject());
if (module == null || sdk == null || !DartSdkLibUtil.isDartSdkEnabled(module)) {
return super.buildVisitor(holder, isOnTheFly);
}
return new PsiElementVisitor() {
@Override
public void visitElement(final PsiElement element) {
ProgressIndicatorProvider.checkCanceled();
if (!(element instanceof YAMLKeyValue) || !PubspecYamlReferenceContributor.isPathPackageDefinition((YAMLKeyValue) element) || ((YAMLKeyValue) element).getValue() == null) {
return;
}
final VirtualFile packageDir = checkReferences(holder, (YAMLKeyValue) element);
if (packageDir == null) {
return;
}
if (packageDir.findChild(PubspecYamlUtil.PUBSPEC_YAML) == null) {
final String message = DartBundle.message("pubspec.yaml.not.found.in", FileUtil.toSystemDependentName(packageDir.getPath()));
holder.registerProblem(((YAMLKeyValue) element).getValue(), message);
return;
}
final VirtualFile file = DartResolveUtil.getRealVirtualFile(element.getContainingFile());
if (file != null && packageDir.equals(file.getParent())) {
holder.registerProblem(((YAMLKeyValue) element).getValue(), DartBundle.message("path.package.reference.to.itself"));
return;
}
final VirtualFile libDir = packageDir.findChild(PubspecYamlUtil.LIB_DIR_NAME);
if (libDir != null && libDir.isDirectory() && !ProjectRootManager.getInstance(element.getProject()).getFileIndex().isInContent(libDir)) {
final String message = DartBundle.message("folder.0.not.in.project.content", FileUtil.toSystemDependentName(packageDir.getPath()));
holder.registerProblem(((YAMLKeyValue) element).getValue(), message, new AddContentRootFix(module, packageDir));
}
}
};
}
use of org.jetbrains.yaml.psi.YAMLKeyValue in project intellij-plugins by JetBrains.
the class BasePathInfo method extractBasePathPair.
@Nullable
private static Pair<YAMLKeyValue, DocumentFragment> extractBasePathPair(@NotNull YAMLDocument yamlDocument) {
final Ref<Pair<YAMLKeyValue, DocumentFragment>> result = Ref.create(null);
final YAMLValue value = yamlDocument.getTopLevelValue();
if (value instanceof YAMLMapping) {
for (YAMLKeyValue keyValue : ((YAMLMapping) value).getKeyValues()) {
if (keyValue != null && isBasePathKey(keyValue) && result.isNull()) {
DocumentFragment valueFragment = JstdConfigFileUtils.extractValueAsDocumentFragment(keyValue);
result.set(Pair.create(keyValue, valueFragment));
}
}
}
return result.get();
}
Aggregations