Merge remote branch 'origin/master'

This commit is contained in:
Dmitry Cheryasov
2011-05-16 18:37:32 +03:00
16 changed files with 162 additions and 91 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
</text>
</splashScreen>
<java mainClass="com.intellij.idea.Main"
vmParameters="&quot;-Xbootclasspath/a:${EXE4J_EXEDIR}/../lib/boot.jar&quot; &quot;-Didea.properties.file=${IDEA_PROPERTIES}&quot; -Didea.platform.prefix=Python -Didea.no.jre.check=true &quot;-Didea.paths.selector=__PRODUCT_SETTINGS_DIR__&quot;"
vmParameters="&quot;-Xbootclasspath/a:${EXE4J_EXEDIR}/../lib/boot.jar&quot; &quot;-Didea.properties.file=${IDEA_PROPERTIES}&quot; -Didea.platform.prefix=Python -Didea.no.jre.check=true &quot;-Didea.paths.selector=__PRODUCT_PATHS_SELECTOR__&quot;"
arguments=""
allowVMPassthroughParameters="true"
minVersion="1.6"
+2
View File
@@ -26,6 +26,8 @@ def getModuleName(prefix, cnt):
def loadSource(fileName):
baseName = os.path.basename(fileName)
moduleName = os.path.splitext(baseName)[0]
if not moduleName.startswith("test"):
return
# for users wanted to run unittests under django
#because of django took advantage of module name
@@ -444,9 +444,9 @@ refactoring.extract.super.name.0.must.be.ident=Name ''{0}'' is invalid.<br/>Must
# move
refactoring.move.class.or.function=Move class or function
refactoring.move.class.or.function.dialog.title=Move Class or Function
refactoring.move.class.$0=Move class {0}
refactoring.move.function.$0=Move function {0}()
refactoring.move.selected.elements=Move selected elements
refactoring.move.class.$0=Move class {0} to file:
refactoring.move.function.$0=Move function {0}() to file:
refactoring.move.selected.elements=Move selected elements to file:
refactoring.move.class.or.function.choose.destination.file.title=Choose Destination File
refactoring.move.class.or.function.to.file=To file:
refactoring.move.class.or.function.error.cannot.place.elements.into.nonpython.file=Cannot place elements into a non-Python file
@@ -159,12 +159,12 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
@Override
public void visitPyNamedParameter(final PyNamedParameter node) {
final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName());
myBuilder.addNode(instruction);
final PyExpression defaultValue = node.getDefaultValue();
if (defaultValue != null) {
defaultValue.accept(this);
}
final ReadWriteInstruction instruction = ReadWriteInstruction.write(myBuilder, node, node.getName());
myBuilder.addNode(instruction);
myBuilder.checkPending(instruction);
}
@@ -610,25 +610,6 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
@Override
public void visitPyLambdaExpression(final PyLambdaExpression node) {
myBuilder.startNode(node);
for (PyParameter parameter : node.getParameterList().getParameters()){
final PyExpression value = parameter.getDefaultValue();
if (value != null){
value.accept(this);
}
final PyNamedParameter namedParameter = parameter.getAsNamed();
if (namedParameter != null){
final PsiElement paramName = namedParameter.getFirstChild();
final ReadWriteInstruction instruction = ReadWriteInstruction.newInstruction(myBuilder, paramName,
parameter.getName(),
ReadWriteInstruction.ACCESS.WRITE);
myBuilder.addNode(instruction);
myBuilder.checkPending(instruction);
}
}
final PyExpression body = node.getBody();
if (body != null){
body.accept(this);
}
}
@Override
@@ -46,8 +46,14 @@ public class ScopeUtil {
@Nullable
public static ScopeOwner getDeclarationScopeOwner(PyReferenceExpression node) {
final String name = node.getName();
PsiElement element = node;
if (name != null) {
ScopeOwner owner = PsiTreeUtil.getParentOfType(node, ScopeOwner.class);
// References in default values of parameters are defined somewhere in outer scopes
if (PsiTreeUtil.getParentOfType(node, PyParameter.class) != null) {
element = PsiTreeUtil.getParentOfType(node, ScopeOwner.class);
}
ScopeOwner owner = PsiTreeUtil.getParentOfType(element, ScopeOwner.class);
while (owner != null) {
Scope scope = ControlFlowCache.getScope(owner);
if (scope.containsDeclaration(name)) {
@@ -17,6 +17,7 @@ import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
import com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.codeInsight.dataflow.scope.Scope;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable;
import com.jetbrains.python.console.PydevConsoleRunner;
import com.jetbrains.python.psi.*;
@@ -56,8 +57,12 @@ public class PyUnboundLocalVariableInspection extends PyInspection {
if (PyImportStatementNavigator.getImportStatementByElement(node) != null){
return;
}
final ScopeOwner owner = PsiTreeUtil.getParentOfType(node, ScopeOwner.class);
if (owner == null){
final ScopeOwner owner = ScopeUtil.getDeclarationScopeOwner(node);
if (owner == null) {
return;
}
// Ignore references declared in outer scopes
if (owner != PsiTreeUtil.getParentOfType(node, ScopeOwner.class)) {
return;
}
final String name = node.getReferencedName();
@@ -69,7 +69,7 @@ class PyUnusedLocalInspectionVisitor extends PyInspectionVisitor {
@Override
public void visitPyLambdaExpression(final PyLambdaExpression node) {
processScope(PsiTreeUtil.getParentOfType(node, ScopeOwner.class), node);
processScope(node, node);
}
static class DontPerformException extends RuntimeException {}
@@ -1,11 +1,12 @@
package com.jetbrains.python.psi;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import org.jetbrains.annotations.Nullable;
/**
* @author yole
*/
public interface PyLambdaExpression extends PyExpression, Callable {
public interface PyLambdaExpression extends PyExpression, Callable, ScopeOwner {
@Nullable
PyExpression getBody();
}
@@ -6,6 +6,7 @@ import com.intellij.psi.ResolveState;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.TypeEvalContext;
@@ -57,6 +58,12 @@ public class PyLambdaExpressionImpl extends PyElementImpl implements PyLambdaExp
return processParamLayer(parameters, processor, state, lastParent);
}
@Override
public void subtreeChanged() {
super.subtreeChanged();
ControlFlowCache.clear(this);
}
private boolean processParamLayer(@NotNull final PyParameter[] parameters,
@NotNull final PsiScopeProcessor processor,
@NotNull final ResolveState state,
@@ -80,6 +80,11 @@ public class PyMoveClassOrFunctionDialog extends RefactoringDialog {
close(OK_EXIT_CODE);
}
@Override
protected String getHelpId() {
return "refactoring.moveClass";
}
private static String getContainingFileName(PsiElement element) {
VirtualFile file = element.getContainingFile().getVirtualFile();
if (file != null) {
@@ -6,11 +6,11 @@
<xy x="20" y="20" width="543" height="467"/>
</constraints>
<properties>
<preferredSize width="320" height="240"/>
<preferredSize width="320" height="160"/>
</properties>
<border type="none"/>
<children>
<grid id="38299" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="38299" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<grid row="0" column="0" row-span="4" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -20,7 +20,7 @@
<children>
<vspacer id="f71eb">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="e9a03" class="javax.swing.JLabel" binding="myElementsToMove">
@@ -33,18 +33,10 @@
</component>
<component id="2a1d8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myBrowseTargetFileButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="7a408" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/jetbrains/python/PyBundle" key="refactoring.move.class.or.function.to.file"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -1,4 +1,4 @@
def help(object, spacing=10, collapse=1):
def help(object, spacing=foo, collapse=1):
"""Выводит методы и строки документации.
В качестве аргумента может использоваться модуль, класс, список, словарь
@@ -1,44 +1,41 @@
0(1) element: null
1(2) WRITE ACCESS: object
2(3) WRITE ACCESS: spacing
3(4) WRITE ACCESS: collapse
4(5) element: PyExpressionStatement
5(6) element: PyAssignmentStatement
6(7) element: PyListCompExpression
7(8) element: PyCallExpression: dir
8(9) READ ACCESS: dir
9(10,19) READ ACCESS: object
10(11) element: PyTargetExpression: method
11(12) WRITE ACCESS: method
12(13) element: PyCallExpression: callable
13(14) READ ACCESS: callable
14(15) READ ACCESS: getattr
15(16) READ ACCESS: object
16(10,17,19) READ ACCESS: method
17(18) element: PyReferenceExpression: method. Condition: callable(getattr(object, method)):true
18(10,19) READ ACCESS: method
19(20) WRITE ACCESS: methodList
20(21) element: PyAssignmentStatement
21(22) READ ACCESS: collapse
22(23) element: PyLambdaExpression
23(24) WRITE ACCESS: s
24(25) READ ACCESS: s
25(26) element: PyLambdaExpression
26(27) WRITE ACCESS: s
27(28) READ ACCESS: s
28(29) WRITE ACCESS: processFunc
29(30) element: PyPrintStatement
30(31) element: PyListCompExpression
31(32) element: PyReferenceExpression: methodList
32(33,43) READ ACCESS: methodList
33(34) element: PyTargetExpression: method
34(35) WRITE ACCESS: method
35(36) element: PyBinaryExpression
36(37) READ ACCESS: method
37(38) READ ACCESS: spacing
38(39) READ ACCESS: processFunc
39(40) READ ACCESS: str
40(41) READ ACCESS: getattr
41(42) READ ACCESS: object
42(33,43) READ ACCESS: method
43() element: null
2(3) READ ACCESS: foo
3(4) WRITE ACCESS: spacing
4(5) WRITE ACCESS: collapse
5(6) element: PyExpressionStatement
6(7) element: PyAssignmentStatement
7(8) element: PyListCompExpression
8(9) element: PyCallExpression: dir
9(10) READ ACCESS: dir
10(11,20) READ ACCESS: object
11(12) element: PyTargetExpression: method
12(13) WRITE ACCESS: method
13(14) element: PyCallExpression: callable
14(15) READ ACCESS: callable
15(16) READ ACCESS: getattr
16(17) READ ACCESS: object
17(11,18,20) READ ACCESS: method
18(19) element: PyReferenceExpression: method. Condition: callable(getattr(object, method)):true
19(11,20) READ ACCESS: method
20(21) WRITE ACCESS: methodList
21(22) element: PyAssignmentStatement
22(23) READ ACCESS: collapse
23(24) element: PyLambdaExpression
24(25) element: PyLambdaExpression
25(26) WRITE ACCESS: processFunc
26(27) element: PyPrintStatement
27(28) element: PyListCompExpression
28(29) element: PyReferenceExpression: methodList
29(30,40) READ ACCESS: methodList
30(31) element: PyTargetExpression: method
31(32) WRITE ACCESS: method
32(33) element: PyBinaryExpression
33(34) READ ACCESS: method
34(35) READ ACCESS: spacing
35(36) READ ACCESS: processFunc
36(37) READ ACCESS: str
37(38) READ ACCESS: getattr
38(39) READ ACCESS: object
39(30,40) READ ACCESS: method
40() element: null
@@ -2,12 +2,9 @@
1(2) element: PyExpressionStatement
2(3) element: PySetCompExpression
3(4) element: PyCallExpression: range
4(5,12) READ ACCESS: range
4(5,9) READ ACCESS: range
5(6) element: PyTargetExpression: i
6(7) WRITE ACCESS: i
7(8) element: PyParenthesizedExpression
8(9) element: PyLambdaExpression
9(10) READ ACCESS: i
10(11) WRITE ACCESS: i
11(5,12) READ ACCESS: i
12() element: null
8(5,9) element: PyLambdaExpression
9() element: null
+39
View File
@@ -0,0 +1,39 @@
def factorial(n):
"""Return the factorial of n, an exact integer >= 0.
If the result is small enough to fit in an int, return an int.
Else return a long.
>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6, 24, 120]
"""
import math
if not n >= 0:
raise ValueError("n must be >= 0")
if math.floor(n) != n:
raise ValueError("n must be exact integer")
if n+1 == n: # catch a value like 1e300
raise OverflowError("n too large")
result = 1
factor = 2
while factor <= n:
result *= factor
factor += 1
return result
class FirstGoodTest:
"""
>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6, 24, 120]
"""
def test_passes(self):
pass
class SecondGoodTest:
def test_passes(self):
"""
>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6, 24, 120]
"""
pass
+39
View File
@@ -0,0 +1,39 @@
def factorial(n):
"""Return the factorial of n, an exact integer >= 0.
If the result is small enough to fit in an int, return an int.
Else return a long.
>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6, 24, 120]
"""
import math
if not n >= 0:
raise ValueError("n must be >= 0")
if math.floor(n) != n:
raise ValueError("n must be exact integer")
if n+1 == n: # catch a value like 1e300
raise OverflowError("n too large")
result = 1
factor = 2
while factor <= n:
result *= factor
factor += 1
return result
class FirstGoodTest:
"""
>>> [factorial(n) for n in range(6)]
[1, 1]
"""
def test_passes(self):
pass
class SecondGoodTest:
def test_passes(self):
"""
>>> [factorial(n) for n in range(6)]
[1, 1, 2, 6]
"""
pass