[python] extract python parser to a separate module

Merge-request: IJ-MR-116296
Merged-by: Vladimir Koshelev <Vladimir.Koshelev@jetbrains.com>

GitOrigin-RevId: e7559fb3215d757e6273543e4aa27d52df755e63
This commit is contained in:
Vladimir Koshelev
2023-10-09 11:56:10 +00:00
committed by intellij-monorepo-bot
parent 609391377b
commit 29f0eb6c77
76 changed files with 3494 additions and 572 deletions

1
.idea/modules.xml generated
View File

@@ -1069,6 +1069,7 @@
<module fileurl="file://$PROJECT_DIR$/python/helpers/tests/intellij.python.helpers.tests.iml" filepath="$PROJECT_DIR$/python/helpers/tests/intellij.python.helpers.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/python/IntelliLang-python/intellij.python.langInjection.iml" filepath="$PROJECT_DIR$/python/IntelliLang-python/intellij.python.langInjection.iml" />
<module fileurl="file://$PROJECT_DIR$/python/python-markdown/intellij.python.markdown.iml" filepath="$PROJECT_DIR$/python/python-markdown/intellij.python.markdown.iml" />
<module fileurl="file://$PROJECT_DIR$/python/python-parser/intellij.python.parser.iml" filepath="$PROJECT_DIR$/python/python-parser/intellij.python.parser.iml" />
<module fileurl="file://$PROJECT_DIR$/python/python-psi-api/intellij.python.psi.iml" filepath="$PROJECT_DIR$/python/python-psi-api/intellij.python.psi.iml" />
<module fileurl="file://$PROJECT_DIR$/python/python-psi-impl/intellij.python.psi.impl.iml" filepath="$PROJECT_DIR$/python/python-psi-impl/intellij.python.psi.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/python/intellij.python.pydev.iml" filepath="$PROJECT_DIR$/python/intellij.python.pydev.iml" />

View File

