Skip to content

Latest commit

 

History

History
70 lines (53 loc) · 2.25 KB

README.md

File metadata and controls

70 lines (53 loc) · 2.25 KB

AutoValue: Nested toString()

Build Status

An extension for Google's AutoValue that prepends the enclosing classes' names to the toString() method of a @Nested annotated nested class.

Usage

Apply the @Nested annotation to any nested class whose toString() you wish to modify in order to include the enclosing classes.

public class TopLevelClass {

  public static class NestedClass {
  
    @AutoValue
    @Nested
    public static abstract class NestedInNestedClass {
       public abstract String property();
    }
  }
}

When you call a NestedInNestedClass instance's toString() this will include the enclosing classes at the beginning

TopLevelClass.NestedClass.NestedInNestedClass{property=name} //auto-value-nested-tostring

as opposed to AutoValue's default (simple class name)

NestedInNestedClass{property=name} //AutoValue's default

Download

Add a Gradle dependency:

annotationProcessor 'com.christiangp:auto-value-nested-tostring:<latest_version>'
provided 'com.christiangp:auto-value-nested-tostring-annotations:<latest_version>'

or Maven:

<dependency>
  <groupId>com.christiangp</groupId>
  <artifactId>auto-value-nested-tostring</artifactId>
  <version>$latest_version</version>
  <scope>provided</scope>
</dependency>

License

Copyright (c) 2017 Christian García

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.