eclipse-pdt / pdt

PHP Development Tools project (PDT)
https://eclipse.org/pdt
Eclipse Public License 2.0
188 stars 46 forks source link

Confusion when importing a class used as attribute argument #244

Closed pounard closed 1 year ago

pounard commented 1 year ago

Consider the following code:

<?php

declare(strict_types=1);

namespace Foo\Domain\ClientSecurity\Query;

use Foo\Domain\Client\Model\SalarieId;
use Foo\Shared\Attr\Repository;
use Foo\Shared\Query\ListQuery

#[Repository(Profil::class)] // HERE IS LACKING THE USE STATEMENT
class ProfilQuery extends ListQuery
{
}

When I hit CTRL+SHIFT+o (re-organise imports), it converts it to:

<?php

declare(strict_types=1);

namespace Foo\Domain\ClientSecurity\Query;

use Foo\Domain\Client\Model\SalarieId;
use Foo\Shared\Attr\Repository;
use Foo\Shared\Attr\Repository as Profil; // PLEASE NOTE HERE THE "as Profil"
use Foo\Shared\Query\ListQuery

#[Repository(Profil::class)]
class ProfilQuery extends ListQuery
{
}

The Foo\Shared\Attr\Repository as Profil use statement is wrong and should be, in my case, Foo\Domain\ClientSecurity\Model\Profil instead.

I should get:

<?php

declare(strict_types=1);

namespace Foo\Domain\ClientSecurity\Query;

use Foo\Domain\Client\Model\SalarieId;
use Foo\Domain\ClientSecurity\Model\Profil;
use Foo\Shared\Attr\Repository;
use Foo\Shared\Query\ListQuery

#[Repository(Profil::class)]
class ProfilQuery extends ListQuery
{
}

Worst part is that once I fixed it manually, if I hit CTRL+SHIFT+o again, it will revert back my fix to the broken one.

It's been a few weeks I'm experiencing this behavior, I was waiting for it to be naturally fixed because a lot of people are writing bugs now.

I'm reproducing it right now with the 8.1.0.202307031117 build.

zulus commented 1 year ago

Fixed

BTW you have syntax error inside use Foo\Shared\Query\ListQuery line, missing semicolon ;)

pounard commented 1 year ago

BTW you have syntax error inside use Foo\Shared\Query\ListQuery line, missing semicolon ;)

Yes, because this is part of a client project, I had to manually change a few things when pasting to anonymize client name and project destination. Anyway, thank you very much !