@@ -13,6 +13,7 @@ object PythonCommunityPluginModules {
"intellij.python.community",
"intellij.python.community.plugin.impl",
"intellij.python.community.plugin.java",
"intellij.python.parser",
"intellij.python.psi",
"intellij.python.psi.impl",
"intellij.python.community.core.impl",

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,565 @@
// Generated by JFlex 1.9.1 http://jflex.de/ (tweaked for IntelliJ platform)
// source: PyType.flex
package com.jetbrains.python.psi.types;
import com.intellij.lexer.FlexLexer;
import com.jetbrains.python.psi.PyElementType;
import static com.jetbrains.python.psi.types.PyTypeTokenTypes.*;
public class _PyTypeLexer implements FlexLexer {
/** This character denotes the end of file */
public static final int YYEOF = -1;
/** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384;
/** lexical states */
public static final int YYINITIAL = 0;
/**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private static final int ZZ_LEXSTATE[] = {
0, 0
};
/**
* Top-level table for translating characters to character classes
*/
private static final int [] ZZ_CMAP_TOP = zzUnpackcmap_top();
private static final String ZZ_CMAP_TOP_PACKED_0 =
"\1\0\u10ff\u0100";
private static int [] zzUnpackcmap_top() {
int [] result = new int[4352];
int offset = 0;
offset = zzUnpackcmap_top(ZZ_CMAP_TOP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackcmap_top(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Second-level tables for translating characters to character classes
*/
private static final int [] ZZ_CMAP_BLOCKS = zzUnpackcmap_blocks();
private static final String ZZ_CMAP_BLOCKS_PACKED_0 =
"\11\0\1\1\1\2\2\0\1\2\22\0\1\1\1\3"+
"\6\0\3\4\1\0\1\4\1\5\1\6\1\0\12\7"+
"\1\10\1\0\1\11\1\12\1\13\2\0\23\14\7\15"+
"\1\4\1\0\1\4\1\0\1\16\1\17\1\20\1\16"+
"\1\21\2\16\1\22\5\16\1\23\1\24\1\16\1\25"+
"\1\26\1\16\1\27\1\30\1\31\4\16\1\32\1\16"+
"\1\33\1\4\1\34\1\3\u0181\0";
private static int [] zzUnpackcmap_blocks() {
int [] result = new int[512];
int offset = 0;
offset = zzUnpackcmap_blocks(ZZ_CMAP_BLOCKS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackcmap_blocks(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates DFA states to action switch labels.
*/
private static final int [] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 =
"\1\0\1\1\1\2\1\3\1\0\1\3\2\0\1\4"+
"\1\5\1\4\1\6\3\4\3\0\1\4\1\3\2\0"+
"\1\4\5\0\1\6";
private static int [] zzUnpackAction() {
int [] result = new int[29];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\35\0\72\0\35\0\127\0\164\0\221\0\256"+
"\0\313\0\313\0\350\0\35\0\u0105\0\u0122\0\u013f\0\u015c"+
"\0\u0179\0\u0196\0\u01b3\0\350\0\u01d0\0\u01ed\0\u020a\0\u0227"+
"\0\u0244\0\u0261\0\u027e\0\u029b\0\u02b8";
private static int [] zzUnpackRowMap() {
int [] result = new int[29];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length() - 1;
while (i < l) {
int high = packed.charAt(i++) << 16;
result[j++] = high | packed.charAt(i++);
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int [] ZZ_TRANS = zzUnpacktrans();
private static final String ZZ_TRANS_PACKED_0 =
"\1\0\1\2\1\3\1\0\1\4\1\5\1\6\1\0"+
"\1\7\1\10\2\0\1\11\1\12\1\13\1\14\2\13"+
"\1\15\2\13\1\16\3\13\1\17\1\13\1\0\1\14"+
"\37\0\1\3\45\0\1\4\27\0\1\20\47\0\1\21"+
"\4\0\1\22\20\0\1\4\31\0\1\13\4\0\3\13"+
"\1\0\13\13\1\14\10\0\1\13\4\0\3\13\1\0"+
"\13\13\11\0\1\13\4\0\3\13\1\0\7\13\1\23"+
"\3\13\11\0\1\13\4\0\3\13\1\0\2\13\1\24"+
"\4\13\1\24\3\13\11\0\1\13\4\0\3\13\1\0"+
"\5\13\1\24\5\13\10\0\1\4\51\0\1\25\43\0"+
"\1\26\11\0\1\13\4\0\3\13\1\0\5\13\1\27"+
"\5\13\22\0\1\30\24\0\1\31\33\0\1\13\4\0"+
"\3\13\1\0\4\13\1\24\6\13\32\0\1\32\25\0"+
"\1\21\43\0\1\33\14\0\1\34\43\0\1\35\20\0"+
"\1\14\31\0";
private static int [] zzUnpacktrans() {
int [] result = new int[725];
int offset = 0;
offset = zzUnpacktrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpacktrans(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
value--;
do result[j++] = value; while (--count > 0);
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
/* error messages for the codes above */
private static final String[] ZZ_ERROR_MSG = {
"Unknown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state {@code aState}
*/
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\1\0\1\11\1\1\1\11\1\0\1\1\2\0\3\1"+
"\1\11\3\1\3\0\2\1\2\0\1\1\5\0\1\1";
private static int [] zzUnpackAttribute() {
int [] result = new int[29];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/** the input device */
private java.io.Reader zzReader;
/** the current state of the DFA */
private int zzState;
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private CharSequence zzBuffer = "";
/** the textposition at the last accepting state */
private int zzMarkedPos;
/** the current text position in the buffer */
private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read
from input */
private int zzEndRead;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/** Number of newlines encountered up to the start of the matched text. */
@SuppressWarnings("unused")
private int yyline;
/** Number of characters from the last newline up to the start of the matched text. */
@SuppressWarnings("unused")
protected int yycolumn;
/** Number of characters up to the start of the matched text. */
@SuppressWarnings("unused")
private long yychar;
/** Whether the scanner is currently at the beginning of a line. */
@SuppressWarnings("unused")
private boolean zzAtBOL = true;
/** Whether the user-EOF-code has already been executed. */
@SuppressWarnings("unused")
private boolean zzEOFDone;
/**
* Creates a new scanner
*
* @param in the java.io.Reader to read input from.
*/
public _PyTypeLexer(java.io.Reader in) {
this.zzReader = in;
}
/** Returns the maximum size of the scanner buffer, which limits the size of tokens. */
private int zzMaxBufferLen() {
return Integer.MAX_VALUE;
}
/** Whether the scanner buffer can grow to accommodate a larger token. */
private boolean zzCanGrow() {
return true;
}
/**
* Translates raw input code points to DFA table row
*/
private static int zzCMap(int input) {
int offset = input & 255;
return offset == input ? ZZ_CMAP_BLOCKS[offset] : ZZ_CMAP_BLOCKS[ZZ_CMAP_TOP[input >> 8] | offset];
}
public final int getTokenStart() {
return zzStartRead;
}
public final int getTokenEnd() {
return getTokenStart() + yylength();
}
public void reset(CharSequence buffer, int start, int end, int initialState) {
zzBuffer = buffer;
zzCurrentPos = zzMarkedPos = zzStartRead = start;
zzAtEOF = false;
zzAtBOL = true;
zzEndRead = end;
yybegin(initialState);
}
/**
* Refills the input buffer.
*
* @return {@code false}, iff there was new input.
*
* @exception java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
return true;
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final CharSequence yytext() {
return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
}
/**
* Returns the character at position {@code pos} from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBuffer.charAt(zzStartRead+pos);
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occurred while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
public void yypushback(int number) {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
public PyElementType advance() throws java.io.IOException
{
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer;
int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP;
int [] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = ZZ_LEXSTATE[zzLexicalState];
// set up zzAction for empty match case:
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
}
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL) {
zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL);
zzCurrentPosL += Character.charCount(zzInput);
}
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL);
zzCurrentPosL += Character.charCount(zzInput);
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
return null;
}
else {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
{ return SPACE;
}
// fall through
case 7: break;
case 2:
{ return NL;
}
// fall through
case 8: break;
case 3:
{ return OP;
}
// fall through
case 9: break;
case 4:
{ return IDENTIFIER;
}
// fall through
case 10: break;
case 5:
{ return PARAMETER;
}
// fall through
case 11: break;
case 6:
{ return MARKUP;
}
// fall through
case 12: break;
default:
zzScanError(ZZ_NO_MATCH);
}
}
}
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-stdlib" level="project" />
<orderEntry type="module" module-name="intellij.platform.core" />
<orderEntry type="module" module-name="intellij.platform.util" />
<orderEntry type="library" name="fastutil-min" level="project" />
</component>
</module>

View File

@@ -0,0 +1,11 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<fileType name="Python"
language="Python"
extensions="py;pyw"
hashBangs="python"
implementationClass="com.jetbrains.python.PythonFileType"
fieldName="INSTANCE"/>
<iconMapper mappingFile="PythonPsiApiIconMappings.json"/>
</extensions>
</idea-plugin>

View File

@@ -0,0 +1,76 @@
# Message we display for inspection if user uses custom class type members that do not exist
custom.type.mimic.name=Dynamic class based on {0}
### parsing
PARSE.expected.expression=Expression expected
PARSE.expected.rbracket=']' expected
PARSE.expected.expr.or.comma.or.bracket=Expected expression, ',' or ']'
PARSE.expected.in='in' expected
PARSE.expected.for.or.bracket=']' or 'for' expected
PARSE.expected.comma=',' expected
PARSE.expected.colon=':' expected
PARSE.expected.rpar=')' expected
PARSE.expected.lpar='(' expected
PARSE.expected.rbrace='}' expected
PARSE.expected.tick='`' (backtick) expected
PARSE.expected.name=Name expected
PARSE.expected.colon.or.rbracket=':' or ']' expected
PARSE.expected.comma.or.rpar=',' or ')' expected
PARSE.expected.else='else' expected
PARSE.expected.identifier=Identifier expected
PARSE.expected.comma.lpar.rpar=',' or '(' or ')' expected
PARSE.expected.statement.break=Statement break expected
PARSE.expected.@.or.def='@' or 'def' expected
PARSE.expected.formal.param.name=Formal parameter name expected
PARSE.0.expected=''{0}'' expected
PARSE.expected.ellipsis='...' expected
PARSE.string.literal.expected=string literal expected
PARSE.expected.symbols=''{0}'' or ''{1}'' expected
PARSE.expected.symbols.first.quotation=''{0}'' or {1} expected
PARSE.expected.symbols.second.quotation={0} or ''{1}'' expected
PARSE.declarator.should.be.empty=declarator should be empty
PARSE.string.literal=string literal
PARSE.newline.expected=newline expected
PARSE.eq.expected='=' expected
PARSE.from.expected='from' expected
PARSE.gt.expected='>' expected
PARSE.expected.fstring.quote={0} expected
PARSE.expected.fstring.rbrace='}' expected
PARSE.expected.fstring.colon.or.rbrace=: or '}' expected
PARSE.expected.fstring.type.conversion.or.colon.or.rbrace=Type conversion, ':' or '}' expected
PARSE.single.star.parameter.not.supported.py2=Single star parameter is not supported in Python 2
PARSE.async.keyword.not.expected.here='async' keyword is not expected here
PARSE.keyword.cannot.be.used.as.identifier.py2=''{0}'' keyword can''t be used as an identifier in Python 2
PARSE.expected.number=Number expected
PARSE.expected.case.clause=Case clause expected
PARSE.expected.pattern=Pattern expected
PARSE.expected.name.or.wildcard=Name or '_' expected
PARSE.expected.type.parameter=Type parameter expected
statement.expected.found.0=Statement expected, found {0}
unexpected.indent=Unexpected indent
unindent.does.not.match.any.outer.indent=Unindent does not match any outer indentation level
except.or.finally.expected='except' or 'finally' expected
expected.statement=Statement expected
indent.expected=Indent expected
cannot.assign.to.yield.expression=Cannot assign to 'yield' expression
end.of.statement.expected=End of statement expected
import.expected='import' expected
def.or.with.or.for.expected='def' or 'with' or 'for' expected
rbracket.or.comma.expected=']' or ',' expected
unexpected.expression.syntax=Unexpected expression syntax
tuple.expression.expected=Tuple expression expected
value.expression.expected=Value expression expected
unexpected.expression.part=Unexpected expression part
unexpected.f.string.token=Unexpected f-string token
can.t.assign.to.await.expression=Cannot assign to await expression
for.expected='for' expected
rarrow.expected='->' expected
unexpected.tokens=Unexpected tokens
PARSE.function.type.annotations.py2=Type annotations are unsupported in Python 2
PARSE.function.return.type.annotations.py2=Return type annotations are unsupported in Python 2
PARSE.console.multiline.magic.warn=Multiline magic cannot be used as an expression
PARSE.console.help.request.warn=IPython introspection syntax error

View File

@@ -0,0 +1,153 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.tree.TokenSet;
import com.jetbrains.python.psi.*;
import static com.jetbrains.python.PyElementTypesFacade.Companion;
public interface PyElementTypes {
IStubElementType FUNCTION_DECLARATION = Companion.getINSTANCE().getFunctionDeclaration();
IStubElementType CLASS_DECLARATION = Companion.getINSTANCE().getClassDeclaration();
IStubElementType PARAMETER_LIST = Companion.getINSTANCE().getParameterList();
IStubElementType DECORATOR_LIST = Companion.getINSTANCE().getDecoratorList();
IStubElementType NAMED_PARAMETER = Companion.getINSTANCE().getNamedParameter();
IStubElementType TUPLE_PARAMETER = Companion.getINSTANCE().getTupleParameter();
IStubElementType SLASH_PARAMETER = Companion.getINSTANCE().getSlashParameter();
IStubElementType SINGLE_STAR_PARAMETER = Companion.getINSTANCE().getSingleStarParameter();
IStubElementType DECORATOR_CALL = Companion.getINSTANCE().getDecoratorCall();
IStubElementType IMPORT_ELEMENT = Companion.getINSTANCE().getImportElement();
IStubElementType ANNOTATION = Companion.getINSTANCE().getAnnotation();
IStubElementType STAR_IMPORT_ELEMENT = Companion.getINSTANCE().getStarImportElement();
IStubElementType EXCEPT_PART = Companion.getINSTANCE().getExceptPart();
IStubElementType FROM_IMPORT_STATEMENT = Companion.getINSTANCE().getFromImportStatement();
IStubElementType IMPORT_STATEMENT = Companion.getINSTANCE().getImportStatement();
IStubElementType TARGET_EXPRESSION = Companion.getINSTANCE().getTargetExpression();
IStubElementType TYPE_PARAMETER = Companion.getINSTANCE().getTypeParameter();
IStubElementType TYPE_PARAMETER_LIST = Companion.getINSTANCE().getTypeParameterList();
IStubElementType TYPE_ALIAS_STATEMENT = Companion.getINSTANCE().getTypeAliasStatement();
TokenSet PARAMETER_LIST_SET = TokenSet.create(PARAMETER_LIST);
TokenSet FORMAL_PARAMETER_SET = TokenSet.create(NAMED_PARAMETER);
PyElementType ARGUMENT_LIST = new PyElementType("ARGUMENT_LIST", Companion.getINSTANCE().getArgumentListConstructor());
PyElementType PRINT_TARGET = new PyElementType("PRINT_TARGET", Companion.getINSTANCE().getPrintTargetConstructor());
PyElementType DECORATOR = new PyElementType("DECORATOR", Companion.getINSTANCE().getDecoratorConstructor());
// Statements
PyElementType EXPRESSION_STATEMENT = new PyElementType("EXPRESSION_STATEMENT", Companion.getINSTANCE().getExpressionStatementConstructor());
PyElementType ASSIGNMENT_STATEMENT = new PyElementType("ASSIGNMENT_STATEMENT", Companion.getINSTANCE().getAssignmentStatementConstructor());
PyElementType AUG_ASSIGNMENT_STATEMENT = new PyElementType("AUG_ASSIGNMENT_STATEMENT", Companion.getINSTANCE().getAugAssignmentStatementConstructor());
PyElementType ASSERT_STATEMENT = new PyElementType("ASSERT_STATEMENT", Companion.getINSTANCE().getAssertStatementConstructor());
PyElementType BREAK_STATEMENT = new PyElementType("BREAK_STATEMENT", Companion.getINSTANCE().getBreakStatementConstructor());
PyElementType CONTINUE_STATEMENT = new PyElementType("CONTINUE_STATEMENT", Companion.getINSTANCE().getContinueStatementConstructor());
PyElementType DEL_STATEMENT = new PyElementType("DEL_STATEMENT", Companion.getINSTANCE().getDelStatementConstructor());
PyElementType EXEC_STATEMENT = new PyElementType("EXEC_STATEMENT", Companion.getINSTANCE().getExecStatementConstructor());
PyElementType FOR_STATEMENT = new PyElementType("FOR_STATEMENT", Companion.getINSTANCE().getForStatementConstructor());
PyElementType TYPE_DECLARATION_STATEMENT = new PyElementType("TYPE_DECLARATION_STATEMENT", Companion.getINSTANCE().getTypeDeclarationStatementConstructor());
PyElementType GLOBAL_STATEMENT = new PyElementType("GLOBAL_STATEMENT", Companion.getINSTANCE().getGlobalStatementConstructor());
PyElementType IF_STATEMENT = new PyElementType("IF_STATEMENT", Companion.getINSTANCE().getIfStatementConstructor());
PyElementType PASS_STATEMENT = new PyElementType("PASS_STATEMENT", Companion.getINSTANCE().getPassStatementConstructor());
PyElementType PRINT_STATEMENT = new PyElementType("PRINT_STATEMENT", Companion.getINSTANCE().getPrintStatementConstructor());
PyElementType RAISE_STATEMENT = new PyElementType("RAISE_STATEMENT", Companion.getINSTANCE().getRaiseStatementConstructor());
PyElementType RETURN_STATEMENT = new PyElementType("RETURN_STATEMENT", Companion.getINSTANCE().getReturnStatementConstructor());
PyElementType TRY_EXCEPT_STATEMENT = new PyElementType("TRY_EXCEPT_STATEMENT", Companion.getINSTANCE().getTryExceptStatementConstructor());
PyElementType WITH_STATEMENT = new PyElementType("WITH_STATEMENT", Companion.getINSTANCE().getWithStatementConstructor());
PyElementType WHILE_STATEMENT = new PyElementType("WHILE_STATEMENT", Companion.getINSTANCE().getWhileStatementConstructor());
PyElementType STATEMENT_LIST = new PyElementType("STATEMENT_LIST", Companion.getINSTANCE().getStatementListConstructor());
PyElementType NONLOCAL_STATEMENT = new PyElementType("NONLOCAL_STATEMENT", Companion.getINSTANCE().getNonlocalStatementConstructor());
PyElementType WITH_ITEM = new PyElementType("WITH_ITEM", Companion.getINSTANCE().getWithItemConstructor());
// Expressions
PyElementType EMPTY_EXPRESSION = new PyElementType("EMPTY_EXPRESSION", Companion.getINSTANCE().getEmptyExpressionConstructor());
PyElementType REFERENCE_EXPRESSION = new PyElementType("REFERENCE_EXPRESSION", Companion.getINSTANCE().getReferenceExpressionConstructor());
PyElementType INTEGER_LITERAL_EXPRESSION = new PyElementType("INTEGER_LITERAL_EXPRESSION", Companion.getINSTANCE().getIntegerLiteralExpressionConstructor());
PyElementType FLOAT_LITERAL_EXPRESSION = new PyElementType("FLOAT_LITERAL_EXPRESSION", Companion.getINSTANCE().getFloatLiteralExpressionConstructor());
PyElementType IMAGINARY_LITERAL_EXPRESSION = new PyElementType("IMAGINARY_LITERAL_EXPRESSION", Companion.getINSTANCE().getImaginaryLiteralExpressionConstructor());
PyElementType STRING_LITERAL_EXPRESSION = new PyElementType("STRING_LITERAL_EXPRESSION", Companion.getINSTANCE().getStringLiteralExpressionConstructor());
PyElementType NONE_LITERAL_EXPRESSION = new PyElementType("NONE_LITERAL_EXPRESSION", Companion.getINSTANCE().getNoneLiteralExpressionConstructor());
PyElementType BOOL_LITERAL_EXPRESSION = new PyElementType("BOOL_LITERAL_EXPRESSION", Companion.getINSTANCE().getBoolLiteralExpressionConstructor());
PyElementType PARENTHESIZED_EXPRESSION = new PyElementType("PARENTHESIZED_EXPRESSION", Companion.getINSTANCE().getParenthesizedExpressionConstructor());
PyElementType SUBSCRIPTION_EXPRESSION = new PyElementType("SUBSCRIPTION_EXPRESSION", Companion.getINSTANCE().getSubscriptionExpressionConstructor());
PyElementType SLICE_EXPRESSION = new PyElementType("SLICE_EXPRESSION", Companion.getINSTANCE().getSliceExpressionConstructor());
PyElementType SLICE_ITEM = new PyElementType("SLICE_ITEM", Companion.getINSTANCE().getSliceItemConstructor());
PyElementType BINARY_EXPRESSION = new PyElementType("BINARY_EXPRESSION", Companion.getINSTANCE().getBinaryExpressionConstructor());
PyElementType PREFIX_EXPRESSION = new PyElementType("PREFIX_EXPRESSION", Companion.getINSTANCE().getPrefixExpressionConstructor());
PyElementType CALL_EXPRESSION = new PyElementType("CALL_EXPRESSION", Companion.getINSTANCE().getCallExpressionConstructor());
PyElementType LIST_LITERAL_EXPRESSION = new PyElementType("LIST_LITERAL_EXPRESSION", Companion.getINSTANCE().getListLiteralExpressionConstructor());
PyElementType TUPLE_EXPRESSION = new PyElementType("TUPLE_EXPRESSION", Companion.getINSTANCE().getTupleExpressionConstructor());
PyElementType KEYWORD_ARGUMENT_EXPRESSION = new PyElementType("KEYWORD_ARGUMENT_EXPRESSION", Companion.getINSTANCE().getKeywordArgumentExpressionConstructor());
PyElementType STAR_ARGUMENT_EXPRESSION = new PyElementType("STAR_ARGUMENT_EXPRESSION", Companion.getINSTANCE().getStarArgumentExpressionConstructor());
PyElementType LAMBDA_EXPRESSION = new PyElementType("LAMBDA_EXPRESSION", Companion.getINSTANCE().getLambdaExpressionConstructor());
PyElementType LIST_COMP_EXPRESSION = new PyElementType("LIST_COMP_EXPRESSION", Companion.getINSTANCE().getListCompExpressionConstructor());
PyElementType DICT_LITERAL_EXPRESSION = new PyElementType("DICT_LITERAL_EXPRESSION", Companion.getINSTANCE().getDictLiteralExpressionConstructor());
PyElementType KEY_VALUE_EXPRESSION = new PyElementType("KEY_VALUE_EXPRESSION", Companion.getINSTANCE().getKeyValueExpressionConstructor());
PyElementType REPR_EXPRESSION = new PyElementType("REPR_EXPRESSION", Companion.getINSTANCE().getReprExpressionConstructor());
PyElementType GENERATOR_EXPRESSION = new PyElementType("GENERATOR_EXPRESSION", Companion.getINSTANCE().getGeneratorExpressionConstructor());
PyElementType CONDITIONAL_EXPRESSION = new PyElementType("CONDITIONAL_EXPRESSION", Companion.getINSTANCE().getConditionalExpressionConstructor());
PyElementType YIELD_EXPRESSION = new PyElementType("YIELD_EXPRESSION", Companion.getINSTANCE().getYieldExpressionConstructor());
PyElementType STAR_EXPRESSION = new PyElementType("STAR_EXPRESSION", Companion.getINSTANCE().getStarExpressionConstructor());
PyElementType DOUBLE_STAR_EXPRESSION = new PyElementType("DOUBLE_STAR_EXPRESSION", Companion.getINSTANCE().getDoubleStarExpressionConstructor());
PyElementType ASSIGNMENT_EXPRESSION = new PyElementType("ASSIGNMENT_EXPRESSION", Companion.getINSTANCE().getAssignmentExpressionConstructor());
PyElementType SET_LITERAL_EXPRESSION = new PyElementType("SET_LITERAL_EXPRESSION", Companion.getINSTANCE().getSetLiteralExpressionConstructor());
PyElementType SET_COMP_EXPRESSION = new PyElementType("SET_COMP_EXPRESSION", Companion.getINSTANCE().getSetCompExpressionConstructor());
PyElementType DICT_COMP_EXPRESSION = new PyElementType("DICT_COMP_EXPRESSION", Companion.getINSTANCE().getDictCompExpressionConstructor());
TokenSet STATEMENT_LISTS = TokenSet.create(STATEMENT_LIST);
TokenSet BINARY_OPS = TokenSet.create(PyTokenTypes.OR_KEYWORD, PyTokenTypes.AND_KEYWORD, PyTokenTypes.LT, PyTokenTypes.GT,
PyTokenTypes.OR, PyTokenTypes.XOR, PyTokenTypes.AND, PyTokenTypes.LTLT, PyTokenTypes.GTGT,
PyTokenTypes.EQEQ, PyTokenTypes.GE, PyTokenTypes.LE, PyTokenTypes.NE, PyTokenTypes.NE_OLD,
PyTokenTypes.IN_KEYWORD, PyTokenTypes.IS_KEYWORD, PyTokenTypes.NOT_KEYWORD, PyTokenTypes.PLUS,
PyTokenTypes.MINUS, PyTokenTypes.MULT, PyTokenTypes.AT, PyTokenTypes.FLOORDIV, PyTokenTypes.DIV,
PyTokenTypes.PERC, PyTokenTypes.EXP);
TokenSet UNARY_OPS = TokenSet.create(PyTokenTypes.NOT_KEYWORD, PyTokenTypes.PLUS, PyTokenTypes.MINUS, PyTokenTypes.TILDE,
PyTokenTypes.AWAIT_KEYWORD);
// Parts
PyElementType IF_PART_IF = new PyElementType("IF_IF", Companion.getINSTANCE().getIfPartIfConstructor());
PyElementType IF_PART_ELIF = new PyElementType("IF_ELIF", Companion.getINSTANCE().getIfPartElifConstructor());
PyElementType FOR_PART = new PyElementType("FOR_PART", Companion.getINSTANCE().getForPartConstructor());
PyElementType WHILE_PART = new PyElementType("WHILE_PART", Companion.getINSTANCE().getWhilePartConstructor());
PyElementType TRY_PART = new PyElementType("TRY_PART", Companion.getINSTANCE().getTryPartConstructor());
PyElementType FINALLY_PART = new PyElementType("FINALLY_PART", Companion.getINSTANCE().getFinallyPartConstructor());
PyElementType ELSE_PART = new PyElementType("ELSE_PART", Companion.getINSTANCE().getElsePartConstructor());
TokenSet PARTS = TokenSet.create(IF_PART_IF, IF_PART_ELIF, FOR_PART, WHILE_PART, TRY_PART, FINALLY_PART, ELSE_PART, EXCEPT_PART);
TokenSet ELIFS = TokenSet.create(IF_PART_ELIF);
TokenSet STAR_PARAMETERS = TokenSet.create(NAMED_PARAMETER, STAR_ARGUMENT_EXPRESSION, STAR_EXPRESSION, DOUBLE_STAR_EXPRESSION);
TokenSet CLASS_OR_FUNCTION = TokenSet.create(CLASS_DECLARATION, FUNCTION_DECLARATION);
TokenSet IMPORT_STATEMENTS = TokenSet.create(IMPORT_STATEMENT, FROM_IMPORT_STATEMENT);
PyElementType FSTRING_NODE = new PyElementType("FSTRING_NODE", Companion.getINSTANCE().getFStringNodeConstructor());
PyElementType FSTRING_FRAGMENT = new PyElementType("FSTRING_FRAGMENT", Companion.getINSTANCE().getFStringFragmentConstructor());
PyElementType FSTRING_FRAGMENT_FORMAT_PART = new PyElementType("FSTRING_FRAGMENT_FORMAT_PART", Companion.getINSTANCE().getFStringFragmentFormatPartConstructor());
PyElementType MATCH_STATEMENT = new PyElementType("MATCH_STATEMENT", Companion.getINSTANCE().getMatchStatementConstructor());
PyElementType CASE_CLAUSE = new PyElementType("CASE_CLAUSE", Companion.getINSTANCE().getCaseClauseConstructor());
PyElementType LITERAL_PATTERN = new PyElementType("LITERAL_PATTERN", Companion.getINSTANCE().getLiteralPatternConstructor());
PyElementType VALUE_PATTERN = new PyElementType("VALUE_PATTERN", Companion.getINSTANCE().getValuePatternConstructor());
PyElementType CAPTURE_PATTERN = new PyElementType("CAPTURE_PATTERN", Companion.getINSTANCE().getCapturePatternConstructor());
PyElementType WILDCARD_PATTERN = new PyElementType("WILDCARD_PATTERN", Companion.getINSTANCE().getWildcardPatternConstructor());
PyElementType GROUP_PATTERN = new PyElementType("GROUP_PATTERN", Companion.getINSTANCE().getGroupPatternConstructor());
PyElementType SEQUENCE_PATTERN = new PyElementType("SEQUENCE_PATTERN", Companion.getINSTANCE().getSequencePatternConstructor());
PyElementType SINGLE_STAR_PATTERN = new PyElementType("SINGLE_STAR_PATTERN", Companion.getINSTANCE().getSingleStarPatternConstructor());
PyElementType DOUBLE_STAR_PATTERN = new PyElementType("DOUBLE_STAR_PATTERN", Companion.getINSTANCE().getDoubleStarPatternConstructor());
PyElementType MAPPING_PATTERN = new PyElementType("KEY_VALUE_PATTERN", Companion.getINSTANCE().getMappingPatternConstructor());
PyElementType KEY_VALUE_PATTERN = new PyElementType("KEY_VALUE_PATTERN", Companion.getINSTANCE().getKeyValuePatternConstructor());
PyElementType CLASS_PATTERN = new PyElementType("CLASS_PATTERN", Companion.getINSTANCE().getClassPatternConstructor());
PyElementType PATTERN_ARGUMENT_LIST = new PyElementType("PATTERN_ARGUMENT_LIST", Companion.getINSTANCE().getPatternArgumentListConstructor());
PyElementType KEYWORD_PATTERN = new PyElementType("KEYWORD_PATTERN", Companion.getINSTANCE().getKeywordPatternConstructor());
PyElementType OR_PATTERN = new PyElementType("OR_PATTERN", Companion.getINSTANCE().getOrPatternConstructor());
PyElementType AS_PATTERN = new PyElementType("AS_PATTERN", Companion.getINSTANCE().getAsPatternConstructor());
}

View File

@@ -0,0 +1,124 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python
import com.intellij.lang.ASTNode
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.IStubElementType
import java.util.function.Function
public abstract class PyElementTypesFacade {
abstract val functionDeclaration: IStubElementType<*, *>
abstract val classDeclaration: IStubElementType<*, *>
abstract val parameterList: IStubElementType<*, *>
abstract val decoratorList: IStubElementType<*, *>
abstract val namedParameter: IStubElementType<*, *>
abstract val tupleParameter: IStubElementType<*, *>
abstract val slashParameter: IStubElementType<*, *>
abstract val singleStarParameter: IStubElementType<*, *>
abstract val decoratorCall: IStubElementType<*, *>
abstract val importElement: IStubElementType<*, *>
abstract val annotation: IStubElementType<*, *>
abstract val starImportElement: IStubElementType<*, *>
abstract val exceptPart: IStubElementType<*, *>
abstract val fromImportStatement: IStubElementType<*, *>
abstract val importStatement: IStubElementType<*, *>
abstract val targetExpression: IStubElementType<*, *>
abstract val typeParameter: IStubElementType<*, *>
abstract val typeParameterList: IStubElementType<*, *>
abstract val typeAliasStatement: IStubElementType<*, *>
abstract val argumentListConstructor: Function<in ASTNode, out PsiElement>
abstract val printTargetConstructor: Function<in ASTNode, out PsiElement>
abstract val decoratorConstructor: Function<in ASTNode, out PsiElement>
abstract val expressionStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val assignmentStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val augAssignmentStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val assertStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val breakStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val continueStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val delStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val execStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val forStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val typeDeclarationStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val globalStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val ifStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val passStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val printStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val raiseStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val returnStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val tryExceptStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val withStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val whileStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val statementListConstructor: Function<in ASTNode, out PsiElement>
abstract val nonlocalStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val withItemConstructor: Function<in ASTNode, out PsiElement>
abstract val emptyExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val referenceExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val integerLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val floatLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val imaginaryLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val stringLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val noneLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val boolLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val parenthesizedExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val subscriptionExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val sliceExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val sliceItemConstructor: Function<in ASTNode, out PsiElement>
abstract val binaryExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val prefixExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val callExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val listLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val tupleExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val keywordArgumentExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val starArgumentExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val lambdaExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val listCompExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val dictLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val keyValueExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val reprExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val generatorExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val conditionalExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val yieldExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val starExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val doubleStarExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val assignmentExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val setLiteralExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val setCompExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val dictCompExpressionConstructor: Function<in ASTNode, out PsiElement>
abstract val ifPartIfConstructor: Function<in ASTNode, out PsiElement>
abstract val ifPartElifConstructor: Function<in ASTNode, out PsiElement>
abstract val forPartConstructor: Function<in ASTNode, out PsiElement>
abstract val whilePartConstructor: Function<in ASTNode, out PsiElement>
abstract val tryPartConstructor: Function<in ASTNode, out PsiElement>
abstract val finallyPartConstructor: Function<in ASTNode, out PsiElement>
abstract val elsePartConstructor: Function<in ASTNode, out PsiElement>
abstract val fStringNodeConstructor: Function<in ASTNode, out PsiElement>
abstract val fStringFragmentConstructor: Function<in ASTNode, out PsiElement>
abstract val fStringFragmentFormatPartConstructor: Function<in ASTNode, out PsiElement>
abstract val matchStatementConstructor: Function<in ASTNode, out PsiElement>
abstract val caseClauseConstructor: Function<in ASTNode, out PsiElement>
abstract val literalPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val valuePatternConstructor: Function<in ASTNode, out PsiElement>
abstract val capturePatternConstructor: Function<in ASTNode, out PsiElement>
abstract val wildcardPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val groupPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val sequencePatternConstructor: Function<in ASTNode, out PsiElement>
abstract val singleStarPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val doubleStarPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val mappingPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val keyValuePatternConstructor: Function<in ASTNode, out PsiElement>
abstract val classPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val patternArgumentListConstructor: Function<in ASTNode, out PsiElement>
abstract val keywordPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val orPatternConstructor: Function<in ASTNode, out PsiElement>
abstract val asPatternConstructor: Function<in ASTNode, out PsiElement>
companion object {
val INSTANCE: PyElementTypesFacade = ApplicationManager.getApplication().service<PyElementTypesFacade>()
}
}

View File

@@ -0,0 +1,15 @@
package com.jetbrains.python
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.psi.PsiElement
import com.jetbrains.python.psi.LanguageLevel
abstract class PyLanguageFacade {
abstract fun forLanguage(psiElement: PsiElement): LanguageLevel
companion object {
val INSTANCE: PyLanguageFacade
get() = ApplicationManager.getApplication().service<PyLanguageFacade>()
}
}

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.google.common.collect.ImmutableMap;
import com.intellij.openapi.util.NlsSafe;
import com.jetbrains.python.psi.LanguageLevel;
import org.jetbrains.annotations.NonNls;
@@ -448,11 +447,11 @@ public final class PyNames {
* @deprecated use {@link #getBuiltinMethods(LanguageLevel)} instead
*/
@Deprecated
public static final ImmutableMap<String, BuiltinDescription> PY36_BUILTIN_METHODS = ImmutableMap.<String, BuiltinDescription>builder().putAll(concat(
public static final Map<String, BuiltinDescription> PY36_BUILTIN_METHODS = concat(
PY35_BUILTIN_METHODS,
Map.entry(INIT_SUBCLASS, new BuiltinDescription("(cls, **kwargs)")),
Map.entry("__set_name__", new BuiltinDescription("(self, owner, name)")),
Map.entry("__fspath__", _only_self_descr))).build();
Map.entry("__fspath__", _only_self_descr));
private static final Map<String, BuiltinDescription> PY37_BUILTIN_METHODS = concat(
PY36_BUILTIN_METHODS,

View File

@@ -0,0 +1,27 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.intellij.DynamicBundle;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.PropertyKey;
import java.util.function.Supplier;
public final class PyParsingBundle extends DynamicBundle {
@NonNls public static final String BUNDLE = "messages.PyParserBundle";
public static final PyParsingBundle INSTANCE = new PyParsingBundle();
private PyParsingBundle() { super(BUNDLE); }
@NotNull
public static @Nls String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) {
return INSTANCE.getMessage(key, params);
}
@NotNull
public static Supplier<@Nls String> messagePointer(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, Object @NotNull ... params) {
return INSTANCE.getLazyMessage(key, params);
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.intellij.psi.TokenType;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python;
import com.intellij.lang.Language;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.lexer;
import com.intellij.psi.tree.IElementType;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.lexer;
import com.intellij.psi.tree.IElementType;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.lexer;
import com.intellij.psi.tree.TokenSet;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.lexer;
import com.intellij.lexer.FlexAdapter;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.SyntaxTreeBuilder;
@@ -26,7 +12,7 @@ import com.jetbrains.python.PyTokenTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.jetbrains.python.PyPsiBundle.message;
import static com.jetbrains.python.PyParsingBundle.message;
public class ExpressionParsing extends Parsing {

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.WhitespacesAndCommentsBinder;
@@ -31,7 +17,7 @@ class FollowingCommentBinder implements WhitespacesAndCommentsBinder {
// TODO[yole] handle more cases?
while (pos < tokens.size() && tokens.get(pos) == PyTokenTypes.LINE_BREAK) {
final CharSequence charSequence = getter.get(pos);
if (charSequence.length() == 0 || charSequence.charAt(charSequence.length()-1) != ' ') {
if (charSequence.isEmpty() || charSequence.charAt(charSequence.length() - 1) != ' ') {
break;
}
pos++;

View File

@@ -1,28 +1,14 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.SyntaxTreeBuilder;
import com.intellij.psi.tree.IElementType;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.PyTokenTypes;
import org.jetbrains.annotations.NotNull;
import static com.jetbrains.python.PyPsiBundle.message;
import static com.jetbrains.python.PyParsingBundle.message;
import static com.jetbrains.python.parsing.StatementParsing.TOK_ASYNC;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.WhitespacesAndCommentsBinder;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.SyntaxTreeBuilder;
@@ -21,9 +7,9 @@ import com.intellij.openapi.util.NlsContexts.ParsingError;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.psi.PyElementType;
import com.jetbrains.python.PyTokenTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -77,7 +63,7 @@ public class Parsing {
if (myBuilder.getTokenType() != PyTokenTypes.STATEMENT_BREAK && !atAnyOfTokens(validSuccessiveTokens)) {
myBuilder.advanceLexer();
}
nameExpected.error(PyPsiBundle.message("PARSE.expected.identifier"));
nameExpected.error(PyParsingBundle.message("PARSE.expected.identifier"));
return false;
}
}
@@ -120,7 +106,7 @@ public class Parsing {
protected void advanceAsync(boolean falseAsync) {
if (falseAsync) {
advanceError(myBuilder, PyPsiBundle.message("PARSE.async.keyword.not.expected.here"));
advanceError(myBuilder, PyParsingBundle.message("PARSE.async.keyword.not.expected.here"));
}
else {
myBuilder.advanceLexer();
@@ -130,7 +116,7 @@ public class Parsing {
protected static void advanceIdentifierLike(@NotNull SyntaxTreeBuilder builder) {
if (isFalseIdentifier(builder)) {
String tokenText = builder.getTokenText();
advanceError(builder, PyPsiBundle.message("PARSE.keyword.cannot.be.used.as.identifier.py2", tokenText));
advanceError(builder, PyParsingBundle.message("PARSE.keyword.cannot.be.used.as.identifier.py2", tokenText));
}
else {
builder.advanceLexer();

View File

@@ -1,10 +1,11 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.SyntaxTreeBuilder;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.containers.Stack;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.PyTokenTypes;
import org.jetbrains.annotations.NotNull;
@@ -55,7 +56,7 @@ public class PatternParsing extends Parsing {
buildTokenElement(PyElementTypes.TARGET_EXPRESSION, myBuilder);
}
else {
myBuilder.error(PyPsiBundle.message("PARSE.expected.name"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.name"));
}
mark.done(PyElementTypes.AS_PATTERN);
consumeIllegalLeftoverExpressionTokens();
@@ -76,7 +77,7 @@ public class PatternParsing extends Parsing {
while (atToken(PyTokenTypes.OR)) {
nextToken();
if (!parseClosedPattern()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.pattern"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.pattern"));
break;
}
}
@@ -132,7 +133,7 @@ public class PatternParsing extends Parsing {
nextToken();
registerConsumedBracket(PyTokenTypes.LPAR);
parseCommaSeparatedPatterns(this::parseClassPatternArgument);
if (checkMatches(PyTokenTypes.RPAR, PyPsiBundle.message("PARSE.expected.rpar"))) {
if (checkMatches(PyTokenTypes.RPAR, PyParsingBundle.message("PARSE.expected.rpar"))) {
registerConsumedBracket(PyTokenTypes.RPAR);
}
mark.done(PyElementTypes.PATTERN_ARGUMENT_LIST);
@@ -144,7 +145,7 @@ public class PatternParsing extends Parsing {
nextToken();
nextToken();
if (!parsePattern()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.pattern"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.pattern"));
}
mark.done(PyElementTypes.KEYWORD_PATTERN);
return true;
@@ -158,7 +159,7 @@ public class PatternParsing extends Parsing {
nextToken();
registerConsumedBracket(PyTokenTypes.LBRACE);
parseCommaSeparatedPatterns(this::parseKeyValuePatternOrDoubleStarPattern);
if (checkMatches(PyTokenTypes.RBRACE, PyPsiBundle.message("PARSE.expected.rbrace"))) {
if (checkMatches(PyTokenTypes.RBRACE, PyParsingBundle.message("PARSE.expected.rbrace"))) {
registerConsumedBracket(PyTokenTypes.RBRACE);
}
mark.done(PyElementTypes.MAPPING_PATTERN);
@@ -177,12 +178,12 @@ public class PatternParsing extends Parsing {
// in an annotator.
SyntaxTreeBuilder.Marker mark = myBuilder.mark();
if (parsePattern()) {
if (!checkMatches(PyTokenTypes.COLON, PyPsiBundle.message("PARSE.expected.colon"))) {
if (!checkMatches(PyTokenTypes.COLON, PyParsingBundle.message("PARSE.expected.colon"))) {
mark.drop();
return true;
}
if (!parsePattern()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.pattern"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.pattern"));
}
mark.done(PyElementTypes.KEY_VALUE_PATTERN);
return true;
@@ -196,7 +197,7 @@ public class PatternParsing extends Parsing {
SyntaxTreeBuilder.Marker mark = myBuilder.mark();
nextToken();
if (!parseCapturePattern()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.name"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.name"));
}
mark.done(PyElementTypes.DOUBLE_STAR_PATTERN);
return true;
@@ -209,7 +210,7 @@ public class PatternParsing extends Parsing {
SyntaxTreeBuilder.Marker mark = myBuilder.mark();
nextToken();
if (!parseWildcardPattern() && !parseCapturePattern()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.name.or.wildcard"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.name.or.wildcard"));
}
mark.done(PyElementTypes.SINGLE_STAR_PATTERN);
return true;
@@ -223,7 +224,7 @@ public class PatternParsing extends Parsing {
nextToken();
registerConsumedBracket(PyTokenTypes.LPAR);
CommaSeparation result = parseCommaSeparatedPatterns(this::parsePattern);
if (checkMatches(PyTokenTypes.RPAR, PyPsiBundle.message("PARSE.expected.rpar"))) {
if (checkMatches(PyTokenTypes.RPAR, PyParsingBundle.message("PARSE.expected.rpar"))) {
registerConsumedBracket(PyTokenTypes.RPAR);
}
mark.done(result == CommaSeparation.SINGLE_NO_COMMA ? PyElementTypes.GROUP_PATTERN : PyElementTypes.SEQUENCE_PATTERN);
@@ -238,7 +239,7 @@ public class PatternParsing extends Parsing {
nextToken();
registerConsumedBracket(PyTokenTypes.LBRACKET);
parseCommaSeparatedPatterns(this::parsePattern);
if (checkMatches(PyTokenTypes.RBRACKET, PyPsiBundle.message("PARSE.expected.rbracket"))) {
if (checkMatches(PyTokenTypes.RBRACKET, PyParsingBundle.message("PARSE.expected.rbracket"))) {
registerConsumedBracket(PyTokenTypes.RBRACKET);
}
mark.done(PyElementTypes.SEQUENCE_PATTERN);
@@ -261,7 +262,7 @@ public class PatternParsing extends Parsing {
while (atToken(PyTokenTypes.COMMA)) {
result = CommaSeparation.EXISTS;
if (!afterPattern) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.pattern"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.pattern"));
}
nextToken();
afterPattern = patternParser.getAsBoolean();
@@ -321,7 +322,7 @@ public class PatternParsing extends Parsing {
refExpr.done(PyElementTypes.REFERENCE_EXPRESSION);
while (matchToken(PyTokenTypes.DOT)) {
refExpr = refExpr.precede();
checkMatches(PyTokenTypes.IDENTIFIER, PyPsiBundle.message("PARSE.expected.name"));
checkMatches(PyTokenTypes.IDENTIFIER, PyParsingBundle.message("PARSE.expected.name"));
refExpr.done(PyElementTypes.REFERENCE_EXPRESSION);
}
return true;
@@ -369,7 +370,7 @@ public class PatternParsing extends Parsing {
SyntaxTreeBuilder.Marker prefixExpression = myBuilder.mark();
nextToken();
if (!parseNumericLiteral()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.number"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.number"));
}
prefixExpression.done(PyElementTypes.PREFIX_EXPRESSION);
}
@@ -379,7 +380,7 @@ public class PatternParsing extends Parsing {
if (atAnyOfTokens(PyTokenTypes.PLUS, PyTokenTypes.MINUS)) {
nextToken();
if (!parseNumericLiteral()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.number"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.number"));
}
complexLiteral.done(PyElementTypes.BINARY_EXPRESSION);
}
@@ -425,7 +426,7 @@ public class PatternParsing extends Parsing {
}
}
if (consumedAny) {
mark.error(PyPsiBundle.message("unexpected.tokens"));
mark.error(PyParsingBundle.message("unexpected.tokens"));
}
else {
mark.drop();

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing;
import com.intellij.lang.ITokenTypeRemapper;
@@ -23,11 +9,11 @@ import com.intellij.psi.tree.TokenSet;
import com.intellij.util.text.CharArrayUtil;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.psi.FutureFeature;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyElementType;
import com.jetbrains.python.PyTokenTypes;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -159,7 +145,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
parseIdentifierOrSkip(PyTokenTypes.LBRACKET, PyTokenTypes.EQ);
parseTypeParameterList();
checkMatches(PyTokenTypes.EQ, PyPsiBundle.message("PARSE.eq.expected"));
checkMatches(PyTokenTypes.EQ, PyParsingBundle.message("PARSE.eq.expected"));
myContext.getExpressionParser().parseExpression();
mark.done(PyElementTypes.TYPE_ALIAS_STATEMENT);
return true;
@@ -192,7 +178,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
if (!parseCaseClause()) {
SyntaxTreeBuilder.Marker illegalStatement = myBuilder.mark();
parseStatement();
illegalStatement.error(PyPsiBundle.message("PARSE.expected.case.clause"));
illegalStatement.error(PyParsingBundle.message("PARSE.expected.case.clause"));
}
}
if (!myBuilder.eof()) {
@@ -201,7 +187,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
}
else {
myBuilder.error(PyPsiBundle.message("indent.expected"));
myBuilder.error(PyParsingBundle.message("indent.expected"));
return false;
}
}
@@ -218,11 +204,11 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
while (!myBuilder.eof() && !atAnyOfTokens(PyTokenTypes.IF_KEYWORD, PyTokenTypes.COLON, PyTokenTypes.STATEMENT_BREAK)) {
nextToken();
}
patternError.error(PyPsiBundle.message("PARSE.expected.pattern"));
patternError.error(PyParsingBundle.message("PARSE.expected.pattern"));
}
if (matchToken(PyTokenTypes.IF_KEYWORD)) {
if (!getExpressionParser().parseNamedTestExpression(false, false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
parseColonAndSuite();
@@ -307,7 +293,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
statementType = PyElementTypes.AUG_ASSIGNMENT_STATEMENT;
builder.advanceLexer();
if (!getExpressionParser().parseYieldOrTupleExpression(false)) {
builder.error(PyPsiBundle.message("PARSE.expected.expression"));
builder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
else if (atToken(PyTokenTypes.EQ) || (atToken(PyTokenTypes.COLON) && (!checkLanguageLevel || myContext.getLanguageLevel().isPy3K()))) {
@@ -330,13 +316,13 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
final boolean isYieldExpr = builder.getTokenType() == PyTokenTypes.YIELD_KEYWORD;
if (!getExpressionParser().parseYieldOrTupleExpression(false)) {
maybeExprMarker.drop();
builder.error(PyPsiBundle.message("PARSE.expected.expression"));
builder.error(PyParsingBundle.message("PARSE.expected.expression"));
break;
}
if (builder.getTokenType() == PyTokenTypes.EQ) {
if (isYieldExpr) {
maybeExprMarker.drop();
builder.error(PyPsiBundle.message("cannot.assign.to.yield.expression"));
builder.error(PyParsingBundle.message("cannot.assign.to.yield.expression"));
}
else {
maybeExprMarker.rollbackTo();
@@ -367,13 +353,13 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
protected void reportParseStatementError(SyntaxTreeBuilder builder, IElementType firstToken) {
if (firstToken == PyTokenTypes.INCONSISTENT_DEDENT) {
builder.error(PyPsiBundle.message("unindent.does.not.match.any.outer.indent"));
builder.error(PyParsingBundle.message("unindent.does.not.match.any.outer.indent"));
}
else if (firstToken == PyTokenTypes.INDENT) {
builder.error(PyPsiBundle.message("unexpected.indent"));
builder.error(PyParsingBundle.message("unexpected.indent"));
}
else {
builder.error(PyPsiBundle.message("statement.expected.found.0", firstToken.toString()));
builder.error(PyParsingBundle.message("statement.expected.found.0", firstToken.toString()));
}
}
@@ -399,7 +385,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
}
else if (!builder.eof()) {
builder.error(PyPsiBundle.message("end.of.statement.expected"));
builder.error(PyParsingBundle.message("end.of.statement.expected"));
}
}
@@ -450,13 +436,13 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
final SyntaxTreeBuilder.Marker delStatement = myBuilder.mark();
myBuilder.advanceLexer();
if (!getExpressionParser().parseSingleExpression(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
while (myBuilder.getTokenType() == PyTokenTypes.COMMA) {
myBuilder.advanceLexer();
if (!getEndOfStatementsTokens().contains(myBuilder.getTokenType())) {
if (!getExpressionParser().parseSingleExpression(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
}
@@ -482,7 +468,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
else if (myBuilder.getTokenType() == PyTokenTypes.FROM_KEYWORD) {
myBuilder.advanceLexer();
if (!getExpressionParser().parseSingleExpression(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
}
@@ -498,13 +484,13 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
if (myBuilder.getTokenType() == PyTokenTypes.COMMA) {
myBuilder.advanceLexer();
if (!getExpressionParser().parseSingleExpression(false)) {
myContext.getBuilder().error(PyPsiBundle.message("PARSE.expected.expression"));
myContext.getBuilder().error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
checkEndOfStatement();
}
else {
myContext.getBuilder().error(PyPsiBundle.message("PARSE.expected.expression"));
myContext.getBuilder().error(PyParsingBundle.message("PARSE.expected.expression"));
}
assertStatement.done(PyElementTypes.ASSERT_STATEMENT);
}
@@ -548,7 +534,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
else if (builder.getTokenType() == PyTokenTypes.LPAR) {
builder.advanceLexer();
parseImportElements(elementType, false, true, from_future);
checkMatches(PyTokenTypes.RPAR, PyPsiBundle.message("PARSE.expected.rpar"));
checkMatches(PyTokenTypes.RPAR, PyParsingBundle.message("PARSE.expected.rpar"));
}
else {
parseImportElements(elementType, false, false, from_future);
@@ -565,7 +551,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
protected ImportTypes checkFromImportKeyword() {
checkMatches(PyTokenTypes.IMPORT_KEYWORD, PyPsiBundle.message("import.expected"));
checkMatches(PyTokenTypes.IMPORT_KEYWORD, PyParsingBundle.message("import.expected"));
return new ImportTypes(PyElementTypes.FROM_IMPORT_STATEMENT, PyElementTypes.IMPORT_ELEMENT, PyElementTypes.STAR_IMPORT_ELEMENT);
}
@@ -630,7 +616,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
return id_text;
}
else {
myBuilder.error(PyPsiBundle.message("PARSE.expected.identifier"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.identifier"));
idMarker.drop();
}
return null;
@@ -648,7 +634,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
protected boolean parseDottedNameAsAware(boolean optional) {
if (myBuilder.getTokenType() != PyTokenTypes.IDENTIFIER) {
if (optional) return true;
myBuilder.error(PyPsiBundle.message("PARSE.expected.identifier"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.identifier"));
return false;
}
SyntaxTreeBuilder.Marker marker = myBuilder.mark();
@@ -657,7 +643,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
while (myBuilder.getTokenType() == PyTokenTypes.DOT) {
marker = marker.precede();
myBuilder.advanceLexer();
checkMatches(PyTokenTypes.IDENTIFIER, PyPsiBundle.message("PARSE.expected.identifier"));
checkMatches(PyTokenTypes.IDENTIFIER, PyParsingBundle.message("PARSE.expected.identifier"));
marker.done(getReferenceType());
}
return true;
@@ -699,7 +685,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
final SyntaxTreeBuilder.Marker ifPart = myBuilder.mark();
myBuilder.advanceLexer();
if (!getExpressionParser().parseNamedTestExpression(false, false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
parseColonAndSuite();
ifPart.done(PyElementTypes.IF_PART_IF);
@@ -707,7 +693,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
while (myBuilder.getTokenType() == elifKeyword) {
myBuilder.advanceLexer();
if (!getExpressionParser().parseNamedTestExpression(false, false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
parseColonAndSuite();
elifPart.done(PyElementTypes.IF_PART_ELIF);
@@ -732,7 +718,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
return true;
}
else if (myBuilder.getTokenType() == PyTokenTypes.STATEMENT_BREAK) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.colon"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.colon"));
return true;
}
final SyntaxTreeBuilder.Marker marker = myBuilder.mark();
@@ -743,7 +729,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
if (!result && atToken(PyTokenTypes.STATEMENT_BREAK)) {
myBuilder.advanceLexer();
}
marker.error(PyPsiBundle.message("PARSE.expected.colon"));
marker.error(PyParsingBundle.message("PARSE.expected.colon"));
return result;
}
@@ -766,7 +752,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
final SyntaxTreeBuilder.Marker forPart = myBuilder.mark();
myBuilder.advanceLexer();
getExpressionParser().parseStarTargets();
checkMatches(PyTokenTypes.IN_KEYWORD, PyPsiBundle.message("PARSE.expected.in"));
checkMatches(PyTokenTypes.IN_KEYWORD, PyParsingBundle.message("PARSE.expected.in"));
getExpressionParser().parseExpression();
parseColonAndSuite();
forPart.done(PyElementTypes.FOR_PART);
@@ -778,7 +764,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
final SyntaxTreeBuilder.Marker whilePart = myBuilder.mark();
myBuilder.advanceLexer();
if (!getExpressionParser().parseNamedTestExpression(false, false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
parseColonAndSuite();
whilePart.done(PyElementTypes.WHILE_PART);
@@ -811,17 +797,17 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
boolean star = matchToken(PyTokenTypes.MULT);
if (myBuilder.getTokenType() != PyTokenTypes.COLON) {
if (!getExpressionParser().parseSingleExpression(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
if (myBuilder.getTokenType() == PyTokenTypes.COMMA || myBuilder.getTokenType() == PyTokenTypes.AS_KEYWORD) {
myBuilder.advanceLexer();
if (!getExpressionParser().parseSingleExpression(true)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
}
else if (star) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
parseColonAndSuite();
exceptBlock.done(PyElementTypes.EXCEPT_PART);
@@ -845,7 +831,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
else {
finallyPart.drop();
if (!haveExceptClause) {
myBuilder.error(PyPsiBundle.message("except.or.finally.expected"));
myBuilder.error(PyParsingBundle.message("except.or.finally.expected"));
// much better to have a statement of incorrectly determined type
// than "TRY" and "COLON" tokens attached to nothing
}
@@ -868,7 +854,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
myBuilder.advanceLexer();
if (!parseParenthesizedWithItems()) {
if (!parseWithItems(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
parseColonAndSuite();
@@ -887,7 +873,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
return false;
}
if (!matchToken(PyTokenTypes.RPAR)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.rpar"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.rpar"));
}
// Reparse something like "(foo()) as bar" or (foo()).bar as a single WithItem
if (!atAnyOfTokens(PyTokenTypes.COLON, PyTokenTypes.STATEMENT_BREAK)) {
@@ -905,7 +891,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
while (matchToken(PyTokenTypes.COMMA)) {
if (!parseWithItem()) {
if (!insideParentheses) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
break;
}
@@ -921,7 +907,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
if (matchToken(PyTokenTypes.AS_KEYWORD)) {
if (!getExpressionParser().parseSingleExpression(true)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.identifier"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.identifier"));
}
}
withItem.done(PyElementTypes.WITH_ITEM);
@@ -979,7 +965,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
else {
marker.drop();
myBuilder.error(PyPsiBundle.message("def.or.with.or.for.expected"));
myBuilder.error(PyParsingBundle.message("def.or.with.or.for.expected"));
}
return false;
}
@@ -1002,7 +988,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
}
else {
myBuilder.error(PyPsiBundle.message("indent.expected"));
myBuilder.error(PyParsingBundle.message("indent.expected"));
}
marker.done(PyElementTypes.STATEMENT_LIST);
@@ -1018,7 +1004,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
else {
final SyntaxTreeBuilder.Marker marker = myBuilder.mark();
if (myBuilder.eof()) {
myBuilder.error(PyPsiBundle.message("expected.statement"));
myBuilder.error(PyParsingBundle.message("expected.statement"));
}
else {
final ParsingContext context = getParsingContext();
@@ -1047,7 +1033,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
nextToken();
do {
if (!parseTypeParameter()) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.type.parameter"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.type.parameter"));
}
if (atToken(PyTokenTypes.COMMA)) {
@@ -1058,7 +1044,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
}
while (!atToken(PyTokenTypes.RBRACKET));
checkMatches(PyTokenTypes.RBRACKET, PyPsiBundle.message("PARSE.expected.symbols", ",", "]"));
checkMatches(PyTokenTypes.RBRACKET, PyParsingBundle.message("PARSE.expected.symbols", ",", "]"));
typeParamList.done(PyElementTypes.TYPE_PARAMETER_LIST);
}
}
@@ -1078,7 +1064,7 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
if (matchToken(PyTokenTypes.COLON)) {
if (!myContext.getExpressionParser().parseSingleExpression(false)) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
}
typeParamMarker.done(PyElementTypes.TYPE_PARAMETER);

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing.console;
import com.intellij.psi.tree.IElementType;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing.console;
import com.intellij.lang.SyntaxTreeBuilder;

View File

@@ -1,9 +1,9 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing.console;
import com.intellij.lang.SyntaxTreeBuilder;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.parsing.ExpressionParsing;
import com.jetbrains.python.parsing.ParsingContext;
@@ -127,7 +127,7 @@ public class PyConsoleParsingContext extends ParsingContext {
return true;
}
if (myBuilder.rawLookup(lookupIndex) != PyTokenTypes.IDENTIFIER) {
myBuilder.error(PyPsiBundle.message("PARSE.console.help.request.warn"));
myBuilder.error(PyParsingBundle.message("PARSE.console.help.request.warn"));
}
ipythonHelp.done(PyElementTypes.EMPTY_EXPRESSION);
myBuilder.advanceLexer();
@@ -177,7 +177,7 @@ public class PyConsoleParsingContext extends ParsingContext {
else {
expr.drop();
command.drop();
myBuilder.error(PyPsiBundle.message("PARSE.expected.identifier"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.identifier"));
return false;
}
while (myBuilder.getTokenType() != null) {
@@ -208,7 +208,7 @@ public class PyConsoleParsingContext extends ParsingContext {
}
if (myBuilder.getTokenType() == PyTokenTypes.PERC) {
if (myBuilder.lookAhead(1) == PyTokenTypes.PERC) {
myBuilder.error(PyPsiBundle.message("PARSE.console.multiline.magic.warn"));
myBuilder.error(PyParsingBundle.message("PARSE.console.multiline.magic.warn"));
}
captureIPythonExpression();
return true;

View File

@@ -1,22 +1,6 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.parsing.console;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.intellij.lexer.Lexer;
import com.intellij.lexer.MergeFunction;
import com.intellij.openapi.util.text.StringUtil;
@@ -36,7 +20,7 @@ public class PythonConsoleLexer extends PythonIndentingLexer {
super(PythonLexerKind.CONSOLE);
}
private final static Map<String, PyElementType> SPECIAL_IPYTHON_SYMBOLS = ImmutableMap.of(
private final static Map<String, PyElementType> SPECIAL_IPYTHON_SYMBOLS = Map.of(
"?", PyConsoleTokenTypes.QUESTION_MARK,
"!", PyConsoleTokenTypes.PLING,
"$", PyConsoleTokenTypes.DOLLAR
@@ -79,13 +63,14 @@ public class PythonConsoleLexer extends PythonIndentingLexer {
!StringUtil.isWhiteSpace(originalLexer.getBufferSequence().charAt(1))) {
return true;
}
int lastIndex = myTokenQueue.size() - 1;
if ((getBaseTokenStart() >= 1 &&
originalLexer.getBufferEnd() > getBaseTokenStart() + 1 &&
originalLexer.getBufferSequence().charAt(getBaseTokenStart() - 1) == '\n' &&
!StringUtil.isWhiteSpace(originalLexer.getBufferSequence().charAt(getBaseTokenStart() + 1))) &&
((!myTokenQueue.isEmpty() &&
(Iterables.getLast(myTokenQueue).getType() == STATEMENT_BREAK ||
Iterables.getLast(myTokenQueue).getType() == END_OF_LINE_COMMENT))
((lastIndex >= 0 &&
(myTokenQueue.get(lastIndex).getType() == STATEMENT_BREAK ||
(myTokenQueue.get(lastIndex).getType() == END_OF_LINE_COMMENT)))
|| StringUtil.isEmptyOrSpaces(originalLexer.getBufferSequence().subSequence(0, getBaseTokenStart())))) {
return true;
}

View File

@@ -1,8 +1,9 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayUtil;
import com.jetbrains.python.PyLanguageFacade;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -195,7 +196,7 @@ public enum LanguageLevel {
@NotNull
public static LanguageLevel forElement(@NotNull PsiElement element) {
return PyPsiFacade.getInstance(element.getProject()).getLanguageLevel(element);
return PyLanguageFacade.Companion.getINSTANCE().forLanguage(element);
}
@NotNull

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.lang.ASTNode;

View File

@@ -1,11 +1,12 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.google.common.collect.ImmutableList;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class PyStringLiteralCoreUtil {
/**
* Valid string prefix characters (lowercased) as defined in Python lexer.
@@ -17,7 +18,7 @@ public class PyStringLiteralCoreUtil {
*/
public static final int MAX_PREFIX_LENGTH = 3;
private static final ImmutableList<String> QUOTES = ImmutableList.of("'''", "\"\"\"", "'", "\"");
private static final List<String> QUOTES = List.of("'''", "\"\"\"", "'", "\"");
protected PyStringLiteralCoreUtil() {
}

View File

@@ -0,0 +1,115 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.lexer.PythonLexer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Mikhail Golubev
*/
public final class PyStringLiteralUtil extends PyStringLiteralCoreUtil {
private static final Logger LOG = Logger.getInstance(PyStringLiteralUtil.class);
private PyStringLiteralUtil() {
}
/**
* 'text' => text
* "text" => text
* text => text
* "text => "text
*
* @return string without heading and trailing pair of ' or "
*/
@NotNull
public static String getStringValue(@NotNull String s) {
return getStringValueTextRange(s).substring(s);
}
public static TextRange getStringValueTextRange(@NotNull String s) {
final Pair<String, String> quotes = getQuotes(s);
if (quotes != null) {
return TextRange.create(quotes.getFirst().length(), s.length() - quotes.getSecond().length());
}
return TextRange.allOf(s);
}
/**
* @return whether the given text is recognized as a valid string literal token by Python lexer
*/
public static boolean isStringLiteralToken(@NotNull String text) {
final PythonLexer lexer = new PythonLexer();
lexer.start(text);
return PyTokenTypes.STRING_NODES.contains(lexer.getTokenType()) && lexer.getTokenEnd() == lexer.getBufferEnd() ||
PyTokenTypes.FSTRING_START == lexer.getTokenType();
}
/**
* Returns the range of the string literal text between the opening quote and the closing one.
* If the closing quote is either missing or mismatched, this range spans until the end of the literal.
*/
@NotNull
public static TextRange getContentRange(@NotNull String text) {
LOG.assertTrue(isStringLiteralToken(text), "Text of a single string literal node expected");
int startOffset = getPrefixLength(text);
int delimiterLength = 1;
final String afterPrefix = text.substring(startOffset);
if (afterPrefix.startsWith("\"\"\"") || afterPrefix.startsWith("'''")) {
delimiterLength = 3;
}
final String delimiter = text.substring(startOffset, startOffset + delimiterLength);
startOffset += delimiterLength;
int endOffset = text.length();
if (text.substring(startOffset).endsWith(delimiter)) {
endOffset -= delimiterLength;
}
return new TextRange(startOffset, endOffset);
}
public static int getPrefixLength(@NotNull String text) {
return getPrefixEndOffset(text, 0);
}
/**
* @return whether the given prefix contains either 'u' or 'U' character
*/
public static boolean isUnicodePrefix(@NotNull String prefix) {
return StringUtil.indexOfIgnoreCase(prefix, 'u', 0) >= 0;
}
/**
* @return whether the given prefix contains either 'b' or 'B' character
*/
public static boolean isBytesPrefix(@NotNull String prefix) {
return StringUtil.indexOfIgnoreCase(prefix, 'b', 0) >= 0;
}
/**
* @return whether the given prefix contains either 'r' or 'R' character
*/
public static boolean isRawPrefix(@NotNull String prefix) {
return StringUtil.indexOfIgnoreCase(prefix, 'r', 0) >= 0;
}
/**
* @return whether the given prefix contains either 'f' or 'F' character
*/
public static boolean isFormattedPrefix(@NotNull String prefix) {
return StringUtil.indexOfIgnoreCase(prefix, 'f', 0) >= 0;
}
/**
* @return alternative quote character, i.e. " for ' and ' for "
*/
public static char flipQuote(char quote) {
return quote == '"' ? '\'' : '"';
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.psi.types;
import com.jetbrains.python.psi.PyElementType;
public final class PyTypeTokenTypes {
private PyTypeTokenTypes() {}
public static final PyElementType NL = new PyElementType("NL");
public static final PyElementType SPACE = new PyElementType("SPACE");
public static final PyElementType MARKUP = new PyElementType("MARKUP");
public static final PyElementType OP = new PyElementType("OP");
public static final PyElementType PARAMETER = new PyElementType("PARAMETER");
public static final PyElementType IDENTIFIER = new PyElementType("IDENTIFIER");
}

View File

@@ -0,0 +1,29 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package icons;
import com.intellij.ui.IconManager;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* NOTE THIS FILE IS AUTO-GENERATED
* DO NOT EDIT IT BY HAND, run "Generate icon classes" configuration instead
*/
public final class PythonPsiApiIcons {
private static @NotNull Icon load(@NotNull String path, int cacheKey, int flags) {
return IconManager.getInstance().loadRasterizedIcon(path, PythonPsiApiIcons.class.getClassLoader(), cacheKey, flags);
}
/** 16x16 */ public static final @NotNull Icon IPythonNotebook = load("icons/com/jetbrains/python/iPythonNotebook.svg", 610765917, 0);
public static final class Nodes {
/** 16x16 */ public static final @NotNull Icon CyanDot = load("icons/com/jetbrains/python/nodes/cyan-dot.svg", -182142090, 0);
/** 16x16 */ public static final @NotNull Icon Lock = load("icons/com/jetbrains/python/nodes/lock.svg", 1450341891, 0);
/** 16x16 */ public static final @NotNull Icon RedInvTriangle = load("icons/com/jetbrains/python/nodes/red-inv-triangle.svg", -1698695951, 0);
}
/** 16x16 */ public static final @NotNull Icon PropertyDeleter = load("icons/com/jetbrains/python/propertyDeleter.svg", 474832287, 2);
/** 16x16 */ public static final @NotNull Icon PropertyGetter = load("icons/com/jetbrains/python/propertyGetter.svg", 1495604199, 2);
/** 16x16 */ public static final @NotNull Icon PropertySetter = load("icons/com/jetbrains/python/propertySetter.svg", -1451064081, 2);
/** 16x16 */ public static final @NotNull Icon PythonFile = load("icons/com/jetbrains/python/pythonFile.svg", -1892316725, 0);
}

View File

@@ -13,5 +13,6 @@
<orderEntry type="module" module-name="intellij.platform.util.ui" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="module" module-name="intellij.platform.analysis" />
<orderEntry type="module" module-name="intellij.python.parser" exported="" />
</component>
</module>

View File

@@ -49,13 +49,6 @@
dynamic="true"/>
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<fileType name="Python"
language="Python"
extensions="py;pyw"
hashBangs="python"
implementationClass="com.jetbrains.python.PythonFileType"
fieldName="INSTANCE"/>
<iconMapper mappingFile="PythonPsiApiIconMappings.json"/>
<projectService serviceInterface="com.jetbrains.python.psi.types.TypeEvalContextCache"
serviceImplementation="com.jetbrains.python.psi.types.TypeEvalContextCacheImpl"/>
</extensions>

View File

@@ -6,6 +6,7 @@ import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -721,6 +722,29 @@ public final class PyPsiUtils {
}
}
@Nullable
public static String getStringValue(@Nullable PsiElement o) {
if (o == null) {
return null;
}
if (o instanceof PyStringLiteralExpression literalExpression) {
return literalExpression.getStringValue();
}
else {
return o.getText();
}
}
public static TextRange getStringValueTextRange(PsiElement element) {
if (element instanceof PyStringLiteralExpression) {
final List<TextRange> ranges = ((PyStringLiteralExpression)element).getStringValueTextRanges();
return ranges.get(0);
}
else {
return new TextRange(0, element.getTextLength());
}
}
@Nullable
public static PsiComment findSameLineComment(@NotNull PsiElement elem) {
// If `elem` is a compound multi-line element, stick to its first line nonetheless

View File

@@ -36,5 +36,6 @@
<orderEntry type="library" name="gson" level="project" />
<orderEntry type="module" module-name="intellij.platform.workspace.jps" />
<orderEntry type="module" module-name="intellij.platform.backend.workspace" />
<orderEntry type="module" module-name="intellij.python.parser" />
</component>
</module>

View File

@@ -10,6 +10,12 @@
<projectService serviceInterface="com.jetbrains.python.psi.PyPsiFacade"
serviceImplementation="com.jetbrains.python.psi.impl.PyPsiFacadeImpl"/>
<applicationService serviceInterface="com.jetbrains.python.PyElementTypesFacade"
serviceImplementation="com.jetbrains.python.PyElementTypesFacadeImpl"/>
<applicationService serviceInterface="com.jetbrains.python.PyLanguageFacade"
serviceImplementation="com.jetbrains.python.PyLanguageFacadeImpl"/>
<projectService serviceInterface="com.jetbrains.python.debugger.PySignatureCacheManager"
serviceImplementation="com.jetbrains.python.debugger.PySignatureCacheManagerImpl"/>

View File

@@ -162,80 +162,6 @@ ANN.continue.break.or.return.in.star.except='break', 'continue' and 'return' can
ANN.await.outside.async.function='await' outside async function
### parsing
PARSE.expected.expression=Expression expected
PARSE.expected.rbracket=']' expected
PARSE.expected.expr.or.comma.or.bracket=Expected expression, ',' or ']'
PARSE.expected.in='in' expected
PARSE.expected.for.or.bracket=']' or 'for' expected
PARSE.expected.comma=',' expected
PARSE.expected.colon=':' expected
PARSE.expected.rpar=')' expected
PARSE.expected.lpar='(' expected
PARSE.expected.rbrace='}' expected
PARSE.expected.tick='`' (backtick) expected
PARSE.expected.name=Name expected
PARSE.expected.colon.or.rbracket=':' or ']' expected
PARSE.expected.comma.or.rpar=',' or ')' expected
PARSE.expected.else='else' expected
PARSE.expected.identifier=Identifier expected
PARSE.expected.comma.lpar.rpar=',' or '(' or ')' expected
PARSE.expected.statement.break=Statement break expected
PARSE.expected.@.or.def='@' or 'def' expected
PARSE.expected.formal.param.name=Formal parameter name expected
PARSE.0.expected=''{0}'' expected
PARSE.expected.ellipsis='...' expected
PARSE.string.literal.expected=string literal expected
PARSE.expected.symbols=''{0}'' or ''{1}'' expected
PARSE.expected.symbols.first.quotation=''{0}'' or {1} expected
PARSE.expected.symbols.second.quotation={0} or ''{1}'' expected
PARSE.declarator.should.be.empty=declarator should be empty
PARSE.string.literal=string literal
PARSE.newline.expected=newline expected
PARSE.eq.expected='=' expected
PARSE.from.expected='from' expected
PARSE.gt.expected='>' expected
PARSE.expected.fstring.quote={0} expected
PARSE.expected.fstring.rbrace='}' expected
PARSE.expected.fstring.colon.or.rbrace=: or '}' expected
PARSE.expected.fstring.type.conversion.or.colon.or.rbrace=Type conversion, ':' or '}' expected
PARSE.single.star.parameter.not.supported.py2=Single star parameter is not supported in Python 2
PARSE.async.keyword.not.expected.here='async' keyword is not expected here
PARSE.keyword.cannot.be.used.as.identifier.py2=''{0}'' keyword can''t be used as an identifier in Python 2
PARSE.expected.number=Number expected
PARSE.expected.case.clause=Case clause expected
PARSE.expected.pattern=Pattern expected
PARSE.expected.name.or.wildcard=Name or '_' expected
PARSE.expected.type.parameter=Type parameter expected
statement.expected.found.0=Statement expected, found {0}
unexpected.indent=Unexpected indent
unindent.does.not.match.any.outer.indent=Unindent does not match any outer indentation level
except.or.finally.expected='except' or 'finally' expected
expected.statement=Statement expected
indent.expected=Indent expected
cannot.assign.to.yield.expression=Cannot assign to 'yield' expression
end.of.statement.expected=End of statement expected
import.expected='import' expected
def.or.with.or.for.expected='def' or 'with' or 'for' expected
rbracket.or.comma.expected=']' or ',' expected
unexpected.expression.syntax=Unexpected expression syntax
tuple.expression.expected=Tuple expression expected
value.expression.expected=Value expression expected
unexpected.expression.part=Unexpected expression part
unexpected.f.string.token=Unexpected f-string token
can.t.assign.to.await.expression=Cannot assign to await expression
for.expected='for' expected
rarrow.expected='->' expected
unexpected.tokens=Unexpected tokens
PARSE.function.type.annotations.py2=Type annotations are unsupported in Python 2
PARSE.function.return.type.annotations.py2=Return type annotations are unsupported in Python 2
PARSE.console.multiline.magic.warn=Multiline magic cannot be used as an expression
PARSE.console.help.request.warn=IPython introspection syntax error
### quick doc generator
QDOC.module.path.unknown=(Module path is unknown)
QDOC.epydoc.python2.sdk.not.found=You need a configured Python 2 SDK to render <a href='http://epydoc.sourceforge.net/'>Epydoc</a> docstrings

View File

@@ -1,177 +0,0 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python;
import com.intellij.psi.tree.TokenSet;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.impl.*;
import com.jetbrains.python.psi.stubs.*;
public interface PyElementTypes {
PyStubElementType<PyFunctionStub, PyFunction> FUNCTION_DECLARATION = PyStubElementTypes.FUNCTION_DECLARATION;
PyStubElementType<PyClassStub, PyClass> CLASS_DECLARATION = PyStubElementTypes.CLASS_DECLARATION;
PyStubElementType<PyParameterListStub, PyParameterList> PARAMETER_LIST = PyStubElementTypes.PARAMETER_LIST;
PyStubElementType<PyDecoratorListStub, PyDecoratorList> DECORATOR_LIST = PyStubElementTypes.DECORATOR_LIST;
PyStubElementType<PyNamedParameterStub, PyNamedParameter> NAMED_PARAMETER = PyStubElementTypes.NAMED_PARAMETER;
PyStubElementType<PyTupleParameterStub, PyTupleParameter> TUPLE_PARAMETER = PyStubElementTypes.TUPLE_PARAMETER;
PyStubElementType<PySlashParameterStub, PySlashParameter> SLASH_PARAMETER = PyStubElementTypes.SLASH_PARAMETER;
PyStubElementType<PySingleStarParameterStub, PySingleStarParameter> SINGLE_STAR_PARAMETER = PyStubElementTypes.SINGLE_STAR_PARAMETER;
PyStubElementType<PyDecoratorStub, PyDecorator> DECORATOR_CALL = PyStubElementTypes.DECORATOR_CALL;
PyStubElementType<PyImportElementStub, PyImportElement> IMPORT_ELEMENT = PyStubElementTypes.IMPORT_ELEMENT;
PyStubElementType<PyAnnotationStub, PyAnnotation> ANNOTATION = PyStubElementTypes.ANNOTATION;
PyStubElementType<PyStarImportElementStub, PyStarImportElement> STAR_IMPORT_ELEMENT = PyStubElementTypes.STAR_IMPORT_ELEMENT;
PyStubElementType<PyExceptPartStub, PyExceptPart> EXCEPT_PART = PyStubElementTypes.EXCEPT_PART;
PyStubElementType<PyFromImportStatementStub, PyFromImportStatement> FROM_IMPORT_STATEMENT = PyStubElementTypes.FROM_IMPORT_STATEMENT;
PyStubElementType<PyImportStatementStub, PyImportStatement> IMPORT_STATEMENT = PyStubElementTypes.IMPORT_STATEMENT;
PyStubElementType<PyTargetExpressionStub, PyTargetExpression> TARGET_EXPRESSION = PyStubElementTypes.TARGET_EXPRESSION;
PyStubElementType<PyTypeParameterStub, PyTypeParameter> TYPE_PARAMETER = PyStubElementTypes.TYPE_PARAMETER;
PyStubElementType<PyTypeParameterListStub, PyTypeParameterList> TYPE_PARAMETER_LIST = PyStubElementTypes.TYPE_PARAMETER_LIST;
PyStubElementType<PyTypeAliasStatementStub, PyTypeAliasStatement> TYPE_ALIAS_STATEMENT = PyStubElementTypes.TYPE_ALIAS_STATEMENT;
TokenSet PARAMETER_LIST_SET = TokenSet.create(PARAMETER_LIST);
TokenSet FORMAL_PARAMETER_SET = TokenSet.create(NAMED_PARAMETER);
PyElementType ARGUMENT_LIST = new PyElementType("ARGUMENT_LIST", node -> new PyArgumentListImpl(node));
PyElementType PRINT_TARGET = new PyElementType("PRINT_TARGET", node -> new PyPrintTargetImpl(node));
PyElementType DECORATOR = new PyElementType("DECORATOR", node -> new PyDecoratorImpl(node));
// Statements
PyElementType EXPRESSION_STATEMENT = new PyElementType("EXPRESSION_STATEMENT", node -> new PyExpressionStatementImpl(node));
PyElementType ASSIGNMENT_STATEMENT = new PyElementType("ASSIGNMENT_STATEMENT", node -> new PyAssignmentStatementImpl(node));
PyElementType AUG_ASSIGNMENT_STATEMENT = new PyElementType("AUG_ASSIGNMENT_STATEMENT", node -> new PyAugAssignmentStatementImpl(node));
PyElementType ASSERT_STATEMENT = new PyElementType("ASSERT_STATEMENT", node -> new PyAssertStatementImpl(node));
PyElementType BREAK_STATEMENT = new PyElementType("BREAK_STATEMENT", node -> new PyBreakStatementImpl(node));
PyElementType CONTINUE_STATEMENT = new PyElementType("CONTINUE_STATEMENT", node -> new PyContinueStatementImpl(node));
PyElementType DEL_STATEMENT = new PyElementType("DEL_STATEMENT", node -> new PyDelStatementImpl(node));
PyElementType EXEC_STATEMENT = new PyElementType("EXEC_STATEMENT", node -> new PyExecStatementImpl(node));
PyElementType FOR_STATEMENT = new PyElementType("FOR_STATEMENT", node -> new PyForStatementImpl(node));
PyElementType TYPE_DECLARATION_STATEMENT = new PyElementType("TYPE_DECLARATION_STATEMENT", node -> new PyTypeDeclarationStatementImpl(node));
PyElementType GLOBAL_STATEMENT = new PyElementType("GLOBAL_STATEMENT", node -> new PyGlobalStatementImpl(node));
PyElementType IF_STATEMENT = new PyElementType("IF_STATEMENT", node -> new PyIfStatementImpl(node));
PyElementType PASS_STATEMENT = new PyElementType("PASS_STATEMENT", node -> new PyPassStatementImpl(node));
PyElementType PRINT_STATEMENT = new PyElementType("PRINT_STATEMENT", node -> new PyPrintStatementImpl(node));
PyElementType RAISE_STATEMENT = new PyElementType("RAISE_STATEMENT", node -> new PyRaiseStatementImpl(node));
PyElementType RETURN_STATEMENT = new PyElementType("RETURN_STATEMENT", node -> new PyReturnStatementImpl(node));
PyElementType TRY_EXCEPT_STATEMENT = new PyElementType("TRY_EXCEPT_STATEMENT", node -> new PyTryExceptStatementImpl(node));
PyElementType WITH_STATEMENT = new PyElementType("WITH_STATEMENT", node -> new PyWithStatementImpl(node));
PyElementType WHILE_STATEMENT = new PyElementType("WHILE_STATEMENT", node -> new PyWhileStatementImpl(node));
PyElementType STATEMENT_LIST = new PyElementType("STATEMENT_LIST", node -> new PyStatementListImpl(node));
PyElementType NONLOCAL_STATEMENT = new PyElementType("NONLOCAL_STATEMENT", node -> new PyNonlocalStatementImpl(node));
PyElementType WITH_ITEM = new PyElementType("WITH_ITEM", node -> new PyWithItemImpl(node));
// Expressions
PyElementType EMPTY_EXPRESSION = new PyElementType("EMPTY_EXPRESSION", node -> new PyEmptyExpressionImpl(node));
PyElementType REFERENCE_EXPRESSION = new PyElementType("REFERENCE_EXPRESSION", node -> new PyReferenceExpressionImpl(node));
PyElementType INTEGER_LITERAL_EXPRESSION = new PyElementType("INTEGER_LITERAL_EXPRESSION", node -> new PyNumericLiteralExpressionImpl(node));
PyElementType FLOAT_LITERAL_EXPRESSION = new PyElementType("FLOAT_LITERAL_EXPRESSION", node -> new PyNumericLiteralExpressionImpl(node));
PyElementType IMAGINARY_LITERAL_EXPRESSION = new PyElementType("IMAGINARY_LITERAL_EXPRESSION", node -> new PyNumericLiteralExpressionImpl(node));
PyElementType STRING_LITERAL_EXPRESSION = new PyElementType("STRING_LITERAL_EXPRESSION", node -> new PyStringLiteralExpressionImpl(node));
PyElementType NONE_LITERAL_EXPRESSION = new PyElementType("NONE_LITERAL_EXPRESSION", node -> new PyNoneLiteralExpressionImpl(node));
PyElementType BOOL_LITERAL_EXPRESSION = new PyElementType("BOOL_LITERAL_EXPRESSION", node -> new PyBoolLiteralExpressionImpl(node));
PyElementType PARENTHESIZED_EXPRESSION = new PyElementType("PARENTHESIZED_EXPRESSION", node -> new PyParenthesizedExpressionImpl(node));
PyElementType SUBSCRIPTION_EXPRESSION = new PyElementType("SUBSCRIPTION_EXPRESSION", node -> new PySubscriptionExpressionImpl(node));
PyElementType SLICE_EXPRESSION = new PyElementType("SLICE_EXPRESSION", node -> new PySliceExpressionImpl(node));
PyElementType SLICE_ITEM = new PyElementType("SLICE_ITEM", node -> new PySliceItemImpl(node));
PyElementType BINARY_EXPRESSION = new PyElementType("BINARY_EXPRESSION", node -> new PyBinaryExpressionImpl(node));
PyElementType PREFIX_EXPRESSION = new PyElementType("PREFIX_EXPRESSION", node -> new PyPrefixExpressionImpl(node));
PyElementType CALL_EXPRESSION = new PyElementType("CALL_EXPRESSION", node -> new PyCallExpressionImpl(node));
PyElementType LIST_LITERAL_EXPRESSION = new PyElementType("LIST_LITERAL_EXPRESSION", node -> new PyListLiteralExpressionImpl(node));
PyElementType TUPLE_EXPRESSION = new PyElementType("TUPLE_EXPRESSION", node -> new PyTupleExpressionImpl(node));
PyElementType KEYWORD_ARGUMENT_EXPRESSION = new PyElementType("KEYWORD_ARGUMENT_EXPRESSION", node -> new PyKeywordArgumentImpl(node));
PyElementType STAR_ARGUMENT_EXPRESSION = new PyElementType("STAR_ARGUMENT_EXPRESSION", node -> new PyStarArgumentImpl(node));
PyElementType LAMBDA_EXPRESSION = new PyElementType("LAMBDA_EXPRESSION", node -> new PyLambdaExpressionImpl(node));
PyElementType LIST_COMP_EXPRESSION = new PyElementType("LIST_COMP_EXPRESSION", node -> new PyListCompExpressionImpl(node));
PyElementType DICT_LITERAL_EXPRESSION = new PyElementType("DICT_LITERAL_EXPRESSION", node -> new PyDictLiteralExpressionImpl(node));
PyElementType KEY_VALUE_EXPRESSION = new PyElementType("KEY_VALUE_EXPRESSION", node -> new PyKeyValueExpressionImpl(node));
PyElementType REPR_EXPRESSION = new PyElementType("REPR_EXPRESSION", node -> new PyReprExpressionImpl(node));
PyElementType GENERATOR_EXPRESSION = new PyElementType("GENERATOR_EXPRESSION", node -> new PyGeneratorExpressionImpl(node));
PyElementType CONDITIONAL_EXPRESSION = new PyElementType("CONDITIONAL_EXPRESSION", node -> new PyConditionalExpressionImpl(node));
PyElementType YIELD_EXPRESSION = new PyElementType("YIELD_EXPRESSION", node -> new PyYieldExpressionImpl(node));
PyElementType STAR_EXPRESSION = new PyElementType("STAR_EXPRESSION", node -> new PyStarExpressionImpl(node));
PyElementType DOUBLE_STAR_EXPRESSION = new PyElementType("DOUBLE_STAR_EXPRESSION", node -> new PyDoubleStarExpressionImpl(node));
PyElementType ASSIGNMENT_EXPRESSION = new PyElementType("ASSIGNMENT_EXPRESSION", node -> new PyAssignmentExpressionImpl(node));
PyElementType SET_LITERAL_EXPRESSION = new PyElementType("SET_LITERAL_EXPRESSION", node -> new PySetLiteralExpressionImpl(node));
PyElementType SET_COMP_EXPRESSION = new PyElementType("SET_COMP_EXPRESSION", node -> new PySetCompExpressionImpl(node));
PyElementType DICT_COMP_EXPRESSION = new PyElementType("DICT_COMP_EXPRESSION", node -> new PyDictCompExpressionImpl(node));
TokenSet STATEMENT_LISTS = TokenSet.create(STATEMENT_LIST);
TokenSet BINARY_OPS = TokenSet.create(PyTokenTypes.OR_KEYWORD, PyTokenTypes.AND_KEYWORD, PyTokenTypes.LT, PyTokenTypes.GT,
PyTokenTypes.OR, PyTokenTypes.XOR, PyTokenTypes.AND, PyTokenTypes.LTLT, PyTokenTypes.GTGT,
PyTokenTypes.EQEQ, PyTokenTypes.GE, PyTokenTypes.LE, PyTokenTypes.NE, PyTokenTypes.NE_OLD,
PyTokenTypes.IN_KEYWORD, PyTokenTypes.IS_KEYWORD, PyTokenTypes.NOT_KEYWORD, PyTokenTypes.PLUS,
PyTokenTypes.MINUS, PyTokenTypes.MULT, PyTokenTypes.AT, PyTokenTypes.FLOORDIV, PyTokenTypes.DIV,
PyTokenTypes.PERC, PyTokenTypes.EXP);
TokenSet UNARY_OPS = TokenSet.create(PyTokenTypes.NOT_KEYWORD, PyTokenTypes.PLUS, PyTokenTypes.MINUS, PyTokenTypes.TILDE,
PyTokenTypes.AWAIT_KEYWORD);
// Parts
PyElementType IF_PART_IF = new PyElementType("IF_IF", node -> new PyIfPartIfImpl(node));
PyElementType IF_PART_ELIF = new PyElementType("IF_ELIF", node -> new PyIfPartElifImpl(node));
PyElementType FOR_PART = new PyElementType("FOR_PART", node -> new PyForPartImpl(node));
PyElementType WHILE_PART = new PyElementType("WHILE_PART", node -> new PyWhilePartImpl(node));
PyElementType TRY_PART = new PyElementType("TRY_PART", node -> new PyTryPartImpl(node));
PyElementType FINALLY_PART = new PyElementType("FINALLY_PART", node -> new PyFinallyPartImpl(node));
PyElementType ELSE_PART = new PyElementType("ELSE_PART", node -> new PyElsePartImpl(node));
TokenSet PARTS = TokenSet.create(IF_PART_IF, IF_PART_ELIF, FOR_PART, WHILE_PART, TRY_PART, FINALLY_PART, ELSE_PART, EXCEPT_PART);
TokenSet ELIFS = TokenSet.create(IF_PART_ELIF);
TokenSet STAR_PARAMETERS = TokenSet.create(NAMED_PARAMETER, STAR_ARGUMENT_EXPRESSION, STAR_EXPRESSION, DOUBLE_STAR_EXPRESSION);
TokenSet CLASS_OR_FUNCTION = TokenSet.create(CLASS_DECLARATION, FUNCTION_DECLARATION);
TokenSet IMPORT_STATEMENTS = TokenSet.create(IMPORT_STATEMENT, FROM_IMPORT_STATEMENT);
PyElementType FSTRING_NODE = new PyElementType("FSTRING_NODE", node -> new PyFormattedStringElementImpl(node));
PyElementType FSTRING_FRAGMENT = new PyElementType("FSTRING_FRAGMENT", node -> new PyFStringFragmentImpl(node));
PyElementType FSTRING_FRAGMENT_FORMAT_PART = new PyElementType("FSTRING_FRAGMENT_FORMAT_PART", node -> new PyFStringFragmentFormatPartImpl(node));
PyElementType MATCH_STATEMENT = new PyElementType("MATCH_STATEMENT", node -> new PyMatchStatementImpl(node));
PyElementType CASE_CLAUSE = new PyElementType("CASE_CLAUSE", node -> new PyCaseClauseImpl(node));
PyElementType LITERAL_PATTERN = new PyElementType("LITERAL_PATTERN", node -> new PyLiteralPatternImpl(node));
PyElementType VALUE_PATTERN = new PyElementType("VALUE_PATTERN", node -> new PyValuePatternImpl(node));
PyElementType CAPTURE_PATTERN = new PyElementType("CAPTURE_PATTERN", node -> new PyCapturePatternImpl(node));
PyElementType WILDCARD_PATTERN = new PyElementType("WILDCARD_PATTERN", node -> new PyWildcardPatternImpl(node));
PyElementType GROUP_PATTERN = new PyElementType("GROUP_PATTERN", node -> new PyGroupPatternImpl(node));
PyElementType SEQUENCE_PATTERN = new PyElementType("SEQUENCE_PATTERN", node -> new PySequencePatternImpl(node));
PyElementType SINGLE_STAR_PATTERN = new PyElementType("SINGLE_STAR_PATTERN", node -> new PySingleStarPatternImpl(node));
PyElementType DOUBLE_STAR_PATTERN = new PyElementType("DOUBLE_STAR_PATTERN", node -> new PyDoubleStarPatternImpl(node));
PyElementType MAPPING_PATTERN = new PyElementType("KEY_VALUE_PATTERN", node -> new PyMappingPatternImpl(node));
PyElementType KEY_VALUE_PATTERN = new PyElementType("KEY_VALUE_PATTERN", node -> new PyKeyValuePatternImpl(node));
PyElementType CLASS_PATTERN = new PyElementType("CLASS_PATTERN", node -> new PyClassPatternImpl(node));
PyElementType PATTERN_ARGUMENT_LIST = new PyElementType("PATTERN_ARGUMENT_LIST", node -> new PyPatternArgumentListImpl(node));
PyElementType KEYWORD_PATTERN = new PyElementType("KEYWORD_PATTERN", node -> new PyKeywordPatternImpl(node));
PyElementType OR_PATTERN = new PyElementType("OR_PATTERN", node -> new PyOrPatternImpl(node));
PyElementType AS_PATTERN = new PyElementType("AS_PATTERN", node -> new PyAsPatternImpl(node));
}

View File

@@ -0,0 +1,227 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python
import com.intellij.lang.ASTNode
import com.intellij.openapi.components.Service
import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.IStubElementType
import com.jetbrains.python.psi.impl.*
import com.jetbrains.python.PyElementTypesFacade
import java.util.function.Function
typealias F = Function<in ASTNode, out PsiElement>
class PyElementTypesFacadeImpl : PyElementTypesFacade() {
override val functionDeclaration: IStubElementType<*, *>
get() = PyStubElementTypes.FUNCTION_DECLARATION
override val classDeclaration: IStubElementType<*, *>
get() = PyStubElementTypes.CLASS_DECLARATION
override val parameterList: IStubElementType<*, *>
get() = PyStubElementTypes.PARAMETER_LIST
override val decoratorList: IStubElementType<*, *>
get() = PyStubElementTypes.DECORATOR_LIST
override val namedParameter: IStubElementType<*, *>
get() = PyStubElementTypes.NAMED_PARAMETER
override val tupleParameter: IStubElementType<*, *>
get() = PyStubElementTypes.TUPLE_PARAMETER
override val slashParameter: IStubElementType<*, *>
get() = PyStubElementTypes.SLASH_PARAMETER
override val singleStarParameter: IStubElementType<*, *>
get() = PyStubElementTypes.SINGLE_STAR_PARAMETER
override val decoratorCall: IStubElementType<*, *>
get() = PyStubElementTypes.DECORATOR_CALL
override val importElement: IStubElementType<*, *>
get() = PyStubElementTypes.IMPORT_ELEMENT
override val annotation: IStubElementType<*, *>
get() = PyStubElementTypes.ANNOTATION
override val starImportElement: IStubElementType<*, *>
get() = PyStubElementTypes.STAR_IMPORT_ELEMENT
override val exceptPart: IStubElementType<*, *>
get() = PyStubElementTypes.EXCEPT_PART
override val fromImportStatement: IStubElementType<*, *>
get() = PyStubElementTypes.FROM_IMPORT_STATEMENT
override val importStatement: IStubElementType<*, *>
get() = PyStubElementTypes.IMPORT_STATEMENT
override val targetExpression: IStubElementType<*, *>
get() = PyStubElementTypes.TARGET_EXPRESSION
override val typeParameter: IStubElementType<*, *>
get() = PyStubElementTypes.TYPE_PARAMETER
override val typeParameterList: IStubElementType<*, *>
get() = PyStubElementTypes.TYPE_PARAMETER_LIST
override val typeAliasStatement: IStubElementType<*, *>
get() = PyStubElementTypes.TYPE_ALIAS_STATEMENT
override val argumentListConstructor: F
get() = F { node: ASTNode -> PyArgumentListImpl(node) }
override val printTargetConstructor: F
get() = F { node: ASTNode -> PyPrintTargetImpl(node) }
override val decoratorConstructor: F
get() = F { node: ASTNode -> PyDecoratorImpl(node) }
override val expressionStatementConstructor: F
get() = F { node -> PyExpressionStatementImpl(node) }
override val assignmentStatementConstructor: F
get() = F { node -> PyAssignmentStatementImpl(node) }
override val augAssignmentStatementConstructor: F
get() = F { node -> PyAugAssignmentStatementImpl(node) }
override val assertStatementConstructor: F
get() = F { node -> PyAssertStatementImpl(node) }
override val breakStatementConstructor: F
get() = F { node -> PyBreakStatementImpl(node) }
override val continueStatementConstructor: F
get() = F { node -> PyContinueStatementImpl(node) }
override val delStatementConstructor: F
get() = F { node -> PyDelStatementImpl(node) }
override val execStatementConstructor: F
get() = F { node -> PyExecStatementImpl(node) }
override val forStatementConstructor: F
get() = F { node -> PyForStatementImpl(node) }
override val typeDeclarationStatementConstructor: F
get() = F { node -> PyTypeDeclarationStatementImpl(node) }
override val globalStatementConstructor: F
get() = F { node -> PyGlobalStatementImpl(node) }
override val ifStatementConstructor: F
get() = F { node -> PyIfStatementImpl(node) }
override val passStatementConstructor: F
get() = F { node -> PyPassStatementImpl(node) }
override val printStatementConstructor: F
get() = F { node -> PyPrintStatementImpl(node) }
override val raiseStatementConstructor: F
get() = F { node -> PyRaiseStatementImpl(node) }
override val returnStatementConstructor: F
get() = F { node -> PyReturnStatementImpl(node) }
override val tryExceptStatementConstructor: F
get() = F { node -> PyTryExceptStatementImpl(node) }
override val withStatementConstructor: F
get() = F { node -> PyWithStatementImpl(node) }
override val whileStatementConstructor: F
get() = F { node -> PyWhileStatementImpl(node) }
override val statementListConstructor: F
get() = F { node -> PyStatementListImpl(node) }
override val nonlocalStatementConstructor: F
get() = F { node -> PyNonlocalStatementImpl(node) }
override val withItemConstructor: F
get() = F { node -> PyWithItemImpl(node) }
override val emptyExpressionConstructor: F
get() = F { node -> PyEmptyExpressionImpl(node) }
override val referenceExpressionConstructor: F
get() = F { node -> PyReferenceExpressionImpl(node) }
override val integerLiteralExpressionConstructor: F
get() = F { node -> PyNumericLiteralExpressionImpl(node) }
override val floatLiteralExpressionConstructor: F
get() = F { node -> PyNumericLiteralExpressionImpl(node) }
override val imaginaryLiteralExpressionConstructor: F
get() = F { node -> PyNumericLiteralExpressionImpl(node) }
override val stringLiteralExpressionConstructor: F
get() = F { node -> PyStringLiteralExpressionImpl(node) }
override val noneLiteralExpressionConstructor: F
get() = F { node -> PyNoneLiteralExpressionImpl(node) }
override val boolLiteralExpressionConstructor: F
get() = F { node -> PyBoolLiteralExpressionImpl(node) }
override val parenthesizedExpressionConstructor: F
get() = F { node -> PyParenthesizedExpressionImpl(node) }
override val subscriptionExpressionConstructor: F
get() = F { node -> PySubscriptionExpressionImpl(node) }
override val sliceExpressionConstructor: F
get() = F { node -> PySliceExpressionImpl(node) }
override val sliceItemConstructor: F
get() = F { node -> PySliceItemImpl(node) }
override val binaryExpressionConstructor: F
get() = F { node -> PyBinaryExpressionImpl(node) }
override val prefixExpressionConstructor: F
get() = F { node -> PyPrefixExpressionImpl(node) }
override val callExpressionConstructor: F
get() = F { node -> PyCallExpressionImpl(node) }
override val listLiteralExpressionConstructor: F
get() = F { node -> PyListLiteralExpressionImpl(node) }
override val tupleExpressionConstructor: F
get() = F { node -> PyTupleExpressionImpl(node) }
override val keywordArgumentExpressionConstructor: F
get() = F { node -> PyKeywordArgumentImpl(node) }
override val starArgumentExpressionConstructor: F
get() = F { node -> PyStarArgumentImpl(node) }
override val lambdaExpressionConstructor: F
get() = F { node -> PyLambdaExpressionImpl(node) }
override val listCompExpressionConstructor: F
get() = F { node -> PyListCompExpressionImpl(node) }
override val dictLiteralExpressionConstructor: F
get() = F { node -> PyDictLiteralExpressionImpl(node) }
override val keyValueExpressionConstructor: F
get() = F { node -> PyKeyValueExpressionImpl(node) }
override val reprExpressionConstructor: F
get() = F { node -> PyReprExpressionImpl(node) }
override val generatorExpressionConstructor: F
get() = F { node -> PyGeneratorExpressionImpl(node) }
override val conditionalExpressionConstructor: F
get() = F { node -> PyConditionalExpressionImpl(node) }
override val yieldExpressionConstructor: F
get() = F { node -> PyYieldExpressionImpl(node) }
override val starExpressionConstructor: F
get() = F { node -> PyStarExpressionImpl(node) }
override val doubleStarExpressionConstructor: F
get() = F { node -> PyDoubleStarExpressionImpl(node) }
override val assignmentExpressionConstructor: F
get() = F { node -> PyAssignmentExpressionImpl(node) }
override val setLiteralExpressionConstructor: F
get() = F { node -> PySetLiteralExpressionImpl(node) }
override val setCompExpressionConstructor: F
get() = F { node -> PySetCompExpressionImpl(node) }
override val dictCompExpressionConstructor: F
get() = F { node -> PyDictCompExpressionImpl(node) }
override val ifPartIfConstructor: F
get() = F { node -> PyIfPartIfImpl(node) }
override val ifPartElifConstructor: F
get() = F { node -> PyIfPartElifImpl(node) }
override val forPartConstructor: F
get() = F { node -> PyForPartImpl(node) }
override val whilePartConstructor: F
get() = F { node -> PyWhilePartImpl(node) }
override val tryPartConstructor: F
get() = F { node -> PyTryPartImpl(node) }
override val finallyPartConstructor: F
get() = F { node -> PyFinallyPartImpl(node) }
override val elsePartConstructor: F
get() = F { node -> PyElsePartImpl(node) }
override val fStringNodeConstructor: F
get() = F { node -> PyFormattedStringElementImpl(node) }
override val fStringFragmentConstructor: F
get() = F { node -> PyFStringFragmentImpl(node) }
override val fStringFragmentFormatPartConstructor: F
get() = F { node -> PyFStringFragmentFormatPartImpl(node) }
override val matchStatementConstructor: F
get() = F { node -> PyMatchStatementImpl(node) }
override val caseClauseConstructor: F
get() = F { node -> PyCaseClauseImpl(node) }
override val literalPatternConstructor: F
get() = F { node -> PyLiteralPatternImpl(node) }
override val valuePatternConstructor: F
get() = F { node -> PyValuePatternImpl(node) }
override val capturePatternConstructor: F
get() = F { node -> PyCapturePatternImpl(node) }
override val wildcardPatternConstructor: F
get() = F { node -> PyWildcardPatternImpl(node) }
override val groupPatternConstructor: F
get() = F { node -> PyGroupPatternImpl(node) }
override val sequencePatternConstructor: F
get() = F { node -> PySequencePatternImpl(node) }
override val singleStarPatternConstructor: F
get() = F { node -> PySingleStarPatternImpl(node) }
override val doubleStarPatternConstructor: F
get() = F { node -> PyDoubleStarPatternImpl(node) }
override val mappingPatternConstructor: F
get() = F { node -> PyMappingPatternImpl(node) }
override val keyValuePatternConstructor: F
get() = F { node -> PyKeyValuePatternImpl(node) }
override val classPatternConstructor: F
get() = F { node -> PyClassPatternImpl(node) }
override val patternArgumentListConstructor: F
get() = F { node -> PyPatternArgumentListImpl(node) }
override val keywordPatternConstructor: F
get() = F { node -> PyKeywordPatternImpl(node) }
override val orPatternConstructor: F
get() = F { node -> PyOrPatternImpl(node) }
override val asPatternConstructor: F
get() = F { node -> PyAsPatternImpl(node) }
}

View File

@@ -0,0 +1,11 @@
package com.jetbrains.python
import com.intellij.psi.PsiElement
import com.jetbrains.python.psi.LanguageLevel
import com.jetbrains.python.psi.PyPsiFacade
class PyLanguageFacadeImpl : PyLanguageFacade() {
override fun forLanguage(psiElement: PsiElement): LanguageLevel {
return PyPsiFacade.getInstance(psiElement.project).getLanguageLevel(psiElement)
}
}

View File

@@ -19,7 +19,7 @@ import com.intellij.lang.SyntaxTreeBuilder;
import com.intellij.openapi.util.NlsContexts.ParsingError;
import com.intellij.psi.tree.IElementType;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.documentation.doctest.PyDocstringTokenTypes;
import com.jetbrains.python.parsing.ExpressionParsing;
@@ -71,14 +71,14 @@ public class PyFunctionTypeAnnotationParser extends PyParser {
if (atToken(PyTokenTypes.LPAR)) {
final SyntaxTreeBuilder.Marker funcTypeMark = myBuilder.mark();
parseParameterTypeList();
checkMatches(PyTokenTypes.RARROW, PyPsiBundle.message("rarrow.expected"));
checkMatches(PyTokenTypes.RARROW, PyParsingBundle.message("rarrow.expected"));
final boolean parsed = getExpressionParser().parseSingleExpression(false);
if (!parsed) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
}
funcTypeMark.done(PyFunctionTypeAnnotationElementTypes.FUNCTION_SIGNATURE);
}
recoverUntilMatches(PyPsiBundle.message("unexpected.tokens"));
recoverUntilMatches(PyParsingBundle.message("unexpected.tokens"));
}
private void parseParameterTypeList() {
@@ -90,7 +90,7 @@ public class PyFunctionTypeAnnotationParser extends PyParser {
int paramCount = 0;
while (!(atAnyOfTokens(PyTokenTypes.RPAR, PyTokenTypes.RARROW, PyTokenTypes.STATEMENT_BREAK) || myBuilder.eof()) ) {
if (paramCount > 0) {
checkMatches(PyTokenTypes.COMMA, PyPsiBundle.message("PARSE.expected.comma"));
checkMatches(PyTokenTypes.COMMA, PyParsingBundle.message("PARSE.expected.comma"));
}
boolean parsed;
if (atToken(PyTokenTypes.MULT)) {
@@ -109,12 +109,12 @@ public class PyFunctionTypeAnnotationParser extends PyParser {
parsed = exprParser.parseSingleExpression(false);
}
if (!parsed) {
myBuilder.error(PyPsiBundle.message("PARSE.expected.expression"));
recoverUntilMatches(PyPsiBundle.message("PARSE.expected.expression"), PyTokenTypes.COMMA, PyTokenTypes.RPAR, PyTokenTypes.RARROW, PyTokenTypes.STATEMENT_BREAK);
myBuilder.error(PyParsingBundle.message("PARSE.expected.expression"));
recoverUntilMatches(PyParsingBundle.message("PARSE.expected.expression"), PyTokenTypes.COMMA, PyTokenTypes.RPAR, PyTokenTypes.RARROW, PyTokenTypes.STATEMENT_BREAK);
}
paramCount++;
}
checkMatches(PyTokenTypes.RPAR, PyPsiBundle.message("PARSE.expected.rpar"));
checkMatches(PyTokenTypes.RPAR, PyParsingBundle.message("PARSE.expected.rpar"));
listMark.done(PyFunctionTypeAnnotationElementTypes.PARAMETER_TYPE_LIST);
}

View File

@@ -1034,7 +1034,8 @@ class PyTypeHintsInspection : PyInspection() {
else {
val newIndexText = newIndexElements.joinToString(prefix = "(", postfix = ")") { it.text }
val expression = PyElementGenerator.getInstance(project).createExpressionFromText(LanguageLevel.forElement(element), newIndexText)
val expression = PyElementGenerator.getInstance(project)
.createExpressionFromText(LanguageLevel.forElement(element), newIndexText)
val newIndex = (expression as? PyParenthesizedExpression)?.containedExpression as? PyTupleExpression ?: return
index.replace(newIndex)

View File

@@ -988,7 +988,8 @@ public final class PyUtil {
*/
public static boolean isPackage(@NotNull PsiDirectory directory, boolean checkSetupToolsPackages, @Nullable PsiElement anchor) {
if (isExplicitPackage(directory)) return true;
final LanguageLevel level = anchor != null ? LanguageLevel.forElement(anchor) : LanguageLevel.forElement(directory);
@NotNull PsiElement element = anchor != null ? anchor : directory;
final LanguageLevel level = LanguageLevel.forElement(element);
if (!level.isPython2()) {
return true;
}

View File

@@ -25,10 +25,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonDialectsTokenSetProvider;
import com.jetbrains.python.*;
import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
@@ -146,7 +143,7 @@ public class PyClassImpl extends PyBaseElementImpl<PyClassStub> implements PyCla
@Override
@Nullable
public PyTypeParameterList getTypeParameterList() {
return getStubOrPsiChild(PyElementTypes.TYPE_PARAMETER_LIST);
return getStubOrPsiChild(PyStubElementTypes.TYPE_PARAMETER_LIST);
}
@Override
@@ -250,7 +247,7 @@ public class PyClassImpl extends PyBaseElementImpl<PyClassStub> implements PyCla
@Nullable
@Override
public PyDecoratorList getDecoratorList() {
return getStubOrPsiChild(PyElementTypes.DECORATOR_LIST);
return getStubOrPsiChild(PyStubElementTypes.DECORATOR_LIST);
}
@Nullable

View File

@@ -13,10 +13,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.QualifiedName;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonDialectsTokenSetProvider;
import com.jetbrains.python.*;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.RatedResolveResult;
import com.jetbrains.python.psi.resolve.ResolveImportUtil;
@@ -106,7 +103,7 @@ public class PyFromImportStatementImpl extends PyBaseElementImpl<PyFromImportSta
@Override
@Nullable
public PyStarImportElement getStarImportElement() {
return getStubOrPsiChild(PyElementTypes.STAR_IMPORT_ELEMENT);
return getStubOrPsiChild(PyStubElementTypes.STAR_IMPORT_ELEMENT);
}
@Override

View File

@@ -18,10 +18,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.PlatformIcons;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.JBIterable;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonDialectsTokenSetProvider;
import com.jetbrains.python.*;
import com.jetbrains.python.codeInsight.controlflow.ControlFlowCache;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
@@ -67,7 +64,7 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Override
@Nullable
public PyTypeParameterList getTypeParameterList() {
return getStubOrPsiChild(PyElementTypes.TYPE_PARAMETER_LIST);
return getStubOrPsiChild(PyStubElementTypes.TYPE_PARAMETER_LIST);
}
private class CachedStructuredDocStringProvider implements CachedValueProvider<StructuredDocString> {
@@ -145,7 +142,7 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Override
public @NotNull PyParameterList getParameterList() {
return getRequiredStubOrPsiChild(PyElementTypes.PARAMETER_LIST);
return getRequiredStubOrPsiChild(PyStubElementTypes.PARAMETER_LIST);
}
@Override
@@ -186,7 +183,7 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Override
public @Nullable PyDecoratorList getDecoratorList() {
return getStubOrPsiChild(PyElementTypes.DECORATOR_LIST); // PsiTreeUtil.getChildOfType(this, PyDecoratorList.class);
return getStubOrPsiChild(PyStubElementTypes.DECORATOR_LIST); // PsiTreeUtil.getChildOfType(this, PyDecoratorList.class);
}
@Override
@@ -552,7 +549,7 @@ public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements
@Override
public PyAnnotation getAnnotation() {
return getStubOrPsiChild(PyElementTypes.ANNOTATION);
return getStubOrPsiChild(PyStubElementTypes.ANNOTATION);
}
@Override

View File

@@ -13,10 +13,7 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.IconManager;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.Processor;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.PythonDialectsTokenSetProvider;
import com.jetbrains.python.*;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
import com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider;
@@ -188,7 +185,7 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
@Override
public PyAnnotation getAnnotation() {
return getStubOrPsiChild(PyElementTypes.ANNOTATION);
return getStubOrPsiChild(PyStubElementTypes.ANNOTATION);
}
@Nullable

View File

@@ -6,6 +6,7 @@ import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.util.IncorrectOperationException;
import com.jetbrains.python.PyElementTypes;
import com.jetbrains.python.PyStubElementTypes;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.stubs.PyTypeAliasStatementStub;
@@ -61,7 +62,7 @@ public class PyTypeAliasStatementImpl extends PyBaseElementImpl<PyTypeAliasState
@Override
@Nullable
public PyTypeParameterList getTypeParameterList() {
return getStubOrPsiChild(PyElementTypes.TYPE_PARAMETER_LIST);
return getStubOrPsiChild(PyStubElementTypes.TYPE_PARAMETER_LIST);
}
@Override

View File

@@ -190,7 +190,7 @@ abstract public class IntroduceHandler implements RefactoringActionHandler {
return super.add(s);
}
};
String text = PyStringLiteralUtil.getStringValue(expression);
String text = PyPsiUtils.getStringValue(expression);
final Pair<PsiElement, TextRange> selection = expression.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE);
if (selection != null) {
text = selection.getSecond().substring(selection.getFirst().getText());

View File

@@ -6,6 +6,7 @@
<module value="com.intellij.modules.python"/>
<xi:include href="/META-INF/PythonParser.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/META-INF/PythonPsi.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/META-INF/PythonPsiImpl.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/META-INF/PythonSdk.xml" xpointer="xpointer(/idea-plugin/*)"/>

View File

@@ -5,7 +5,7 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.*;
import com.intellij.util.ArrayUtil;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.PyParsingBundle;
import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor;
import com.jetbrains.python.codeInsight.editorActions.smartEnter.SmartEnterUtil;
import com.jetbrains.python.psi.*;
@@ -83,6 +83,6 @@ public class PyCollectionLiteralFixer extends PyFixer<PySequenceExpression> {
private static boolean isMissingColonError(@NotNull PsiElement element) {
PsiErrorElement errorElement = as(element, PsiErrorElement.class);
return errorElement != null && PyPsiBundle.message("PARSE.expected.colon").equals(errorElement.getErrorDescription());
return errorElement != null && PyParsingBundle.message("PARSE.expected.colon").equals(errorElement.getErrorDescription());
}
}

View File

@@ -50,7 +50,7 @@ class PyUnifiedStubsTest : PyTestCase() {
doTest { level, file ->
val functionStub = file.topLevelFunctions[0].stub
val paramListStub: StubElement<*> = functionStub!!.childrenStubs[0]
assertNotNull("Function should contain star argument stub", paramListStub.findChildStubByType(PyElementTypes.SINGLE_STAR_PARAMETER))
assertNotNull("Function should contain star argument stub", paramListStub.findChildStubByType(PyStubElementTypes.SINGLE_STAR_PARAMETER))
level.isPython2
}
}
@@ -58,7 +58,7 @@ class PyUnifiedStubsTest : PyTestCase() {
fun testAnnotations() {
doTest { level, file ->
val functionStub = file.topLevelFunctions[0].stub
assertNotNull("Function should contain annotation stub", functionStub!!.findChildStubByType(PyElementTypes.ANNOTATION))
assertNotNull("Function should contain annotation stub", functionStub!!.findChildStubByType(PyStubElementTypes.ANNOTATION))
level.isPython2
}
}

View File

@@ -42,6 +42,8 @@ public class PythonConsoleParsingTest extends ParsingTestCase {
registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new PythonTokenSetContributor());
addExplicitExtension(LanguageASTFactory.INSTANCE, PythonLanguage.getInstance(), new PythonASTFactory());
getProject().registerService(PyPsiFacade.class, PyPsiFacadeImpl.class);
getApplication().registerService(PyElementTypesFacade.class, PyElementTypesFacadeImpl.class);
getApplication().registerService(PyLanguageFacade.class, PyLanguageFacadeImpl.class);
if (PythonRuntimeService.getInstance() == null) {
myServiceDisposable = Disposer.newDisposable();

View File

@@ -40,6 +40,8 @@ public class PythonParsingTest extends ParsingTestCase {
registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new PythonTokenSetContributor());
addExplicitExtension(LanguageASTFactory.INSTANCE, PythonLanguage.getInstance(), new PythonASTFactory());
getProject().registerService(PyPsiFacade.class, PyPsiFacadeImpl.class);
getApplication().registerService(PyElementTypesFacade.class, PyElementTypesFacadeImpl.class);
getApplication().registerService(PyLanguageFacade.class, PyLanguageFacadeImpl.class);
}
@Override