Merge branch 'liana/simplified_debugger'
[idea/community.git] / python / edu / src / com / jetbrains / python / edu / PyEduUtils.java
1 package com.jetbrains.python.edu;
2
3 import com.intellij.psi.PsiDirectory;
4 import com.intellij.psi.PsiElement;
5 import com.intellij.psi.PsiFile;
6 import com.jetbrains.python.psi.PyQualifiedExpression;
7 import com.jetbrains.python.psi.resolve.ImportedResolveResult;
8 import com.jetbrains.python.psi.resolve.RatedResolveResult;
9 import org.jetbrains.annotations.NotNull;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 public class PyEduUtils {
15   private PyEduUtils() {
16   }
17
18   public static List<RatedResolveResult> getResolveResultFromContainingDirectory(@NotNull PyQualifiedExpression element,
19                                                                                  @NotNull List<PsiElement> definers) {
20     final List<RatedResolveResult> result = new ArrayList<RatedResolveResult>();
21     final PsiFile containingFile = element.getContainingFile();
22     if (containingFile == null) return result;
23     final PsiDirectory directory = containingFile.getContainingDirectory();
24     if (directory == null) return result;
25     final String elementName = element.getName();
26     final PsiFile file = directory.findFile(elementName + ".py");
27     if (file != null) {
28       result.add(new ImportedResolveResult(file, RatedResolveResult.RATE_NORMAL, definers));
29     }
30     return result;
31   }
32 }