-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete with special values for matchStrategy and matchingRole
- Loading branch information
1 parent
732327d
commit 52f9e5e
Showing
11 changed files
with
208 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/com/gman/idea/plugin/concordion/ConcordionPatternConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.gman.idea.plugin.concordion; | ||
|
||
import com.intellij.patterns.PatternCondition; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.xml.XmlAttribute; | ||
import com.intellij.util.ProcessingContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static com.gman.idea.plugin.concordion.Concordion.isConcordionHtmlSpec; | ||
import static java.util.Arrays.asList; | ||
|
||
public class ConcordionPatternConditions { | ||
|
||
public static final ConcordionHtmlSpec CONCORDION_HTML_SPEC = new ConcordionHtmlSpec(); | ||
public static final SpecificConcordionTag MATCH_STRATEGY_ATTRIBUTE = new SpecificConcordionTag("matchStrategy", "match-strategy"); | ||
public static final SpecificConcordionTag MATCHING_ROLE_ATTRIBUTE = new SpecificConcordionTag("matchingRole", "matching-Role"); | ||
|
||
private static final class ConcordionHtmlSpec extends PatternCondition<PsiElement> { | ||
|
||
public ConcordionHtmlSpec() { | ||
super(ConcordionHtmlSpec.class.getName()); | ||
} | ||
|
||
@Override | ||
public boolean accepts(@NotNull PsiElement element, ProcessingContext context) { | ||
return isConcordionHtmlSpec(element.getContainingFile()); | ||
} | ||
}; | ||
|
||
private static final class SpecificConcordionTag extends PatternCondition<PsiElement> { | ||
|
||
private final Set<String> expectedTagNames = new HashSet<>(); | ||
|
||
public SpecificConcordionTag(String... expectedTagNames) { | ||
super(SpecificConcordionTag.class.getName()); | ||
this.expectedTagNames.addAll(asList(expectedTagNames)); | ||
} | ||
|
||
@Override | ||
public boolean accepts(@NotNull PsiElement element, ProcessingContext context) { | ||
String localName = ((XmlAttribute) element.getParent().getParent()).getLocalName(); | ||
return expectedTagNames.contains(localName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/com/gman/idea/plugin/concordion/autocomplete/ConcordionHtmlSpec.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...man/idea/plugin/concordion/autocomplete/ConcordionNonExpressionCompletionContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.gman.idea.plugin.concordion.autocomplete; | ||
|
||
import com.intellij.codeInsight.completion.*; | ||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder; | ||
import com.intellij.psi.xml.XmlAttributeValue; | ||
import com.intellij.util.ProcessingContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.gman.idea.plugin.concordion.ConcordionPatternConditions.MATCHING_ROLE_ATTRIBUTE; | ||
import static com.gman.idea.plugin.concordion.ConcordionPatternConditions.MATCH_STRATEGY_ATTRIBUTE; | ||
import static com.intellij.patterns.PlatformPatterns.psiElement; | ||
import static java.util.Arrays.stream; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class ConcordionNonExpressionCompletionContributor extends CompletionContributor { | ||
|
||
public ConcordionNonExpressionCompletionContributor() { | ||
extend( | ||
CompletionType.BASIC, | ||
psiElement().withParent(XmlAttributeValue.class).with(MATCH_STRATEGY_ATTRIBUTE), | ||
new ConcordionMatchStrategyProvider() | ||
); | ||
extend( | ||
CompletionType.BASIC, | ||
psiElement().withParent(XmlAttributeValue.class).with(MATCHING_ROLE_ATTRIBUTE), | ||
new ConcordionMatchingRoleProvider() | ||
); | ||
} | ||
|
||
private static final class ConcordionMatchStrategyProvider extends CompletionProvider<CompletionParameters> { | ||
@Override | ||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { | ||
result.addAllElements(fromStrings("Default", "BestMatch", "KeyMatch")); | ||
//TODO contribute by classes extending RowsMatchStrategy | ||
} | ||
} | ||
|
||
private static final class ConcordionMatchingRoleProvider extends CompletionProvider<CompletionParameters> { | ||
@Override | ||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { | ||
result.addAllElements(fromStrings("key")); | ||
} | ||
} | ||
|
||
private static Iterable<LookupElement> fromStrings(String... strings) { | ||
return stream(strings).map(LookupElementBuilder::create).collect(toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html xmlns:c="http://www.concordion.org/2007/concordion"> | ||
<head> | ||
<title>Test spec</title> | ||
</head> | ||
<body> | ||
|
||
<table c:verifyRows="#var : values()" c:matchStrategy="<caret>"> | ||
<tr> | ||
<td>Key</td> | ||
<td>Value</td> | ||
</tr> | ||
</table> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.test; | ||
|
||
import org.concordion.integration.junit4.ConcordionRunner; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.lang.Object; | ||
import java.util.Collections; | ||
|
||
@RunWith(ConcordionRunner.class) | ||
public class MatchStrategy { | ||
|
||
public List<Object> values() { | ||
return Collections.<Object>emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html xmlns:c="http://www.concordion.org/2007/concordion"> | ||
<head> | ||
<title>Test spec</title> | ||
</head> | ||
<body> | ||
|
||
<table c:verifyRows="#var : values()" c:matchStrategy="KeyMatch"> | ||
<tr> | ||
<td c:matchingRole="<caret>">Key</td> | ||
<td>Value</td> | ||
</tr> | ||
</table> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.test; | ||
|
||
import org.concordion.integration.junit4.ConcordionRunner; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(ConcordionRunner.class) | ||
public class MatchingRole { | ||
|
||
public List<Object> values() { | ||
return Collections.<Object>emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/com/gman/idea/plugin/concordion/completion/CompleteWithSpecialValuesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.gman.idea.plugin.concordion.completion; | ||
|
||
import com.gman.idea.plugin.concordion.ConcordionCodeInsightFixtureTestCase; | ||
import com.intellij.codeInsight.completion.CompletionType; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CompleteWithSpecialValuesTest extends ConcordionCodeInsightFixtureTestCase { | ||
|
||
@Override | ||
protected String getTestDataPath() { | ||
return "testData/completion"; | ||
} | ||
|
||
public void testShouldCompleteMatchStrategyWithPredefinedStrategies() { | ||
|
||
copyJavaRunnerToConcordionProject("MatchStrategy.java"); | ||
VirtualFile htmlSpec = copyHtmlSpecToConcordionProject("MatchStrategy.html"); | ||
|
||
myFixture.configureFromExistingVirtualFile(htmlSpec); | ||
myFixture.complete(CompletionType.BASIC, 1); | ||
|
||
assertThat(myFixture.getLookupElementStrings()).containsAll(asList("Default", "BestMatch", "KeyMatch")); | ||
} | ||
|
||
public void testShouldCompleteMatchingRoleWithKeyRole() { | ||
|
||
copyJavaRunnerToConcordionProject("MatchingRole.java"); | ||
VirtualFile htmlSpec = copyHtmlSpecToConcordionProject("MatchingRole.html"); | ||
|
||
myFixture.configureFromExistingVirtualFile(htmlSpec); | ||
myFixture.complete(CompletionType.BASIC, 1); | ||
|
||
assertThat(myFixture.getLookupElementStrings()).contains("key"); | ||
} | ||
} |