Skip to content

Commit c4710a9

Browse files
committed
FindImplementations: indexes instead of ReferenceSearch, which uses too much memory
1 parent 5c5ceae commit c4710a9

21 files changed

+353
-29
lines changed

META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<li>UML Diagram improvements</li>
1414
<li>NEWTHREAD: implement notify action</li>
1515
<li>NAVIGATOR SCHEDULE support</li>
16+
<li>FindImplementations optimisation</li>
1617
</ul>
1718
]]>
1819
</change-notes>
@@ -218,6 +219,8 @@
218219
<stubIndex implementation="com.lsfusion.lang.psi.indexes.GroupIndex"/>
219220
<stubIndex implementation="com.lsfusion.lang.psi.indexes.TableIndex"/>
220221
<stubIndex implementation="com.lsfusion.lang.psi.indexes.WindowIndex"/>
222+
<stubIndex implementation="com.lsfusion.lang.psi.indexes.OverrideActionIndex"/>
223+
<stubIndex implementation="com.lsfusion.lang.psi.indexes.OverridePropertyIndex"/>
221224
<stubIndex implementation="com.lsfusion.lang.psi.indexes.NavigatorElementIndex"/>
222225
<!-- <stubIndex implementation="com.lsfusion.lang.psi.indexes.ComponentIndex"/>-->
223226

lib/psiImplUtils.jar

484 Bytes
Binary file not shown.

src/com/lsfusion/lang/LSF.bnf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,17 +2058,23 @@ overrideActionStatement ::= mappedActionClassParamDeclare PLUS
20582058
topActionPropertyDefinitionBody OPTIMISTICASYNC?
20592059
{
20602060
// pin = 2;
2061-
implements="com.lsfusion.lang.psi.context.ModifyParamContext"
2061+
implements="com.lsfusion.lang.psi.context.ModifyParamContext,com.lsfusion.lang.psi.declarations.LSFOverrideActionDeclaration"
20622062
methods = [ getContextModifier getContextInferrer getIcon getDocumentation]
2063+
stubClass = "com.lsfusion.lang.psi.stubs.OverrideActionStubElement"
2064+
elementTypeFactory = "com.lsfusion.lang.psi.stubs.types.LSFStubElementTypeFactory.create"
2065+
mixin="com.lsfusion.lang.psi.declarations.impl.LSFOverrideActionDeclarationImpl"
20632066
}
20642067

20652068
overridePropertyStatement ::= mappedPropertyClassParamDeclare PLUSEQ
20662069
(WHEN propertyExpression THEN)?
20672070
propertyExpression SEMI
20682071
{
20692072
pin = 2;
2070-
implements="com.lsfusion.lang.psi.context.ModifyParamContext"
2073+
implements="com.lsfusion.lang.psi.context.ModifyParamContext,com.lsfusion.lang.psi.declarations.LSFOverridePropertyDeclaration"
20712074
methods = [ getContextModifier getContextInferrer getIcon getDocumentation]
2075+
stubClass = "com.lsfusion.lang.psi.stubs.OverridePropertyStubElement"
2076+
elementTypeFactory = "com.lsfusion.lang.psi.stubs.types.LSFStubElementTypeFactory.create"
2077+
mixin="com.lsfusion.lang.psi.declarations.impl.LSFOverridePropertyDeclarationImpl"
20722078
}
20732079

