Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompareTo Method generation also includes variables which are not comparable #15

Closed
arolfes opened this issue Jul 7, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@arolfes
Copy link
Contributor

arolfes commented Jul 7, 2015

if you a variable which does not implement the comparable interface generated code does not compile.

Example

public class SampleBean implements Comparable<SampleBean> {

    private int testInt;

    private String testString;

    private Object testObject;

    @Override
    public int compareTo(SampleBean that){
        return ComparisonChain.start()
            .compare(this.testInt, that.testInt)
            .compare(this.testString, that.testString)
// The next line does not compile
// should be comment out
            .compare(this.testObject, that.testObject)
            .result();
        }
}
@arolfes arolfes added the bug label Jul 7, 2015
@arolfes
Copy link
Contributor Author

arolfes commented Jul 9, 2015

for given example the output would be:

public class SampleBean implements Comparable<SampleBean> {

    private int testInt;

    private String testString;

    private Object testObject;

    @Override
    public int compareTo(SampleBean that) {
        return ComparisonChain.start().compare(this.testInt, that.testInt)
                .compare(this.testString, that.testString)
                // XXX field 'testObject' java.lang.Object is not comparable 
                //.compare(this.testObject, that.testObject)
                .result();
    }

}

@arolfes arolfes self-assigned this Jul 9, 2015
@arolfes
Copy link
Contributor Author

arolfes commented Jul 9, 2015

a more complex example

public class CompareTest implements Comparable<CompareTest> {

    private String[] arraySample1;

    private ClassWithComparable compEnabled;

    private ClassWithoutComparable compDisabled;

    private int intValue3;

    private SampleEnum enumValue1;

    private String simpleString1;

    private InterfaceWithComparable iFaceWithComp;

    private InterfaceWithoutComparable iFaceWithoutComp;

    private ClassExtendsSomeComparable compEnabled2;

    private ClassExtendSomeNonComparable compDisabled2;

    private AbstractClassWithComparable compEnabled3;

    private AbstractClassWithoutComparable compDisabled3;

    @Override
    public int compareTo(CompareTest that) {
        return ComparisonChain.start()
                // XXX field 'arraySample1' is an Array! and they are not comparable by default 
                //.compare(this.arraySample1, that.arraySample1)
                .compare(this.compEnabled, that.compEnabled)
                // XXX field 'compDisabled'  does not implements java.lang.Comparable 
                //.compare(this.compDisabled, that.compDisabled)
                .compare(this.intValue3, that.intValue3)
                .compare(this.enumValue1, that.enumValue1)
                .compare(this.simpleString1, that.simpleString1)
                .compare(this.iFaceWithComp, that.iFaceWithComp)
                // XXX field 'iFaceWithoutComp'  does not implements java.lang.Comparable 
                //.compare(this.iFaceWithoutComp, that.iFaceWithoutComp)
                .compare(this.compEnabled2, that.compEnabled2)
                // XXX field 'compDisabled2'  does not implements java.lang.Comparable 
                //.compare(this.compDisabled2, that.compDisabled2)
                .compare(this.compEnabled3, that.compEnabled3)
                // XXX field 'compDisabled3'  does not implements java.lang.Comparable 
                //.compare(this.compDisabled3, that.compDisabled3)
                .result();
    }

}

@arolfes arolfes added this to the 1.4.0 milestone Jul 9, 2015
arolfes added a commit that referenced this issue Jul 9, 2015
non comparable variables are now commented out
arolfes added a commit that referenced this issue Jul 9, 2015
added more testcases
@arolfes
Copy link
Contributor Author

arolfes commented Jul 9, 2015

fixed with latest snapshot 1.4.0.201507091317
https://GuavaEclipseHelperTeam.github.io/updateSite/snapshots/LATEST

i will prepare a full release

@arolfes arolfes closed this as completed Jul 9, 2015
@arolfes arolfes reopened this Jul 14, 2015
@arolfes
Copy link
Contributor Author

arolfes commented Jul 14, 2015

2ebd7cf

arolfes added a commit that referenced this issue Jul 14, 2015
option to choose if the plugin should print comments
arolfes added a commit that referenced this issue Jul 14, 2015
added saveAll in tearDown
@arolfes arolfes closed this as completed Jul 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant