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 Oct 30, 2020
1 parent 0c09572 commit 0815044
Show file tree
Hide file tree
Showing 12 changed files with 263 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/**",
]) + select_for_ide(
android_studio = glob([
"com/google/idea/sdkcompat/cpp/**",
Expand All @@ -31,6 +32,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,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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
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/**",
]) + select_for_ide(
android_studio = glob([
"com/google/idea/sdkcompat/cpp/**",
Expand All @@ -31,6 +32,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,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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
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/**",
]) + select_for_ide(
android_studio = glob([
"com/google/idea/sdkcompat/cpp/**",
Expand All @@ -31,6 +32,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,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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 0815044

Please sign in to comment.