Skip to content

Commit 2b5e313

Browse files
committed
fixing some tests for new yaml psi/lexer changes #626
1 parent 2ce9cdc commit 2b5e313

17 files changed

+263
-316
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<PsiElement> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
354+
List<YAMLSequenceItem> yamlArrayOnSequenceOrArrayElements = YamlHelper.getYamlArrayOnSequenceOrArrayElements((YAMLCompoundValue) yamlCompoundValue);
355355
if(yamlArrayOnSequenceOrArrayElements != null) {
356356
serviceArguments = yamlArrayOnSequenceOrArrayElements.size();
357357
}

src/fr/adrienbrault/idea/symfony2plugin/config/yaml/YamlAnnotator.java

+36-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.intellij.patterns.PlatformPatterns;
1010
import com.intellij.psi.PsiElement;
1111
import com.intellij.psi.tree.IElementType;
12-
import com.intellij.psi.util.PsiTreeUtil;
1312
import com.intellij.util.Function;
1413
import com.intellij.util.IncorrectOperationException;
1514
import com.intellij.util.containers.ContainerUtil;
@@ -29,10 +28,7 @@
2928
import org.jetbrains.annotations.Nls;
3029
import org.jetbrains.annotations.NotNull;
3130
import org.jetbrains.yaml.YAMLTokenTypes;
32-
import org.jetbrains.yaml.psi.YAMLArray;
33-
import org.jetbrains.yaml.psi.YAMLCompoundValue;
34-
import org.jetbrains.yaml.psi.YAMLKeyValue;
35-
import org.jetbrains.yaml.psi.YAMLSequence;
31+
import org.jetbrains.yaml.psi.*;
3632

3733
import java.util.Collection;
3834
import java.util.List;
@@ -173,29 +169,29 @@ private void annotateConstructorArguments(@NotNull final PsiElement psiElement,
173169
if (!isStringValue(psiElement)) {
174170
return;
175171
}
176-
172+
177173
// @TODO: simplify code checks
178174

179-
if(!(psiElement.getContext() instanceof YAMLArray)) {
175+
if(!(psiElement.getContext() instanceof YAMLSequenceItem)) {
180176
return;
181177
}
182-
183-
YAMLArray yamlArray = (YAMLArray) psiElement.getContext();
184-
if(!(yamlArray.getContext() instanceof YAMLCompoundValue)) {
178+
final YAMLSequenceItem sequenceItem = (YAMLSequenceItem) psiElement.getContext();
179+
180+
if (!(sequenceItem.getContext() instanceof YAMLSequence)) {
185181
return;
186182
}
187-
188-
YAMLCompoundValue yamlCompoundValue = (YAMLCompoundValue) yamlArray.getContext();
189-
if(!(yamlCompoundValue.getContext() instanceof YAMLKeyValue)) {
183+
final YAMLSequence yamlArray = (YAMLSequence) sequenceItem.getContext();
184+
185+
if(!(yamlArray.getContext() instanceof YAMLKeyValue)) {
190186
return;
191187
}
192188

193-
YAMLKeyValue yamlKeyValue = (YAMLKeyValue) yamlCompoundValue.getContext();
194-
if(yamlKeyValue == null || !yamlKeyValue.getKeyText().equals("arguments")) {
189+
final YAMLKeyValue yamlKeyValue = (YAMLKeyValue) yamlArray.getContext();
190+
if(!yamlKeyValue.getKeyText().equals("arguments")) {
195191
return;
196192
}
197193

198-
YAMLKeyValue classKeyValue = YamlHelper.getYamlKeyValue(yamlKeyValue.getContext(), "class");
194+
final YAMLKeyValue classKeyValue = yamlKeyValue.getParentMapping().getKeyValueByKey("class");
199195
if(classKeyValue == null) {
200196
return;
201197
}
@@ -227,39 +223,47 @@ private void annotateCallsArguments(@NotNull final PsiElement psiElement, @NotNu
227223
}
228224

229225
// @TODO: simplify code checks
230-
if(!(psiElement.getContext() instanceof YAMLArray)) {
226+
if(!(psiElement.getContext() instanceof YAMLSequenceItem)) {
227+
return;
228+
}
229+
final YAMLSequenceItem sequenceItem = (YAMLSequenceItem) psiElement.getContext();
230+
231+
if (!(sequenceItem.getContext() instanceof YAMLSequence)) {
231232
return;
232233
}
233234

234-
YAMLArray yamlCallParameterArray = (YAMLArray) psiElement.getContext();
235-
if(!(yamlCallParameterArray.getContext() instanceof YAMLArray)) {
235+
YAMLSequence yamlCallParameterArray = (YAMLSequence) sequenceItem.getContext();
236+
if(!(yamlCallParameterArray.getContext() instanceof YAMLSequenceItem)) {
236237
return;
237238
}
238239

239-
YAMLArray yamlCallArray = (YAMLArray) yamlCallParameterArray.getContext();
240+
final YAMLSequenceItem enclosingItem = (YAMLSequenceItem) yamlCallParameterArray.getContext();
241+
if (!(enclosingItem.getContext() instanceof YAMLSequence)) {
242+
return;
243+
}
244+
245+
YAMLSequence yamlCallArray = (YAMLSequence) enclosingItem.getContext();
240246
if(!(yamlCallArray.getContext() instanceof YAMLSequence)) {
241247
return;
242248
}
243249

244-
List<PsiElement> methodParameter = YamlHelper.getYamlArrayValues(yamlCallArray);
250+
final List<YAMLSequenceItem> methodParameter = YamlHelper.getYamlArrayValues(yamlCallArray);
245251
if(methodParameter.size() < 2) {
246252
return;
247253
}
248254

249-
String methodName = PsiElementUtils.getText(methodParameter.get(0));
250-
251-
YAMLSequence yamlSequence = (YAMLSequence) yamlCallArray.getContext();
252-
if(!(yamlSequence.getContext() instanceof YAMLCompoundValue)) {
253-
return;
254-
}
255+
final YAMLValue methodNameElement = methodParameter.get(0).getValue();
256+
final String methodName = methodNameElement instanceof YAMLScalar
257+
? ((YAMLScalar) methodNameElement).getTextValue()
258+
: "";
255259

256-
YAMLCompoundValue yamlCompoundValue = (YAMLCompoundValue) yamlSequence.getContext();
257-
if(!(yamlCompoundValue.getContext() instanceof YAMLKeyValue)) {
260+
261+
YAMLSequence yamlSequence = (YAMLSequence) enclosingItem.getContext();
262+
if(!(yamlSequence.getContext() instanceof YAMLKeyValue)) {
258263
return;
259264
}
260265

261-
YAMLCompoundValue serviceDefinition = PsiTreeUtil.getParentOfType(yamlCompoundValue, YAMLCompoundValue.class);
262-
YAMLKeyValue classKeyValue = YamlHelper.getYamlKeyValue(serviceDefinition, "class");
266+
final YAMLKeyValue classKeyValue = ((YAMLKeyValue) yamlSequence.getContext()).getParentMapping().getKeyValueByKey("class");
263267
if(classKeyValue == null) {
264268
return;
265269
}
@@ -305,7 +309,7 @@ private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder ho
305309
}
306310
}
307311

308-
private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder holder, YAMLArray yamlArray, Method constructor) {
312+
private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder holder, YAMLSequence yamlArray, Method constructor) {
309313

310314
if(psiElement == null) {
311315
return;

0 commit comments

Comments
 (0)