|
9 | 9 | import com.intellij.patterns.PlatformPatterns;
|
10 | 10 | import com.intellij.psi.PsiElement;
|
11 | 11 | import com.intellij.psi.tree.IElementType;
|
12 |
| -import com.intellij.psi.util.PsiTreeUtil; |
13 | 12 | import com.intellij.util.Function;
|
14 | 13 | import com.intellij.util.IncorrectOperationException;
|
15 | 14 | import com.intellij.util.containers.ContainerUtil;
|
|
29 | 28 | import org.jetbrains.annotations.Nls;
|
30 | 29 | import org.jetbrains.annotations.NotNull;
|
31 | 30 | 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.*; |
36 | 32 |
|
37 | 33 | import java.util.Collection;
|
38 | 34 | import java.util.List;
|
@@ -173,29 +169,29 @@ private void annotateConstructorArguments(@NotNull final PsiElement psiElement,
|
173 | 169 | if (!isStringValue(psiElement)) {
|
174 | 170 | return;
|
175 | 171 | }
|
176 |
| - |
| 172 | + |
177 | 173 | // @TODO: simplify code checks
|
178 | 174 |
|
179 |
| - if(!(psiElement.getContext() instanceof YAMLArray)) { |
| 175 | + if(!(psiElement.getContext() instanceof YAMLSequenceItem)) { |
180 | 176 | return;
|
181 | 177 | }
|
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)) { |
185 | 181 | return;
|
186 | 182 | }
|
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)) { |
190 | 186 | return;
|
191 | 187 | }
|
192 | 188 |
|
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")) { |
195 | 191 | return;
|
196 | 192 | }
|
197 | 193 |
|
198 |
| - YAMLKeyValue classKeyValue = YamlHelper.getYamlKeyValue(yamlKeyValue.getContext(), "class"); |
| 194 | + final YAMLKeyValue classKeyValue = yamlKeyValue.getParentMapping().getKeyValueByKey("class"); |
199 | 195 | if(classKeyValue == null) {
|
200 | 196 | return;
|
201 | 197 | }
|
@@ -227,39 +223,47 @@ private void annotateCallsArguments(@NotNull final PsiElement psiElement, @NotNu
|
227 | 223 | }
|
228 | 224 |
|
229 | 225 | // @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)) { |
231 | 232 | return;
|
232 | 233 | }
|
233 | 234 |
|
234 |
| - YAMLArray yamlCallParameterArray = (YAMLArray) psiElement.getContext(); |
235 |
| - if(!(yamlCallParameterArray.getContext() instanceof YAMLArray)) { |
| 235 | + YAMLSequence yamlCallParameterArray = (YAMLSequence) sequenceItem.getContext(); |
| 236 | + if(!(yamlCallParameterArray.getContext() instanceof YAMLSequenceItem)) { |
236 | 237 | return;
|
237 | 238 | }
|
238 | 239 |
|
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(); |
240 | 246 | if(!(yamlCallArray.getContext() instanceof YAMLSequence)) {
|
241 | 247 | return;
|
242 | 248 | }
|
243 | 249 |
|
244 |
| - List<PsiElement> methodParameter = YamlHelper.getYamlArrayValues(yamlCallArray); |
| 250 | + final List<YAMLSequenceItem> methodParameter = YamlHelper.getYamlArrayValues(yamlCallArray); |
245 | 251 | if(methodParameter.size() < 2) {
|
246 | 252 | return;
|
247 | 253 | }
|
248 | 254 |
|
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 | + : ""; |
255 | 259 |
|
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)) { |
258 | 263 | return;
|
259 | 264 | }
|
260 | 265 |
|
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"); |
263 | 267 | if(classKeyValue == null) {
|
264 | 268 | return;
|
265 | 269 | }
|
@@ -305,7 +309,7 @@ private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder ho
|
305 | 309 | }
|
306 | 310 | }
|
307 | 311 |
|
308 |
| - private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder holder, YAMLArray yamlArray, Method constructor) { |
| 312 | + private void attachInstanceAnnotation(PsiElement psiElement, AnnotationHolder holder, YAMLSequence yamlArray, Method constructor) { |
309 | 313 |
|
310 | 314 | if(psiElement == null) {
|
311 | 315 | return;
|
|
0 commit comments