sockeqwe / sqlbrite-dao

DAO for SQLBrite
http://hannesdorfmann.com/android/sqlbrite-dao
Apache License 2.0
182 stars 22 forks source link

Inner classes incorrectly referenced in mappers #39

Open koral-- opened 8 years ago

koral-- commented 8 years ago

Trying to compile project with static inner class Foo:

    @ObjectMappable
    public static class Foo {
        public Foo() {
        }

        @Column("id")
        public void setId(final long id) {

        }
    }

results in compilation error: Error:(11, 87) error: cannot find symbol class Foo Relevant part of generated mapper:

import android.content.ContentValues;
import android.database.Cursor;
import rx.functions.Func1;

/**
 * Generated class to work with Cursors and ContentValues for MediaStoreManager.Foo
 */
public final class FooMapper {
  public static final Func1<Cursor, MediaStoreManager.Foo> MAPPER = new Func1<Cursor, Foo>() {
    @Override public Foo call(Cursor cursor) {
      int idIndex = cursor.getColumnIndexOrThrow("id");
      MediaStoreManager.Foo item = new MediaStoreManager.Foo();
      if (idIndex >= 0) {
        item.setId( cursor.getLong( idIndex ) );
      }
      return item;
    }
  };

  private FooMapper() {
  }

There is proper enclosing class in variable declaration and javadoc but it is missing in type parameter and return value. Dependencies versions:

    apt 'com.hannesdorfmann.sqlbrite:object-mapper:0.6.0'
    compile 'com.hannesdorfmann.sqlbrite:annotations:0.6.0'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

BTW is it intended that there is checking whether column index >=0 in case when getColumnIndexOrThrow() is used? According to javadoc exception will be thrown in such case and condition is never false. BTW2 javadoc may use `{@link MediaStoreManager.Foo}.

sockeqwe commented 8 years ago

Thanks for reporting!

Yes this is an issue and I will fix it in next release (end of April).

Regarding index >=0: Good catch! This is caused because I share the code generation part with "optional columns" where cursor.getColumnIndex() will be used and here it will return -1 if column has not been found. But yes, this check is redundant and I will optimize that.

Adding javadoc link shouldn't be a big deal ...

Will fix all these issues in next version

nhattan123 commented 8 years ago

I want to check my source.!!!! The wep page I visit it all navigate to 1 other wep! And the time on my phone also does not run properly with the place I'm in! Please help me!