Skip to content

Commit b549550

Browse files
authored
Merge pull request #321 from cedricziel/319-no-components-anymore
2 parents 8825f7a + c8c44bf commit b549550

File tree

6 files changed

+53
-82
lines changed

6 files changed

+53
-82
lines changed

typo3-cms/src/main/java/com/cedricziel/idea/typo3/TYPO3CMSProjectSettings.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.cedricziel.idea.typo3;
22

33
import com.intellij.ide.actions.ShowSettingsUtilImpl;
4-
import com.intellij.openapi.components.PersistentStateComponent;
5-
import com.intellij.openapi.components.ServiceManager;
6-
import com.intellij.openapi.components.State;
7-
import com.intellij.openapi.components.Storage;
4+
import com.intellij.openapi.components.*;
85
import com.intellij.openapi.project.Project;
96
import com.intellij.psi.PsiElement;
107
import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -14,7 +11,7 @@
1411
@State(
1512
name = "typo3cmsproject",
1613
storages = {
17-
@Storage("/typo3-cms.xml")
14+
@Storage(value = "/typo3-cms.xml", roamingType = RoamingType.DISABLED)
1815
}
1916
)
2017
public class TYPO3CMSProjectSettings implements PersistentStateComponent<TYPO3CMSProjectSettings> {

typo3-cms/src/main/java/com/cedricziel/idea/typo3/TYPO3CMSSettings.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.cedricziel.idea.typo3;
22

3-
import com.intellij.openapi.components.PersistentStateComponent;
4-
import com.intellij.openapi.components.ServiceManager;
5-
import com.intellij.openapi.components.State;
6-
import com.intellij.openapi.components.Storage;
3+
import com.intellij.openapi.components.*;
74
import com.intellij.openapi.project.Project;
85
import org.jdom.Element;
96
import org.jetbrains.annotations.NotNull;
107
import org.jetbrains.annotations.Nullable;
118

129
@State(
1310
name = "TYPO3Settings",
14-
storages = {@Storage("$WORKSPACE_FILE$")}
11+
storages = {@Storage(value = "$WORKSPACE_FILE$", roamingType = RoamingType.DISABLED)}
1512
)
1613
public class TYPO3CMSSettings implements PersistentStateComponent<Element> {
1714
/**

typo3-cms/src/main/java/com/cedricziel/idea/typo3/TYPO3CMSProjectComponent.java renamed to typo3-cms/src/main/java/com/cedricziel/idea/typo3/listener/TYPO3DetectionListener.java

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,28 @@
1-
package com.cedricziel.idea.typo3;
1+
package com.cedricziel.idea.typo3.listener;
22

3+
import com.cedricziel.idea.typo3.IdeHelper;
4+
import com.cedricziel.idea.typo3.TYPO3CMSProjectSettings;
5+
import com.cedricziel.idea.typo3.TYPO3CMSSettings;
36
import com.cedricziel.idea.typo3.index.*;
47
import com.cedricziel.idea.typo3.index.extbase.ControllerActionIndex;
58
import com.cedricziel.idea.typo3.index.extensionScanner.MethodArgumentDroppedIndex;
69
import com.cedricziel.idea.typo3.index.php.LegacyClassesForIDEIndex;
710
import com.intellij.ide.plugins.IdeaPluginDescriptor;
811
import com.intellij.ide.plugins.PluginManager;
9-
import com.intellij.notification.Notification;
10-
import com.intellij.notification.NotificationType;
11-
import com.intellij.notification.Notifications;
12-
import com.intellij.openapi.components.ProjectComponent;
13-
import com.intellij.openapi.diagnostic.Logger;
1412
import com.intellij.openapi.extensions.PluginId;
1513
import com.intellij.openapi.project.Project;
14+
import com.intellij.openapi.project.ProjectManagerListener;
1615
import com.intellij.openapi.vfs.VfsUtil;
1716
import com.intellij.psi.search.FilenameIndex;
1817
import com.intellij.psi.search.GlobalSearchScope;
1918
import com.intellij.util.indexing.FileBasedIndex;
2019
import org.jetbrains.annotations.NotNull;
2120
import org.jetbrains.annotations.Nullable;
2221

23-
public class TYPO3CMSProjectComponent implements ProjectComponent {
24-
25-
private static final Logger LOG = Logger.getInstance("TYPO3-CMS-Plugin");
26-
27-
private Project project;
28-
29-
public TYPO3CMSProjectComponent(Project project) {
30-
this.project = project;
31-
}
32-
33-
public static Logger getLogger() {
34-
return LOG;
35-
}
36-
37-
@Override
38-
public void initComponent() {
39-
}
40-
41-
@Override
42-
public void disposeComponent() {
43-
}
44-
45-
@Override
46-
@NotNull
47-
public String getComponentName() {
48-
return "com.cedricziel.idea.typo3.TYPO3CMSProjectComponent";
49-
}
50-
22+
public class TYPO3DetectionListener implements ProjectManagerListener {
5123
@Override
52-
public void projectOpened() {
53-
this.checkProject();
24+
public void projectOpened(@NotNull Project project) {
25+
this.checkProject(project);
5426

5527
TYPO3CMSSettings instance = TYPO3CMSSettings.getInstance(project);
5628
IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId("com.cedricziel.idea.typo3"));
@@ -75,34 +47,24 @@ public void projectOpened() {
7547
}
7648
}
7749

78-
@Override
79-
public void projectClosed() {
80-
}
81-
82-
public void showInfoNotification(String content) {
83-
Notification notification = new Notification("TYPO3 CMS Plugin", "TYPO3 CMS Plugin", content, NotificationType.INFORMATION);
84-
85-
Notifications.Bus.notify(notification, this.project);
86-
}
87-
8850
public boolean isEnabled(@Nullable Project project) {
8951

9052
return project != null && TYPO3CMSProjectSettings.getInstance(project).pluginEnabled;
9153
}
9254

93-
private void checkProject() {
94-
if (!this.isEnabled(project) && !notificationIsDismissed() && containsPluginRelatedFiles()) {
55+
private void checkProject(@NotNull Project project) {
56+
if (!this.isEnabled(project) && !notificationIsDismissed(project) && containsPluginRelatedFiles(project)) {
9557
IdeHelper.notifyEnableMessage(project);
9658
}
9759
}
9860

99-
private boolean notificationIsDismissed() {
61+
private boolean notificationIsDismissed(@NotNull Project project) {
10062

10163
return TYPO3CMSProjectSettings.getInstance(project).dismissEnableNotification;
10264
}
10365

104-
private boolean containsPluginRelatedFiles() {
105-
return (VfsUtil.findRelativeFile(this.project.getBaseDir(), "vendor", "typo3") != null)
66+
private boolean containsPluginRelatedFiles(@NotNull Project project) {
67+
return (VfsUtil.findRelativeFile(project.getBaseDir(), "vendor", "typo3") != null)
10668
|| FilenameIndex.getFilesByName(project, "ext_emconf.php", GlobalSearchScope.allScope(project)).length > 0;
10769
}
10870
}

typo3-cms/src/main/java/com/cedricziel/idea/typo3/XLFFileTypeApplicationComponent.java renamed to typo3-cms/src/main/java/com/cedricziel/idea/typo3/listener/XLFFileTypeListener.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
package com.cedricziel.idea.typo3;
1+
package com.cedricziel.idea.typo3.listener;
22

33
import com.intellij.ide.highlighter.XmlFileType;
44
import com.intellij.notification.*;
55
import com.intellij.openapi.application.ApplicationManager;
66
import com.intellij.openapi.command.WriteCommandAction;
7-
import com.intellij.openapi.components.ProjectComponent;
87
import com.intellij.openapi.fileTypes.FileTypeManager;
98
import com.intellij.openapi.project.Project;
109
import com.intellij.openapi.project.ProjectManager;
10+
import com.intellij.openapi.project.ProjectManagerListener;
11+
import org.jetbrains.annotations.NotNull;
1112

12-
public class XLFFileTypeApplicationComponent implements ProjectComponent {
13-
13+
public class XLFFileTypeListener implements ProjectManagerListener {
1414
private static final NotificationGroup GROUP_DISPLAY_ID_INFO = new NotificationGroup(
15-
"TYPO3 CMS Plugin: XLF File Type Association",
16-
NotificationDisplayType.BALLOON, true
15+
"TYPO3 CMS Plugin: XLF File Type Association",
16+
NotificationDisplayType.BALLOON, true
1717
);
1818

1919
@Override
20-
public void projectOpened() {
20+
public void projectOpened(@NotNull Project project) {
2121
if (!(FileTypeManager.getInstance().getFileTypeByExtension("xlf") instanceof XmlFileType)) {
2222
WriteCommandAction.runWriteCommandAction(ProjectManager.getInstance().getOpenProjects()[0], () -> {
2323
FileTypeManager.getInstance().associateExtension(XmlFileType.INSTANCE, "xlf");
2424

2525
ApplicationManager.getApplication().invokeLater(() -> {
2626
Notification notification = GROUP_DISPLAY_ID_INFO.createNotification(
27-
"TYPO3 CMS Plugin",
28-
"XLF File Type Association",
29-
"The XLF File Type was re-assigned to XML to prevent errors with the XLIFF Plugin and allow autocompletion. Please re-index your projects.",
30-
NotificationType.INFORMATION
27+
"TYPO3 CMS Plugin",
28+
"XLF File Type Association",
29+
"The XLF File Type was re-assigned to XML to prevent errors with the XLIFF Plugin and allow autocompletion. Please re-index your projects.",
30+
NotificationType.INFORMATION
3131
);
3232
Project[] projects = ProjectManager.getInstance().getOpenProjects();
3333
Notifications.Bus.notify(notification, projects[0]);

typo3-cms/src/main/resources/META-INF/plugin.xml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</change-notes>
1717

1818
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
19-
<idea-version since-build="173"/>
19+
<idea-version since-build="193"/>
2020

2121
<depends>com.intellij.modules.platform</depends>
2222
<depends>com.jetbrains.php</depends>
@@ -38,6 +38,11 @@
3838
<typeProvider4 implementation="com.cedricziel.idea.typo3.contextApi.ContextTypeProvider"/>
3939
</extensions>
4040

41+
<projectListeners>
42+
<listener class="com.cedricziel.idea.typo3.listener.TYPO3DetectionListener" topic="com.intellij.openapi.project.ProjectManagerListener"/>
43+
<listener class="com.cedricziel.idea.typo3.listener.XLFFileTypeListener" topic="com.intellij.openapi.project.ProjectManagerListener"/>
44+
</projectListeners>
45+
4146
<extensions defaultExtensionNs="com.intellij">
4247

4348
<projectService serviceImplementation="com.cedricziel.idea.typo3.TYPO3CMSSettings"/>
@@ -213,13 +218,4 @@
213218
<add-to-group group-id="GenerateGroup" anchor="last"/>
214219
</action>
215220
</actions>
216-
217-
<project-components>
218-
<component>
219-
<implementation-class>com.cedricziel.idea.typo3.TYPO3CMSProjectComponent</implementation-class>
220-
</component>
221-
<component>
222-
<implementation-class>com.cedricziel.idea.typo3.XLFFileTypeApplicationComponent</implementation-class>
223-
</component>
224-
</project-components>
225221
</idea-plugin>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.cedricziel.idea.typo3.util;
2+
3+
import com.cedricziel.idea.typo3.AbstractTestCase;
4+
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
5+
import com.jetbrains.php.lang.psi.elements.MethodReference;
6+
7+
public class PhpTypeProviderUtilTest extends AbstractTestCase {
8+
public void testSignaturesAreProvided() {
9+
MethodReference methodReference = PhpPsiElementFactory.createMethodReference(
10+
getProject(),
11+
"<?php\n" +
12+
"use App\\Foo\\Bar\\Foo;\n" +
13+
"GeneralUtility::makeInstance(Foo::class);"
14+
);
15+
String referenceSignatureByFirstParameter = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, '%');
16+
17+
assertEquals("#M#C\\GeneralUtility.makeInstance%#K#C\\App\\Foo\\Bar\\Foo.class", referenceSignatureByFirstParameter);
18+
}
19+
}

0 commit comments

Comments
 (0)