20742080
////////////////////////////////////////////////////////////////////////////////
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.lsfusion.lang.psi.declarations;
2+
3+
import com.lsfusion.documentation.LSFDocumentation;
4+
import com.lsfusion.lang.psi.stubs.OverrideActionStubElement;
5+
6+
public interface LSFOverrideActionDeclaration extends LSFFullNameDeclaration<LSFOverrideActionDeclaration, OverrideActionStubElement>, LSFDocumentation {
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.lsfusion.lang.psi.declarations;
2+
3+
import com.lsfusion.documentation.LSFDocumentation;
4+
import com.lsfusion.lang.psi.stubs.OverridePropertyStubElement;
5+
6+
public interface LSFOverridePropertyDeclaration extends LSFFullNameDeclaration<LSFOverridePropertyDeclaration, OverridePropertyStubElement>, LSFDocumentation {
7+
}

src/com/lsfusion/lang/psi/declarations/impl/LSFActionOrGlobalPropDeclarationImpl.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import com.intellij.lang.ASTNode;
44
import com.intellij.openapi.util.Condition;
55
import com.intellij.psi.PsiElement;
6-
import com.intellij.psi.PsiReference;
76
import com.intellij.psi.search.GlobalSearchScope;
8-
import com.intellij.psi.search.searches.ReferencesSearch;
97
import com.intellij.psi.stubs.IStubElementType;
108
import com.intellij.psi.util.PsiTreeUtil;
119
import com.lsfusion.LSFIcons;
@@ -15,6 +13,8 @@
1513
import com.lsfusion.lang.psi.declarations.LSFActionOrPropDeclaration;
1614
import com.lsfusion.lang.psi.declarations.LSFExprParamDeclaration;
1715
import com.lsfusion.lang.psi.declarations.LSFParamDeclaration;
16+
import com.lsfusion.lang.psi.indexes.OverrideActionIndex;
17+
import com.lsfusion.lang.psi.indexes.OverridePropertyIndex;
1818
import com.lsfusion.lang.psi.references.LSFActionOrPropReference;
1919
import com.lsfusion.lang.psi.stubs.ActionOrPropStubElement;
2020
import com.lsfusion.lang.typeinfer.InferExResult;
@@ -203,18 +203,27 @@ public PsiElement[] processImplementationsSearch() {
203203
}
204204

205205
protected List<LSFActionOrPropReference<?, ?>> findImplementations(LSFId nameIdentifier) {
206-
Collection<PsiReference> refs = ReferencesSearch.search(nameIdentifier, getUseScope()).findAll();
207-
208206
List<LSFActionOrPropReference<?, ?>> impls = new ArrayList<>();
209-
for (PsiReference ref : refs) {
210-
LSFActionOrPropReference<?, ?> impl = getImplementation(ref);
211-
if(impl != null)
212-
impls.add(impl);
207+
List<LSFClassSet> thisClasses = resolveParamClasses();
208+
if (isAction()) {
209+
LSFGlobalResolver.getItemsFromIndex(OverrideActionIndex.getInstance(), nameIdentifier.getName(), getProject(), GlobalSearchScope.allScope(getProject()), LSFLocalSearchScope.GLOBAL).forEach(prop -> {
210+
if (checkClasses(thisClasses, ((LSFOverrideActionStatement) prop).getMappedActionClassParamDeclare().resolveParamClasses())) {
211+
impls.add(((LSFOverrideActionStatement) prop).getMappedActionClassParamDeclare().getActionUsageWrapper().getActionUsage());
212+
}
213+
});
214+
} else {
215+
LSFGlobalResolver.getItemsFromIndex(OverridePropertyIndex.getInstance(), nameIdentifier.getName(), getProject(), GlobalSearchScope.allScope(getProject()), LSFLocalSearchScope.GLOBAL).forEach(prop -> {
216+
if (checkClasses(thisClasses, ((LSFOverridePropertyStatement) prop).getMappedPropertyClassParamDeclare().resolveParamClasses())) {
217+
impls.add(((LSFOverridePropertyStatement) prop).getMappedPropertyClassParamDeclare().getPropertyUsageWrapper().getPropertyUsage());
218+
}
219+
});
213220
}
214221
return impls;
215222
}
216223

217-
protected abstract LSFActionOrPropReference<?, ?> getImplementation(PsiReference ref);
224+
private boolean checkClasses(List<LSFClassSet> thisClasses, List<LSFClassSet> declClasses) {
225+
return declClasses != null && declClasses.size() == thisClasses.size() && LSFPsiImplUtil.containsAll(declClasses, thisClasses, false);
226+
}
218227

219228
@Override
220229
public String getCaption() {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.lsfusion.lang.psi.declarations.impl;
2+
3+
import com.intellij.lang.ASTNode;
4+
import com.intellij.psi.PsiElement;
5+
import com.intellij.psi.stubs.IStubElementType;
6+
import com.lsfusion.LSFIcons;
7+
import com.lsfusion.lang.psi.LSFId;
8+
import com.lsfusion.lang.psi.LSFSimpleName;
9+
import com.lsfusion.lang.psi.declarations.LSFOverrideActionDeclaration;
10+
import com.lsfusion.lang.psi.stubs.OverrideActionStubElement;
11+
import com.lsfusion.lang.psi.stubs.types.FullNameStubElementType;
12+
import com.lsfusion.lang.psi.stubs.types.LSFStubElementTypes;
13+
import com.lsfusion.util.LSFPsiUtils;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.jetbrains.annotations.Nullable;
16+
17+
import javax.swing.*;
18+
import java.util.Collection;
19+
20+
public class LSFOverrideActionDeclarationImpl extends LSFFullNameDeclarationImpl<LSFOverrideActionDeclaration, OverrideActionStubElement> implements LSFOverrideActionDeclaration {
21+
22+
protected LSFOverrideActionDeclarationImpl(@NotNull ASTNode node) {
23+
super(node);
24+
}
25+
26+
protected LSFOverrideActionDeclarationImpl(@NotNull OverrideActionStubElement overrideActionStubElement, @NotNull IStubElementType nodeType) {
27+
super(overrideActionStubElement, nodeType);
28+
}
29+
30+
private LSFSimpleName getSimpleName() {
31+
Collection<PsiElement> result = LSFPsiUtils.findChildrenOfType(this, LSFSimpleName.class);
32+
for (PsiElement psiElement : result) {
33+
return (LSFSimpleName) psiElement;
34+
}
35+
return null;
36+
}
37+
38+
@Nullable
39+
@Override
40+
public LSFId getNameIdentifier() {
41+
return getSimpleName();
42+
}
43+
44+
@Nullable
45+
@Override
46+
public Icon getIcon(int flags) {
47+
return LSFIcons.PROPERTY;
48+
}
49+
50+
@Override
51+
protected FullNameStubElementType getType() {
52+
return LSFStubElementTypes.OVERRIDEACTION;
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.lsfusion.lang.psi.declarations.impl;
2+
3+
import com.intellij.lang.ASTNode;
4+
import com.intellij.psi.PsiElement;
5+
import com.intellij.psi.stubs.IStubElementType;
6+
import com.lsfusion.LSFIcons;
7+
import com.lsfusion.lang.psi.LSFId;
8+
import com.lsfusion.lang.psi.LSFSimpleName;
9+
import com.lsfusion.lang.psi.declarations.LSFOverridePropertyDeclaration;
10+
import com.lsfusion.lang.psi.stubs.OverridePropertyStubElement;
11+
import com.lsfusion.lang.psi.stubs.types.FullNameStubElementType;
12+
import com.lsfusion.lang.psi.stubs.types.LSFStubElementTypes;
13+
import com.lsfusion.util.LSFPsiUtils;
14+
import org.jetbrains.annotations.NotNull;
15+
import org.jetbrains.annotations.Nullable;
16+
17+
import javax.swing.*;
18+
import java.util.Collection;
19+
20+
public class LSFOverridePropertyDeclarationImpl extends LSFFullNameDeclarationImpl<LSFOverridePropertyDeclaration, OverridePropertyStubElement> implements LSFOverridePropertyDeclaration {
21+
22+
protected LSFOverridePropertyDeclarationImpl(@NotNull ASTNode node) {
23+
super(node);
24+
}
25+
26+
protected LSFOverridePropertyDeclarationImpl(@NotNull OverridePropertyStubElement overridePropertyStubElement, @NotNull IStubElementType nodeType) {
27+
super(overridePropertyStubElement, nodeType);
28+
}
29+
30+
private LSFSimpleName getSimpleName() {
31+
Collection<PsiElement> result = LSFPsiUtils.findChildrenOfType(this, LSFSimpleName.class);
32+
for (PsiElement psiElement : result) {
33+
return (LSFSimpleName) psiElement;
34+
}
35+
return null;
36+
}
37+
38+
@Nullable
39+
@Override
40+
public LSFId getNameIdentifier() {
41+
return getSimpleName();
42+
}
43+
44+
@Nullable
45+
@Override
46+
public Icon getIcon(int flags) {
47+
return LSFIcons.PROPERTY;
48+
}
49+
50+
@Override
51+
protected FullNameStubElementType getType() {
52+
return LSFStubElementTypes.OVERRIDEPROPERTY;
53+
}
54+
}

src/com/lsfusion/lang/psi/declarations/impl/LSFStatementActionDeclarationImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ protected FullNameStubElementType getType() {
5656
return LSFStubElementTypes.STATEMENTACTION;
5757
}
5858

59-
@Override
60-
protected LSFActionReference getImplementation(PsiReference ref) {
61-
LSFOverrideActionStatement overrideStatement = PsiTreeUtil.getParentOfType((PsiElement) ref, LSFOverrideActionStatement.class);
62-
if (overrideStatement != null && ref.equals(overrideStatement.getMappedActionClassParamDeclare().getActionUsageWrapper().getActionUsage())) {
63-
return overrideStatement.getMappedActionClassParamDeclare().getActionUsageWrapper().getActionUsage();
64-
}
65-
return null;
66-
}
67-
6859
@Override
6960
public boolean isAbstract() {
7061
LSFActionUnfriendlyPD unfriend = getActionUnfriendlyPD();

src/com/lsfusion/lang/psi/declarations/impl/LSFStatementGlobalPropDeclarationImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.intellij.lang.ASTNode;
44
import com.intellij.psi.PsiElement;
5-
import com.intellij.psi.PsiReference;
65
import com.intellij.psi.stubs.IStubElementType;
76
import com.intellij.psi.util.PsiTreeUtil;
87
import com.lsfusion.lang.classes.LSFClassSet;
@@ -190,14 +189,6 @@ public Collection<FullNameStubElementType> getTypes() {
190189
return Arrays.asList(LSFStubElementTypes.STATEMENTPROP, LSFStubElementTypes.AGGRPARAMPROP);
191190
}
192191

193-
@Override
194-
protected LSFPropReference getImplementation(PsiReference ref) {
195-
LSFOverridePropertyStatement overrideStatement = PsiTreeUtil.getParentOfType((PsiElement) ref, LSFOverridePropertyStatement.class);
196-
if (overrideStatement != null && ref.equals(overrideStatement.getMappedPropertyClassParamDeclare().getPropertyUsageWrapper().getPropertyUsage()))
197-
return overrideStatement.getMappedPropertyClassParamDeclare().getPropertyUsageWrapper().getPropertyUsage();
198-
return null;
199-
}
200-
201192
public static Integer getPropComplexity(LSFPropDeclaration prop) {
202193
return getPropComplexity(prop, new HashSet<>());
203194
}

0 commit comments

Comments
 (0)