resolve foreign imports in QualifiedNameResolver; simplified PyImportResolver API

This commit is contained in:
Dmitry Jemerov
2012-08-13 17:51:57 +02:00
parent 00aacada71
commit 85d753f866
11 changed files with 73 additions and 76 deletions
@@ -2,8 +2,7 @@ package com.jetbrains.python.psi.impl;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.psi.PyElement;
import org.jetbrains.annotations.NotNull;
import com.jetbrains.python.psi.resolve.QualifiedNameResolveContext;
import org.jetbrains.annotations.Nullable;
/**
@@ -13,6 +12,5 @@ public interface PyImportResolver {
ExtensionPointName<PyImportResolver> EP_NAME = ExtensionPointName.create("Pythonid.importResolver");
@Nullable
PsiElement resolveImportReference(@NotNull PyElement importElement, @NotNull PyQualifiedName importText,
@Nullable PyQualifiedName importFrom);
PsiElement resolveImportReference(PyQualifiedName name, QualifiedNameResolveContext context);
}
@@ -58,6 +58,13 @@ public class PyQualifiedName {
return result;
}
public PyQualifiedName append(PyQualifiedName qName) {
PyQualifiedName result = new PyQualifiedName(myComponents.size()+qName.getComponentCount());
result.myComponents.addAll(myComponents);
result.myComponents.addAll(result.getComponents());
return result;
}
@NotNull
public PyQualifiedName removeLastComponent() {
return removeTail(1);
@@ -74,6 +81,17 @@ public class PyQualifiedName {
return result;
}
@NotNull
public PyQualifiedName removeHead(int count) {
int size = myComponents.size();
PyQualifiedName result = new PyQualifiedName(size);
result.myComponents.addAll(myComponents);
for (int i = 0; i < count && result.myComponents.size() > 0; i++) {
result.myComponents.remove(0);
}
return result;
}
@NotNull
public List<String> getComponents() {
return myComponents;
@@ -65,6 +65,7 @@ public class QualifiedNameResolveContext {
return true;
}
@Nullable
public PsiFile getFootholdFile() {
return myFootholdFile;
}
@@ -74,6 +75,7 @@ public class QualifiedNameResolveContext {
return myPsiManager;
}
@NotNull
public Project getProject() {
return myPsiManager.getProject();
}
@@ -42,4 +42,6 @@ public interface QualifiedNameResolver {
<T extends PsiElement> T firstResultOfType(Class<T> clazz);
QualifiedNameResolver withContext(QualifiedNameResolveContext context);
QualifiedNameResolver withoutForeign();
}