Skip to content

Commit d042f78

Browse files
authored
Merge pull request #1952 from Haehnchen/feature/contraint-message-leaf
constraint message property linemarker should only be triggered on smallest (leaf) elements
2 parents 41317a2 + 8467ac6 commit d042f78

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/ConstraintMessageGotoCompletionRegistrar.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.patterns.PlatformPatterns;
44
import com.intellij.patterns.PsiElementPattern;
55
import com.intellij.psi.PsiElement;
6+
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
67
import com.jetbrains.php.lang.psi.elements.Field;
78
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
89
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionContributor;
@@ -33,7 +34,10 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
3334

3435
@NotNull
3536
public static PsiElementPattern.Capture<PsiElement> getConstraintPropertyMessagePattern() {
36-
return PlatformPatterns.psiElement().withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
37+
return PlatformPatterns.psiElement().withElementType(PlatformPatterns.elementType().or(
38+
PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE,
39+
PhpTokenTypes.STRING_LITERAL
40+
)).withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
3741
.withParent(PlatformPatterns.psiElement(Field.class)
3842
.withName(PlatformPatterns.string().startsWith("message"))
3943
));

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/ServiceLineMarkerProviderTest.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.intellij.patterns.PatternCondition;
55
import com.intellij.patterns.PlatformPatterns;
66
import com.intellij.patterns.XmlPatterns;
7-
import com.intellij.psi.PsiFile;
87
import com.intellij.util.ProcessingContext;
98
import com.jetbrains.php.lang.PhpFileType;
109
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
@@ -13,9 +12,6 @@
1312
import org.jetbrains.yaml.YAMLFileType;
1413
import org.jetbrains.yaml.psi.YAMLKeyValue;
1514

16-
import java.util.Arrays;
17-
import java.util.Collection;
18-
1915
/**
2016
* @author Daniel Espendiller <daniel@espendiller.net>
2117
*
@@ -25,6 +21,8 @@ public class ServiceLineMarkerProviderTest extends SymfonyLightCodeInsightFixtur
2521

2622
public void setUp() throws Exception {
2723
super.setUp();
24+
25+
myFixture.copyFileToProject("validators.de.yml", "translations/validators.de.yml");
2826
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("ServiceLineMarkerProvider.php"));
2927
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("SymfonyPhpReferenceContributor.php"));
3028
}
@@ -211,4 +209,20 @@ public void testThatAutowireConstructorIsGivenALineMarker() {
211209
"}"
212210
), markerInfo -> markerInfo.getLineMarkerTooltip() != null && markerInfo.getLineMarkerTooltip().toLowerCase().contains("autowire"));
213211
}
212+
213+
public void testNavigateToTranslationForConstraintMessage() {
214+
assertLineMarker(myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
215+
"class LessThan extends \\Symfony\\Component\\Validator\\Constraint\n" +
216+
"{\n" +
217+
" public $message = 'validator_message';\n" +
218+
"}"
219+
), new LineMarker.ToolTipEqualsAssert("Navigate to translation"));
220+
221+
assertLineMarker(myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
222+
"class LessThan extends \\Symfony\\Component\\Validator\\Constraint\n" +
223+
"{\n" +
224+
" public $message = \"validator_message\";\n" +
225+
"}"
226+
), new LineMarker.ToolTipEqualsAssert("Navigate to translation"));
227+
}
214228
}

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/fixtures/ServiceLineMarkerProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ interface ContainerInterface
66
{
77
public function get();
88
}
9+
}
10+
11+
namespace Symfony\Component\Validator
12+
{
13+
abstract class Constraint
14+
{
15+
}
916
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
foo_yaml:
2+
symfony.great: 'YAML Symfony2 is really great'
3+
validator_message: 'YAML Symfony2 is really great'

0 commit comments

Comments
 (0)