Class PmdCoordinatesSystem
- java.lang.Object
-
- net.sourceforge.pmd.util.fxdesigner.util.codearea.PmdCoordinatesSystem
-
public final class PmdCoordinatesSystem extends java.lang.Object
Maps 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 class
PmdCoordinatesSystem.TextPos2D
TwoDimensional.Position
keeps a reference to the codearea we don't need.static class
PmdCoordinatesSystem.TextRange
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
contains(net.sourceforge.pmd.lang.ast.Node node, PmdCoordinatesSystem.TextPos2D pos)
Returns true if the given node contains the position.static PmdCoordinatesSystem.TextPos2D
endPosition(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 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.static PmdCoordinatesSystem.TextPos2D
getPmdLineAndColumnFromOffset(org.fxmisc.richtext.CodeArea codeArea, int absoluteOffset)
Inverse ofgetOffsetFromPmdPosition(CodeArea, int, int)
.static int
getPmdLineFromRtfxParIndex(int line)
static int
getRtfxParIndexFromPmdLine(int line)
static PmdCoordinatesSystem.TextRange
rangeOf(net.sourceforge.pmd.lang.ast.Node node)
static PmdCoordinatesSystem.TextPos2D
rtfxRangeOf(net.sourceforge.pmd.lang.ast.Node node, org.fxmisc.richtext.CodeArea area)
Returns aPmdCoordinatesSystem.TextPos2D
that uses its coordinates as begin and end offset of the [node] in the [area].static PmdCoordinatesSystem.TextPos2D
startPosition(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.TextPos2D
that uses its coordinates as begin and end offset of the [node] in the [area].
-
-