objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.38k stars 302 forks source link

Cursor class generation name conflict #715

Open joseldgois opened 5 years ago

joseldgois commented 5 years ago

Issue Basics

Reproducing the bug

Description

Add a ToMany property with a backlink to a property named "entity" in another class. When the cursor is generating, a variable name conflict occurs since the generated parameter for the put method in the cursor is also called "entity".

Code

An @Entity with ToMany link

class Entity {
...
@Backlink(to="entity")
    private ToMany<TradingSession> tradingSessions;
}

The TradingSession Entiy has the ToOne link.

class TradingSession{
...
ToOne<Entity> entity;
}

The conflict occurs in the Cursor generated code.

TradingSessionCursor
{
....
@Override
    public final long put(TradingSession entity) {
        ToOne<Entity> entity = entity.entity;

.....
}
}
greenrobot-team commented 5 years ago

Thanks for reporting. However, not sure we should change this (e.g. replace entity -> arg0 or something) because it would make the generated code harder to read.

Typically one avoids naming classes similar to names used in an API (here the @Entity annotation) so this should not be that big of an issue. -Uwe