Cannot resolve class when a package is registered with ((StandardTypeLocator) standardEvaluationContext.getTypeLocator()).registerImport()

Answered

I am using Spring and I have a repository interface like

 

public interface MyRepository {

    @Override
    @NonNull
    @PreAuthorize("hasAnyRole(T(com.package.ofMyPrivilege.MyPrivilege).SOME_PRIVILEGE)")
    Optional<MySchema> findById(@NonNull @Param("uuid") UUID uuid);

...
}

which works and SOME_PRIVILEGE comes in code completion. But if I use it in the following way

 

public interface MyRepository {

    @Override
    @NonNull
    @PreAuthorize("hasAnyRole(T(MyPrivilege).SOME_PRIVILEGE)")
    Optional<MySchema> findById(@NonNull @Param("uuid") UUID uuid);

...
}

IDEA says that Cannot resolve MyPrivilege. I have tried importing com.package.ofMyPrivilege.MyPrivilege into the repository class but it does not help.

I am able to use MyPrivilege as is cause I have registered it like the following

public class CustomMethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler {
    @Override
    public StandardEvaluationContext createEvaluationContextInternal(Authentication auth, MethodInvocation mi) {
        StandardEvaluationContext standardEvaluationContext = super.createEvaluationContextInternal(auth, mi);
        ((StandardTypeLocator) standardEvaluationContext.getTypeLocator()).registerImport("com.package.ofMyPrivilege");
        return standardEvaluationContext;
    }
}

 

Is there any way to tell the IDE that MyPrivilege points to com.package.ofMyPrivilege.MyPrivilege?

0
5 comments

Please file a bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce the issue.

0

Facing the same problem here, did you find any solution? I appreciate your response and effort opening this issue!

0

Hello,

Please follow the issue for updates. I asked developers to check it.

0

Hello Yaroslav Bedrov, 

Thanks for your support, I will keep an eye out for updates.

0

Please sign in to leave a comment.