Files
openide/plugins/devkit/devkit-core/resources/inspectionDescriptions/SimplifiableServiceRetrieving.html
Yann Cébron 7bbd97677c [devkit] cleanup inspection descriptions
GitOrigin-RevId: d9bfdce9a581af49b9f743874a21d001dcc74403
2024-05-14 15:24:08 +00:00

35 lines
1.0 KiB
HTML

<html>
<body>
Reports service getting calls that can be replaced with a calls to an existing static <code>getInstance()</code>
or <code>getInstance(Project)</code> methods.
<p>Example (Java):</p>
<pre><code lang="java">
@Service
public class MyAppService {
public static MyAppService getInstance() {
return ApplicationManager.getApplication().getService(MyAppService.class);
}
}
@Service(Service.Level.PROJECT)
public class MyProjectService {
public static MyProjectService getInstance(Project project) {
return project.getService(MyProjectService.class);
}
}
</code></pre>
<pre><code lang="java">
// Bad:
MyAppService applicationService = ApplicationManager.getApplication().getService(MyAppService.class);
MyProjectService projectService = project.getService(MyProjectService.class);
</code></pre>
<pre><code lang="java">
// Good:
MyAppService applicationService = MyAppService.getInstance();
MyProjectService projectService = MyProjectService.getInstance(project);
</code></pre>
<!-- tooltip end -->
<p><small>New in 2023.2</small>
</body>
</html>