Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-08-21 18:30:00 +02:00
7 changed files with 600 additions and 571 deletions
+4 -1
View File
@@ -67,6 +67,8 @@ if PYVERSION > [1, 4, 0]:
items[nodeid] = name
def pytest_runtest_logreport(report):
if report.when != "call":
return
name = items[report.nodeid]
if report.failed:
messages.testFailed(name, details=report.longrepr)
@@ -126,7 +128,8 @@ else:
messages.testFailed(name, details=report.longrepr)
elif report.skipped:
messages.testIgnored(name)
messages.testFinished(name)
else:
messages.testFinished(name)
def pytest_collectreport(report):
if report.collector.name != "()":
@@ -1,9 +1,9 @@
package com.jetbrains.python.codeInsight.intentions;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
@@ -59,28 +59,12 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
PyStringLiteralExpression string = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyStringLiteralExpression.class);
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
if (string != null) {
StringBuilder strBuilder = new StringBuilder();
List<ASTNode> nodes = string.getStringNodes();
if (nodes.size() == 1)
strBuilder.append(string.getText());
else {
// There possible situation that several triple quoted string are situated together
String firstNode = nodes.get(0).getText();
strBuilder.append(firstNode.substring(0, firstNode.length()-3));
for (int i = 1; i != nodes.size(); ++i) {
ASTNode node = nodes.get(i);
String text = node.getText();
if (text.length() > 3)
strBuilder.append(text.substring(3, text.length()-3));
}
strBuilder.append(firstNode.substring(0, 3));
}
String stringText = strBuilder.toString();
String[] subStrings = stringText.split("\n");
String stringText = string.getStringValue();
List<String> subStrings = StringUtil.split(stringText, "\n", false, true);
Character firstQuote = stringText.charAt(0);
Character firstQuote = string.getText().charAt(0);
StringBuilder result = new StringBuilder();
if (subStrings.length != 1)
if (subStrings.size() != 1)
result.append("(");
boolean lastString = false;
for (String s : subStrings) {
@@ -93,9 +77,9 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
result.append(validSubstring);
result.append(firstQuote);
if (!lastString)
result.append(" ").append(firstQuote).append("\\n").append(firstQuote).append("\n");
result.append(" ").append("\n");
}
if (subStrings.length != 1)
if (subStrings.size() != 1)
result.append(")");
PyExpressionStatement e = elementGenerator.createFromText(LanguageLevel.forElement(string), PyExpressionStatement.class, result.toString());
string.replace(e.getExpression());
@@ -111,7 +95,7 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
subString = convertToValidSubString(trimmed.substring(0, trimmed.length() - 3), firstQuote);
}
else {
s = s.trim();
s = StringUtil.escapeStringCharacters(s);
StringBuilder stringBuilder = new StringBuilder();
for (Character ch : s.toCharArray()) {
if (ch == firstQuote) {
@@ -4,6 +4,8 @@ import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.template.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
@@ -139,22 +141,33 @@ public class SpecifyTypeInPy3AnnotationsIntention implements IntentionAction {
Callable callable = ((PyCallExpression)assignedValue).resolveCalleeFunction(PyResolveContext.defaultContext());
if (callable instanceof PyFunction && ((PyFunction)callable).getAnnotation() == null) {
final String functionSignature = "def " + callable.getName() + callable.getParameterList().getText();
String functionText = functionSignature +
" -> object:";
for (PyStatement st : ((PyFunction)callable).getStatementList().getStatements()) {
functionText = functionText + "\n\t" + st.getText();
}
final PyFunction function = elementGenerator.createFromText(LanguageLevel.forElement(problemElement), PyFunction.class,
functionSignature +
" -> object:\n\t" +
((PyFunction)callable).getStatementList().getText());
functionText);
callable = (PyFunction)callable.replace(function);
callable = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(callable);
final PyExpression value = ((PyFunction)callable).getAnnotation().getValue();
final int offset = value.getTextOffset();
editor.getCaretModel().moveToOffset(offset);
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().
createTemplateBuilder(value);
builder.replaceRange(TextRange.create(0, PyNames.OBJECT.length()), PyNames.OBJECT);
Template template = ((TemplateBuilderImpl)builder).buildInlineTemplate();
TemplateManager.getInstance(project).startTemplate(editor, template);
OpenFileDescriptor descriptor = new OpenFileDescriptor(
project,
value.getContainingFile().getVirtualFile(),
offset
);
Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
if (targetEditor != null) {
targetEditor.getCaretModel().moveToOffset(offset);
TemplateManager.getInstance(project).startTemplate(targetEditor, template);
}
}
}
}
@@ -70,6 +70,7 @@ APOS_STRING_CHAR = [^\\'] | {ANY_ESCAPE_SEQUENCE} | {ONE_TWO_APOS}
TRIPLE_APOS_LITERAL = {THREE_APOS} {APOS_STRING_CHAR}* {THREE_APOS}?
%state PENDING_DOCSTRING
%state IN_DOCSTRING_OWNER
%state USUAL
%{
private int getSpaceLength(CharSequence string) {
@@ -92,7 +93,7 @@ return yylength()-i-1;
. { yypushback(1); yybegin(PENDING_DOCSTRING);}
}
<USUAL> {
<USUAL, IN_DOCSTRING_OWNER> {
{LONGINTEGER} { return PyTokenTypes.INTEGER_LITERAL; }
{INTEGER} { return PyTokenTypes.INTEGER_LITERAL; }
{FLOATNUMBER} { return PyTokenTypes.FLOAT_LITERAL; }
@@ -104,9 +105,9 @@ return yylength()-i-1;
"and" { return PyTokenTypes.AND_KEYWORD; }
"assert" { return PyTokenTypes.ASSERT_KEYWORD; }
"break" { return PyTokenTypes.BREAK_KEYWORD; }
"class" { return PyTokenTypes.CLASS_KEYWORD; }
"class" { yybegin(IN_DOCSTRING_OWNER); return PyTokenTypes.CLASS_KEYWORD; }
"continue" { return PyTokenTypes.CONTINUE_KEYWORD; }
"def" { return PyTokenTypes.DEF_KEYWORD; }
"def" { yybegin(IN_DOCSTRING_OWNER); return PyTokenTypes.DEF_KEYWORD; }
"del" { return PyTokenTypes.DEL_KEYWORD; }
"elif" { return PyTokenTypes.ELIF_KEYWORD; }
"else" { return PyTokenTypes.ELSE_KEYWORD; }
@@ -172,7 +173,7 @@ return yylength()-i-1;
"@" { return PyTokenTypes.AT; }
"," { return PyTokenTypes.COMMA; }
":" { return PyTokenTypes.COLON; }
":"(\ )*"\n" { yypushback(yylength()-1); yybegin(PENDING_DOCSTRING); return PyTokenTypes.COLON; }
"." { return PyTokenTypes.DOT; }
"`" { return PyTokenTypes.TICK; }
"=" { return PyTokenTypes.EQ; }
@@ -181,6 +182,10 @@ return yylength()-i-1;
. { return PyTokenTypes.BAD_CHARACTER; }
}
<IN_DOCSTRING_OWNER> {
":"(\ )*"\n" { yypushback(yylength()-1); yybegin(PENDING_DOCSTRING); return PyTokenTypes.COLON; }
}
<PENDING_DOCSTRING> {
{SINGLE_QUOTED_STRING} { if (zzInput == YYEOF) return PyTokenTypes.DOCSTRING;
else yybegin(USUAL); return PyTokenTypes.SINGLE_QUOTED_STRING; }
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,7 @@
if True:
if True:
a = ('\'Hello\' - said man.\n' '\n'
'Let\'s go.' '\n'
'And they went out.')
a = ('\'Hello\' - said man.\n'
'\n'
' Let\'s go.\n'
' And they went out.'
)
@@ -232,6 +232,19 @@ public class PythonLexerTest extends PyLexerTestCase {
"Py:STATEMENT_BREAK");
}
// PY-7255
public void testDocstringInDict() {
doTest("d = {\n" +
" 'foo':\n" +
" 'bar'\n" +
" 'baz'\n" +
"}",
"Py:IDENTIFIER", "Py:SPACE", "Py:EQ", "Py:SPACE", "Py:LBRACE", "Py:LINE_BREAK",
"Py:SINGLE_QUOTED_STRING", "Py:COLON", "Py:LINE_BREAK", "Py:SINGLE_QUOTED_STRING", "Py:LINE_BREAK",
"Py:SINGLE_QUOTED_STRING", "Py:LINE_BREAK", "Py:RBRACE", "Py:STATEMENT_BREAK");
}
// PY-3067
public void testErrorOpenParInMethod() {
doTest("class C:\n" +