Skip to content

Commit fdce4fa

Browse files
authored
Merge pull request #7 from cedricziel/service-index
Add system service type inference
2 parents 7b0bb26 + 4b28376 commit fdce4fa

File tree

11 files changed

+644
-2
lines changed

11 files changed

+644
-2
lines changed

META-INF/plugin.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<idea-plugin version="2">
22
<id>com.cedricziel.idea.typo3</id>
33
<name>TYPO3 CMS Plugin</name>
4-
<version>0.1.1</version>
4+
<version>0.1.2</version>
55
<vendor email="cedric@cedric-ziel.com" url="https://www.cedric-ziel.com">Cedric Ziel</vendor>
66

77
<description><![CDATA[
88
<h1>TYPO3 CMS Plugin</h1>
99
10+
<a href="https://github.com/cedricziel/idea-php-typo3-plugin">GitHub Repository</a>
11+
<br/>
12+
1013
<strong>beta quality</strong>
14+
<br/>
1115
1216
<h2>Features:</h2>
1317
@@ -21,6 +25,7 @@
2125
2226
<ul>
2327
<li>infer return type of GeneralUtility::makeInstance() calls without meta file</li>
28+
<li>infer return type of GeneralUtility::makeInstanceService() calls without meta file</li>
2429
<li>infer return type of ObjectManager::get() calls without meta file</li>
2530
</ul>
2631
@@ -38,19 +43,40 @@ It is a great inspiration for possible solutions and parts of the code.</p>
3843
]]></description>
3944

4045
<change-notes><![CDATA[
41-
Added TypeProvider for GeneralUtility::makeInstance<br>
46+
47+
<h2>0.1.2</h2>
48+
<ul>
49+
<li>Added TypeProvider for GeneralUtility::makeInstanceService</li>
50+
</ul>
51+
52+
<h2>0.1.1</h2>
53+
<ul>
54+
<li>Added TypeProvider for ObjectManager::get</li>
55+
</ul>
56+
57+
<h2>0.1.0</h2>
58+
<ul>
59+
<li>Added TypeProvider for GeneralUtility::makeInstance</li>
60+
</ul>
61+
62+
<br/>
4263
]]>
4364
</change-notes>
4465

4566
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
4667
<idea-version since-build="145.0"/>
4768

69+
<depends>com.intellij.modules.platform</depends>
4870
<depends>com.jetbrains.php</depends>
4971

5072
<extensions defaultExtensionNs="com.intellij">
5173
<!-- Add your extensions here -->
5274
<php.typeProvider2 implementation="com.cedricziel.idea.typo3.provider.GeneralUtilityTypeProvider" />
75+
<php.typeProvider2 implementation="com.cedricziel.idea.typo3.provider.GeneralUtilityServiceTypeProvider" />
5376
<php.typeProvider2 implementation="com.cedricziel.idea.typo3.provider.ObjectManagerTypeProvider" />
77+
78+
<!-- indexes -->
79+
<fileBasedIndex implementation="com.cedricziel.idea.typo3.index.CoreServiceMapStubIndex"/>
5480
</extensions>
5581

5682
<extensions defaultExtensionNs="com.jetbrains.php">
@@ -61,4 +87,9 @@ It is a great inspiration for possible solutions and parts of the code.</p>
6187
<!-- Add your actions here -->
6288
</actions>
6389

90+
<project-components>
91+
<component>
92+
<implementation-class>com.cedricziel.idea.typo3.TYPO3CMSProjectComponent</implementation-class>
93+
</component>
94+
</project-components>
6495
</idea-plugin>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ On PhpStorm or IntelliJ:
1919
## Features
2020

2121
* TypeProvider for `GeneralUtility::makeInstance`
22+
* TypeProvider for `GeneralUtility::makeInstanceService`
2223
* TypeProvider for `ObjectManager::get`
2324

