use of com.intellij.json.psi.JsonElement in project intellij-community by JetBrains.
the class JsonQualifiedNameProvider method getQualifiedName.
@Nullable
@Override
public String getQualifiedName(PsiElement element) {
if (!(element instanceof JsonElement)) {
return null;
}
final LinkedList<String> qualifiers = new LinkedList<>();
JsonProperty parentProperty = PsiTreeUtil.getNonStrictParentOfType(element, JsonProperty.class);
while (parentProperty != null) {
qualifiers.addFirst(parentProperty.getName());
parentProperty = PsiTreeUtil.getParentOfType(parentProperty, JsonProperty.class);
}
return qualifiers.isEmpty() ? null : StringUtil.join(qualifiers, ".");
}
use of com.intellij.json.psi.JsonElement in project intellij-community by JetBrains.
the class JsonSurroundDescriptor method getElementsToSurround.
@NotNull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
PsiElement firstElement = file.findElementAt(startOffset);
PsiElement lastElement = file.findElementAt(endOffset - 1);
// Extend selection beyond possible delimiters
while (firstElement != null && (firstElement instanceof PsiWhiteSpace || firstElement.getNode().getElementType() == JsonElementTypes.COMMA)) {
firstElement = firstElement.getNextSibling();
}
while (lastElement != null && (lastElement instanceof PsiWhiteSpace || lastElement.getNode().getElementType() == JsonElementTypes.COMMA)) {
lastElement = lastElement.getPrevSibling();
}
if (firstElement != null) {
startOffset = firstElement.getTextRange().getStartOffset();
}
if (lastElement != null) {
endOffset = lastElement.getTextRange().getEndOffset();
}
final JsonElement property = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, JsonProperty.class);
if (property != null) {
final List<JsonElement> properties = ContainerUtil.newArrayList(property);
PsiElement nextSibling = property.getNextSibling();
while (nextSibling != null && nextSibling.getTextRange().getEndOffset() <= endOffset) {
if (nextSibling instanceof JsonProperty) {
properties.add((JsonProperty) nextSibling);
}
nextSibling = nextSibling.getNextSibling();
}
return properties.toArray(new PsiElement[properties.size()]);
}
final JsonValue value = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, JsonValue.class);
if (value != null) {
return new PsiElement[] { value };
}
return PsiElement.EMPTY_ARRAY;
}
Aggregations