From c6dc0b048b000e299edb6a40d6a522a05991dfec Mon Sep 17 00:00:00 2001 From: Alice Kober-Sotzek Date: Thu, 12 Nov 2020 05:21:02 -0800 Subject: [PATCH] Python parts: Compatibility fixes for 2020.2 PiperOrigin-RevId: 342027212 --- sdkcompat/v193/BUILD | 2 ++ .../sdkcompat/python/PyParserAdapter.java | 23 +++++++++++++++++ .../python/SyntaxTreeBuilderWrapper.java | 25 +++++++++++++++++++ sdkcompat/v201/BUILD | 2 ++ .../sdkcompat/python/PyParserAdapter.java | 23 +++++++++++++++++ .../python/SyntaxTreeBuilderWrapper.java | 25 +++++++++++++++++++ sdkcompat/v202/BUILD | 2 ++ .../sdkcompat/python/PyParserAdapter.java | 23 +++++++++++++++++ .../python/SyntaxTreeBuilderWrapper.java | 25 +++++++++++++++++++ 9 files changed, 150 insertions(+) create mode 100644 sdkcompat/v193/com/google/idea/sdkcompat/python/PyParserAdapter.java create mode 100644 sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java create mode 100644 sdkcompat/v201/com/google/idea/sdkcompat/python/PyParserAdapter.java create mode 100644 sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java create mode 100644 sdkcompat/v202/com/google/idea/sdkcompat/python/PyParserAdapter.java create mode 100644 sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java diff --git a/sdkcompat/v193/BUILD b/sdkcompat/v193/BUILD index 9d68bab7be0..a1f00557c3c 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/**", "com/google/idea/sdkcompat/vcs/**", ]) + select_for_ide( android_studio = glob([ @@ -32,6 +33,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/PyParserAdapter.java b/sdkcompat/v193/com/google/idea/sdkcompat/python/PyParserAdapter.java new file mode 100644 index 00000000000..0b6845c7e98 --- /dev/null +++ b/sdkcompat/v193/com/google/idea/sdkcompat/python/PyParserAdapter.java @@ -0,0 +1,23 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compatibility adapter for {@link PyParser}. #api201 */ +public abstract class PyParserAdapter extends PyParser { + + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) { + return createParsingContext(SyntaxTreeBuilderWrapper.wrap(builder), languageLevel, futureFlag); + } + + protected abstract ParsingContext createParsingContext( + SyntaxTreeBuilderWrapper builder, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); +} diff --git a/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java b/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java new file mode 100644 index 00000000000..350e0227f0d --- /dev/null +++ b/sdkcompat/v193/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java @@ -0,0 +1,25 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import java.util.function.Supplier; + +/** + * Compatibility wrapper to support that constructor of ParsingContext uses new interface + * SyntaxTreeBuilder in 2020.2. #api201 + */ +public interface SyntaxTreeBuilderWrapper extends Supplier { + + static SyntaxTreeBuilderWrapper wrap(PsiBuilder builder) { + return () -> builder; + } + + /** + * #api201: Compatibility wrapper for marker which is represented by a new interface in 2020.2. + */ + interface MarkerWrapper extends Supplier { + + static MarkerWrapper wrap(PsiBuilder.Marker marker) { + return () -> marker; + } + } +} diff --git a/sdkcompat/v201/BUILD b/sdkcompat/v201/BUILD index 5304871e2fc..6436a97b0f3 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/**", "com/google/idea/sdkcompat/vcs/**", ]) + select_for_ide( android_studio = glob([ @@ -32,6 +33,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/PyParserAdapter.java b/sdkcompat/v201/com/google/idea/sdkcompat/python/PyParserAdapter.java new file mode 100644 index 00000000000..0b6845c7e98 --- /dev/null +++ b/sdkcompat/v201/com/google/idea/sdkcompat/python/PyParserAdapter.java @@ -0,0 +1,23 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compatibility adapter for {@link PyParser}. #api201 */ +public abstract class PyParserAdapter extends PyParser { + + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + PsiBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) { + return createParsingContext(SyntaxTreeBuilderWrapper.wrap(builder), languageLevel, futureFlag); + } + + protected abstract ParsingContext createParsingContext( + SyntaxTreeBuilderWrapper builder, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); +} diff --git a/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java b/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java new file mode 100644 index 00000000000..350e0227f0d --- /dev/null +++ b/sdkcompat/v201/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java @@ -0,0 +1,25 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.PsiBuilder; +import java.util.function.Supplier; + +/** + * Compatibility wrapper to support that constructor of ParsingContext uses new interface + * SyntaxTreeBuilder in 2020.2. #api201 + */ +public interface SyntaxTreeBuilderWrapper extends Supplier { + + static SyntaxTreeBuilderWrapper wrap(PsiBuilder builder) { + return () -> builder; + } + + /** + * #api201: Compatibility wrapper for marker which is represented by a new interface in 2020.2. + */ + interface MarkerWrapper extends Supplier { + + static MarkerWrapper wrap(PsiBuilder.Marker marker) { + return () -> marker; + } + } +} diff --git a/sdkcompat/v202/BUILD b/sdkcompat/v202/BUILD index 03bff7a9e20..c0607cbb03b 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/**", "com/google/idea/sdkcompat/vcs/**", ]) + select_for_ide( android_studio = glob([ @@ -32,6 +33,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/PyParserAdapter.java b/sdkcompat/v202/com/google/idea/sdkcompat/python/PyParserAdapter.java new file mode 100644 index 00000000000..ee0c64c85e2 --- /dev/null +++ b/sdkcompat/v202/com/google/idea/sdkcompat/python/PyParserAdapter.java @@ -0,0 +1,23 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.SyntaxTreeBuilder; +import com.jetbrains.python.parsing.ParsingContext; +import com.jetbrains.python.parsing.PyParser; +import com.jetbrains.python.parsing.StatementParsing; +import com.jetbrains.python.psi.LanguageLevel; + +/** Compatibility adapter for {@link PyParser}. #api201 */ +public abstract class PyParserAdapter extends PyParser { + + /** #api201: Super method uses new interface SyntaxTreeBuilder in 2020.2 */ + @Override + protected ParsingContext createParsingContext( + SyntaxTreeBuilder builder, LanguageLevel languageLevel, StatementParsing.FUTURE futureFlag) { + return createParsingContext(SyntaxTreeBuilderWrapper.wrap(builder), languageLevel, futureFlag); + } + + protected abstract ParsingContext createParsingContext( + SyntaxTreeBuilderWrapper builder, + LanguageLevel languageLevel, + StatementParsing.FUTURE futureFlag); +} diff --git a/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java b/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java new file mode 100644 index 00000000000..84f77ecee89 --- /dev/null +++ b/sdkcompat/v202/com/google/idea/sdkcompat/python/SyntaxTreeBuilderWrapper.java @@ -0,0 +1,25 @@ +package com.google.idea.sdkcompat.python; + +import com.intellij.lang.SyntaxTreeBuilder; +import java.util.function.Supplier; + +/** + * Compatibility wrapper to support that constructor of ParsingContext uses new interface + * SyntaxTreeBuilder in 2020.2. #api201 + */ +public interface SyntaxTreeBuilderWrapper extends Supplier { + + static SyntaxTreeBuilderWrapper wrap(SyntaxTreeBuilder builder) { + return () -> builder; + } + + /** + * #api201: Compatibility wrapper for marker which is represented by a new interface in 2020.2. + */ + interface MarkerWrapper extends Supplier { + + static MarkerWrapper wrap(SyntaxTreeBuilder.Marker marker) { + return () -> marker; + } + } +}