All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openrewrite.python.tree.Py Maven / Gradle / Ivy

There is a newer version: 1.24.4
Show newest version
/*
 * Copyright 2023 the original author or authors.
 * 

* 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 *

* https://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 org.openrewrite.python.tree; import lombok.*; import lombok.experimental.FieldDefaults; import lombok.experimental.NonFinal; import org.jspecify.annotations.Nullable; import org.openrewrite.*; import org.openrewrite.java.JavaPrinter; import org.openrewrite.java.internal.TypesInUse; import org.openrewrite.java.tree.*; import org.openrewrite.marker.Markers; import org.openrewrite.python.PythonVisitor; import org.openrewrite.python.internal.PythonPrinter; import java.beans.Transient; import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; public interface Py extends J { @SuppressWarnings("unchecked") @Override default R accept(TreeVisitor v, P p) { final String visitorName = v.getClass().getCanonicalName(); // FIXME HACK TO AVOID RUNTIME VISITOR-ADAPTING IN NATIVE IMAGE if (visitorName != null && visitorName.startsWith("io.moderne.serialization.")) { return (R) this; } return (R) acceptPython(v.adapt(PythonVisitor.class), p); } @Override default

boolean isAcceptable(TreeVisitor v, P p) { return v.isAdaptableTo(PythonVisitor.class); } default

@Nullable J acceptPython(PythonVisitor

v, P p) { return v.defaultValue(this, p); } @Override Space getPrefix(); @Override default List getComments() { return getPrefix().getComments(); } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) @Data final class Binary implements Py, Expression, TypedTree { @Nullable @NonFinal transient WeakReference padding; @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Expression left; JLeftPadded operator; public Type getOperator() { return operator.getElement(); } public Py.Binary withOperator(Type operator) { return getPadding().withOperator(this.operator.withElement(operator)); } @Nullable @With Space negation; @With Expression right; @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitBinary(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public enum Type { In, Is, IsNot, NotIn, FloorDivision, MatrixMultiplication, Power, StringConcatenation, } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @Override public String toString() { return withPrefix(Space.EMPTY).printTrimmed(new JavaPrinter<>()); } @RequiredArgsConstructor public static class Padding { private final Py.Binary t; public JLeftPadded getOperator() { return t.operator; } public Py.Binary withOperator(JLeftPadded operator) { return t.operator == operator ? t : new Py.Binary(t.id, t.prefix, t.markers, t.left, operator, t.negation, t.right, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @Data final class ExceptionType implements Py, TypeTree { @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With JavaType type; @With boolean isExceptionGroup; @With Expression expression; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitExceptionType(this, p); } } @Getter @With @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class TypeHint implements Py, TypeTree { @EqualsAndHashCode.Include UUID id; Space prefix; Markers markers; // Using `Expression` to also cater for `None` Expression typeTree; JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitTypeHint(this, p); } } @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class CompilationUnit implements Py, JavaSourceFile, SourceFile { @Nullable @NonFinal transient SoftReference typesInUse; @Nullable @NonFinal transient WeakReference padding; @EqualsAndHashCode.Include @With @Getter UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Path sourcePath; @With @Getter @Nullable FileAttributes fileAttributes; @Nullable // for backwards compatibility @With(AccessLevel.PRIVATE) String charsetName; @With @Getter boolean charsetBomMarked; @With @Getter @Nullable Checksum checksum; @Override public Charset getCharset() { return charsetName == null ? StandardCharsets.UTF_8 : Charset.forName(charsetName); } @SuppressWarnings("unchecked") @Override public SourceFile withCharset(Charset charset) { return withCharsetName(charset.name()); } List> imports; @Override public List getImports() { return JRightPadded.getElements(imports); } @Override public Py.CompilationUnit withImports(List imports) { return getPadding().withImports(JRightPadded.withElements(this.imports, imports)); } List> statements; public List getStatements() { return JRightPadded.getElements(statements); } public Py.CompilationUnit withStatements(List statements) { return getPadding().withStatements(JRightPadded.withElements(this.statements, statements)); } @With @Getter Space eof; @Override @Transient public List getClasses() { return statements.stream() .map(JRightPadded::getElement) .filter(J.ClassDeclaration.class::isInstance) .map(J.ClassDeclaration.class::cast) .collect(Collectors.toList()); } @Override public JavaSourceFile withClasses(List classes) { // FIXME unsupported return this; } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitCompilationUnit(this, p); } @Override public

TreeVisitor> printer(Cursor cursor) { return new PythonPrinter<>(); } @Override @Transient public TypesInUse getTypesInUse() { TypesInUse cache; if (this.typesInUse == null) { cache = TypesInUse.build(this); this.typesInUse = new SoftReference<>(cache); } else { cache = this.typesInUse.get(); if (cache == null || cache.getCu() != this) { cache = TypesInUse.build(this); this.typesInUse = new SoftReference<>(cache); } } return cache; } @Override public @Nullable Package getPackageDeclaration() { return null; } @Override public JavaSourceFile withPackageDeclaration(Package pkg) { throw new IllegalStateException("Python does not support package declarations"); } @Override public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding implements JavaSourceFile.Padding { private final Py.CompilationUnit t; @Override public List> getImports() { return t.imports; } @Override public Py.CompilationUnit withImports(List> imports) { return t.imports == imports ? t : new Py.CompilationUnit(t.id, t.prefix, t.markers, t.sourcePath, t.fileAttributes, t.charsetName, t.charsetBomMarked, null, imports, t.statements, t.eof); } public List> getStatements() { return t.statements; } public Py.CompilationUnit withStatements(List> statements) { return t.statements == statements ? t : new Py.CompilationUnit(t.id, t.prefix, t.markers, t.sourcePath, t.fileAttributes, t.charsetName, t.charsetBomMarked, t.checksum, t.imports, statements, t.eof); } } } @Getter @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @AllArgsConstructor final class ExpressionStatement implements Py, Expression, Statement { @With UUID id; @With Expression expression; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitExpressionStatement(this, p); } @Override public P2 withPrefix(Space space) { return (P2) withExpression(expression.withPrefix(space)); } @Override public Space getPrefix() { return expression.getPrefix(); } @Override public P2 withMarkers(Markers markers) { return (P2) withExpression(expression.withMarkers(markers)); } @Override public Markers getMarkers() { return expression.getMarkers(); } @Override public @Nullable JavaType getType() { return expression.getType(); } @Override public T withType(@Nullable JavaType type) { //noinspection unchecked return (T) withExpression(expression.withType(type)); } @Transient @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } } @Getter @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @AllArgsConstructor final class StatementExpression implements Py, Expression, Statement { @With UUID id; @With Statement statement; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitStatementExpression(this, p); } @Override public P2 withPrefix(Space space) { return (P2) withStatement(statement.withPrefix(space)); } @Override public Space getPrefix() { return statement.getPrefix(); } @Override public P2 withMarkers(Markers markers) { return (P2) withStatement(statement.withMarkers(markers)); } @Override public Markers getMarkers() { return statement.getMarkers(); } @Override public @Nullable JavaType getType() { return null; } @Override public T withType(@Nullable JavaType type) { return (T) this; } @Transient @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class MultiImport implements Py, Statement { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; @Nullable JRightPadded from; public @Nullable NameTree getFrom() { return from == null ? null : from.getElement(); } public MultiImport withFrom(NameTree from) { return getPadding().withFrom(JRightPadded.withElement(this.from, from)); } @Getter @With boolean parenthesized; JContainer names; public List getNames() { return this.names.getElements(); } public MultiImport withNames(List names) { return getPadding().withNames(JContainer.withElements(this.names, names)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitMultiImport(this, p); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final MultiImport t; public @Nullable JRightPadded getFrom() { return t.from; } public MultiImport withFrom(@Nullable JRightPadded from) { return t.from == from ? t : new MultiImport(t.id, t.prefix, t.markers, from, t.parenthesized, t.names); } public JContainer getNames() { return t.names; } public MultiImport withNames(JContainer names) { return t.names == names ? t : new MultiImport(t.id, t.prefix, t.markers, t.from, t.parenthesized, names); } } @Override @Transient public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } @Override public String toString() { return withPrefix(Space.EMPTY).printTrimmed(new PythonPrinter<>()); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class KeyValue implements Py, Expression, TypedTree { @Nullable @NonFinal transient WeakReference padding; @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; JRightPadded key; public Expression getKey() { return key.getElement(); } public KeyValue withKey(@Nullable Expression key) { return getPadding().withKey(JRightPadded.withElement(this.key, key)); } @Getter @With Expression value; @Getter @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitKeyValue(this, p); } @Transient @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final KeyValue t; public @Nullable JRightPadded getKey() { return t.key; } public KeyValue withKey(@Nullable JRightPadded key) { return t.key == key ? t : new KeyValue(t.id, t.prefix, t.markers, key, t.value, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class DictLiteral implements Py, Expression, TypedTree { @Nullable @NonFinal transient WeakReference padding; @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; JContainer elements; public List getElements() { return elements.getElements(); } public DictLiteral withElements(List elements) { return getPadding().withElements(JContainer.withElements(this.elements, elements)); } @Getter @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitDictLiteral(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final DictLiteral t; public JContainer getElements() { return t.elements; } public DictLiteral withElements(JContainer elements) { return t.elements == elements ? t : new DictLiteral(t.id, t.prefix, t.markers, elements, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class CollectionLiteral implements Py, Expression, TypedTree { public enum Kind { LIST, SET, TUPLE } @Nullable @NonFinal transient WeakReference padding; @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; @Getter @With Kind kind; JContainer elements; public List getElements() { return elements.getElements(); } public CollectionLiteral withElements(List elements) { return getPadding().withElements(JContainer.withElements(this.elements, elements)); } @Getter @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitCollectionLiteral(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final CollectionLiteral t; public JContainer getElements() { return t.elements; } public CollectionLiteral withElements(JContainer elements) { return t.elements == elements ? t : new CollectionLiteral(t.id, t.prefix, t.markers, t.kind, elements, t.type); } } } @Getter @With @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class FormattedString implements Py, Expression, TypedTree { @EqualsAndHashCode.Include UUID id; Space prefix; Markers markers; String delimiter; List parts; @Override public JavaType getType() { return JavaType.Primitive.String; } @Override public T withType(@Nullable JavaType type) { //noinspection unchecked return (T) this; } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitFormattedString(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) public static final class Value implements Py, Expression, TypedTree { public enum Conversion { STR, REPR, ASCII } @Nullable @NonFinal transient WeakReference padding; @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; JRightPadded expression; public Expression getExpression() { return expression.getElement(); } public Value withExpression(Expression expression) { return getPadding().withExpression(JRightPadded.withElement(this.expression, expression)); } @Nullable JRightPadded debug; public boolean isDebug() { return debug != null && debug.getElement(); } public Value withDebug(boolean debug) { return getPadding().withDebug(debug ? JRightPadded.withElement(this.debug, true) : null); } @Nullable @Getter @With Conversion conversion; @Nullable @Getter @With Expression format; @Override public JavaType getType() { return JavaType.Primitive.String; } @Override public T withType(@Nullable JavaType type) { //noinspection unchecked return (T) this; } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitFormattedStringValue(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final Value t; public JRightPadded getExpression() { return t.expression; } public Value withExpression(JRightPadded expression) { return t.expression == expression ? t : new Value(t.id, t.prefix, t.markers, expression, t.debug, t.conversion, t.format); } public @Nullable JRightPadded getDebug() { return t.debug; } public Value withDebug(@Nullable JRightPadded debug) { return t.debug == debug ? t : new Value(t.id, t.prefix, t.markers, t.expression, debug, t.conversion, t.format); } } } } @Getter @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @AllArgsConstructor final class Pass implements Py, Statement { @With UUID id; @With Space prefix; @With Markers markers; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitPass(this, p); } @Transient @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } } @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class TrailingElseWrapper implements Py, Statement { @Nullable @NonFinal transient WeakReference padding; @With @Getter UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Statement statement; JLeftPadded elseBlock; public Block getElseBlock() { return elseBlock.getElement(); } public TrailingElseWrapper withElseBlock(Block elseBlock) { return this.getPadding().withElseBlock(JLeftPadded.withElement(this.elseBlock, elseBlock)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitTrailingElseWrapper(this, p); } @Transient @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final TrailingElseWrapper t; public JLeftPadded getElseBlock() { return t.elseBlock; } public TrailingElseWrapper withElseBlock(JLeftPadded elseBlock) { return t.elseBlock == elseBlock ? t : new TrailingElseWrapper(t.padding, t.id, t.prefix, t.markers, t.statement, elseBlock); } } } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class ComprehensionExpression implements Py, Expression { public enum Kind { LIST, SET, DICT, GENERATOR } @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Kind kind; @With Expression result; @With List clauses; @With Space suffix; @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitComprehensionExpression(this, p); } @Transient @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor public static final class Condition implements Py { @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Expression expression; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitComprehensionCondition(this, p); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) public static final class Clause implements Py { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Expression iteratorVariable; JLeftPadded iteratedList; @With @Getter @Nullable List conditions; public Expression getIteratedList() { return this.iteratedList.getElement(); } public Clause withIteratedList(Expression expression) { return this.getPadding().withIteratedList(this.iteratedList.withElement(expression)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitComprehensionClause(this, p); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final Clause t; public JLeftPadded getIteratedList() { return t.iteratedList; } public Clause withIteratedList(JLeftPadded iteratedList) { return t.iteratedList == iteratedList ? t : new Clause(t.id, t.prefix, t.markers, t.iteratorVariable, iteratedList, t.conditions); } } } } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class Await implements Py, Expression { @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Expression expression; @With JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitAwait(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @Value @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) @With class YieldFrom implements Py, Expression { @Getter @EqualsAndHashCode.Include UUID id; Space prefix; Markers markers; Expression expression; JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitYieldFrom(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class VariableScope implements Py, Statement { public enum Kind { GLOBAL, NONLOCAL, } @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Kind kind; List> names; public List getNames() { return JRightPadded.getElements(names); } public VariableScope withNames(List names) { return this.getPadding().withNames(JRightPadded.withElements(this.names, names)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitVariableScope(this, p); } @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final VariableScope t; public List> getNames() { return t.names; } public VariableScope withNames(List> names) { return names == t.names ? t : new VariableScope(t.id, t.prefix, t.markers, t.kind, names); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class Del implements Py, Statement { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; List> targets; public List getTargets() { return JRightPadded.getElements(targets); } public Del withTargets(List expressions) { return this.getPadding().withTargets(JRightPadded.withElements(this.targets, expressions)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitDel(this, p); } @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final Del t; public List> getTargets() { return t.targets; } public Del withTargets(List> expressions) { return expressions == t.targets ? t : new Del(t.id, t.prefix, t.markers, expressions); } } } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class SpecialParameter implements Py, TypeTree { public enum Kind { KWARGS, ARGS, } @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Kind kind; @With @Nullable TypeHint typeHint; @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitSpecialParameter(this, p); } } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class Star implements Py, Expression { public enum Kind { LIST, DICT, } @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With Kind kind; @With Expression expression; @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitStar(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class NamedArgument implements Py, Expression { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter J.Identifier name; JLeftPadded value; @With @Getter @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitNamedArgument(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final NamedArgument t; public JLeftPadded getValue() { return t.value; } public NamedArgument withValue(JLeftPadded value) { return value == t.value ? t : new NamedArgument(t.id, t.prefix, t.markers, t.name, value, t.type); } } } @Getter @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor final class TypeHintedExpression implements Py, Expression { @With @EqualsAndHashCode.Include UUID id; @With Space prefix; @With Markers markers; @With TypeHint typeHint; @With Expression expression; @With @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitTypeHintedExpression(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class ErrorFrom implements Py, Expression { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Expression error; JLeftPadded from; @With @Getter JavaType type; public Expression getFrom() { return from.getElement(); } public ErrorFrom withFrom(Expression from) { return this.getPadding().withFrom(this.from.withElement(from)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitErrorFrom(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final ErrorFrom t; public JLeftPadded getFrom() { return t.from; } public ErrorFrom withFrom(JLeftPadded from) { return from == t.from ? t : new ErrorFrom(t.id, t.prefix, t.markers, t.error, from, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class MatchCase implements Py, Expression { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Pattern pattern; @Nullable JLeftPadded guard; @With @Getter @Nullable JavaType type; public @Nullable Expression getGuard() { return guard == null ? null : guard.getElement(); } public MatchCase withGuard(Expression guard) { return this.getPadding().withGuard( JLeftPadded.withElement(this.guard, guard) ); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitMatchCase(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final MatchCase t; public @Nullable JLeftPadded getGuard() { return t.guard; } public MatchCase withGuard(JLeftPadded guard) { return guard == t.guard ? t : new MatchCase(t.id, t.prefix, t.markers, t.pattern, guard, null); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) public final static class Pattern implements Py, Expression { public enum Kind { AS, CAPTURE, CLASS, DOUBLE_STAR, GROUP, KEY_VALUE, KEYWORD, LITERAL, MAPPING, OR, SEQUENCE, SEQUENCE_LIST, SEQUENCE_TUPLE, STAR, VALUE, WILDCARD, } @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Kind kind; JContainer children; @With @Getter @Nullable JavaType type; public List getChildren() { return children.getElements(); } public Pattern withChildren(List children) { return this.getPadding().withChildren( JContainer.withElements(this.children, children) ); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitMatchCasePattern(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final Pattern t; public JContainer getChildren() { return t.children; } public Pattern withChildren(JContainer children) { return children == t.children ? t : new Pattern(t.id, t.prefix, t.markers, t.kind, children, t.type); } } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class Slice implements Py, Expression, TypedTree { @Nullable @NonFinal transient WeakReference padding; @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; @Nullable JRightPadded start; public @Nullable Expression getStart() { return start != null ? start.getElement() : null; } public Slice withStart(@Nullable Expression start) { return getPadding().withStart(JRightPadded.withElement(this.start, start)); } @Nullable JRightPadded stop; public @Nullable Expression getStop() { return stop != null ? stop.getElement() : null; } public Slice withStop(@Nullable Expression stop) { return getPadding().withStop(JRightPadded.withElement(this.stop, stop)); } @Nullable JRightPadded step; public @Nullable Expression getStep() { return step != null ? step.getElement() : null; } public Slice withStep(@Nullable Expression step) { return getPadding().withStep(JRightPadded.withElement(this.step, step)); } @Override public @Nullable JavaType getType() { return null; } @Override public T withType(@Nullable JavaType type) { //noinspection unchecked return (T) this; } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitSlice(this, p); } @Override @Transient public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } public Padding getPadding() { Padding p; if (this.padding == null) { p = new Padding(this); this.padding = new WeakReference<>(p); } else { p = this.padding.get(); if (p == null || p.t != this) { p = new Padding(this); this.padding = new WeakReference<>(p); } } return p; } @RequiredArgsConstructor public static class Padding { private final Slice t; public @Nullable JRightPadded getStart() { return t.start; } public Slice withStart(@Nullable JRightPadded start) { return t.start == start ? t : new Slice(t.id, t.prefix, t.markers, start, t.stop, t.step); } public @Nullable JRightPadded getStop() { return t.stop; } public Slice withStop(@Nullable JRightPadded stop) { return t.stop == stop ? t : new Slice(t.id, t.prefix, t.markers, t.start, stop, t.step); } public @Nullable JRightPadded getStep() { return t.step; } public Slice withStep(@Nullable JRightPadded step) { return t.step == step ? t : new Slice(t.id, t.prefix, t.markers, t.start, step, t.step); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy