Skip to content

Commit 98559bb

Browse files
committed
migrate LineMarker target to leaf elements to fix performance warning / error #1122
1 parent 85ceb96 commit 98559bb

7 files changed

+116
-70
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ env:
1616
- PHPSTORM_ENV=2017.2
1717
- PHPSTORM_ENV=2017.2.4
1818
- PHPSTORM_ENV=2017.3.2
19-
- PHPSTORM_ENV=eap
19+
#- PHPSTORM_ENV=eap # disabled never used
2020

2121
matrix:
2222
allow_failures:
23-
- env: PHPSTORM_ENV=eap
23+
- env: PHPSTORM_ENV=eap
24+
- env: PHPSTORM_ENV=2017.3.2

src/fr/adrienbrault/idea/symfony2plugin/dic/ControllerMethodLineMarkerProvider.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.openapi.extensions.ExtensionPointName;
99
import com.intellij.psi.PsiElement;
1010
import com.intellij.util.ConstantFunction;
11+
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
1112
import com.jetbrains.php.lang.psi.elements.Method;
1213
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
1314
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
@@ -36,16 +37,16 @@ public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
3637

3738
@Nullable
3839
public LineMarkerInfo collect(PsiElement psiElement) {
39-
40-
if(!Symfony2ProjectComponent.isEnabled(psiElement)) {
40+
if(!Symfony2ProjectComponent.isEnabled(psiElement) || psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER) {
4141
return null;
4242
}
4343

44-
if(!(psiElement instanceof Method) || !((Method) psiElement).getAccess().isPublic()) {
44+
PsiElement method = psiElement.getParent();
45+
if(!(method instanceof Method) || !((Method) method).getAccess().isPublic()) {
4546
return null;
4647
}
4748

48-
List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) psiElement);
49+
List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) method);
4950

