diff --git a/sdkcompat/v193/BUILD b/sdkcompat/v193/BUILD index 9f556f62e58..2a5f9dae648 100644 --- a/sdkcompat/v193/BUILD +++ b/sdkcompat/v193/BUILD @@ -9,6 +9,7 @@ java_library( srcs = glob([ "com/google/idea/sdkcompat/general/**", "com/google/idea/sdkcompat/platform/**", + "com/google/idea/sdkcompat/python/**", ]) + select_for_ide( android_studio = glob([ "com/google/idea/sdkcompat/cpp/**", @@ -31,6 +32,7 @@ java_library( deps = [ "//intellij_platform_sdk:jsr305", "//intellij_platform_sdk:plugin_api", + "//third_party/python", "//third_party/scala", ], ) diff --git a/sdkcompat/v193/com/google/idea/sdkcompat/python/FunctionParsingCompat.java b/sdkcompat/v193/com/google/idea/sdkcompat/python/FunctionParsingCompat.java new file mode 100644 index 00000000000..b5ad812b8c0 --- /dev/null +++ b/sdkcompat/v193/com/google/idea/sdkcompat/python/FunctionParsingCompat.java @@ -0,0 +1,32 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiBuilder.Marker; +import com.intellij.psi.tree.IElementType; +import com.jetbrains.python.parsing.FunctionParsing; +import com.jetbrains.python.parsing.ParsingContext; + +/** #api201: Compat class for {@link FunctionParsing}. */ +public class FunctionParsingCompat extends FunctionParsing { + + public FunctionParsingCompat(ParsingContext context) { + super(context); + } + + protected MarkerCompat getMarker() { + return new MarkerCompat(myBuilder.mark()); + } + + /** #api201: Compat class for marker which is represented by a new interface in 2020.2. */ + protected static class MarkerCompat { + private final PsiBuilder.Marker marker; + + private MarkerCompat(Marker marker) { + this.marker = marker; + } + + public void done(IElementType type) { + marker.done(type); + } + } +} diff --git a/sdkcompat/v193/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java b/sdkcompat/v193/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java new file mode 100644 index 00000000000..ae1a05827b3 --- /dev/null +++ b/sdkcompat/v193/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java @@ -0,0 +1,33 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiParser; +import com.intellij.openapi.project.Project; +import com.jetbrains.python.PythonParserDefinition; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compat class for {@link PythonParserDefinition}. #api201 */ +public abstract class PythonParserDefinitionCompat extends PythonParserDefinition { + + protected abstract ParsingContext createCustomParsingContext( + Project project, + SyntaxTreeBuilderCompat builderCompat, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); + + @Override + public PsiParser createParser(Project project) { + return new PyParser() { + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) { + return createCustomParsingContext( + project, new SyntaxTreeBuilderCompat(builder), languageLevel, futureFlag); + } + }; + } +} diff --git a/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java b/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java new file mode 100644 index 00000000000..a7304fd2293 --- /dev/null +++ b/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java @@ -0,0 +1,20 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; + +/** + * Compat class to support that constructor of ParsingContext uses new interface SyntaxTreeBuilder + * in 2020.2. #api201 + */ +public class SyntaxTreeBuilderCompat { + + private final PsiBuilder builder; + + public SyntaxTreeBuilderCompat(PsiBuilder builder) { + this.builder = builder; + } + + public PsiBuilder getBuilder() { + return builder; + } +} diff --git a/sdkcompat/v201/BUILD b/sdkcompat/v201/BUILD index c833eda1f88..88fd62f643b 100644 --- a/sdkcompat/v201/BUILD +++ b/sdkcompat/v201/BUILD @@ -9,6 +9,7 @@ java_library( srcs = glob([ "com/google/idea/sdkcompat/general/**", "com/google/idea/sdkcompat/platform/**", + "com/google/idea/sdkcompat/python/**", ]) + select_for_ide( android_studio = glob([ "com/google/idea/sdkcompat/cpp/**", @@ -31,6 +32,7 @@ java_library( deps = [ "//intellij_platform_sdk:jsr305", "//intellij_platform_sdk:plugin_api", + "//third_party/python", "//third_party/scala", ], ) diff --git a/sdkcompat/v201/com/google/idea/sdkcompat/python/FunctionParsingCompat.java b/sdkcompat/v201/com/google/idea/sdkcompat/python/FunctionParsingCompat.java new file mode 100644 index 00000000000..b5ad812b8c0 --- /dev/null +++ b/sdkcompat/v201/com/google/idea/sdkcompat/python/FunctionParsingCompat.java @@ -0,0 +1,32 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiBuilder.Marker; +import com.intellij.psi.tree.IElementType; +import com.jetbrains.python.parsing.FunctionParsing; +import com.jetbrains.python.parsing.ParsingContext; + +/** #api201: Compat class for {@link FunctionParsing}. */ +public class FunctionParsingCompat extends FunctionParsing { + + public FunctionParsingCompat(ParsingContext context) { + super(context); + } + + protected MarkerCompat getMarker() { + return new MarkerCompat(myBuilder.mark()); + } + + /** #api201: Compat class for marker which is represented by a new interface in 2020.2. */ + protected static class MarkerCompat { + private final PsiBuilder.Marker marker; + + private MarkerCompat(Marker marker) { + this.marker = marker; + } + + public void done(IElementType type) { + marker.done(type); + } + } +} diff --git a/sdkcompat/v201/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java b/sdkcompat/v201/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java new file mode 100644 index 00000000000..ae1a05827b3 --- /dev/null +++ b/sdkcompat/v201/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java @@ -0,0 +1,33 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.intellij.lang.PsiParser; +import com.intellij.openapi.project.Project; +import com.jetbrains.python.PythonParserDefinition; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compat class for {@link PythonParserDefinition}. #api201 */ +public abstract class PythonParserDefinitionCompat extends PythonParserDefinition { + + protected abstract ParsingContext createCustomParsingContext( + Project project, + SyntaxTreeBuilderCompat builderCompat, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); + + @Override + public PsiParser createParser(Project project) { + return new PyParser() { + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) { + return createCustomParsingContext( + project, new SyntaxTreeBuilderCompat(builder), languageLevel, futureFlag); + } + }; + } +} diff --git a/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java b/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java new file mode 100644 index 00000000000..a7304fd2293 --- /dev/null +++ b/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java @@ -0,0 +1,20 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; + +/** + * Compat class to support that constructor of ParsingContext uses new interface SyntaxTreeBuilder + * in 2020.2. #api201 + */ +public class SyntaxTreeBuilderCompat { + + private final PsiBuilder builder; + + public SyntaxTreeBuilderCompat(PsiBuilder builder) { + this.builder = builder; + } + + public PsiBuilder getBuilder() { + return builder; + } +} diff --git a/sdkcompat/v202/BUILD b/sdkcompat/v202/BUILD index 27dce3b987a..d294a8d25c1 100644 --- a/sdkcompat/v202/BUILD +++ b/sdkcompat/v202/BUILD @@ -9,6 +9,7 @@ java_library( srcs = glob([ "com/google/idea/sdkcompat/general/**", "com/google/idea/sdkcompat/platform/**", + "com/google/idea/sdkcompat/python/**", ]) + select_for_ide( android_studio = glob([ "com/google/idea/sdkcompat/cpp/**", @@ -31,6 +32,7 @@ java_library( deps = [ "//intellij_platform_sdk:jsr305", "//intellij_platform_sdk:plugin_api", + "//third_party/python", "//third_party/scala", ], ) diff --git a/sdkcompat/v202/com/google/idea/sdkcompat/python/FunctionParsingCompat.java b/sdkcompat/v202/com/google/idea/sdkcompat/python/FunctionParsingCompat.java new file mode 100644 index 00000000000..75100290996 --- /dev/null +++ b/sdkcompat/v202/com/google/idea/sdkcompat/python/FunctionParsingCompat.java @@ -0,0 +1,32 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.SyntaxTreeBuilder; +import com.intellij.lang.SyntaxTreeBuilder.Marker; +import com.intellij.psi.tree.IElementType; +import com.jetbrains.python.parsing.FunctionParsing; +import com.jetbrains.python.parsing.ParsingContext; + +/** #api201: Compat class for {@link FunctionParsing}. */ +public class FunctionParsingCompat extends FunctionParsing { + + public FunctionParsingCompat(ParsingContext context) { + super(context); + } + + protected MarkerCompat getMarker() { + return new MarkerCompat(myBuilder.mark()); + } + + /** #api201: Compat class for marker which is represented by a new interface in 2020.2. */ + protected static class MarkerCompat { + private final SyntaxTreeBuilder.Marker marker; + + private MarkerCompat(Marker marker) { + this.marker = marker; + } + + public void done(IElementType type) { + marker.done(type); + } + } +} diff --git a/sdkcompat/v202/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java b/sdkcompat/v202/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java new file mode 100644 index 00000000000..d199f261138 --- /dev/null +++ b/sdkcompat/v202/com/google/idea/sdkcompat/python/PythonParserDefinitionCompat.java @@ -0,0 +1,35 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiParser; +import com.intellij.lang.SyntaxTreeBuilder; +import com.intellij.openapi.project.Project; +import com.jetbrains.python.PythonParserDefinition; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compat class for {@link PythonParserDefinition}. #api201 */ +public abstract class PythonParserDefinitionCompat extends PythonParserDefinition { + + protected abstract ParsingContext createCustomParsingContext( + Project project, + SyntaxTreeBuilderCompat builderCompat, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); + + @Override + public PsiParser createParser(Project project) { + return new PyParser() { + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + SyntaxTreeBuilder builder, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag) { + return createCustomParsingContext( + project, new SyntaxTreeBuilderCompat(builder), languageLevel, futureFlag); + } + }; + } +} diff --git a/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java b/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java new file mode 100644 index 00000000000..56854512c40 --- /dev/null +++ b/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderCompat.java @@ -0,0 +1,20 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.SyntaxTreeBuilder; + +/** + * Compat class to support that constructor of ParsingContext uses new interface SyntaxTreeBuilder + * in 2020.2. #api201 + */ +public class SyntaxTreeBuilderCompat { + + private final SyntaxTreeBuilder builder; + + public SyntaxTreeBuilderCompat(SyntaxTreeBuilder builder) { + this.builder = builder; + } + + public SyntaxTreeBuilder getBuilder() { + return builder; + } +}