@Test public void rangeToHighlight_with_no_name_but_some_signature() { TreeMetaDataProvider metaDataProvider = new TreeMetaDataProvider(emptyList(), Arrays.asList( new TokenImpl(range(5, 1, 5, 10), "fun", Token.Type.KEYWORD), new TokenImpl(range(5, 11, 5, 15), "foo", Token.Type.OTHER), new TokenImpl(range(5, 17, 5, 18), "{", Token.Type.OTHER), new TokenImpl(range(5, 19, 5, 20), "}", Token.Type.OTHER))); TreeMetaData functionMetaData = metaDataProvider.metaData(range(5, 1, 5, 20)); TreeMetaData bodyMetaData = metaDataProvider.metaData(range(5, 17, 5, 20)); BlockTree body = new BlockTreeImpl(bodyMetaData, emptyList()); assertThat(new FunctionDeclarationTreeImpl(functionMetaData, emptyList(), false, null, null, emptyList(), body, emptyList()).rangeToHighlight()) .isEqualTo(range(5, 1, 5, 15)); }
@Override public TextRange rangeToHighlight() { if (name != null) { return name.metaData().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); }
FunctionDeclarationTreeImpl extends BaseTreeImpl implements FunctionDeclarationTree { @Override public TextRange rangeToHighlight() { if (name != null) { return name.metaData().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); } }
FunctionDeclarationTreeImpl extends BaseTreeImpl implements FunctionDeclarationTree { @Override public TextRange rangeToHighlight() { if (name != null) { return name.metaData().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); } FunctionDeclarationTreeImpl(
    TreeMetaData metaData,
    List<Tree> modifiers,
    boolean isConstructor,
    @Nullable Tree returnType,
    @Nullable IdentifierTree name,
    List<Tree> formalParameters,
    @Nullable BlockTree body,
    List<Tree> nativeChildren); }
FunctionDeclarationTreeImpl extends BaseTreeImpl implements FunctionDeclarationTree { @Override public TextRange rangeToHighlight() { if (name != null) { return name.metaData().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); } FunctionDeclarationTreeImpl(
    TreeMetaData metaData,
    List<Tree> modifiers,
    boolean isConstructor,
    @Nullable Tree returnType,
    @Nullable IdentifierTree name,
    List<Tree> formalParameters,
    @Nullable BlockTree body,
    List<Tree> nativeChildren); @Override List<Tree> modifiers(); @Override boolean isConstructor(); @CheckForNull @Override Tree returnType(); @CheckForNull @Override IdentifierTree name(); @Override List<Tree> formalParameters(); @CheckForNull @Override BlockTree body(); @Override List<Tree> nativeChildren(); @Override TextRange rangeToHighlight(); @Override List<Tree> children(); }
FunctionDeclarationTreeImpl extends BaseTreeImpl implements FunctionDeclarationTree { @Override public TextRange rangeToHighlight() { if (name != null) { return name.metaData().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); } FunctionDeclarationTreeImpl(
    TreeMetaData metaData,
    List<Tree> modifiers,
    boolean isConstructor,
    @Nullable Tree returnType,
    @Nullable IdentifierTree name,
    List<Tree> formalParameters,
    @Nullable BlockTree body,
    List<Tree> nativeChildren); @Override List<Tree> modifiers(); @Override boolean isConstructor(); @CheckForNull @Override Tree returnType(); @CheckForNull @Override IdentifierTree name(); @Override List<Tree> formalParameters(); @CheckForNull @Override BlockTree body(); @Override List<Tree> nativeChildren(); @Override TextRange rangeToHighlight(); @Override List<Tree> children();  }