Skip to content

Commit 206c795

Browse files
author
Vitaliy
authored
Merge pull request #192 from magento/107-mftf-test-extends
Implemented MFTF test extends reference and completion
2 parents 65be14c + 2782c3b commit 206c795

File tree

21 files changed

+326
-128
lines changed

21 files changed

+326
-128
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.ActionGroupIndex" />
106106
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.DataIndex" />
107107
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.PageIndex" />
108-
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.StepKeyIndex" />
108+
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.mftf.TestNameIndex" />
109109
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.RequireJsIndex" />
110110
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.js.MagentoLibJsIndex" />
111111

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
package com.magento.idea.magento2plugin.completion.provider.mftf;
6+
7+
import com.intellij.codeInsight.completion.CompletionParameters;
8+
import com.intellij.codeInsight.completion.CompletionProvider;
9+
import com.intellij.codeInsight.completion.CompletionResultSet;
10+
import com.intellij.codeInsight.lookup.LookupElementBuilder;
11+
import com.intellij.psi.PsiElement;
12+
import com.intellij.psi.util.PsiTreeUtil;
13+
import com.intellij.psi.xml.XmlAttribute;
14+
import com.intellij.psi.xml.XmlAttributeValue;
15+
import com.intellij.psi.xml.XmlTag;
16+
import com.intellij.util.ProcessingContext;
17+
import com.intellij.util.indexing.FileBasedIndex;
18+
import com.magento.idea.magento2plugin.magento.files.MftfTest;
19+
import com.magento.idea.magento2plugin.stubs.indexes.mftf.TestNameIndex;
20+
import org.jetbrains.annotations.NotNull;
21+
import java.util.Collection;
22+
23+
public class TestNameCompletionProvider extends CompletionProvider<CompletionParameters> {
24+
25+
@Override
26+
protected void addCompletions(
27+
@NotNull CompletionParameters parameters,
28+
ProcessingContext context,
29+
@NotNull CompletionResultSet result) {
30+
PsiElement position = parameters.getPosition().getOriginalElement();
31+
32+
if (position == null) {
33+
return;
34+
}
35+
36+
Collection<String> allKeys = FileBasedIndex.getInstance().getAllKeys(TestNameIndex.KEY, position.getProject());
37+
38+
String currentTestName = getCurrentTestName((XmlAttributeValue) parameters.getPosition().getParent());
39+
for (String testName: allKeys) {
40+
if (testName.equals(currentTestName)) {
41+
continue;
42+
}
43+
result.addElement(LookupElementBuilder.create(testName));
44+
}
45+
}
46+
47+
private String getCurrentTestName(XmlAttributeValue xmlAttributeValue) {
48+
PsiElement xmlAttribute = xmlAttributeValue.getParent();
49+
XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlAttribute, XmlTag.class);
50+
if (xmlTag == null) {
51+
return null;
52+
}
53+
XmlAttribute nameAttribute = xmlTag.getAttribute(MftfTest.NAME_ATTRIBUTE);
54+
if (nameAttribute == null) {
55+
return null;
56+
}
57+
String value = nameAttribute.getValue();
58+
if (value == null || value.isEmpty()) {
59+
return null;
60+
}
61+
62+
return value;
63+
}
64+
}

src/com/magento/idea/magento2plugin/completion/xml/XmlCompletionContributor.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,20 @@ public XmlCompletionContributor() {
248248
new DataCompletionProvider()
249249
);
250250

251+
// MFTF Test extends completion contributor
252+
extend(
253+
CompletionType.BASIC,
254+
psiElement(XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN)
255+
.inside(
256+
XmlPatterns.xmlAttribute().withName(MftfTest.EXTENDS_ATTRIBUTE)
257+
.withParent(XmlPatterns.xmlTag().withName(MftfTest.TEST_TAG)
258+
.withParent(XmlPatterns.xmlTag().withName(MftfTest.ROOT_TAG)
259+
)
260+
)
261+
),
262+
new TestNameCompletionProvider()
263+
);
264+
251265
registerCompletionsForDifferentNesting();
252266
}
253267

