mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
35 lines
1.0 KiB
HTML
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> |