Search in sources :

Example 1 with DocumentFragment

use of com.intellij.openapi.editor.DocumentFragment 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 2 with DocumentFragment

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

the class JstdConfigFileUtils method extractValueAsDocumentFragment.

@Nullable
public static DocumentFragment extractValueAsDocumentFragment(@NotNull YAMLKeyValue keyValue) {
    PsiElement content = keyValue.getValue();
    if (content == null || content.getTextLength() == 0) {
        return null;
    }
    Document document = JsPsiUtils.getDocument(keyValue);
    if (document == null) {
        return null;
    }
    TextRange contentTextRange = content.getTextRange();
    int endLineNumber = getEndLineNumber(document, content);
    if (endLineNumber > 0 && document.getLineStartOffset(endLineNumber) == contentTextRange.getEndOffset()) {
        endLineNumber--;
    }
    int documentEndOffset = document.getLineEndOffset(endLineNumber);
    DocumentFragment fragment = new DocumentFragment(document, contentTextRange.getStartOffset(), documentEndOffset);
    return UnquotedText.unquoteDocumentFragment(fragment);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) DocumentFragment(com.intellij.openapi.editor.DocumentFragment) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DocumentFragment

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

the class PsiElementFragment method toDocumentFragment.

@Nullable
public DocumentFragment toDocumentFragment() {
    Document document = JsPsiUtils.getDocument(myElement);
    if (document == null) {
        return null;
    }
    TextRange documentTextRange = getDocumentTextRange();
    return new DocumentFragment(document, documentTextRange.getStartOffset(), documentTextRange.getEndOffset());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) DocumentFragment(com.intellij.openapi.editor.DocumentFragment) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DocumentFragment

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

the class UnquotedText method unquoteDocumentFragment.

public static DocumentFragment unquoteDocumentFragment(@NotNull DocumentFragment fragment) {
    String str = fragment.getDocument().getText(fragment.getTextRange());
    TextRange unquoted = calcUnquotedDocumentTextRange(str, fragment.getTextRange());
    return new DocumentFragment(fragment.getDocument(), unquoted.getStartOffset(), unquoted.getEndOffset());
}
Also used : TextRange(com.intellij.openapi.util.TextRange) DocumentFragment(com.intellij.openapi.editor.DocumentFragment)

Example 5 with DocumentFragment

use of com.intellij.openapi.editor.DocumentFragment 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

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