Skip to content

Commit

Permalink
Python parts: Compatibility fixes for 2020.2
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 338496735
  • Loading branch information
alice-ks authored and copybara-github committed Nov 12, 2020
1 parent 6fd7565 commit bdd0f25
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdkcompat/v193/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -32,6 +33,7 @@ java_library(
deps = [
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:plugin_api",
"//third_party/python",
"//third_party/scala",
],
)
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<PsiBuilder> {

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<PsiBuilder.Marker> {

static MarkerWrapper wrap(PsiBuilder.Marker marker) {
return () -> marker;
}
}
}
2 changes: 2 additions & 0 deletions sdkcompat/v201/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -32,6 +33,7 @@ java_library(
deps = [
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:plugin_api",
"//third_party/python",
"//third_party/scala",
],
)
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<PsiBuilder> {

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<PsiBuilder.Marker> {

static MarkerWrapper wrap(PsiBuilder.Marker marker) {
return () -> marker;
}
}
}
2 changes: 2 additions & 0 deletions sdkcompat/v202/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -32,6 +33,7 @@ java_library(
deps = [
"//intellij_platform_sdk:jsr305",
"//intellij_platform_sdk:plugin_api",
"//third_party/python",
"//third_party/scala",
],
)
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<SyntaxTreeBuilder> {

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<SyntaxTreeBuilder.Marker> {

static MarkerWrapper wrap(SyntaxTreeBuilder.Marker marker) {
return () -> marker;
}
}
}

0 comments on commit bdd0f25

Please sign in to comment.