Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ec4b13

Browse files
authored
Merge pull requestHaehnchen#1683 from adamwojs/issue_1667
FixedHaehnchen#1667: Rename refactoring ignores constants inside yaml files
2 parents8a6621c +a6fb4b4 commit6ec4b13

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
packagefr.adrienbrault.idea.symfony2plugin.config.yaml;
2+
3+
importcom.intellij.psi.PsiElement;
4+
importcom.intellij.psi.PsiElementResolveResult;
5+
importcom.intellij.psi.PsiPolyVariantReferenceBase;
6+
importcom.intellij.psi.ResolveResult;
7+
importcom.intellij.util.IncorrectOperationException;
8+
importfr.adrienbrault.idea.symfony2plugin.dic.container.util.ServiceContainerUtil;
9+
importorg.apache.commons.lang.StringUtils;
10+
importorg.jetbrains.annotations.NotNull;
11+
importorg.jetbrains.yaml.psi.YAMLScalar;
12+
13+
publicclassConstantYamlReferenceextendsPsiPolyVariantReferenceBase<YAMLScalar> {
14+
15+
publicConstantYamlReference(@NotNullYAMLScalarelement) {
16+
super(element);
17+
}
18+
19+
@NotNull
20+
@Override
21+
publicResolveResult[]multiResolve(booleanincompleteCode) {
22+
varconstantName =getElement().getTextValue();
23+
if (StringUtils.isBlank(constantName)) {
24+
returnResolveResult.EMPTY_ARRAY;
25+
}
26+
27+
returnPsiElementResolveResult.createResults(
28+
ServiceContainerUtil.getTargetsForConstant(getElement().getProject(),constantName)
29+
);
30+
}
31+
32+
@Override
33+
publicPsiElementhandleElementRename(@NotNullStringnewElementName)throwsIncorrectOperationException {
34+
varconstantName =getValue();
35+
if (isClassConst(constantName)) {
36+
newElementName =getClassName(constantName) +"::" +newElementName;
37+
}
38+
39+
returnsuper.handleElementRename(newElementName);
40+
}
41+
42+
privatebooleanisClassConst(@NotNullStringvalue) {
43+
returnvalue.contains("::");
44+
}
45+
46+
@NotNull
47+
privateStringgetClassName(@NotNullStringvalue) {
48+
returnvalue.substring(0,value.indexOf("::"));
49+
}
50+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagefr.adrienbrault.idea.symfony2plugin.config.yaml;
2+
3+
importcom.intellij.patterns.PlatformPatterns;
4+
importcom.intellij.patterns.StandardPatterns;
5+
importcom.intellij.psi.*;
6+
importcom.intellij.util.ProcessingContext;
7+
importfr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
8+
importorg.jetbrains.annotations.NotNull;
9+
importorg.jetbrains.yaml.psi.YAMLScalar;
10+
11+
publicclassYamlReferenceContributorextendsPsiReferenceContributor {
12+
privatestaticfinalStringTAG_PHP_CONST ="!php/const";
13+
14+
@Override
15+
publicvoidregisterReferenceProviders(@NotNullPsiReferenceRegistrarregistrar) {
16+
registrar.registerReferenceProvider(
17+
PlatformPatterns.psiElement(YAMLScalar.class)
18+
.withText(StandardPatterns.string()
19+
.contains(TAG_PHP_CONST)
20+
),
21+
newPsiReferenceProvider() {
22+
@NotNull
23+
@Override
24+
publicPsiReference[]getReferencesByElement(@NotNullPsiElementelement,@NotNullProcessingContextcontext) {
25+
if (!Symfony2ProjectComponent.isEnabled(element)) {
26+
returnPsiReference.EMPTY_ARRAY;
27+
}
28+
29+
varscalar = (YAMLScalar)element;
30+
if (scalar.getTextValue().isEmpty()) {
31+
returnPsiReference.EMPTY_ARRAY;
32+
}
33+
34+
returnnewPsiReference[]{
35+
newConstantYamlReference(scalar)
36+
};
37+
}
38+
}
39+
);
40+
}
41+
}

‎src/main/resources/META-INF/plugin.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.routing.PhpRouteReferenceContributor"/>
171171
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.config.xml.XmlReferenceContributor"/>
172172
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.config.php.PhpConfigReferenceContributor"/>
173+
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlReferenceContributor"/>
173174
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.form.FormTypeReferenceContributor"/>
174175
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.util.DocHashTagReferenceContributor"/>
175176
<psi.referenceContributorimplementation="fr.adrienbrault.idea.symfony2plugin.util.MethodParameterReferenceContributor"/>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagefr.adrienbrault.idea.symfony2plugin.tests.config.yaml;
2+
3+
importcom.intellij.patterns.PlatformPatterns;
4+
importcom.jetbrains.php.lang.psi.elements.Field;
5+
importcom.jetbrains.php.lang.psi.elements.PhpDefine;
6+
importfr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
7+
importorg.jetbrains.yaml.YAMLFileType;
8+
9+
publicclassYamlReferenceContributorTestextendsSymfonyLightCodeInsightFixtureTestCase {
10+
11+
publicvoidsetUp()throwsException {
12+
super.setUp();
13+
myFixture.copyFileToProject("YamlReferenceContributor.php");
14+
}
15+
16+
publicStringgetTestDataPath() {
17+
return"src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/yaml/fixtures";
18+
}
19+
20+
publicvoidtestConstantProvidesReferences() {
21+
assertReferenceMatchOnParent(
22+
YAMLFileType.YML,
23+
"services:\n" +
24+
" app.service.example:\n" +
25+
" arguments:\n" +
26+
" - !php/const CONST_<caret>FOO\n",
27+
PlatformPatterns.psiElement(PhpDefine.class).withName("CONST_FOO")
28+
);
29+
30+
assertReferenceMatchOnParent(
31+
YAMLFileType.YML,
32+
"services:\n" +
33+
" app.service.example:\n" +
34+
" arguments:\n" +
35+
" - !php/const Foo\\Bar::F<caret>OO\n",
36+
PlatformPatterns.psiElement(Field.class).withName("FOO")
37+
);
38+
}
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace
4+
{
5+
define('CONST_FOO','CONST_FOO');
6+
}
7+
8+
namespaceFoo
9+
{
10+
class Bar
11+
{
12+
constFOO ='foo';
13+
}
14+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp