Files
Andrey Cherkasovandintellij-monorepo-bot ddabcc31c7 [devkit] Simplifiable service retrieving: fix false positives
The inspection must not suggest replacing a service retrieving call if this call is an initializer of a variable annotated as @Nullable.

GitOrigin-RevId: f3f219dacd41f2540085bbb076779be1e742e0b7
2023-12-07 16:47:39 +00:00

28 lines
814 B
Java

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;
@Service(Service.Level.PROJECT)
final class MyProjectService {
public static MyProjectService getInstance(Project project) {
return project.getService(MyProjectService.class);
}
void test(Project project) {
@Nullable MyProjectService myProjectService = project.getService(MyProjectService.class);
}
}
@Service
final class MyAppService {
public static MyAppService getInstance() {
return ApplicationManager.getApplication().getService(MyAppService.class);
}
void test() {
@Nullable MyAppService myAppService = ApplicationManager.getApplication().getService(MyAppService.class);
}
}