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.17.2
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.openrewrite.*; import org.openrewrite.internal.lang.Nullable; 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); } @Nullable default

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 = 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); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor final class TypeHint implements Py, TypeTree { public enum Kind { RETURN_TYPE, VARIABLE_TYPE, } @Getter @With @EqualsAndHashCode.Include UUID id; @Getter @With Space prefix; @Getter @With Markers markers; @Getter @With Kind kind; @Getter @With Expression expression; @Getter @With 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, onlyExplicitlyIncluded = 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); } } } @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @AllArgsConstructor final class ExpressionStatement implements Py, Expression, Statement { @With @Getter UUID id; @With @Getter Expression expression; // For backwards compatibility with older ASTs before there was an id field @SuppressWarnings("unused") public ExpressionStatement(Expression expression) { this.id = Tree.randomId(); this.expression = expression; } @Override public

J acceptPython(PythonVisitor

v, P p) { J j = v.visit(getExpression(), p); if (j instanceof ExpressionStatement) { return j; } else if (j instanceof Expression) { return withExpression((Expression) j); } return j; } @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); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = 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; @Nullable public 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, onlyExplicitlyIncluded = 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); } } } @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @AllArgsConstructor final class PassStatement implements Py, Statement { @With @Getter UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitPassStatement(this, p); } @Transient @Override public CoordinateBuilder.Statement getCoordinates() { return new CoordinateBuilder.Statement(this); } } @ToString @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = 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); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor final class ComprehensionExpression implements Py, Expression { public enum Kind { LIST, SET, DICT, GENERATOR } @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Kind kind; @With @Getter Expression result; @Getter @With List clauses; @With @Getter Space suffix; @Getter @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); } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor public static final class Condition implements Py { @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Expression expression; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitComprehensionCondition(this, p); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = 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); } } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor final class AwaitExpression implements Py, Expression { @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Expression expression; @With @Getter JavaType type; @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitAwaitExpression(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class YieldExpression implements Py, Expression { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; JLeftPadded from; List> expressions; @With @Getter JavaType type; public boolean isFrom() { return this.from.getElement(); } public YieldExpression withFrom(boolean from) { return this.getPadding().withFrom(JLeftPadded.withElement(this.from, from)); } public List getExpressions() { return JRightPadded.getElements(expressions); } public YieldExpression withExpressions(List expressions) { return this.getPadding().withExpressions(JRightPadded.withElements(this.expressions, expressions)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitYieldExpression(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 YieldExpression t; public JLeftPadded getFrom() { return t.from; } public YieldExpression withFrom(JLeftPadded from) { return from == t.from ? t : new YieldExpression(t.id, t.prefix, t.markers, from, t.expressions, t.type); } public List> getExpressions() { return t.expressions; } public YieldExpression withExpressions(List> expressions) { return expressions == t.expressions ? t : new YieldExpression(t.id, t.prefix, t.markers, t.from, expressions, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class VariableScopeStatement 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 VariableScopeStatement withNames(List names) { return this.getPadding().withNames(JRightPadded.withElements(this.names, names)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitVariableScopeStatement(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 VariableScopeStatement t; public List> getNames() { return t.names; } public VariableScopeStatement withNames(List> names) { return names == t.names ? t : new VariableScopeStatement(t.id, t.prefix, t.markers, t.kind, names); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class AssertStatement implements Py, Statement { @Nullable @NonFinal transient WeakReference padding; @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; List> expressions; public List getExpressions() { return JRightPadded.getElements(expressions); } public AssertStatement withExpressions(List expressions) { return this.getPadding().withExpressions(JRightPadded.withElements(this.expressions, expressions)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitAssertStatement(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 AssertStatement t; public List> getExpressions() { return t.expressions; } public AssertStatement withExpressions(List> expressions) { return expressions == t.expressions ? t : new AssertStatement(t.id, t.prefix, t.markers, expressions); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class DelStatement 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 DelStatement withTargets(List expressions) { return this.getPadding().withTargets(JRightPadded.withElements(this.targets, expressions)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitDelStatement(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 DelStatement t; public List> getTargets() { return t.targets; } public DelStatement withTargets(List> expressions) { return expressions == t.targets ? t : new DelStatement(t.id, t.prefix, t.markers, expressions); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor final class SpecialParameter implements Py, TypeTree { public enum Kind { KWARGS, ARGS, } @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter Kind kind; @With @Getter @Nullable TypeHint typeHint; @With @Getter @Nullable JavaType type; @Override public

J acceptPython(PythonVisitor

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

J acceptPython(PythonVisitor

v, P p) { return v.visitSpecialArgument(this, p); } @Override public CoordinateBuilder.Expression getCoordinates() { return new CoordinateBuilder.Expression(this); } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = 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 withFrom(JLeftPadded value) { return value == t.value ? t : new NamedArgument(t.id, t.prefix, t.markers, t.name, value, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = false) @RequiredArgsConstructor final class TypeHintedExpression implements Py, Expression { @With @Getter @EqualsAndHashCode.Include UUID id; @With @Getter Space prefix; @With @Getter Markers markers; @With @Getter TypeHint typeHint; @With @Getter Expression expression; @With @Getter @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, onlyExplicitlyIncluded = false) @RequiredArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) final class ErrorFromExpression 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 ErrorFromExpression withFrom(Expression from) { return this.getPadding().withFrom(this.from.withElement(from)); } @Override public

J acceptPython(PythonVisitor

v, P p) { return v.visitErrorFromExpression(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 ErrorFromExpression t; public JLeftPadded getFrom() { return t.from; } public ErrorFromExpression withFrom(JLeftPadded from) { return from == t.from ? t : new ErrorFromExpression(t.id, t.prefix, t.markers, t.error, from, t.type); } } } @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = 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, onlyExplicitlyIncluded = 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); } } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy