mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
i18n: Extract messages from and annotate remaining Python annotators
* FStringAnnotator * Pep8ExternalAnnotator * AssignTargetAnnotator GitOrigin-RevId: 73b2feabd42c7061b4dad22e5d7f7a31ad3f338d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e8612fce3a
commit
63be8f70f2
@@ -217,6 +217,7 @@ refactoring.rename.inheritors=Rename inheritors
|
||||
|
||||
### Annotators ###
|
||||
ANN.default.except.must.be.last=default 'except:' must be last
|
||||
ANN.no.exception.to.reraise=No exception to reraise
|
||||
|
||||
ANN.$0.both.global.and.param=Name ''{0}'' used both as a parameter and as a global
|
||||
|
||||
@@ -234,6 +235,14 @@ ANN.can.t.use.starred.expression.here=Can't use starred expression here
|
||||
ANN.illegal.target.for.variable.annotation=Illegal target for variable annotation
|
||||
ANN.variable.annotation.cannot.be.combined.with.tuple.unpacking=Variable annotation cannot be combined with tuple unpacking
|
||||
ANN.variable.annotation.cannot.be.used.in.assignment.with.multiple.targets=Variable annotation cannot be used in assignment with multiple targets
|
||||
ANN.generator.expression.must.be.parenthesized.if.not.sole.argument=Generator expression must be parenthesized if not sole argument
|
||||
|
||||
ANN.fstrings.expression.fragment.inside.fstring.nested.too.deeply=Expression fragment inside f-string is nested too deeply
|
||||
ANN.fstrings.missing.conversion.character=Conversion character is expected: should be one of 's', 'r', 'a'
|
||||
ANN.fstrings.illegal.conversion.character=Illegal conversion character ''{0}'': should be one of ''s'', ''r'', ''a''
|
||||
ANN.fstrings.expression.fragments.cannot.include.backslashes=Expression fragments inside f-strings cannot include backslashes
|
||||
ANN.fstrings.single.right.brace.not.allowed.inside.fstrings=Single '}' is not allowed inside f-strings
|
||||
ANN.fstrings.expression.fragments.cannot.include.line.comments=Expression fragments inside f-strings cannot include line comments
|
||||
|
||||
python.run.select.script=Select Script
|
||||
python.run.configuration=Python run configuration
|
||||
@@ -1143,3 +1152,4 @@ python.console.rename.message=Enter new console name:
|
||||
python.introduce.variable.refactoring.name=Introduce Variable
|
||||
|
||||
settings.completion.ml.python.display.name=Python
|
||||
QFIX.pep8.edit.inspection.profile.setting=Edit inspection profile setting
|
||||
|
||||
@@ -24,6 +24,7 @@ ANN.cant.assign.to.set.comprh=Can't assign to set comprehension
|
||||
ANN.cant.aug.assign.to.comprh=Augmented assign to list comprehension not possible
|
||||
ANN.cant.aug.assign.to.dict.comprh=Augmented assign to dict comprehension not possible
|
||||
ANN.cant.aug.assign.to.set.comprh=Augmented assign to set comprehension not possible
|
||||
ANN.cant.aug.assign.starred.assignment.target.must.be.in.list.or.tuple=Starred assignment target must be in a list or tuple
|
||||
ANN.cant.assign.to.literal=Can't assign to literal
|
||||
ANN.cant.delete.literal=Can't delete literal
|
||||
ANN.cant.assign.to.lambda=Can't assign to lambda
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.intellij.codeInspection.util.InspectionMessage;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
@@ -49,7 +50,7 @@ public abstract class PyAnnotator extends PyElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected void markError(PsiElement element, String message) {
|
||||
protected void markError(@NotNull PsiElement element, @NotNull @InspectionMessage String message) {
|
||||
getHolder().newAnnotation(HighlightSeverity.ERROR, message).range(element).create();
|
||||
}
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ public class AssignTargetAnnotator extends PyAnnotator {
|
||||
public void visitPyStarExpression(PyStarExpression node) {
|
||||
super.visitPyStarExpression(node);
|
||||
if (!(node.getParent() instanceof PySequenceExpression)) {
|
||||
markError(node, "starred assignment target must be in a list or tuple");
|
||||
markError(node, message("ANN.cant.aug.assign.starred.assignment.target.must.be.in.list.or.tuple"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInspection.util.InspectionMessage;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.PyFStringFragment;
|
||||
import com.jetbrains.python.psi.PyFStringFragmentFormatPart;
|
||||
import com.jetbrains.python.psi.PyFormattedStringElement;
|
||||
@@ -40,16 +42,16 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
final List<PyFStringFragment> enclosingFragments = PsiTreeUtil.collectParents(node, PyFStringFragment.class, false,
|
||||
PyStringLiteralExpression.class::isInstance);
|
||||
if (enclosingFragments.size() > 1) {
|
||||
report(node, "Expression fragment inside f-string is nested too deeply");
|
||||
report(node, PyBundle.message("ANN.fstrings.expression.fragment.inside.fstring.nested.too.deeply"));
|
||||
}
|
||||
final PsiElement typeConversion = node.getTypeConversion();
|
||||
if (typeConversion != null) {
|
||||
final String conversionChar = typeConversion.getText().substring(1);
|
||||
if (conversionChar.isEmpty()) {
|
||||
report(typeConversion, "Conversion character is expected: should be one of 's', 'r', 'a'");
|
||||
report(typeConversion, PyBundle.message("ANN.fstrings.missing.conversion.character"));
|
||||
}
|
||||
else if (conversionChar.length() > 1 || "sra".indexOf(conversionChar.charAt(0)) < 0) {
|
||||
report(typeConversion, "Illegal conversion character '" + conversionChar + "': should be one of 's', 'r', 'a'");
|
||||
report(typeConversion, PyBundle.message("ANN.fstrings.illegal.conversion.character", conversionChar));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
final TextRange range = fragment.getExpressionContentRange();
|
||||
for (int i = range.getStartOffset(); i < range.getEndOffset(); i++) {
|
||||
if (wholeNodeText.charAt(i) == '\\') {
|
||||
reportCharacter(fragment, i, "Expression fragments inside f-strings cannot include backslashes");
|
||||
reportCharacter(fragment, i, PyBundle.message("ANN.fstrings.expression.fragments.cannot.include.backslashes"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +91,7 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
reportCharacter(node, i, "Single '}' is not allowed inside f-strings");
|
||||
reportCharacter(node, i, PyBundle.message("ANN.fstrings.single.right.brace.not.allowed.inside.fstrings"));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -108,16 +110,16 @@ public class FStringsAnnotator extends PyAnnotator {
|
||||
public void visitComment(@NotNull PsiComment comment) {
|
||||
final boolean insideFragment = PsiTreeUtil.getParentOfType(comment, PyFStringFragment.class) != null;
|
||||
if (insideFragment) {
|
||||
report(comment, "Expression fragments inside f-strings cannot include line comments");
|
||||
report(comment, PyBundle.message("ANN.fstrings.expression.fragments.cannot.include.line.comments"));
|
||||
}
|
||||
}
|
||||
|
||||
public void reportCharacter(PsiElement element, int offset, String message) {
|
||||
public void reportCharacter(@NotNull PsiElement element, int offset, @NotNull @InspectionMessage String message) {
|
||||
final int nodeStartOffset = element.getTextRange().getStartOffset();
|
||||
getHolder().newAnnotation(HighlightSeverity.ERROR, message).range(TextRange.from(offset, 1).shiftRight(nodeStartOffset)).create();
|
||||
}
|
||||
|
||||
public void report(PsiElement element, String error) {
|
||||
public void report(@NotNull PsiElement element, @NotNull @InspectionMessage String error) {
|
||||
getHolder().newAnnotation(HighlightSeverity.ERROR, error).range(element).create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.PyArgumentList;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
@@ -32,7 +33,7 @@ public class GeneratorInArgumentListAnnotator extends PyAnnotator {
|
||||
if (expression instanceof PyGeneratorExpression) {
|
||||
ASTNode firstChildNode = expression.getNode().getFirstChildNode();
|
||||
if (firstChildNode.getElementType() != PyTokenTypes.LPAR) {
|
||||
markError(expression, "Generator expression must be parenthesized if not sole argument");
|
||||
markError(expression, PyBundle.message("ANN.generator.expression.must.be.parenthesized.if.not.sole.argument"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator<Pep8ExternalAnnotat
|
||||
builder
|
||||
.withFix(new IgnoreErrorFix(problem.myCode))
|
||||
.withFix(new CustomEditInspectionToolsSettingsAction(HighlightDisplayKey.find(PyPep8Inspection.INSPECTION_SHORT_NAME),
|
||||
() -> "Edit inspection profile setting")).create();
|
||||
() -> PyBundle.message("QFIX.pep8.edit.inspection.profile.setting"))).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class TryExceptAnnotator extends PyAnnotator {
|
||||
public void visitPyRaiseStatement(PyRaiseStatement node) {
|
||||
if (node.getExpressions().length == 0 &&
|
||||
PsiTreeUtil.getParentOfType(node, PyExceptPart.class, PyFinallyPart.class, PyFunction.class) == null) {
|
||||
markError(node, "No exception to reraise");
|
||||
markError(node, PyBundle.message("ANN.no.exception.to.reraise"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<error descr="starred assignment target must be in a list or tuple">*hi</error> = [1, 2]
|
||||
<error descr="Starred assignment target must be in a list or tuple">*hi</error> = [1, 2]
|
||||
*a, = range(5)
|
||||
for a, *b in [(1, 2, 3), (4, 5, 6, 7)]:
|
||||
print(b)
|
||||
|
||||
Reference in New Issue
Block a user