@@ -264,7 +278,7 @@ private void registerCompletionsForDifferentNesting() {
264278
i,
265279
XmlPatterns.xmlTag().withParent(
266280
XmlPatterns.xmlTag().withName(
267-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
281+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.TEST_TAG)
268282
)))
269283
),
270284
new SelectorCompletionProvider()
@@ -278,7 +292,7 @@ private void registerCompletionsForDifferentNesting() {
278292
XmlPatterns.xmlAttribute().withName(MftfActionGroup.URL_ATTRIBUTE)
279293
.withSuperParent(i ,XmlPatterns.xmlTag().withParent(
280294
XmlPatterns.xmlTag().withName(
281-
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.ROOT_TAG)
295+
string().oneOf(MftfActionGroup.ROOT_TAG, MftfTest.TEST_TAG)
282296
)))
283297
),
284298
new PageCompletionProvider()

src/com/magento/idea/magento2plugin/indexes/IndexManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void manualReindex() {
4040
DataIndex.KEY,
4141
PageIndex.KEY,
4242
SectionIndex.KEY,
43-
StepKeyIndex.KEY,
43+
TestNameIndex.KEY,
4444
//graphql
4545
GraphQlResolverIndex.KEY
4646
};

src/com/magento/idea/magento2plugin/linemarker/php/PluginTargetLineMarkerProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ private String getTargetMethodName(Method pluginMethod, String pluginPrefix) {
169169
String pluginMethodName = pluginMethod.getName();
170170
String targetClassMethodName = pluginMethodName.
171171
replace(pluginPrefix, "");
172+
if (targetClassMethodName.isEmpty()) {
173+
return null;
174+
}
172175
char firstCharOfTargetName = targetClassMethodName.charAt(0);
173176
int charType = Character.getType(firstCharOfTargetName);
174177
if (charType == Character.LOWERCASE_LETTER) {

src/com/magento/idea/magento2plugin/magento/files/MftfTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66

77
public class MftfTest {
88

9-
public static String ROOT_TAG = "test";
9+
public static String ROOT_TAG = "tests";
10+
public static String TEST_TAG = "test";
11+
public static String NAME_ATTRIBUTE = "name";
12+
public static String EXTENDS_ATTRIBUTE = "extends";
13+
public static String FILE_DIR_PARENTS = "Test/Mftf";
1014
}

src/com/magento/idea/magento2plugin/reference/provider/mftf/ActionGroupReferenceProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.reference.provider.mftf;
26

37
import com.intellij.ide.highlighter.XmlFileType;
@@ -12,7 +16,6 @@
1216
import com.magento.idea.magento2plugin.stubs.indexes.mftf.ActionGroupIndex;
1317
import com.magento.idea.magento2plugin.util.xml.XmlPsiTreeUtil;
1418
import org.jetbrains.annotations.NotNull;
15-
1619
import java.util.ArrayList;
1720
import java.util.Collection;
1821
import java.util.List;

src/com/magento/idea/magento2plugin/reference/provider/mftf/DataReferenceProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.reference.provider.mftf;
26

37
import com.intellij.ide.highlighter.XmlFileType;
@@ -18,12 +22,10 @@
1822
import com.magento.idea.magento2plugin.stubs.indexes.mftf.DataIndex;
1923
import com.magento.idea.magento2plugin.util.xml.XmlPsiTreeUtil;
2024
import org.jetbrains.annotations.NotNull;
21-
2225
import java.util.ArrayList;
2326
import java.util.Collection;
2427
import java.util.List;
2528

26-
2729
public class DataReferenceProvider extends PsiReferenceProvider {
2830

2931
@NotNull

src/com/magento/idea/magento2plugin/reference/provider/mftf/PageReferenceProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.reference.provider.mftf;
26

37
import com.intellij.ide.highlighter.XmlFileType;
@@ -16,7 +20,6 @@
1620
import com.magento.idea.magento2plugin.stubs.indexes.mftf.PageIndex;
1721
import com.magento.idea.magento2plugin.util.xml.XmlPsiTreeUtil;
1822
import org.jetbrains.annotations.NotNull;
19-
2023
import java.util.ArrayList;
2124
import java.util.Collection;
2225
import java.util.List;

src/com/magento/idea/magento2plugin/reference/provider/mftf/SectionReferenceProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
15
package com.magento.idea.magento2plugin.reference.provider.mftf;
26

37
import com.intellij.ide.highlighter.XmlFileType;

0 commit comments

Comments
 (0)