mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/ultimate
This commit is contained in:
@@ -55,7 +55,9 @@
|
||||
<archive location="lib/jdom.jar" failOnError="true"/>
|
||||
<archive location="lib/extensions.jar" failOnError="true"/>
|
||||
</classPath>
|
||||
<nativeLibraryDirectories/>
|
||||
<nativeLibraryDirectories>
|
||||
<directory name="./bin"/>
|
||||
</nativeLibraryDirectories>
|
||||
</java>
|
||||
<includedFiles/>
|
||||
</exe4j>
|
||||
|
||||
@@ -13,6 +13,8 @@ public class PythonBundledColorSchemeProvider implements BundledColorSchemesProv
|
||||
|
||||
public static final String[] PATHS = {
|
||||
"/colorSchemes/WarmNeon",
|
||||
"/colorSchemes/monokai",
|
||||
"/colorSchemes/twilight",
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jetbrains.python.actions;
|
||||
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
@@ -12,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class AddIgnoredIdentifierFix implements LocalQuickFix {
|
||||
public class AddIgnoredIdentifierFix implements LocalQuickFix, LowPriorityAction {
|
||||
private final String myIdentifier;
|
||||
|
||||
public AddIgnoredIdentifierFix(String identifier) {
|
||||
|
||||
-2
@@ -59,8 +59,6 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
|
||||
functionBuilder.statement("return " + body.getText());
|
||||
PyFunction function = functionBuilder.buildFunction(project);
|
||||
|
||||
|
||||
|
||||
PyFunction parentFunction = PsiTreeUtil.getTopmostParentOfType(lambdaExpression, PyFunction.class);
|
||||
if (parentFunction != null ) {
|
||||
PyClass parentClass = PsiTreeUtil.getTopmostParentOfType(parentFunction, PyClass.class);
|
||||
|
||||
+2
-2
@@ -41,9 +41,9 @@ public class PyDictLiteralFormToConstructorIntention extends BaseIntentionAction
|
||||
if (elements.length != 0) {
|
||||
for (PyKeyValueExpression element : elements) {
|
||||
PyExpression key = element.getKey();
|
||||
if (! (key instanceof PyStringLiteralExpression)) canConvert = false;
|
||||
if (! (key instanceof PyStringLiteralExpression)) return false;
|
||||
String str = ((PyStringLiteralExpression)key).getStringValue();
|
||||
if(Character.isDigit(str.charAt(0))) canConvert = false;
|
||||
if(Character.isDigit(str.charAt(0))) return false;
|
||||
try {
|
||||
Integer.parseInt(str) ;
|
||||
canConvert = false;
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.jetbrains.python.codeInsight.intentions;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -11,6 +13,8 @@ import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: catherine
|
||||
* Intention to merge the if clauses in the case of nested ifs where only the inner if contains code (the outer if only contains the inner one)
|
||||
@@ -37,10 +41,13 @@ public class PyJoinIfIntention extends BaseIntentionAction {
|
||||
PyIfStatement expression =
|
||||
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyIfStatement.class);
|
||||
|
||||
|
||||
PyIfStatement ifStatement = getIfStatement(expression);
|
||||
PyStatement firstStatement = getFirstStatement(ifStatement);
|
||||
|
||||
if (firstStatement != null) {
|
||||
if (((PyIfStatement)firstStatement).getElifParts().length != 0) return false;
|
||||
if (((PyIfStatement)firstStatement).getElsePart() != null) return false;
|
||||
PyStatementList stList = ((PyIfStatement)firstStatement).getIfPart().getStatementList();
|
||||
if (stList != null)
|
||||
if (stList.getStatements().length != 0)
|
||||
@@ -59,11 +66,22 @@ public class PyJoinIfIntention extends BaseIntentionAction {
|
||||
if (firstStatement != null && firstStatement instanceof PyIfStatement) {
|
||||
PyExpression condition = ((PyIfStatement)firstStatement).getIfPart().getCondition();
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
PyExpression newCondition = elementGenerator.createExpressionFromText(ifStatement.getIfPart().getCondition().getText() + " and " + condition.getText());
|
||||
PyExpression newCondition = elementGenerator.createExpressionFromText(
|
||||
ifStatement.getIfPart().getCondition().getText() + " and " + condition.getText());
|
||||
ifStatement.getIfPart().getCondition().replace(newCondition);
|
||||
|
||||
PyStatementList stList = ((PyIfStatement)firstStatement).getIfPart().getStatementList();
|
||||
PyStatementList ifStatementList = ifStatement.getIfPart().getStatementList();
|
||||
|
||||
List<PsiComment> comments = PsiTreeUtil.getChildrenOfTypeAsList(ifStatement.getIfPart(), PsiComment.class);
|
||||
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(((PyIfStatement)firstStatement).getIfPart(), PsiComment.class));
|
||||
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(ifStatementList, PsiComment.class));
|
||||
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(stList, PsiComment.class));
|
||||
|
||||
for (PsiElement comm : comments) {
|
||||
ifStatement.getIfPart().addBefore(comm, ifStatementList);
|
||||
comm.delete();
|
||||
}
|
||||
ifStatementList.replace(stList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.actions.AugmentedAssignmentQuickFix;
|
||||
@@ -43,17 +44,19 @@ public class PyAugmentAssignmentInspection extends PyInspection {
|
||||
PyExpression leftExpression = expression.getLeftExpression();
|
||||
PyExpression rightExpression = expression.getRightExpression();
|
||||
if (rightExpression != null) {
|
||||
boolean changedParts = false;
|
||||
if (rightExpression.getText().equals(target.getText())) {
|
||||
PyExpression tmp = rightExpression;
|
||||
rightExpression = leftExpression;
|
||||
leftExpression = tmp;
|
||||
changedParts = true;
|
||||
}
|
||||
PyElementType op = expression.getOperator();
|
||||
if (PyTokenTypes.ADDITIVE_OPERATIONS.contains(op) ||
|
||||
PyTokenTypes.MULTIPLICATIVE_OPERATIONS.contains(op) ||
|
||||
PyTokenTypes.SHIFT_OPERATIONS.contains(op) ||
|
||||
PyTokenTypes.BITWISE_OPERATIONS.contains(op) ||
|
||||
op == PyTokenTypes.EXP) {
|
||||
final TokenSet operations = TokenSet.create(PyTokenTypes.PLUS, PyTokenTypes.MINUS, PyTokenTypes.MULT,
|
||||
PyTokenTypes.FLOORDIV, PyTokenTypes.DIV, PyTokenTypes.PERC, PyTokenTypes.AND, PyTokenTypes.OR,
|
||||
PyTokenTypes.XOR, PyTokenTypes.LTLT, PyTokenTypes.GTGT, PyTokenTypes.EXP);
|
||||
final TokenSet commutativeOperations = TokenSet.create(PyTokenTypes.PLUS, PyTokenTypes.MULT);
|
||||
if ((operations.contains(op) && !changedParts) || (changedParts && commutativeOperations.contains(op))) {
|
||||
if (leftExpression != null
|
||||
&& (leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression)) {
|
||||
if (leftExpression.getText().equals(target.getText())) {
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiPolyVariantReference;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.actions.DictCreationQuickFix;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: catherine
|
||||
@@ -57,5 +55,74 @@ public class PyDictDuplicateKeysInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyCallExpression(PyCallExpression node) {
|
||||
if (isDict(node)) {
|
||||
HashSet<String> set = new HashSet<String>();
|
||||
PyExpression[] argumentList = node.getArgumentList().getArguments();
|
||||
for (PyExpression argument : argumentList) {
|
||||
if (argument instanceof PyParenthesizedExpression)
|
||||
argument = ((PyParenthesizedExpression)argument).getContainedExpression();
|
||||
if (argument instanceof PySequenceExpression) {
|
||||
for (PyElement el : ((PySequenceExpression)argument).getElements()) {
|
||||
String key = getKey(el);
|
||||
checkKey(key, set, node);
|
||||
}
|
||||
}
|
||||
else {
|
||||
String key = getKey(argument);
|
||||
checkKey(key, set, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkKey(String key, Set<String> set, PyCallExpression node) {
|
||||
if (key != null) {
|
||||
if (set.contains(key)) {
|
||||
registerProblem(node, "Dictionary contains duplicate keys " + key);
|
||||
}
|
||||
set.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getKey(PyElement argument) {
|
||||
if (argument instanceof PyParenthesizedExpression) {
|
||||
PyExpression expr = ((PyParenthesizedExpression)argument).getContainedExpression();
|
||||
if (expr instanceof PyTupleExpression) {
|
||||
PyElement key = ((PyTupleExpression)expr).getElements()[0];
|
||||
if (key instanceof PyStringLiteralExpression) {
|
||||
return ((PyStringLiteralExpression)key).getStringValue();
|
||||
}
|
||||
else {
|
||||
return key.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argument instanceof PyKeywordArgument) {
|
||||
return ((PyKeywordArgument)argument).getKeyword();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isDict(PyCallExpression expression) {
|
||||
String name = expression.getCallee().getText();
|
||||
if ("dict".equals(name)) {
|
||||
PyType type = expression.getType(myTypeEvalContext);
|
||||
Application application = ApplicationManager.getApplication();
|
||||
if (application != null && application.isUnitTestMode()) {
|
||||
return true;
|
||||
}
|
||||
if (type != null) {
|
||||
if (type.isBuiltin()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +25,6 @@ var_7 += 2
|
||||
<warning descr="Assignment can be replaced with augmented assignment">x = x | 3</warning>
|
||||
<warning descr="Assignment can be replaced with augmented assignment">x = x & 3</warning>
|
||||
<warning descr="Assignment can be replaced with augmented assignment">x = x ^ 3</warning>
|
||||
|
||||
#PY-2514
|
||||
dy = 1 - dy
|
||||
|
||||
@@ -7,4 +7,11 @@ import random
|
||||
def foo():
|
||||
return random.random()
|
||||
|
||||
{foo(): 1, foo():2}
|
||||
{foo(): 1, foo():2}
|
||||
|
||||
# PY-2511
|
||||
dict = <warning descr="Dictionary contains duplicate keys key">dict([('key', 666), ('key', 123)])</warning>
|
||||
dict = <warning descr="Dictionary contains duplicate keys key">dict((('key', 666), ('key', 123)))</warning>
|
||||
dict = <warning descr="Dictionary contains duplicate keys key">dict((('key', 666), ('k', 123)), key=4)</warning>
|
||||
|
||||
dict([('key', 666), ('ky', 123)])
|
||||
|
||||
Reference in New Issue
Block a user