• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package com.update.check.action;
17 
18 import com.update.check.model.BaseContext;
19 import com.update.check.model.ComponentKey;
20 import com.intellij.openapi.Disposable;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.util.Disposer;
23 import org.jetbrains.annotations.NotNull;
24 import java.util.function.Function;
25 
26 /**
27  * UpdateCheckService
28  *
29  * @since 23-04-07
30  */
31 public class UpdateCheckService extends BaseContext<UpdateCheckService> implements Disposable {
32     private final Project project;
33 
34     private final Mode mode;
35 
36     /**
37      * UpdateCheckService
38      *
39      * @param project project
40      */
UpdateCheckService(@otNull Project project)41     public UpdateCheckService(@NotNull Project project) {
42         this.project = project;
43         this.mode = initMode(project);
44         Disposer.register(this.project, this);
45     }
46 
47     /**
48      * Mode
49      *
50      * @since 23-04-07
51      */
52     public enum Mode {NONE, CONVERSION, FIX}
53 
initMode(@otNull Project project)54     private Mode initMode(@NotNull Project project) {
55         return Mode.NONE;
56     }
57 
58     @Override
getContextImpl()59     public UpdateCheckService getContextImpl() {
60         return this;
61     }
62 
63     /**
64      * getMode
65      *
66      * @return Mode
67      */
68     @NotNull
getMode()69     public Mode getMode() {
70         return this.mode;
71     }
72 
73     /**
74      * getProject
75      *
76      * @return Project
77      */
78     @NotNull
getProject()79     public Project getProject() {
80         return this.project;
81     }
82 
83     @Override
dispose()84     public void dispose() {
85 
86     }
87 
88     /**
89      * addComponent
90      *
91      * @param key key
92      * @param supplier supplier
93      * @param <T1> T1
94      * @return T
95      */
addComponent(ComponentKey<T1> key, Function<? super Project, T1> supplier)96     public synchronized <T1> T1 addComponent(ComponentKey<T1> key, Function<? super Project, T1> supplier) {
97         return super.addComponent(key, supplier, this.project);
98     }
99 
100     /**
101      * getInstance
102      *
103      * @param project project
104      * @return UpdateCheckService
105      */
getInstance(@otNull Project project)106     public static UpdateCheckService getInstance(@NotNull Project project) {
107         return project.getService(UpdateCheckService.class);
108     }
109 
110 }
111