Search in sources :

Example 6 with YAMLKeyValue

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;
}
Also used : YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) DocumentFragment(com.intellij.openapi.editor.DocumentFragment) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with YAMLKeyValue

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;
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 8 with YAMLKeyValue

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;
}
Also used : PsiRecursiveElementVisitor(com.intellij.psi.PsiRecursiveElementVisitor) YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

Example 9 with YAMLKeyValue

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));
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with YAMLKeyValue

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();
}
Also used : YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) YAMLValue(org.jetbrains.yaml.psi.YAMLValue) YAMLMapping(org.jetbrains.yaml.psi.YAMLMapping) DocumentFragment(com.intellij.openapi.editor.DocumentFragment) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

YAMLKeyValue (org.jetbrains.yaml.psi.YAMLKeyValue)11 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 YAMLValue (org.jetbrains.yaml.psi.YAMLValue)3 DocumentFragment (com.intellij.openapi.editor.DocumentFragment)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiRecursiveElementVisitor (com.intellij.psi.PsiRecursiveElementVisitor)2 HashSet (com.intellij.util.containers.HashSet)2 YAMLDocument (org.jetbrains.yaml.psi.YAMLDocument)2 YAMLMapping (org.jetbrains.yaml.psi.YAMLMapping)2 ASTNode (com.intellij.lang.ASTNode)1 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 ProcessingContext (com.intellij.util.ProcessingContext)1 DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)1