Skip to content

Commit 487744c

Browse files
committed
Initial commit
0 parents  commit 487744c

File tree

6 files changed

+243
-0
lines changed

6 files changed

+243
-0
lines changed

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Java template
3+
*.class
4+
5+
# Log file
6+
*.log
7+
8+
# BlueJ files
9+
*.ctxt
10+
11+
# Mobile Tools for Java (J2ME)
12+
.mtj.tmp/
13+
14+
# Package Files #
15+
*.jar
16+
*.war
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
### JetBrains template
25+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
26+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
27+
28+
# User-specific stuff:
29+
.idea/**/workspace.xml
30+
.idea/**/tasks.xml
31+
32+
# Sensitive or high-churn files:
33+
.idea/**/dataSources/
34+
.idea/**/dataSources.ids
35+
.idea/**/dataSources.xml
36+
.idea/**/dataSources.local.xml
37+
.idea/**/sqlDataSources.xml
38+
.idea/**/dynamic.xml
39+
.idea/**/uiDesigner.xml
40+
41+
# Gradle:
42+
.idea/**/gradle.xml
43+
.idea/**/libraries
44+
45+
# Mongo Explorer plugin:
46+
.idea/**/mongoSettings.xml
47+
48+
## File-based project format:
49+
*.iws
50+
51+
## Plugin-specific files:
52+
53+
# IntelliJ
54+
/out/
55+
56+
# mpeltonen/sbt-idea plugin
57+
.idea_modules/
58+
59+
# JIRA plugin
60+
atlassian-ide-plugin.xml
61+
62+
# Crashlytics plugin (for Android Studio and IntelliJ)
63+
com_crashlytics_export_strings.xml
64+
crashlytics.properties
65+
crashlytics-build.properties
66+
fabric.properties
67+

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017 Cedric Ziel
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# EXPERIMENTAL TYPO3 CMS Plugin for Jetbrains IDEA based products
2+
3+
## Features
4+
5+
* TypeProvider for `GeneralUtility::makeInstance`
6+
7+
# License
8+
9+
MIT

resources/META-INF/plugin.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<idea-plugin version="2">
2+
<id>com.cedricziel.idea.typo3</id>
3+
<name>TYPO3</name>
4+
<version>0.1</version>
5+
<vendor email="cedric@cedric-ziel.com" url="https://www.cedric-ziel.com">Cedric Ziel</vendor>
6+
7+
<description><![CDATA[
8+
TYPO3 CMS Plugin for IntelliJ IDEA products.
9+
<strong>EXPERIMENTAL</strong>
10+
]]></description>
11+
12+
<change-notes><![CDATA[
13+
Added TypeProvider for GeneralUtility::makeInstance<br>
14+
]]>
15+
</change-notes>
16+
17+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
18+
<idea-version since-build="145.0"/>
19+
20+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
21+
on how to target different products -->
22+
<!-- uncomment to enable plugin in all products
23+
<depends>com.intellij.modules.lang</depends>
24+
-->
25+
<depends>com.jetbrains.php</depends>
26+
27+
<extensions defaultExtensionNs="com.intellij">
28+
<!-- Add your extensions here -->
29+
<php.typeProvider2 implementation="com.cedricziel.idea.typo3.provider.GeneralUtilityTypeProvider" />
30+
</extensions>
31+
32+
<extensions defaultExtensionNs="com.jetbrains.php">
33+
<!-- Add your extensions here -->
34+
</extensions>
35+
36+
<actions>
37+
<!-- Add your actions here -->
38+
</actions>
39+
40+
</idea-plugin>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.cedricziel.idea.typo3.provider;
2+
3+
import com.cedricziel.idea.typo3.psi.PhpElementsUtil;
4+
import com.intellij.openapi.project.DumbService;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.psi.PsiElement;
7+
import com.jetbrains.php.PhpIndex;
8+
import com.jetbrains.php.lang.psi.elements.MethodReference;
9+
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
10+
import com.jetbrains.php.lang.psi.elements.PhpReference;
11+
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
import java.util.Collection;
15+
import java.util.Collections;
16+
17+
/**
18+
* TypeProvider for `GeneralUtility::makeInstance`
19+
*/
20+
public class GeneralUtilityTypeProvider implements PhpTypeProvider2 {
21+
22+
@Override
23+
public char getKey() {
24+
return '\u0205';
25+
}
26+
27+
@Nullable
28+
@Override
29+
public String getType(PsiElement psiElement) {
30+
if (DumbService.getInstance(psiElement.getProject()).isDumb()) {
31+
return null;
32+
}
33+
34+
if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "makeInstance")) {
35+
return null;
36+
}
37+
38+
MethodReference methodReference = (MethodReference) psiElement;
39+
if (methodReference.getParameters().length == 0) {
40+
return null;
41+
}
42+
43+
PsiElement firstParam = methodReference.getParameters()[0];
44+
45+
if (firstParam instanceof PhpReference) {
46+
PhpReference ref = (PhpReference) firstParam;
47+
if (ref.getText().toLowerCase().contains("::class")) {
48+
return methodReference.getSignature() + "%" + ref.getSignature();
49+
}
50+
}
51+
52+
return null;
53+
}
54+
55+
@Override
56+
public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
57+
int endIndex = s.lastIndexOf("%");
58+
if (endIndex == -1) {
59+
return Collections.emptySet();
60+
}
61+
62+
// Get FQN from parameter string.
63+
// Example (PhpStorm 8): #K#C\Foo\Bar::get()%#K#C\Bar\Baz. -> \Bar\Baz.
64+
// Example (PhpStorm 9): #K#C\Foo\Bar::get()%#K#C\Bar\Baz.class -> \Bar\Baz.class
65+
String parameter = s.substring(endIndex + 5, s.length());
66+
67+
if (parameter.contains(".class")) { // for PhpStorm 9
68+
parameter = parameter.replace(".class", "");
69+
}
70+
71+
if (parameter.contains(".")) {
72+
parameter = parameter.replace(".", "");
73+
}
74+
75+
return PhpIndex.getInstance(project).getAnyByFQN(parameter);
76+
}
77+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.cedricziel.idea.typo3.psi;
2+
3+
import com.intellij.patterns.PlatformPatterns;
4+
import com.intellij.psi.PsiElement;
5+
import com.jetbrains.php.lang.parser.PhpElementTypes;
6+
import com.jetbrains.php.lang.psi.elements.MethodReference;
7+
8+
import java.util.Arrays;
9+
10+
public class PhpElementsUtil {
11+
public static boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
12+
if(!PlatformPatterns
13+
.psiElement(PhpElementTypes.METHOD_REFERENCE)
14+
.withChild(PlatformPatterns
15+
.psiElement(PhpElementTypes.PARAMETER_LIST)
16+
.withFirstChild(PlatformPatterns.or(
17+
PlatformPatterns.psiElement(PhpElementTypes.STRING),
18+
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
19+
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
20+
))
21+
).accepts(psiElement)) {
22+
23+
return false;
24+
}
25+
26+
// cant we move it up to PlatformPatterns? withName condition dont looks working
27+
String methodRefName = ((MethodReference) psiElement).getName();
28+
29+
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
30+
}
31+
}

0 commit comments

Comments
 (0)