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;
}
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);
}
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());
}
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());
}
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();
}
Aggregations