2425
## Credits
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.cedricziel.idea.typo3;
2+
3+
import com.intellij.openapi.components.ProjectComponent;
4+
import com.intellij.openapi.diagnostic.Logger;
5+
import com.intellij.openapi.project.Project;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public class TYPO3CMSProjectComponent implements ProjectComponent {
9+
10+
final private static Logger LOG = Logger.getInstance("TYPO3-CMS-Plugin");
11+
12+
private Project project;
13+
14+
public TYPO3CMSProjectComponent(Project project) {
15+
this.project = project;
16+
}
17+
18+
@Override
19+
public void initComponent() {
20+
}
21+
22+
@Override
23+
public void disposeComponent() {
24+
}
25+
26+
@Override
27+
@NotNull
28+
public String getComponentName() {
29+
return "com.cedricziel.idea.typo3.TYPO3CMSProjectComponent";
30+
}
31+
32+
@Override
33+
public void projectOpened() {
34+
// called when project is opened
35+
}
36+
37+
@Override
38+
public void projectClosed() {
39+
// called when project is being closed
40+
}
41+
42+
public static Logger getLogger() {
43+
return LOG;
44+
}
45+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.cedricziel.idea.typo3.container;
2+
3+
import com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition;
4+
import com.cedricziel.idea.typo3.psi.visitor.CoreServiceDefinitionParserVisitor;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.vfs.VirtualFile;
7+
import com.intellij.psi.PsiFile;
8+
import com.intellij.psi.PsiManager;
9+
import com.intellij.psi.search.FileTypeIndex;
10+
import com.intellij.psi.search.GlobalSearchScope;
11+
import com.intellij.util.indexing.FileBasedIndex;
12+
import com.jetbrains.php.lang.PhpFileType;
13+
14+
import java.util.*;
15+
16+
/**
17+
* Parses the core services to a map. Core Services are not traditional
18+
* services in a DIC, but rather named elements in a service locator.
19+
*/
20+
public class CoreServiceParser {
21+
22+
private HashMap<String, ArrayList<TYPO3ServiceDefinition>> serviceMap;
23+
24+
public CoreServiceParser() {
25+
this.serviceMap = new HashMap<>();
26+
}
27+
28+
private void collectServices(Project project) {
29+
FileBasedIndex index = FileBasedIndex.getInstance();
30+
Collection<VirtualFile> containingFiles = index.getContainingFiles(
31+
FileTypeIndex.NAME,
32+
PhpFileType.INSTANCE,
33+
GlobalSearchScope.allScope(project)
34+
);
35+
containingFiles.removeIf(virtualFile -> !(virtualFile.getName().contains("ext_localconf.php")));
36+
37+
for (VirtualFile projectFile : containingFiles) {
38+
PsiFile psiFile = PsiManager.getInstance(project).findFile(projectFile);
39+
if (psiFile != null) {
40+
psiFile.accept(new CoreServiceDefinitionParserVisitor(serviceMap));
41+
}
42+
}
43+
}
44+
45+
public Boolean has(Project project, String serviceId) {
46+
return this.serviceMap.containsKey(serviceId);
47+
}
48+
49+
public List<TYPO3ServiceDefinition> resolve(Project project, String serviceId) {
50+
return this.serviceMap.get(serviceId);
51+
}
52+
53+
public void collect(Project project) {
54+
collectServices(project);
55+
}
56+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.cedricziel.idea.typo3.domain;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.io.Serializable;
6+
7+
public class TYPO3ServiceDefinition implements Serializable {
8+
9+
@NotNull
10+
private final String id;
11+
private String extensionName;
12+
private String className;
13+
private String title;
14+
private String description;
15+
private String subType;
16+
private Boolean available;
17+
private Integer priority;
18+
private Integer quality;
19+
private String os;
20+
private String exec;
21+
private String signature;
22+
23+
public TYPO3ServiceDefinition(@NotNull String id) {
24+
this.id = id;
25+
}
26+
27+
public String getSubType() {
28+
return subType;
29+
}
30+
31+
public void setSubType(String subType) {
32+
this.subType = subType;
33+
}
34+
35+
public Boolean getAvailable() {
36+
return available;
37+
}
38+
39+
public void setAvailable(Boolean available) {
40+
this.available = available;
41+
}
42+
43+
public Integer getPriority() {
44+
return priority;
45+
}
46+
47+
public void setPriority(Integer priority) {
48+
this.priority = priority;
49+
}
50+
51+
public Integer getQuality() {
52+
return quality;
53+
}
54+
55+
public void setQuality(Integer quality) {
56+
this.quality = quality;
57+
}
58+
59+
public String getOs() {
60+
return os;
61+
}
62+
63+
public void setOs(String os) {
64+
this.os = os;
65+
}
66+
67+
public String getExec() {
68+
return exec;
69+
}
70+
71+
public void setExec(String exec) {
72+
this.exec = exec;
73+
}
74+
75+
@NotNull
76+
public String getId() {
77+
return id;
78+
}
79+
80+
public String getExtensionName() {
81+
return extensionName;
82+
}
83+
84+
public void setExtensionName(String extensionName) {
85+
this.extensionName = extensionName;
86+
}
87+
88+
public void setClass(String aClass) {
89+
this.className = aClass;
90+
}
91+
92+
public String getClassName() {
93+
return className;
94+
}
95+
96+
public void setClassName(String className) {
97+
this.className = className;
98+
}
99+
100+
public String getTitle() {
101+
return title;
102+
}
103+
104+
public void setTitle(String title) {
105+
this.title = title;
106+
}
107+
108+
public String getDescription() {
109+
return description;
110+
}
111+
112+
public void setDescription(String description) {
113+
this.description = description;
114+
}
115+
116+
public String getSignature() {
117+
return signature;
118+
}
119+
120+
public void setSignature(String signature) {
121+
this.signature = signature;
122+
}
123+
124+
@Override
125+
public boolean equals(Object o) {
126+
if (this == o) return true;
127+
if (o == null || getClass() != o.getClass()) return false;
128+
129+
TYPO3ServiceDefinition that = (TYPO3ServiceDefinition) o;
130+
131+
if (!id.equals(that.id)) return false;
132+
if (extensionName != null ? !extensionName.equals(that.extensionName) : that.extensionName != null)
133+
return false;
134+
if (className != null ? !className.equals(that.className) : that.className != null) return false;
135+
if (title != null ? !title.equals(that.title) : that.title != null) return false;
136+
if (description != null ? !description.equals(that.description) : that.description != null) return false;
137+
if (subType != null ? !subType.equals(that.subType) : that.subType != null) return false;
138+
if (available != null ? !available.equals(that.available) : that.available != null) return false;
139+
if (priority != null ? !priority.equals(that.priority) : that.priority != null) return false;
140+
if (quality != null ? !quality.equals(that.quality) : that.quality != null) return false;
141+
if (os != null ? !os.equals(that.os) : that.os != null) return false;
142+
if (exec != null ? !exec.equals(that.exec) : that.exec != null) return false;
143+
return signature != null ? signature.equals(that.signature) : that.signature == null;
144+
}
145+
146+
@Override
147+
public int hashCode() {
148+
int result = id.hashCode();
149+
result = 31 * result + (extensionName != null ? extensionName.hashCode() : 0);
150+
result = 31 * result + (className != null ? className.hashCode() : 0);
151+
result = 31 * result + (title != null ? title.hashCode() : 0);
152+
result = 31 * result + (description != null ? description.hashCode() : 0);
153+
result = 31 * result + (subType != null ? subType.hashCode() : 0);
154+
result = 31 * result + (available != null ? available.hashCode() : 0);
155+
result = 31 * result + (priority != null ? priority.hashCode() : 0);
156+
result = 31 * result + (quality != null ? quality.hashCode() : 0);
157+
result = 31 * result + (os != null ? os.hashCode() : 0);
158+
result = 31 * result + (exec != null ? exec.hashCode() : 0);
159+
result = 31 * result + (signature != null ? signature.hashCode() : 0);
160+
return result;
161+
}
162+
}

0 commit comments

Comments
 (0)