Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd4ed27

Browse files
committedMar 27, 2016
reimplement some more yaml plugin related features #626
1 parent a2c9fa8 commit fd4ed27

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed
 

‎src/fr/adrienbrault/idea/symfony2plugin/action/ServiceActionUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public static List<String> getYamlMissingArgumentTypes(Project project, ServiceA
351351

352352
PsiElement yamlCompoundValue = container.getArgument().getValue();
353353
if(yamlCompoundValue instanceof YAMLCompoundValue) {
354-
List<YAMLSequenceItem> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
354+
List<PsiElement> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
355355
if(yamlArrayOnSequenceOrArrayElements != null) {
356356
serviceArguments = yamlArrayOnSequenceOrArrayElements.size();
357357
}

‎src/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/util/DoctrineMetadataUtil.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import org.apache.xmlbeans.XmlLanguage;
3131
import org.jetbrains.annotations.NotNull;
3232
import org.jetbrains.annotations.Nullable;
33-
import org.jetbrains.yaml.psi.YAMLDocument;
34-
import org.jetbrains.yaml.psi.YAMLFile;
35-
import org.jetbrains.yaml.psi.YAMLKeyValue;
33+
import org.jetbrains.yaml.psi.*;
3634

3735
import java.util.*;
3836
import java.util.regex.Matcher;
@@ -306,11 +304,14 @@ public boolean value(PsiElement psiElement) {
306304
PsiFile psiFile = psiElement.getContainingFile();
307305
YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(psiFile, YAMLDocument.class);
308306
if(yamlDocument != null) {
309-
PsiElement firstChild = yamlDocument.getFirstChild();
310-
if(firstChild instanceof YAMLKeyValue) {
311-
String keyText = ((YAMLKeyValue) firstChild).getKeyText();
312-
if(StringUtils.isNotBlank(keyText)) {
313-
return keyText;
307+
YAMLValue topLevelValue = yamlDocument.getTopLevelValue();
308+
if(topLevelValue instanceof YAMLMapping) {
309+
PsiElement firstChild = topLevelValue.getFirstChild();
310+
if(firstChild instanceof YAMLKeyValue) {
311+
String keyText = ((YAMLKeyValue) firstChild).getKeyText();
312+
if(StringUtils.isNotBlank(keyText)) {
313+
return keyText;
314+
}
314315
}
315316
}
316317
}

‎src/fr/adrienbrault/idea/symfony2plugin/intentions/yaml/dict/YamlUpdateArgumentServicesCallback.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void insert(List<String> items) {
6666
} else if(firstChild1 instanceof YAMLArrayImpl) {
6767

6868
// we wound array
69-
List<YAMLSequenceItem> yamlArguments = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
69+
List<PsiElement> yamlArguments = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
7070
if(yamlArguments != null && yamlArguments.size() > 0) {
7171
appendEndOffset = yamlArguments.get(yamlArguments.size() - 1).getTextRange().getEndOffset();
7272

‎src/fr/adrienbrault/idea/symfony2plugin/routing/YamlLineMarkerProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
4848

4949
private void attachEntityClass(Collection<LineMarkerInfo> lineMarkerInfos, PsiElement psiElement) {
5050

51-
if(psiElement instanceof YAMLKeyValue && psiElement.getParent() instanceof YAMLDocument) {
51+
if(psiElement instanceof YAMLKeyValue && psiElement.getParent() instanceof YAMLMapping) {
5252

5353
PsiFile containingFile;
5454
try {
@@ -82,7 +82,7 @@ private void attachRouteActions(Collection<LineMarkerInfo> lineMarkerInfos, PsiE
8282
* defaults:
8383
* _controller: "Bundle:Foo:Bar"
8484
*/
85-
if(psiElement instanceof YAMLKeyValue && psiElement.getParent() instanceof YAMLDocument) {
85+
if(psiElement instanceof YAMLKeyValue && psiElement.getParent() instanceof YAMLMapping) {
8686
YAMLKeyValue yamlKeyValue = YamlHelper.getYamlKeyValue((YAMLKeyValue) psiElement, "defaults");
8787
if(yamlKeyValue != null) {
8888
final YAMLValue container = yamlKeyValue.getValue();

‎src/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.jetbrains.annotations.Nullable;
1818
import org.jetbrains.yaml.YAMLUtil;
1919
import org.jetbrains.yaml.psi.*;
20+
import org.jetbrains.yaml.psi.impl.YAMLHashImpl;
2021

2122
import java.util.*;
2223

@@ -519,12 +520,16 @@ public static String getServiceDefinitionClass(PsiElement psiElement) {
519520
* arguments:
520521
* - @foo
521522
*
523+
* TODO: can be handled nice know because on new yaml plugin
522524
*/
523525
@Nullable
524-
public static List<YAMLSequenceItem> getYamlArrayOnSequenceOrArrayElements(@NotNull YAMLCompoundValue yamlCompoundValue) {
525-
526+
public static List<PsiElement> getYamlArrayOnSequenceOrArrayElements(@NotNull YAMLCompoundValue yamlCompoundValue) {
526527
if (yamlCompoundValue instanceof YAMLSequence) {
527-
return ((YAMLSequence) yamlCompoundValue).getItems();
528+
return new ArrayList<PsiElement>(((YAMLSequence) yamlCompoundValue).getItems());
529+
}
530+
531+
if (yamlCompoundValue instanceof YAMLMapping) {
532+
return new ArrayList<PsiElement>(((YAMLMapping) yamlCompoundValue).getKeyValues());
528533
}
529534

530535
return null;
@@ -547,7 +552,7 @@ public static YAMLKeyValue findServiceInContext(@NotNull PsiElement psiElement)
547552

548553
// we are inside a YAMLHash element, find most parent array key
549554
// { name: foo }
550-
if(serviceSubKeyCompound instanceof YAMLMapping) {
555+
if(serviceSubKeyCompound instanceof YAMLHashImpl) {
551556
YAMLKeyValue yamlKeyValue = PsiTreeUtil.getParentOfType(serviceSubKeyCompound, YAMLKeyValue.class);
552557
if(yamlKeyValue == null) {
553558
return null;

‎tests/fr/adrienbrault/idea/symfony2plugin/tests/util/yaml/YamlHelperLightTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void testGetYamlArrayOnSequenceOrArrayElements() {
151151
YAMLCompoundValue fromText = YamlPsiElementFactory.createFromText(getProject(), YAMLCompoundValue.class, s);
152152
assertNotNull(fromText);
153153

154-
List<YAMLSequenceItem> elements = YamlHelper.getYamlArrayOnSequenceOrArrayElements(fromText);
154+
List<PsiElement> elements = YamlHelper.getYamlArrayOnSequenceOrArrayElements(fromText);
155155
assertNotNull(elements);
156156

157157
String join = StringUtils.join(ContainerUtil.map(elements, new Function<PsiElement, String>() {

0 commit comments

Comments
 (0)
Please sign in to comment.