Skip to content

Commit f3c707a

Browse files
authored
Merge pull request #2357 from Haehnchen/feature/type-provider-flag
provide checkbox to allow disable cost intensive parameter type provider resolving
2 parents 12ad1df + fbdc2ce commit f3c707a

10 files changed

+73
-21
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class Settings implements PersistentStateComponent<Settings> {
5959
public boolean codeFoldingTwigTemplate = true;
6060
public boolean codeFoldingTwigConstant = true;
6161
public boolean featureTwigIcon = true;
62+
public boolean featureTypeProvider = true;
6263

6364
public boolean twigBundleNamespaceSupport = false;
6465

src/main/java/fr/adrienbrault/idea/symfony2plugin/SettingsForm.form

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<rowspec value="center:max(d;4px):noGrow"/>
3939
<rowspec value="top:4dlu:noGrow"/>
4040
<rowspec value="center:max(d;4px):noGrow"/>
41+
<rowspec value="top:4dlu:noGrow"/>
42+
<rowspec value="center:max(d;4px):noGrow"/>
4143
<colspec value="fill:max(d;4px):noGrow"/>
4244
<colspec value="left:4dlu:noGrow"/>
4345
<colspec value="fill:d:grow"/>
@@ -207,7 +209,7 @@
207209
</component>
208210
<component id="58414" class="javax.swing.JLabel" binding="directoryToAppLabel">
209211
<constraints>
210-
<grid row="28" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
212+
<grid row="30" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
211213
<forms/>
212214
</constraints>
213215
<properties>
@@ -216,7 +218,7 @@
216218
</component>
217219
<component id="c6525" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="directoryToApp">
218220
<constraints>
219-
<grid row="28" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
221+
<grid row="30" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
220222
<preferred-size width="150" height="-1"/>
221223
</grid>
222224
<forms defaultalign-horz="false"/>
@@ -225,7 +227,7 @@
225227
</component>
226228
<component id="b7268" class="javax.swing.JButton" binding="directoryToAppReset">
227229
<constraints>
228-
<grid row="28" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
230+
<grid row="30" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
229231
<forms/>
230232
</constraints>
231233
<properties>
@@ -234,13 +236,23 @@
234236
</component>
235237
<component id="4cd0" class="javax.swing.JLabel">
236238
<constraints>
237-
<grid row="26" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
239+
<grid row="28" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
238240
<forms/>
239241
</constraints>
240242
<properties>
241243
<text value="Legacy Features"/>
242244
</properties>
243245
</component>
246+
<component id="3c3bc" class="javax.swing.JCheckBox" binding="featureTypeProvider">
247+
<constraints>
248+
<grid row="26" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
249+
<forms/>
250+
</constraints>
251+
<properties>
252+
<text value="Type Provider"/>
253+
<toolTipText value="Resolve return type via parameter eg &quot;ContainerInterface::get, EntityManager::find&quot;"/>
254+
</properties>
255+
</component>
244256
</children>
245257
</grid>
246258
<component id="2ef99" class="javax.swing.JCheckBox" binding="pluginEnabled">

src/main/java/fr/adrienbrault/idea/symfony2plugin/SettingsForm.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class SettingsForm implements Configurable {
6060
private JCheckBox enableSchedulerCheckBox;
6161
private JCheckBox featureTwigIcon;
6262
private JButton buttonAutoConfigure;
63+
private JCheckBox featureTypeProvider;
6364

6465
public SettingsForm(@NotNull final Project project) {
6566
this.project = project;
@@ -135,6 +136,7 @@ public boolean isModified() {
135136
|| !codeFoldingTwigTemplate.isSelected() == getSettings().codeFoldingTwigTemplate
136137
|| !codeFoldingTwigConstant.isSelected() == getSettings().codeFoldingTwigConstant
137138
|| !featureTwigIcon.isSelected() == getSettings().featureTwigIcon
139+
|| !featureTypeProvider.isSelected() == getSettings().featureTypeProvider
138140

139141
|| !directoryToApp.getText().equals(getSettings().directoryToApp)
140142
|| !directoryToWeb.getText().equals(getSettings().directoryToWeb)
@@ -156,6 +158,7 @@ public void apply() throws ConfigurationException {
156158
getSettings().codeFoldingTwigTemplate = codeFoldingTwigTemplate.isSelected();
157159
getSettings().codeFoldingTwigConstant = codeFoldingTwigConstant.isSelected();
158160
getSettings().featureTwigIcon = featureTwigIcon.isSelected();
161+
getSettings().featureTypeProvider = featureTypeProvider.isSelected();
159162

160163
getSettings().directoryToApp = directoryToApp.getText();
161164
getSettings().directoryToWeb = directoryToWeb.getText();
@@ -188,6 +191,7 @@ private void updateUIFromSettings() {
188191
codeFoldingTwigTemplate.setSelected(getSettings().codeFoldingTwigTemplate);
189192
codeFoldingTwigConstant.setSelected(getSettings().codeFoldingTwigConstant);
190193
featureTwigIcon.setSelected(getSettings().featureTwigIcon);
194+
featureTypeProvider.setSelected(getSettings().featureTypeProvider);
191195

192196
directoryToApp.setText(getSettings().directoryToApp);
193197
directoryToWeb.setText(getSettings().directoryToWeb);

src/main/java/fr/adrienbrault/idea/symfony2plugin/assistant/signature/MethodSignatureTypeProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ public char getKey() {
4040
@Nullable
4141
@Override
4242
public PhpType getType(PsiElement e) {
43-
if (!Settings.getInstance(e.getProject()).pluginEnabled || !(e instanceof MethodReference methodReference)) {
43+
if (!(e instanceof MethodReference methodReference)) {
44+
return null;
45+
}
46+
47+
Project project = e.getProject();
48+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
4449
return null;
4550
}
4651

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/SymfonyContainerTypeProvider.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@ public char getKey() {
3535
@Nullable
3636
@Override
3737
public PhpType getType(PsiElement e) {
38-
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
38+
// container calls are only on "get" methods
39+
if(!(e instanceof MethodReference methodReference)) {
40+
return null;
41+
}
42+
43+
Project project = e.getProject();
44+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
3945
return null;
4046
}
4147

4248
// container calls are only on "get" methods
43-
if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
49+
if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "get")) {
4450
return null;
4551
}
4652

47-
String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
53+
String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, TRIM_KEY);
4854
return signature == null ? null : new PhpType().add("#" + this.getKey() + signature);
4955
}
5056

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/ObjectManagerFindContextTypeProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public char getKey() {
3838
@Nullable
3939
@Override
4040
public PhpType getType(PsiElement e) {
41-
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
41+
if (!(e instanceof MethodReference methodRef)) {
42+
return null;
43+
}
44+
45+
Project project = e.getProject();
46+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
4247
return null;
4348
}
4449

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/ObjectManagerFindTypeProvider.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ public char getKey() {
3636
@Nullable
3737
@Override
3838
public PhpType getType(PsiElement e) {
39-
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
39+
if(!(e instanceof MethodReference methodReference)) {
4040
return null;
4141
}
4242

43-
if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) {
43+
Project project = e.getProject();
44+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
4445
return null;
4546
}
4647

47-
String refSignature = ((MethodReference)e).getSignature();
48+
if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "find")) {
49+
return null;
50+
}
51+
52+
String refSignature = methodReference.getSignature();
4853
if(StringUtil.isEmpty(refSignature)) {
4954
return null;
5055
}
5156

5257
// we need the param key on getBySignature(), since we are already in the resolved method there attach it to signature
5358
// param can have dotted values split with \
54-
PsiElement[] parameters = ((MethodReference)e).getParameters();
59+
PsiElement[] parameters = methodReference.getParameters();
5560
if (parameters.length >= 2) {
5661
String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter((MethodReference) e, TRIM_KEY);
5762
if(signature != null) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/ObjectRepositoryResultTypeProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public char getKey() {
5656
@Nullable
5757
@Override
5858
public PhpType getType(PsiElement e) {
59-
if (!(e instanceof MethodReference methodRef) || !Settings.getInstance(e.getProject()).pluginEnabled) {
59+
if (!(e instanceof MethodReference methodRef)) {
60+
return null;
61+
}
62+
63+
Project project = e.getProject();
64+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
6065
return null;
6166
}
6267

src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/ObjectRepositoryTypeProvider.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ public char getKey() {
4141
@Nullable
4242
@Override
4343
public PhpType getType(PsiElement e) {
44-
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
44+
if(!(e instanceof MethodReference methodReference)) {
4545
return null;
4646
}
4747

48-
if(!(e instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository")) {
48+
Project project = e.getProject();
49+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
4950
return null;
5051
}
5152

53+
if(!PhpElementsUtil.isMethodWithFirstStringOrFieldReference(e, "getRepository")) {
54+
return null;
55+
}
5256

53-
String refSignature = ((MethodReference)e).getSignature();
57+
String refSignature = methodReference.getSignature();
5458
if(StringUtil.isEmpty(refSignature)) {
5559
return null;
5660
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/EventDispatcherTypeProvider.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ public char getKey() {
2929
@Nullable
3030
@Override
3131
public PhpType getType(PsiElement e) {
32-
if (!Settings.getInstance(e.getProject()).pluginEnabled) {
32+
if(!(e instanceof MethodReference methodReference)) {
33+
return null;
34+
}
35+
36+
Project project = e.getProject();
37+
if (!Settings.getInstance(project).pluginEnabled || !Settings.getInstance(project).featureTwigIcon) {
3338
return null;
3439
}
3540

3641
// container calls are only on "get" methods
37-
if(!(e instanceof MethodReference) || !"dispatch".equals(((MethodReference) e).getName())) {
42+
if(!"dispatch".equals(methodReference.getName())) {
3843
return null;
3944
}
4045

41-
PsiElement[] parameters = ((MethodReference) e).getParameters();
46+
PsiElement[] parameters = methodReference.getParameters();
4247
if(parameters.length < 2) {
4348
return null;
4449
}
4550

46-
String refSignature = ((MethodReference) e).getSignature();
51+
String refSignature = methodReference.getSignature();
4752
if(StringUtils.isBlank(refSignature)) {
4853
return null;
4954
}

0 commit comments

Comments
 (0)