### Question:
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();  }### Answer:
@Test public void rangeToHighlight_with_name() { TreeMetaDataProvider metaDataProvider = new TreeMetaDataProvider(emptyList(), emptyList()); TreeMetaData nameMetaData = metaDataProvider.metaData(range(1, 2, 3, 4)); TreeMetaData bodyMetaData = metaDataProvider.metaData(range(5, 1, 5, 7)); IdentifierTree name = new IdentifierTreeImpl(nameMetaData, "foo"); BlockTree body = new BlockTreeImpl(bodyMetaData, emptyList()); assertThat(new FunctionDeclarationTreeImpl(body.metaData(), emptyList(), false, null, name, emptyList(), body, emptyList()).rangeToHighlight()) .isEqualTo(nameMetaData.textRange()); }
@Test public void rangeToHighlight_with_body_only() { TreeMetaDataProvider metaDataProvider = new TreeMetaDataProvider(emptyList(), Arrays.asList( new TokenImpl(range(5, 1, 17, 18), "{", Token.Type.OTHER), new TokenImpl(range(5, 1, 19, 20), "}", Token.Type.OTHER))); TreeMetaData bodyMetaData = metaDataProvider.metaData(range(5, 1, 17, 20)); BlockTree body = new BlockTreeImpl(bodyMetaData, emptyList()); assertThat(new FunctionDeclarationTreeImpl(body.metaData(), emptyList(), false, null, null, emptyList(), body, emptyList()).rangeToHighlight()) .isEqualTo(body.metaData().textRange()); }
@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)); }