@Test public void rangeToHighlight() { TreeMetaDataProvider metaDataProvider = new TreeMetaDataProvider(emptyList(), TOKENS); TreeMetaData matchCaseMetaData = metaDataProvider.metaData(range(1, 1, 1, 10)); TreeMetaData bodyMetaData = metaDataProvider.metaData(range(1, 9, 1, 10)); BlockTree body = new BlockTreeImpl(bodyMetaData, Collections.singletonList(new IdentifierTreeImpl(bodyMetaData, "a"))); assertThat(new MatchCaseTreeImpl(matchCaseMetaData, null, body).rangeToHighlight()) .isEqualTo(range(1, 1, 1, 8)); }
@Override public TextRange rangeToHighlight() { if (body == null) { return textRange(); } TextRange bodyRange = body.metaData().textRange(); List<TextRange> tokenRangesBeforeBody = metaData().tokens().stream() .map(Token::textRange) .filter(t -> t.start().compareTo(bodyRange.start()) < 0) .collect(Collectors.toList()); if (tokenRangesBeforeBody.isEmpty()) { return bodyRange; } return TextRanges.merge(tokenRangesBeforeBody); }
MatchCaseTreeImpl extends BaseTreeImpl implements MatchCaseTree { @Override public TextRange rangeToHighlight() { if (body == null) { return textRange(); } TextRange bodyRange = body.metaData().textRange(); List<TextRange> tokenRangesBeforeBody = metaData().tokens().stream() .map(Token::textRange) .filter(t -> t.start().compareTo(bodyRange.start()) < 0) .collect(Collectors.toList()); if (tokenRangesBeforeBody.isEmpty()) { return bodyRange; } return TextRanges.merge(tokenRangesBeforeBody); } }
MatchCaseTreeImpl extends BaseTreeImpl implements MatchCaseTree { @Override public TextRange rangeToHighlight() { if (body == null) { return textRange(); } TextRange bodyRange = body.metaData().textRange(); List<TextRange> tokenRangesBeforeBody = metaData().tokens().stream() .map(Token::textRange) .filter(t -> t.start().compareTo(bodyRange.start()) < 0) .collect(Collectors.toList()); if (tokenRangesBeforeBody.isEmpty()) { return bodyRange; } return TextRanges.merge(tokenRangesBeforeBody); } MatchCaseTreeImpl(TreeMetaData metaData, @Nullable Tree expression, @Nullable Tree body); }
MatchCaseTreeImpl extends BaseTreeImpl implements MatchCaseTree { @Override public TextRange rangeToHighlight() { if (body == null) { return textRange(); } TextRange bodyRange = body.metaData().textRange(); List<TextRange> tokenRangesBeforeBody = metaData().tokens().stream() .map(Token::textRange) .filter(t -> t.start().compareTo(bodyRange.start()) < 0) .collect(Collectors.toList()); if (tokenRangesBeforeBody.isEmpty()) { return bodyRange; } return TextRanges.merge(tokenRangesBeforeBody); } MatchCaseTreeImpl(TreeMetaData metaData, @Nullable Tree expression, @Nullable Tree body); @CheckForNull @Override Tree expression(); @CheckForNull @Override Tree body(); @Override TextRange rangeToHighlight(); @Override List<Tree> children(); }
MatchCaseTreeImpl extends BaseTreeImpl implements MatchCaseTree { @Override public TextRange rangeToHighlight() { if (body == null) { return textRange(); } TextRange bodyRange = body.metaData().textRange(); List<TextRange> tokenRangesBeforeBody = metaData().tokens().stream() .map(Token::textRange) .filter(t -> t.start().compareTo(bodyRange.start()) < 0) .collect(Collectors.toList()); if (tokenRangesBeforeBody.isEmpty()) { return bodyRange; } return TextRanges.merge(tokenRangesBeforeBody); } MatchCaseTreeImpl(TreeMetaData metaData, @Nullable Tree expression, @Nullable Tree body); @CheckForNull @Override Tree expression(); @CheckForNull @Override Tree body(); @Override TextRange rangeToHighlight(); @Override List<Tree> children();  }