Class PmdCoordinatesSystem
- java.lang.Object
-
- net.sourceforge.pmd.util.fxdesigner.util.codearea.PmdCoordinatesSystem
-
public final class PmdCoordinatesSystem extends java.lang.ObjectMaps PMD's (line, column) coordinate system to and from the code area's one-dimensional (absolute offset-based) system.- Since:
- 6.13.0
- Author:
- Clément Fournier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPmdCoordinatesSystem.TextPos2DTwoDimensional.Positionkeeps a reference to the codearea we don't need.static classPmdCoordinatesSystem.TextRange
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontains(net.sourceforge.pmd.lang.ast.Node node, PmdCoordinatesSystem.TextPos2D pos)Returns true if the given node contains the position.static PmdCoordinatesSystem.TextPos2DendPosition(net.sourceforge.pmd.lang.ast.Node node)static java.util.Optional<net.sourceforge.pmd.lang.ast.Node>findNodeAt(net.sourceforge.pmd.lang.ast.Node root, PmdCoordinatesSystem.TextPos2D target)Locates the innermost node in the given [root] that contains the position at [textOffset] in the [codeArea].static java.util.Optional<net.sourceforge.pmd.lang.ast.Node>findNodeCovering(net.sourceforge.pmd.lang.ast.Node root, PmdCoordinatesSystem.TextRange range, boolean exact)Returns the innermost node that covers the entire given text range in the given tree.static intgetOffsetFromPmdPosition(org.fxmisc.richtext.CodeArea codeArea, int line, int column)Returns the absolute offset of the given pair (line, column) as computed by a PMD parser in the code area.static PmdCoordinatesSystem.TextPos2DgetPmdLineAndColumnFromOffset(org.fxmisc.richtext.CodeArea codeArea, int absoluteOffset)Inverse ofgetOffsetFromPmdPosition(CodeArea, int, int).static intgetPmdLineFromRtfxParIndex(int line)static intgetRtfxParIndexFromPmdLine(int line)static PmdCoordinatesSystem.TextRangerangeOf(net.sourceforge.pmd.lang.ast.Node node)static PmdCoordinatesSystem.TextPos2DrtfxRangeOf(net.sourceforge.pmd.lang.ast.Node node, org.fxmisc.richtext.CodeArea area)Returns aPmdCoordinatesSystem.TextPos2Dthat uses its coordinates as begin and end offset of the [node] in the [area].static PmdCoordinatesSystem.TextPos2DstartPosition(net.sourceforge.pmd.lang.ast.Node node)
-
-
-
Method Detail
-
getRtfxParIndexFromPmdLine
public static int getRtfxParIndexFromPmdLine(int line)
-
getPmdLineFromRtfxParIndex
public static int getPmdLineFromRtfxParIndex(int line)
-
getPmdLineAndColumnFromOffset
public static PmdCoordinatesSystem.TextPos2D getPmdLineAndColumnFromOffset(org.fxmisc.richtext.CodeArea codeArea, int absoluteOffset)
Inverse ofgetOffsetFromPmdPosition(CodeArea, int, int). Converts an absolute offset obtained from the given code area into the line and column a PMD parser would have assigned to it.
-
getOffsetFromPmdPosition
public static int getOffsetFromPmdPosition(org.fxmisc.richtext.CodeArea codeArea, int line, int column)Returns the absolute offset of the given pair (line, column) as computed by a PMD parser in the code area.- CodeArea counts a tab as 1 column width but displays it as 8 columns width. PMD counts it correctly as 8 columns, so the position must be offset.
- PMD lines start at 1 but paragraph nums start at 0 in the code area, same for columns.
- PMD's end column is inclusive and not exclusive.
-
findNodeAt
public static java.util.Optional<net.sourceforge.pmd.lang.ast.Node> findNodeAt(net.sourceforge.pmd.lang.ast.Node root, PmdCoordinatesSystem.TextPos2D target)Locates the innermost node in the given [root] that contains the position at [textOffset] in the [codeArea].
-
findNodeCovering
public static java.util.Optional<net.sourceforge.pmd.lang.ast.Node> findNodeCovering(net.sourceforge.pmd.lang.ast.Node root, PmdCoordinatesSystem.TextRange range, boolean exact)Returns the innermost node that covers the entire given text range in the given tree.- Parameters:
root- Root of the treerange- Range to findexact- If true, will return the *outermost* node whose range is *exactly* the given text range, otherwise it may be larger.
-
contains
public static boolean contains(net.sourceforge.pmd.lang.ast.Node node, PmdCoordinatesSystem.TextPos2D pos)Returns true if the given node contains the position.
-
startPosition
public static PmdCoordinatesSystem.TextPos2D startPosition(net.sourceforge.pmd.lang.ast.Node node)
-
endPosition
public static PmdCoordinatesSystem.TextPos2D endPosition(net.sourceforge.pmd.lang.ast.Node node)
-
rangeOf
public static PmdCoordinatesSystem.TextRange rangeOf(net.sourceforge.pmd.lang.ast.Node node)
-
rtfxRangeOf
public static PmdCoordinatesSystem.TextPos2D rtfxRangeOf(net.sourceforge.pmd.lang.ast.Node node, org.fxmisc.richtext.CodeArea area)
Returns aPmdCoordinatesSystem.TextPos2Dthat uses its coordinates as begin and end offset of the [node] in the [area].
-
-