Search in sources :

Example 6 with DocumentFragment

use of com.intellij.openapi.editor.DocumentFragment in project intellij-plugins by JetBrains.

the class JstdConfigFileAnnotator method annotateFileSequence.

private static void annotateFileSequence(@NotNull YAMLSequenceItem sequence, @NotNull final AnnotationHolder holder, @Nullable final VirtualFile basePath, @NotNull final String expectedIndent) {
    checkSequenceIndent(sequence, holder, expectedIndent);
    final YAMLValue value = sequence.getValue();
    if (value == null) {
        holder.createErrorAnnotation(sequence, "Sequence item is empty");
        return;
    }
    if (value instanceof YAMLSequence) {
        for (YAMLSequenceItem item : ((YAMLSequence) value).getItems()) {
            annotateFileSequence(item, holder, basePath, expectedIndent);
        }
    }
    if (value instanceof YAMLScalar && ((YAMLScalar) value).isMultiline()) {
        holder.createErrorAnnotation(sequence, "Unexpected multiline path");
        return;
    }
    PsiElementFragment<YAMLSequenceItem> sequenceTextFragment = JstdConfigFileUtils.buildSequenceTextFragment(sequence);
    if (basePath != null && sequenceTextFragment != null) {
        DocumentFragment documentFragment = sequenceTextFragment.toDocumentFragment();
        if (documentFragment != null) {
            annotatePath(basePath, documentFragment, holder, true, false);
        }
    }
}
Also used : DocumentFragment(com.intellij.openapi.editor.DocumentFragment)

Example 7 with DocumentFragment

use of com.intellij.openapi.editor.DocumentFragment in project intellij-plugins by JetBrains.

the class JstdConfigFileAnnotator method annotateBasePath.

private static void annotateBasePath(@NotNull BasePathInfo basePathInfo, @NotNull AnnotationHolder holder) {
    YAMLKeyValue keyValue = basePathInfo.getKeyValue();
    if (keyValue != null) {
        DocumentFragment documentFragment = basePathInfo.getValueAsDocumentFragment();
        if (documentFragment == null) {
            int offset = keyValue.getTextRange().getEndOffset();
            holder.createErrorAnnotation(TextRange.create(offset - 1, offset), "path is unspecified");
        } else {
            VirtualFile configDir = basePathInfo.getConfigDir();
            if (configDir != null) {
                annotatePath(configDir, documentFragment, holder, false, true);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentFragment(com.intellij.openapi.editor.DocumentFragment)

Aggregations

DocumentFragment (com.intellij.openapi.editor.DocumentFragment)7 Nullable (org.jetbrains.annotations.Nullable)4 TextRange (com.intellij.openapi.util.TextRange)3 Document (com.intellij.openapi.editor.Document)2 YAMLKeyValue (org.jetbrains.yaml.psi.YAMLKeyValue)2 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 YAMLMapping (org.jetbrains.yaml.psi.YAMLMapping)1 YAMLValue (org.jetbrains.yaml.psi.YAMLValue)1