All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aya.intellij.MarkerNodeWrapper Maven / Gradle / Ivy

The newest version!
package org.aya.intellij;

import com.intellij.openapi.util.TextRange;
import com.intellij.psi.tree.IElementType;
import com.jetbrains.lang.parsing.AstMarkersSyntaxNode;
import com.jetbrains.lang.parsing.builder.AstMarkerVisitorKt;
import com.jetbrains.lang.syntax.SyntaxNodeExtKt;
import kala.text.StringSlice;
import kotlin.sequences.Sequence;
import kotlin.sequences.SequencesKt;
import org.jetbrains.annotations.NotNull;

public record MarkerNodeWrapper(
  @NotNull AstMarkersSyntaxNode node,
  @Override @NotNull StringSlice tokenText
) implements GenericNode {
  public MarkerNodeWrapper(@NotNull String code, @NotNull AstMarkersSyntaxNode node) {
    this(node, StringSlice.of(code, (int) node.getStartOffset(), (int) node.getEndOffset()));
  }

  @Override public @NotNull IElementType elementType() {
    return node.getElementType();
  }

  @SuppressWarnings("UnstableApiUsage") @Override
  public @NotNull Sequence childrenSequence() {
    return SequencesKt.map(SyntaxNodeExtKt.children(node), c ->
      new MarkerNodeWrapper(tokenText.source(), (AstMarkersSyntaxNode) c));
  }

  @Override public @NotNull TextRange range() {
    return new TextRange((int) node.getStartOffset(), (int) node.getEndOffset());
  }

  @Override public @NotNull String toDebugString() {
    return AstMarkerVisitorKt.toDebugString(node);
  }

  @Override public @NotNull String pp() {
    return SyntaxNodeExtKt.pp(node, "  ");
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy