Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2012-05-30 16:09:12 +04:00
12 changed files with 64 additions and 52 deletions
+3 -1
View File
@@ -24,7 +24,7 @@ but seemingly no one uses them in C extensions yet anyway.
# * re.search-bound, ~30% time, in likes of builtins and _gtk with complex docstrings.
# None of this can seemingly be easily helped. Maybe there's a simpler and faster parser library?
VERSION = "1.107" # Must be a number-dot-number string, updated with each change that affects generated skeletons
VERSION = "1.108" # Must be a number-dot-number string, updated with each change that affects generated skeletons
# Note: DON'T FORGET TO UPDATE!
VERSION_CONTROL_HEADER_FORMAT = '# from %s by generator %s'
@@ -1795,6 +1795,8 @@ class ModuleRedeclarator(object):
for item_name in sortedNoCase(others.keys()):
item = others[item_name]
self.fmtValue(out, item, indent + 1, prefix=item_name + " = ")
if p_name == "object":
out(indent + 1, "__module__ = ''")
if others:
out(0, "") # empty line after the block
#
+1 -1
View File
@@ -6,7 +6,7 @@
(default) 1.92 # anything not explicitly marked
(built-in) 1.106 # skeletons of all built-in modules are built together
(built-in) 1.108 # skeletons of all built-in modules are built together
# Note: modules like itertools, etc are "(built-in)" and are ignored if given separately
_fileio 1.101
@@ -37,7 +37,7 @@ public class PyToJavaResolveTest extends ResolveTestCase {
public void testReturnValue() throws Exception {
PsiElement target = resolve();
Assert.assertTrue(target instanceof PsiMethod);
Assert.assertEquals("java.util.List", ((PsiMethod) target).getContainingClass().getQualifiedName());
Assert.assertEquals(CommonClassNames.JAVA_UTIL_LIST, ((PsiMethod) target).getContainingClass().getQualifiedName());
}
public void testPackageType() throws Exception {
@@ -454,7 +454,7 @@ refactoring.extract.method.error.cannot.perform.refactoring.no.corresponding.loo
refactoring.extract.method.error.cannot.perform.refactoring.when.execution.flow.is.interrupted=Cannot perform refactoring when execution flow is interrupted
refactoring.extract.method.error.cannot.perform.refactoring.when.from.import.inside=Cannot perform refactoring with from import statement inside code block
refactoring.extract.method.error.cannot.perform.refactoring.using.selected.elements=Cannot perform extract method using selected element(s)
refactoring.extract.method.error.name.clash=Method name clashes with already existing method name
refactoring.extract.method.error.name.clash=Method name clashes with already existing name
# extract superclass
refactoring.extract.super.target.path.outside.roots=Target directory is outside the project.<br>Must be within content roots
@@ -12,6 +12,7 @@ import com.jetbrains.python.psi.impl.CallArgumentsMappingImpl;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.PyTypeReference;
import com.jetbrains.python.psi.types.TypeEvalContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -29,7 +30,7 @@ public class PyUsageTypeProvider implements UsageTypeProviderEx {
return getUsageType(element, UsageTarget.EMPTY_ARRAY);
}
public UsageType getUsageType(PsiElement element, UsageTarget[] targets) {
public UsageType getUsageType(PsiElement element, @NotNull UsageTarget[] targets) {
if (element instanceof PyElement) {
if (PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class) != null) {
return IN_IMPORT;
@@ -76,7 +77,7 @@ public class PyUsageTypeProvider implements UsageTypeProviderEx {
if (targets.length == 1 && targets[0] instanceof PsiElementUsageTarget) {
final PsiElement element = ((PsiElementUsageTarget)targets[0]).getElement();
if (element instanceof PyFunction) {
PyFunction function = (PyFunction) element;
PyFunction function = (PyFunction)element;
final PyFunction.Modifier modifier = function.getModifier();
PyCallExpression.PyMarkedCallee callee = new PyCallExpression.PyMarkedCallee(function, modifier, 1, true);
CallArgumentsMappingImpl mapping = new CallArgumentsMappingImpl(call.getArgumentList());
@@ -44,6 +44,7 @@ import java.util.Map;
public class PyBuiltinCache {
public static final @NonNls String BUILTIN_FILE = "__builtin__.py";
@NonNls public static final String BUILTIN_FILE_3K = "builtins.py";
public static final String EXCEPTIONS_FILE = "exceptions.py";
private PyType STRING_TYPE_PY2 = null;
@@ -99,14 +100,19 @@ public class PyBuiltinCache {
}
@Nullable
public static PyFile getBuiltinsForSdk(Project project, Sdk sdk) {
public static PyFile getBuiltinsForSdk(@NotNull Project project, @NotNull Sdk sdk) {
return getSkeletonFile(project, sdk, PythonSdkType.getBuiltinsFileName(sdk));
}
@Nullable
public static PyFile getSkeletonFile(@NotNull Project project, @NotNull Sdk sdk, @NotNull String name) {
SdkTypeId sdkType = sdk.getSdkType();
if (sdkType instanceof PythonSdkType) {
// dig out the builtins file, create an instance based on it
final String[] urls = sdk.getRootProvider().getUrls(PythonSdkType.BUILTIN_ROOT_TYPE);
for (String url : urls) {
if (url.contains(PythonSdkType.SKELETON_DIR_NAME)) {
final String builtins_url = url + "/" + PythonSdkType.getBuiltinsFileName(sdk);
final String builtins_url = url + "/" + name;
File builtins = new File(VfsUtil.urlToPath(builtins_url));
if (builtins.isFile() && builtins.canRead()) {
VirtualFile builtins_vfile = LocalFileSystem.getInstance().findFileByIoFile(builtins);
@@ -123,7 +129,7 @@ public class PyBuiltinCache {
return null;
}
private static final PyBuiltinCache DUD_INSTANCE = new PyBuiltinCache((PyFile)null);
private static final PyBuiltinCache DUD_INSTANCE = new PyBuiltinCache(null, null);
@Nullable
static PyType createLiteralCollectionType(final PySequenceExpression sequence, final String name) {
@@ -136,7 +142,9 @@ public class PyBuiltinCache {
}
private PyFile myBuiltinsFile;
@Nullable private PyFile myBuiltinsFile;
@Nullable private PyFile myExceptionsFile;
public PyBuiltinCache() {
}
@@ -144,8 +152,9 @@ public class PyBuiltinCache {
public static final Key<String> MARKER_KEY = new Key<String>("python.builtins.skeleton.file");
public PyBuiltinCache(@Nullable final PyFile builtins) {
public PyBuiltinCache(@Nullable final PyFile builtins, @Nullable PyFile exceptions) {
myBuiltinsFile = builtins;
myExceptionsFile = exceptions;
if (myBuiltinsFile != null) {
myBuiltinsFile.putUserData(MARKER_KEY, ""); // mark this file as builtins
}
@@ -336,6 +345,7 @@ public class PyBuiltinCache {
if (!(the_file instanceof PyFile)) {
return false;
}
return myBuiltinsFile == the_file; // files are singletons, no need to compare URIs
// files are singletons, no need to compare URIs
return the_file == myBuiltinsFile || the_file == myExceptionsFile;
}
}
@@ -94,7 +94,8 @@ public class PythonSdkPathCache extends PythonPathCache implements Disposable {
while (true) {
PyBuiltinCache pyBuiltinCache = myBuiltins.get();
if (pyBuiltinCache == null || !pyBuiltinCache.isValid()) {
PyBuiltinCache newCache = new PyBuiltinCache(PyBuiltinCache.getBuiltinsForSdk(myProject, mySdk));
PyBuiltinCache newCache = new PyBuiltinCache(PyBuiltinCache.getBuiltinsForSdk(myProject, mySdk),
PyBuiltinCache.getSkeletonFile(myProject, mySdk, PyBuiltinCache.EXCEPTIONS_FILE));
if (myBuiltins.compareAndSet(pyBuiltinCache, newCache)) {
return newCache;
}
@@ -553,45 +553,26 @@ public class PyExtractMethodUtil {
public PyExtractMethodValidator(final PsiElement element, final Project project) {
myElement = element;
myProject = project;
ScopeOwner owner = ScopeUtil.getScopeOwner(myElement);
if (owner instanceof PyFunction) {
owner = ScopeUtil.getScopeOwner(owner);
}
final ScopeOwner parent = owner;
if (parent instanceof PyFile){
final List<PyFunction> functions = ((PyFile)parent).getTopLevelFunctions();
myFunction = new Function<String, Boolean>() {
public Boolean fun(@NotNull final String s) {
for (PyFunction function : functions) {
if (s.equals(function.getName())){
final ScopeOwner parent = ScopeUtil.getScopeOwner(myElement);
myFunction = new Function<String, Boolean>() {
@Override
public Boolean fun(String s) {
ScopeOwner owner = parent;
while (owner != null) {
if (owner instanceof PyClass) {
if (((PyClass)owner).findMethodByName(s, true) != null) {
return false;
}
}
return true;
final Scope scope = ControlFlowCache.getScope(owner);
if (scope.containsDeclaration(s)) {
return false;
}
owner = ScopeUtil.getScopeOwner(owner);
}
};
}
else if (parent instanceof PyClass){
myFunction = new Function<String, Boolean>() {
public Boolean fun(@NotNull final String s) {
return ((PyClass) parent).findMethodByName(s, true) == null;
}
};
}
else if (parent instanceof PyFunction) {
final Scope scope = ControlFlowCache.getScope(parent);
myFunction = new Function<String, Boolean>() {
@Override
public Boolean fun(String s) {
return !scope.containsDeclaration(s);
}
};
}
else {
myFunction = null;
}
return true;
}
};
}
public String check(final String name) {
+1 -1
View File
@@ -2,4 +2,4 @@ class C(object):
pass
C.__m<caret>
C.__mr<caret>
@@ -0,0 +1,12 @@
class OldStyle:
pass
class NewStyle(object):
pass
x = OldStyle()
y = NewStyle()
print(OldStyle.__module__)
print(NewStyle.__module__)
print(x.__module__)
print(y.__module__)
@@ -121,6 +121,11 @@ public class PyUnresolvedReferencesInspectionTest extends PyTestCase {
doTest();
}
// PY-6634
public void testModuleAttribute() {
doTest();
}
private void doTest() {
myFixture.configureByFile(TEST_DIRECTORY + getTestName(true) + ".py");
myFixture.enableInspections(PyUnresolvedReferencesInspection.class);
@@ -91,15 +91,15 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
}
public void testNameCollisionClass() {
doFail("hello", "Method name clashes with already existing method name");
doFail("hello", "Method name clashes with already existing name");
}
public void testNameCollisionFile() {
doFail("hello", "Method name clashes with already existing method name");
doFail("hello", "Method name clashes with already existing name");
}
public void testNameCollisionSuperClass() {
doFail("hello", "Method name clashes with already existing method name");
doFail("hello", "Method name clashes with already existing name");
}
public void testOutNotEmptyStatements() {