5051
if(gotoRelatedItems.size() == 0) {
5152
return null;

src/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/XmlLineMarkerProvider.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
import com.intellij.patterns.XmlPatterns;
77
import com.intellij.patterns.XmlTagPattern;
88
import com.intellij.psi.PsiElement;
9+
import com.intellij.psi.xml.XmlElementType;
910
import com.intellij.psi.xml.XmlTag;
1011
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1112
import fr.adrienbrault.idea.symfony2plugin.config.xml.XmlHelper;
12-
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerService;
1313
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
1414
import org.apache.commons.lang.StringUtils;
1515
import org.jetbrains.annotations.NotNull;
1616
import org.jetbrains.annotations.Nullable;
1717

1818
import java.util.Collection;
1919
import java.util.List;
20-
import java.util.Map;
2120

2221
/**
2322
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -38,21 +37,28 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3837
LazyDecoratedServiceValues lazyDecoratedServiceValues = null;
3938

4039
for (PsiElement psiElement : psiElements) {
40+
if(psiElement.getNode().getElementType() != XmlElementType.XML_NAME) {
41+
continue;
42+
}
43+
44+
PsiElement xmlTag = psiElement.getParent();
45+
if(!(xmlTag instanceof XmlTag) || !getServiceIdPattern().accepts(xmlTag)) {
46+
continue;
47+
}
48+
4149
if(lazyDecoratedServiceValues == null) {
42-
lazyDecoratedServiceValues = new LazyDecoratedServiceValues(psiElements.get(0).getProject());
50+
lazyDecoratedServiceValues = new LazyDecoratedServiceValues(psiElement.getProject());
4351
}
4452

4553
// <services><service id="foo"/></services>
46-
if(psiElement instanceof XmlTag && getServiceIdPattern().accepts(psiElement)) {
47-
visitServiceId((XmlTag) psiElement, result, lazyDecoratedServiceValues);
48-
}
54+
visitServiceId(psiElement, (XmlTag) xmlTag, result, lazyDecoratedServiceValues);
4955
}
5056
}
5157

5258
/**
5359
* <service id="foo"/>
5460
*/
55-
private void visitServiceId(@NotNull XmlTag xmlTag, @NotNull Collection<LineMarkerInfo> result, @NotNull LazyDecoratedServiceValues lazyDecoratedServiceValues) {
61+
private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull XmlTag xmlTag, @NotNull Collection<LineMarkerInfo> result, @NotNull LazyDecoratedServiceValues lazyDecoratedServiceValues) {
5662
String id = xmlTag.getAttributeValue("id");
5763
if(StringUtils.isBlank(id)) {
5864
return;
@@ -61,18 +67,20 @@ private void visitServiceId(@NotNull XmlTag xmlTag, @NotNull Collection<LineMark
6167
// <service id="foo" decorates=foobar" />
6268
String decorates = xmlTag.getAttributeValue("decorates");
6369
if(decorates != null && StringUtils.isNotBlank(decorates)) {
64-
result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(xmlTag, decorates));
70+
result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(leafTarget, decorates));
6571
}
6672

6773
NavigationGutterIconBuilder<PsiElement> lineMarker = ServiceUtil.getLineMarkerForDecoratedServiceId(
68-
xmlTag.getProject(), lazyDecoratedServiceValues.getDecoratedServices(), id
74+
xmlTag.getProject(),
75+
lazyDecoratedServiceValues.getDecoratedServices(),
76+
id
6977
);
7078

7179
if(lineMarker == null) {
7280
return;
7381
}
7482

75-
result.add(lineMarker.createLineMarkerInfo(xmlTag));
83+
result.add(lineMarker.createLineMarkerInfo(leafTarget));
7684
}
7785

7886
/**

src/fr/adrienbrault/idea/symfony2plugin/dic/linemarker/YamlLineMarkerProvider.java

+25-16
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
import com.intellij.psi.PsiElement;
77
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
88
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
9-
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerService;
109
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
1110
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
1211
import org.apache.commons.lang.StringUtils;
1312
import org.jetbrains.annotations.NotNull;
1413
import org.jetbrains.annotations.Nullable;
14+
import org.jetbrains.yaml.YAMLTokenTypes;
1515
import org.jetbrains.yaml.psi.YAMLKeyValue;
1616

1717
import java.util.Collection;
1818
import java.util.List;
19-
import java.util.Map;
2019

2120
/**
2221
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -34,21 +33,29 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3433
return;
3534
}
3635

37-
final LazyDecoratedServiceValues[] lazyDecoratedServices = {null};
36+
LazyDecoratedServiceValues lazyDecoratedServices = null;
3837

39-
// services -> service_name
40-
psiElements.stream()
41-
.filter(psiElement -> psiElement instanceof YAMLKeyValue && YamlElementPatternHelper.getServiceIdKeyValuePattern().accepts(psiElement))
42-
.forEach((PsiElement psiElement) -> {
43-
if(lazyDecoratedServices[0] == null) {
44-
lazyDecoratedServices[0] = new LazyDecoratedServiceValues(psiElements.get(0).getProject());
45-
}
4638

47-
visitServiceId((YAMLKeyValue) psiElement, result, lazyDecoratedServices[0]);
48-
});
39+
for (PsiElement psiElement : psiElements) {
40+
if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
41+
continue;
42+
}
43+
44+
PsiElement yamlKeyValue = psiElement.getParent();
45+
if(!(yamlKeyValue instanceof YAMLKeyValue) || !YamlElementPatternHelper.getServiceIdKeyValuePattern().accepts(yamlKeyValue)) {
46+
continue;
47+
}
48+
49+
if(lazyDecoratedServices == null) {
50+
lazyDecoratedServices = new LazyDecoratedServiceValues(psiElement.getProject());
51+
}
52+
53+
// services -> service_name
54+
visitServiceId(psiElement, (YAMLKeyValue) yamlKeyValue, result, lazyDecoratedServices);
55+
}
4956
}
5057

51-
private void visitServiceId(@NotNull YAMLKeyValue yamlKeyValue, @NotNull Collection<LineMarkerInfo> result, @NotNull LazyDecoratedServiceValues lazyDecoratedServices) {
58+
private void visitServiceId(@NotNull PsiElement leafTarget, @NotNull YAMLKeyValue yamlKeyValue, @NotNull Collection<LineMarkerInfo> result, @NotNull LazyDecoratedServiceValues lazyDecoratedServices) {
5259
String id = yamlKeyValue.getKeyText();
5360
if(StringUtils.isBlank(id)) {
5461
return;
@@ -57,17 +64,19 @@ private void visitServiceId(@NotNull YAMLKeyValue yamlKeyValue, @NotNull Collect
5764
// decorates: @foobar
5865
String decorates = YamlHelper.getYamlKeyValueAsString(yamlKeyValue, "decorates");
5966
if(decorates != null && StringUtils.isNotBlank(decorates)) {
60-
result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(yamlKeyValue, decorates));
67+
result.add(ServiceUtil.getLineMarkerForDecoratesServiceId(leafTarget, decorates));
6168
}
6269

6370
NavigationGutterIconBuilder<PsiElement> lineMarker = ServiceUtil.getLineMarkerForDecoratedServiceId(
64-
yamlKeyValue.getProject(), lazyDecoratedServices.getDecoratedServices(), id
71+
yamlKeyValue.getProject(),
72+
lazyDecoratedServices.getDecoratedServices(),
73+
id
6574
);
6675

6776
if(lineMarker == null) {
6877
return;
6978
}
7079

71-
result.add(lineMarker.createLineMarkerInfo(yamlKeyValue));
80+
result.add(lineMarker.createLineMarkerInfo(leafTarget));
7281
}
7382
}

src/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/DoctrineMetadataLineMarkerProvider.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.intellij.openapi.project.Project;
77
import com.intellij.psi.PsiElement;
88
import com.intellij.psi.xml.XmlAttributeValue;
9+
import com.intellij.psi.xml.XmlTokenType;
910
import com.jetbrains.php.lang.psi.elements.PhpClass;
1011
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
1112
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
@@ -30,7 +31,6 @@ public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
3031

3132
@Override
3233
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> results) {
33-
3434
// we need project element; so get it from first item
3535
if(psiElements.size() == 0) {
3636
return;
@@ -42,13 +42,18 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
4242
}
4343

4444
for(PsiElement psiElement: psiElements) {
45-
if(psiElement instanceof XmlAttributeValue && (DoctrineMetadataPattern.getXmlTargetDocumentClass().accepts(psiElement) || DoctrineMetadataPattern.getXmlTargetEntityClass().accepts(psiElement) || DoctrineMetadataPattern.getEmbeddableNameClassPattern().accepts(psiElement))) {
46-
attachXmlRelationMarker((XmlAttributeValue) psiElement, results);
45+
if(psiElement.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
46+
continue;
47+
}
48+
49+
PsiElement xmlAttributeValue = psiElement.getParent();
50+
if(xmlAttributeValue instanceof XmlAttributeValue && (DoctrineMetadataPattern.getXmlTargetDocumentClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getXmlTargetEntityClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getEmbeddableNameClassPattern().accepts(xmlAttributeValue))) {
51+
attachXmlRelationMarker(psiElement, (XmlAttributeValue) xmlAttributeValue, results);
4752
}
4853
}
4954
}
5055

51-
private void attachXmlRelationMarker(@NotNull XmlAttributeValue psiElement, @NotNull Collection<LineMarkerInfo> results) {
56+
private void attachXmlRelationMarker(@NotNull PsiElement target, @NotNull XmlAttributeValue psiElement, @NotNull Collection<LineMarkerInfo> results) {
5257
String value = psiElement.getValue();
5358
if(StringUtils.isBlank(value)) {
5459
return;
@@ -63,7 +68,7 @@ private void attachXmlRelationMarker(@NotNull XmlAttributeValue psiElement, @Not
6368
setTargets(classesInterface).
6469
setTooltipText("Navigate to class");
6570

66-
results.add(builder.createLineMarkerInfo(psiElement));
71+
results.add(builder.createLineMarkerInfo(target));
6772
}
6873

6974
}

src/fr/adrienbrault/idea/symfony2plugin/routing/XmlLineMarkerProvider.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.patterns.XmlTagPattern;
99
import com.intellij.psi.PsiElement;
1010
import com.intellij.psi.PsiFile;
11+
import com.intellij.psi.xml.XmlElementType;
1112
import com.intellij.psi.xml.XmlFile;
1213
import com.intellij.psi.xml.XmlTag;
1314
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
@@ -33,8 +34,8 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3334
}
3435

3536
for(PsiElement psiElement: psiElements) {
36-
if(psiElement instanceof XmlTag) {
37-
attachRouteActions((XmlTag) psiElement, lineMarkerInfos);
37+
if(psiElement.getNode().getElementType() == XmlElementType.XML_NAME) {
38+
attachRouteActions(psiElement, lineMarkerInfos);
3839
} else if(psiElement instanceof XmlFile) {
3940
RelatedItemLineMarkerInfo<PsiElement> lineMarker = FileResourceUtil.getFileImplementsLineMarker((PsiFile) psiElement);
4041
if(lineMarker != null) {
@@ -45,20 +46,21 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
4546

4647
}
4748

48-
private void attachRouteActions(@NotNull XmlTag xmlTag, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
49-
if(!Pattern.getRouteTag().accepts(xmlTag)) {
49+
private void attachRouteActions(@NotNull PsiElement psiElement, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
50+
PsiElement xmlTag = psiElement.getParent();
51+
if(!(xmlTag instanceof XmlTag) || !Pattern.getRouteTag().accepts(xmlTag)) {
5052
return;
5153
}
5254

53-
String controller = RouteHelper.getXmlController(xmlTag);
55+
String controller = RouteHelper.getXmlController((XmlTag) xmlTag);
5456
if(controller != null) {
5557
PsiElement[] methods = RouteHelper.getMethodsOnControllerShortcut(xmlTag.getProject(), controller);
5658
if(methods.length > 0) {
5759
NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.TWIG_CONTROLLER_LINE_MARKER).
5860
setTargets(methods).
5961
setTooltipText("Navigate to action");
6062

61-
lineMarkerInfos.add(builder.createLineMarkerInfo(xmlTag));
63+
lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
6264
}
6365
}
6466
}

0 commit comments

Comments
 (0)