/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://docs.moderne.io/licensing/moderne-source-available-license
*
* 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.csharp.tree;
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.*;
import lombok.experimental.FieldDefaults;
import lombok.experimental.NonFinal;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.csharp.CSharpPrinter;
import org.openrewrite.csharp.CSharpVisitor;
import org.openrewrite.csharp.service.CSharpNamingService;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.NamingService;
import org.openrewrite.java.JavaPrinter;
import org.openrewrite.java.JavaTypeVisitor;
import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.internal.TypesInUse;
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.Marker;
import org.openrewrite.marker.Markers;
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.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static java.util.Collections.singletonList;
public interface Cs extends J {
@SuppressWarnings("unchecked")
@Override
default R accept(TreeVisitor v, P p) {
return (R) acceptCSharp(v.adapt(CSharpVisitor.class), p);
}
@Override
default boolean isAcceptable(TreeVisitor, P> v, P p) {
return v.isAdaptableTo(CSharpVisitor.class);
}
@Nullable J acceptCSharp(CSharpVisitor
v, P p);
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class CompilationUnit implements Cs, JavaSourceFile {
@Nullable
@NonFinal
transient SoftReference typesInUse;
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
@Getter
@With
Path sourcePath;
@Getter
@With
@Nullable
FileAttributes fileAttributes;
@Getter
@Nullable
@With(AccessLevel.PRIVATE)
String charsetName;
@Getter
@With
boolean charsetBomMarked;
@Getter
@With
@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());
}
@Override
public @Nullable Package getPackageDeclaration() {
return null;
}
@Override
public Cs.CompilationUnit withPackageDeclaration(Package packageDeclaration) {
return this;
}
List> externs;
public List getExterns() {
return JRightPadded.getElements(externs);
}
public Cs.CompilationUnit withExterns(List externs) {
return getPadding().withExterns(JRightPadded.withElements(this.externs, externs));
}
List> usings;
public List getUsings() {
return JRightPadded.getElements(usings);
}
public Cs.CompilationUnit withUsings(List usings) {
return getPadding().withUsings(JRightPadded.withElements(this.usings, usings));
}
@Getter
@With
List attributeLists;
List> members;
public List getMembers() {
return JRightPadded.getElements(members);
}
public Cs.CompilationUnit withMembers(List members) {
return getPadding().withMembers(JRightPadded.withElements(this.members, members));
}
@Override
@Transient
public List getImports() {
return Collections.emptyList();
}
@Override
public Cs.CompilationUnit withImports(List imports) {
return this;
}
@Override
@Transient
public List getClasses() {
return Collections.emptyList();
}
@Override
public JavaSourceFile withClasses(List classes) {
return this;
}
@Getter
@With
Space eof;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitCompilationUnit(this, p);
}
@Override
public
TreeVisitor, PrintOutputCapture
> printer(Cursor cursor) {
return new CSharpPrinter<>();
}
@Override
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;
}
@Transient
@Override
public long getWeight(Predicate uniqueIdentity) {
AtomicInteger n = new AtomicInteger();
new CSharpVisitor() {
final JavaTypeVisitor typeVisitor = new JavaTypeVisitor() {
@Override
public JavaType visit(@Nullable JavaType javaType, AtomicInteger n) {
if (javaType != null && uniqueIdentity.test(javaType)) {
n.incrementAndGet();
return super.visit(javaType, n);
}
//noinspection ConstantConditions
return javaType;
}
};
@Override
public J preVisit(J tree, AtomicInteger n) {
n.incrementAndGet();
return tree;
}
@Override
public JavaType visitType(@Nullable JavaType javaType, AtomicInteger n) {
return typeVisitor.visit(javaType, n);
}
}.visit(this, n);
return n.get();
}
@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;
}
@Override
@Incubating(since = "8.2.0")
public T service(Class service) {
if (NamingService.class.getName().equals(service.getName())) {
return (T) new CSharpNamingService();
}
return JavaSourceFile.super.service(service);
}
@RequiredArgsConstructor
public static class Padding implements JavaSourceFile.Padding {
private final Cs.CompilationUnit t;
@Override
public List> getImports() {
return Collections.emptyList();
}
@Override
public JavaSourceFile withImports(List> imports) {
return t;
}
public List> getMembers() {
return t.members;
}
public Cs.CompilationUnit withMembers(List> members) {
return t.members == members ? t : new Cs.CompilationUnit(t.id, t.prefix, t.markers, t.sourcePath, t.fileAttributes, t.charsetName, t.charsetBomMarked, t.checksum, t.externs, t.usings, t.attributeLists, members, t.eof);
}
public List> getExterns() {
return t.externs;
}
public Cs.CompilationUnit withExterns(List> externs) {
return t.externs == externs ? t : new Cs.CompilationUnit(t.id, t.prefix, t.markers, t.sourcePath, t.fileAttributes, t.charsetName, t.charsetBomMarked, t.checksum, externs, t.usings, t.attributeLists, t.members, t.eof);
}
public List> getUsings() {
return t.usings;
}
public Cs.CompilationUnit withUsings(List> usings) {
return t.usings == usings ? t : new Cs.CompilationUnit(t.id, t.prefix, t.markers, t.sourcePath, t.fileAttributes, t.charsetName, t.charsetBomMarked, t.checksum, t.externs, usings, t.attributeLists, t.members, t.eof);
}
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class ForEachVariableLoop implements Cs, Loop {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
Control controlElement;
JRightPadded body;
@Override
public Statement getBody() {
return body.getElement();
}
@Override
@SuppressWarnings("unchecked")
public ForEachVariableLoop withBody(Statement body) {
return getPadding().withBody(this.body.withElement(body));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitForEachVariableLoop(this, p);
}
@Override
@Transient
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)
public static final class Control implements Cs {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
JRightPadded variable;
public Expression getVariable() {
return variable.getElement();
}
public Control withVariable(Expression variable) {
return getPadding().withVariable(this.variable.withElement(variable));
}
JRightPadded iterable;
public Expression getIterable() {
return iterable.getElement();
}
public Control withIterable(Expression iterable) {
return getPadding().withIterable(this.iterable.withElement(iterable));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitForEachVariableLoopControl(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;
}
@Override
public String toString() {
return withPrefix(Space.EMPTY).printTrimmed(new JavaPrinter<>());
}
@RequiredArgsConstructor
public static class Padding {
private final Control t;
public JRightPadded getVariable() {
return t.variable;
}
public Control withVariable(JRightPadded variable) {
return t.variable == variable ? t : new Control(t.id, t.prefix, t.markers, variable, t.iterable);
}
public JRightPadded getIterable() {
return t.iterable;
}
public Control withIterable(JRightPadded iterable) {
return t.iterable == iterable ? t : new Control(t.id, t.prefix, t.markers, t.variable, iterable);
}
}
}
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 Cs.ForEachVariableLoop t;
public JRightPadded getBody() {
return t.body;
}
public ForEachVariableLoop withBody(JRightPadded body) {
return t.body == body ? t : new ForEachVariableLoop(t.id, t.prefix, t.markers, t.controlElement, body);
}
}
}
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class Argument implements Cs, Expression {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@Getter
@EqualsAndHashCode.Include
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@Nullable
JRightPadded nameColumn;
@Nullable
@Getter
@With
Keyword refKindKeyword;
public @Nullable Identifier getNameColumn() {
return nameColumn == null ? null : nameColumn.getElement();
}
public Argument withNameColumn(@Nullable Identifier nameColumn) {
return getPadding().withNameColumn(JRightPadded.withElement(this.nameColumn, nameColumn));
}
@With
Expression expression;
@Override
public @Nullable JavaType getType() {
return expression.getType();
}
@SuppressWarnings("unchecked")
@Override
public Argument withType(@Nullable JavaType type) {
return expression.getType() == type ? this : new Argument(id, prefix, markers, nameColumn, refKindKeyword, expression.withType(type));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitArgument(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;
}
@Override
@Transient
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
@Override
public String toString() {
return withPrefix(Space.EMPTY).printTrimmed(new CSharpPrinter<>());
}
@RequiredArgsConstructor
public static class Padding {
private final Argument t;
public @Nullable JRightPadded getNameColumn() {
return t.nameColumn;
}
public Argument withNameColumn(@Nullable JRightPadded target) {
return t.nameColumn == target ? t : new Argument(t.id, t.prefix, t.markers, target, t.refKindKeyword, t.expression);
}
}
}
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
final class AnnotatedStatement implements Cs, Statement {
@With
@EqualsAndHashCode.Include
UUID id;
@With
Space prefix;
@With
Markers markers;
@With
List attributeLists;
@With
Statement statement;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitAnnotatedStatement(this, p);
}
@Override
@Transient
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public String toString() {
return withPrefix(Space.EMPTY).printTrimmed(new CSharpPrinter<>());
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class ArrayRankSpecifier implements Cs, Expression {
@Nullable
@NonFinal
transient WeakReference padding;
@EqualsAndHashCode.Include
@Getter
@With
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
JContainer sizes;
public List getSizes() {
return sizes.getElements();
}
public ArrayRankSpecifier withSizes(List sizes) {
return getPadding().withSizes(JContainer.withElements(this.sizes, sizes));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitArrayRankSpecifier(this, p);
}
@Override
public @Nullable JavaType getType() {
return sizes.getElements().isEmpty() ? null : sizes.getPadding().getElements().get(0).getElement().getType();
}
@Override
public T withType(@Nullable JavaType type) {
throw new IllegalArgumentException("Cannot set type on " + getClass());
}
@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 ArrayRankSpecifier t;
public @Nullable JContainer getSizes() {
return t.sizes;
}
public ArrayRankSpecifier withSizes(@Nullable JContainer sizes) {
return t.sizes == sizes ? t : new ArrayRankSpecifier(t.id, t.prefix, t.markers, sizes);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class AssignmentOperation implements Cs, Statement, Expression, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
Expression variable;
JLeftPadded operator;
public OperatorType getOperator() {
return operator.getElement();
}
public Cs.AssignmentOperation withOperator(OperatorType operator) {
return getPadding().withOperator(this.operator.withElement(operator));
}
@With
@Getter
Expression assignment;
@With
@Nullable
@Getter
JavaType type;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitAssignmentOperation(this, p);
}
@Override
@Transient
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
@Transient
public List getSideEffects() {
return singletonList(this);
}
public enum OperatorType {
NullCoalescing
}
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 CSharpPrinter<>());
}
@RequiredArgsConstructor
public static class Padding {
private final Cs.AssignmentOperation t;
public JLeftPadded getOperator() {
return t.operator;
}
public Cs.AssignmentOperation withOperator(JLeftPadded operator) {
return t.operator == operator ? t : new Cs.AssignmentOperation(t.id, t.prefix, t.markers, t.variable, operator, t.assignment, t.type);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class AttributeList implements Cs {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@Nullable
JRightPadded target;
public @Nullable Identifier getTarget() {
return target == null ? null : target.getElement();
}
public AttributeList withTarget(@Nullable Identifier target) {
return getPadding().withTarget(JRightPadded.withElement(this.target, target));
}
List> attributes;
public List getAttributes() {
return JRightPadded.getElements(attributes);
}
public AttributeList withAttributes(List attributes) {
return getPadding().withAttributes(JRightPadded.withElements(this.attributes, attributes));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitAttributeList(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;
}
@Override
public String toString() {
return withPrefix(Space.EMPTY).printTrimmed(new JavaPrinter<>());
}
@RequiredArgsConstructor
public static class Padding {
private final AttributeList t;
public @Nullable JRightPadded getTarget() {
return t.target;
}
public AttributeList withTarget(@Nullable JRightPadded target) {
return t.target == target ? t : new AttributeList(t.id, t.prefix, t.markers, target, t.attributes);
}
public List> getAttributes() {
return t.attributes;
}
public AttributeList withAttributes(List> attributes) {
return t.attributes == attributes ? t : new AttributeList(t.id, t.prefix, t.markers, t.target, attributes);
}
}
}
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@With
final class AwaitExpression implements Cs, Expression, Statement {
@EqualsAndHashCode.Include
UUID id;
Space prefix;
Markers markers;
J expression;
@Nullable
JavaType type;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitAwaitExpression(this, p);
}
@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)
@Data
final class Binary implements Cs, Expression, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
UUID id;
@With
Space prefix;
@With
Markers markers;
@With
Expression left;
JLeftPadded operator;
public OperatorType getOperator() {
return operator.getElement();
}
public Cs.Binary withOperator(OperatorType operator) {
return getPadding().withOperator(this.operator.withElement(operator));
}
@With
Expression right;
@With
@Nullable
JavaType type;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitBinary(this, p);
}
@Override
@Transient
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
@Transient
@Override
public List getSideEffects() {
List sideEffects = new ArrayList<>(2);
sideEffects.addAll(left.getSideEffects());
sideEffects.addAll(right.getSideEffects());
return sideEffects;
}
public enum OperatorType {
As,
NullCoalescing
}
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 CSharpPrinter<>());
}
@RequiredArgsConstructor
public static class Padding {
private final Cs.Binary t;
public JLeftPadded getOperator() {
return t.operator;
}
public Cs.Binary withOperator(JLeftPadded operator) {
return t.operator == operator ? t : new Cs.Binary(t.id, t.prefix, t.markers, t.left, operator, t.right, t.type);
}
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class BlockScopeNamespaceDeclaration implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
JRightPadded name;
public Expression getName() {
return name.getElement();
}
public BlockScopeNamespaceDeclaration withName(Expression name) {
return getPadding().withName(JRightPadded.withElement(this.name, name));
}
List> externs;
public List getExterns() {
return JRightPadded.getElements(externs);
}
public BlockScopeNamespaceDeclaration withExterns(List externs) {
return getPadding().withExterns(JRightPadded.withElements(this.externs, externs));
}
List> usings;
public List getUsings() {
return JRightPadded.getElements(usings);
}
public BlockScopeNamespaceDeclaration withUsings(List usings) {
return getPadding().withUsings(JRightPadded.withElements(this.usings, usings));
}
List> members;
public List getMembers() {
return JRightPadded.getElements(members);
}
public BlockScopeNamespaceDeclaration withMembers(List members) {
return getPadding().withMembers(JRightPadded.withElements(this.members, members));
}
@Getter
@With
Space end;
@Override
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitBlockScopeNamespaceDeclaration(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 BlockScopeNamespaceDeclaration t;
public JRightPadded getName() {
return t.name;
}
public BlockScopeNamespaceDeclaration withName(JRightPadded name) {
return t.name == name ? t : new BlockScopeNamespaceDeclaration(t.id, t.prefix, t.markers, name, t.externs, t.usings, t.members, t.end);
}
public List> getExterns() {
return t.externs;
}
public BlockScopeNamespaceDeclaration withExterns(List> externs) {
return t.externs == externs ? t : new BlockScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, externs, t.usings, t.members, t.end);
}
public List> getUsings() {
return t.usings;
}
public BlockScopeNamespaceDeclaration withUsings(List> usings) {
return t.usings == usings ? t : new BlockScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, t.externs, usings, t.members, t.end);
}
public List> getMembers() {
return t.members;
}
public BlockScopeNamespaceDeclaration withMembers(List> members) {
return t.members == members ? t : new BlockScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, t.externs, t.usings, members, t.end);
}
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class CollectionExpression implements Cs, Expression, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
List> elements;
public List getElements() {
return JRightPadded.getElements(elements);
}
public CollectionExpression withElements(List elements) {
return getPadding().withElements(JRightPadded.withElements(this.elements, elements));
}
@Getter
@With
JavaType type;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitCollectionExpression(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 CollectionExpression t;
public List> getElements() {
return t.elements;
}
public CollectionExpression withElements(List> elements) {
return t.elements == elements ? t : new CollectionExpression(t.id, t.prefix, t.markers, elements, t.type);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class ExpressionStatement implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
JRightPadded expression;
public Expression getExpression() {
return expression.getElement();
}
public ExpressionStatement withExpression(Expression expression) {
return getPadding().withExpression(this.expression.withElement(expression));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitExpressionStatement(this, p);
}
@Override
@Transient
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 ExpressionStatement t;
public JRightPadded getExpression() {
return t.expression;
}
public ExpressionStatement withExpression(JRightPadded expression) {
return t.expression == expression ? t : new ExpressionStatement(t.id, t.prefix, t.markers, expression);
}
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class ExternAlias implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
JLeftPadded identifier;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitExternAlias(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 ExternAlias t;
public JLeftPadded getIdentifier() {
return t.identifier;
}
public ExternAlias withIdentifier(JLeftPadded identifier) {
return t.identifier == identifier ? t : new ExternAlias(t.id, t.prefix, t.markers, identifier);
}
}
}
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class FileScopeNamespaceDeclaration implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
JRightPadded name;
public Expression getName() {
return name.getElement();
}
public FileScopeNamespaceDeclaration withName(Expression name) {
return getPadding().withName(JRightPadded.withElement(this.name, name));
}
List> externs;
public List getExterns() {
return JRightPadded.getElements(externs);
}
public FileScopeNamespaceDeclaration withExterns(List externs) {
return getPadding().withExterns(JRightPadded.withElements(this.externs, externs));
}
List> usings;
public List getUsings() {
return JRightPadded.getElements(usings);
}
public FileScopeNamespaceDeclaration withUsings(List usings) {
return getPadding().withUsings(JRightPadded.withElements(this.usings, usings));
}
List> members;
public List getMembers() {
return JRightPadded.getElements(members);
}
public FileScopeNamespaceDeclaration withMembers(List members) {
return getPadding().withMembers(JRightPadded.withElements(this.members, members));
}
@Override
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitFileScopeNamespaceDeclaration(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 FileScopeNamespaceDeclaration t;
public JRightPadded getName() {
return t.name;
}
public FileScopeNamespaceDeclaration withName(JRightPadded name) {
return t.name == name ? t : new FileScopeNamespaceDeclaration(t.id, t.prefix, t.markers, name, t.externs, t.usings, t.members);
}
public List> getExterns() {
return t.externs;
}
public FileScopeNamespaceDeclaration withExterns(List> externs) {
return t.externs == externs ? t : new FileScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, externs, t.usings, t.members);
}
public List> getUsings() {
return t.usings;
}
public FileScopeNamespaceDeclaration withUsings(List> usings) {
return t.usings == usings ? t : new FileScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, t.externs, usings, t.members);
}
public List> getMembers() {
return t.members;
}
public FileScopeNamespaceDeclaration withMembers(List> members) {
return t.members == members ? t : new FileScopeNamespaceDeclaration(t.id, t.prefix, t.markers, t.name, t.externs, t.usings, members);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class InterpolatedString implements Cs, Expression {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
@Getter
@With
String start;
List> parts;
public List getParts() {
return JRightPadded.getElements(parts);
}
public InterpolatedString withParts(List parts) {
return getPadding().withParts(JRightPadded.withElements(this.parts, parts));
}
@Getter
@With
String end;
@Override
public JavaType getType() {
return JavaType.Primitive.String;
}
@SuppressWarnings("unchecked")
@Override
public InterpolatedString withType(@Nullable JavaType type) {
return this;
}
@Override
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitInterpolatedString(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 InterpolatedString t;
public List> getParts() {
return t.parts;
}
public InterpolatedString withParts(List> parts) {
return t.parts == parts ? t : new InterpolatedString(t.id, t.prefix, t.markers, t.start, parts, t.end);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class Interpolation implements Cs, Expression {
@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 Interpolation withExpression(Expression expression) {
return getPadding().withExpression(JRightPadded.withElement(this.expression, expression));
}
@Nullable
JRightPadded alignment;
public @Nullable Expression getAlignment() {
return alignment != null ? alignment.getElement() : null;
}
public Interpolation withAlignment(@Nullable Expression alignment) {
return getPadding().withAlignment(JRightPadded.withElement(this.alignment, alignment));
}
@Nullable
JRightPadded format;
public @Nullable Expression getFormat() {
return format != null ? format.getElement() : null;
}
public Interpolation withFormat(@Nullable Expression format) {
return getPadding().withFormat(JRightPadded.withElement(this.format, format));
}
@Override
public JavaType getType() {
return expression.getElement().getType();
}
@SuppressWarnings("unchecked")
@Override
public Interpolation withType(@Nullable JavaType type) {
return getPadding().withExpression(expression.withElement(expression.getElement().withType(type)));
}
@Override
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitInterpolation(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 Interpolation t;
public JRightPadded getExpression() {
return t.expression;
}
public Interpolation withExpression(JRightPadded expression) {
return t.expression == expression ? t : new Interpolation(t.id, t.prefix, t.markers, expression, t.alignment, t.format);
}
public @Nullable JRightPadded getAlignment() {
return t.alignment;
}
public Interpolation withAlignment(@Nullable JRightPadded alignment) {
return t.alignment == alignment ? t : new Interpolation(t.id, t.prefix, t.markers, t.expression, alignment, t.format);
}
public @Nullable JRightPadded getFormat() {
return t.format;
}
public Interpolation withFormat(@Nullable JRightPadded format) {
return t.format == format ? t : new Interpolation(t.id, t.prefix, t.markers, t.expression, t.alignment, format);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class NullSafeExpression implements Cs, Expression {
@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 NullSafeExpression withExpression(Expression expression) {
return getPadding().withExpression(JRightPadded.withElement(this.expression, expression));
}
@Override
public @Nullable JavaType getType() {
return expression.getElement().getType();
}
@Override
public T withType(@Nullable JavaType type) {
Expression newExpression = expression.getElement().withType(type);
if (newExpression == expression.getElement()) {
return (T) this;
}
return (T) new NullSafeExpression(id, prefix, markers, JRightPadded.withElement(expression, newExpression));
}
@Override
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitNullSafeExpression(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 NullSafeExpression t;
public JRightPadded getExpression() {
return t.expression;
}
public NullSafeExpression withExpression(JRightPadded expression) {
return t.expression == expression ? t : new NullSafeExpression(t.id, t.prefix, t.markers, expression);
}
}
}
@Getter
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@With
final class StatementExpression implements Cs, Expression {
@EqualsAndHashCode.Include
UUID id;
Space prefix;
Markers markers;
Statement statement;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitStatementExpression(this, p);
}
@Override
public @Nullable JavaType getType() {
return null;
}
@Override
public T withType(@Nullable JavaType type) {
return (T) this;
}
@Transient
@Override
public CoordinateBuilder.Expression getCoordinates() {
return new CoordinateBuilder.Expression(this);
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class UsingDirective implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
JRightPadded global;
public boolean isGlobal() {
return global.getElement();
}
public UsingDirective withGlobal(boolean global) {
return getPadding().withGlobal(JRightPadded.withElement(this.global, global));
}
JLeftPadded statik;
public boolean isStatic() {
return statik.getElement();
}
public UsingDirective withStatic(boolean statik) {
return getPadding().withStatic(JLeftPadded.withElement(this.statik, statik));
}
JLeftPadded unsafe;
public boolean isUnsafe() {
return unsafe.getElement();
}
public UsingDirective withUnsafe(boolean unsafe) {
return getPadding().withUnsafe(JLeftPadded.withElement(this.unsafe, unsafe));
}
@Nullable
JRightPadded alias;
public @Nullable Identifier getAlias() {
return alias != null ? alias.getElement() : null;
}
public UsingDirective withAlias(@Nullable Identifier alias) {
return getPadding().withAlias(JRightPadded.withElement(this.alias, alias));
}
@Getter
@With
TypeTree namespaceOrType;
@Override
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitUsingDirective(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 UsingDirective t;
public JRightPadded getGlobal() {
return t.global;
}
public UsingDirective withGlobal(JRightPadded global) {
return t.global == global ? t : new UsingDirective(t.id, t.prefix, t.markers, global, t.statik, t.unsafe, t.alias, t.namespaceOrType);
}
public JLeftPadded getStatic() {
return t.statik;
}
public UsingDirective withStatic(JLeftPadded statik) {
return t.statik == statik ? t : new UsingDirective(t.id, t.prefix, t.markers, t.global, statik, t.unsafe, t.alias, t.namespaceOrType);
}
public JLeftPadded getUnsafe() {
return t.unsafe;
}
public UsingDirective withUnsafe(JLeftPadded unsafe) {
return t.unsafe == unsafe ? t : new UsingDirective(t.id, t.prefix, t.markers, t.global, t.statik, unsafe, t.alias, t.namespaceOrType);
}
public @Nullable JRightPadded getAlias() {
return t.alias;
}
public UsingDirective withAlias(JRightPadded alias) {
return t.alias == alias ? t : new UsingDirective(t.id, t.prefix, t.markers, t.global, t.statik, t.unsafe, t.alias, t.namespaceOrType);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
class PropertyDeclaration implements Cs, Statement, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@Getter
@With
@EqualsAndHashCode.Include
UUID id;
@Getter
@With
Space prefix;
@Getter
@With
Markers markers;
@With
@Getter
List attributeLists;
@With
@Getter
List modifiers;
@With
@Getter
TypeTree typeExpression;
@Nullable
JRightPadded interfaceSpecifier;
@With
@Getter
Identifier name;
@With
@Getter
Block accessors;
@Nullable
JLeftPadded initializer;
@Override
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public JavaType getType() {
return typeExpression.getType();
}
@Override
public PropertyDeclaration withType(@Nullable JavaType type) {
return getPadding().withType(this.typeExpression.withType(type));
}
public @Nullable NameTree getInterfaceSpecifier() {
return interfaceSpecifier != null ? interfaceSpecifier.getElement() : null;
}
public PropertyDeclaration withInterfaceSpecifier(@Nullable NameTree interfaceSpecifier) {
return getPadding().withInterfaceSpecifier(JRightPadded.withElement(this.interfaceSpecifier, interfaceSpecifier));
}
public @Nullable Expression getInitializer() {
return initializer != null ? initializer.getElement() : null;
}
public PropertyDeclaration withInitializer(@Nullable Expression initializer) {
return getPadding().withInitializer(JLeftPadded.withElement(this.initializer, initializer));
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitPropertyDeclaration(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.pd != this) {
p = new Padding(this);
this.padding = new WeakReference<>(p);
}
}
return p;
}
@RequiredArgsConstructor
public static class Padding {
private final PropertyDeclaration pd;
public TypeTree getType() {
return pd.typeExpression;
}
public @Nullable JRightPadded getInterfaceSpecifier() {
return pd.interfaceSpecifier;
}
public PropertyDeclaration withInterfaceSpecifier(@Nullable JRightPadded interfaceSpecifier) {
return pd.interfaceSpecifier == interfaceSpecifier ? pd : new PropertyDeclaration(pd.id,
pd.prefix,
pd.markers,
pd.attributeLists,
pd.modifiers,
pd.typeExpression,
interfaceSpecifier,
pd.name,
pd.accessors,
pd.initializer);
}
public PropertyDeclaration withType(TypeTree type) {
return pd.typeExpression == type ? pd : new PropertyDeclaration(pd.id,
pd.prefix,
pd.markers,
pd.attributeLists,
pd.modifiers,
type,
pd.interfaceSpecifier,
pd.name,
pd.accessors,
pd.initializer);
}
public @Nullable JLeftPadded getInitializer() {
return pd.initializer;
}
public PropertyDeclaration withInitializer(@Nullable JLeftPadded initializer) {
return pd.initializer == initializer ? pd : new PropertyDeclaration(pd.id,
pd.prefix,
pd.markers,
pd.attributeLists,
pd.modifiers,
pd.typeExpression,
pd.interfaceSpecifier,
pd.name,
pd.accessors,
initializer);
}
}
}
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
final class Keyword implements Cs {
@With
@Getter
@EqualsAndHashCode.Include
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
KeywordKind kind;
@Override
public @Nullable J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitKeyword(this, p);
}
public enum KeywordKind {
Ref,
Out,
Await,
Base,
This,
Break,
Return,
Not
}
}
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
final class Lambda implements Cs, Statement, Expression {
@Override
public
J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitLambda(this, p);
}
@With
@Getter
@EqualsAndHashCode.Include
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
J.Lambda lambdaExpression;
@With
@Getter
List modifiers;
@Override
public CoordinateBuilder.Statement getCoordinates() {
return new CoordinateBuilder.Statement(this);
}
@Override
public @Nullable JavaType getType() {
return lambdaExpression.getType();
}
@Override
public Cs.Lambda withType(@Nullable JavaType type) {
return this.getType() == type ? this : new Cs.Lambda(
id,
prefix,
markers,
lambdaExpression.withType(type),
modifiers);
}
@Override
public String toString() {
return withPrefix(Space.EMPTY).printTrimmed(new CSharpPrinter<>());
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class ClassDeclaration implements Cs, Statement, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@Getter
@EqualsAndHashCode.Include
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
List attributeList;
@With
@Getter
List modifiers;
J.ClassDeclaration.Kind kind;
public J.ClassDeclaration.Kind.Type getKind() {
return kind.getType();
}
public Cs.ClassDeclaration withKind(J.ClassDeclaration.Kind.Type type) {
J.ClassDeclaration.Kind k = getPadding().getKind();
if (k.getType() == type) {
return this;
} else {
return getPadding().withKind(k.withType(type));
}
}
@With
@Getter
Identifier name;
@Nullable
JContainer typeParameters;
public @Nullable List getTypeParameters() {
return typeParameters == null ? null : typeParameters.getElements();
}
public Cs.ClassDeclaration withTypeParameters(@Nullable List typeParameters) {
return getPadding().withTypeParameters(JContainer.withElementsNullable(this.typeParameters, typeParameters));
}
@Nullable
JContainer primaryConstructor;
public @Nullable List getPrimaryConstructor() {
return primaryConstructor == null ? null : primaryConstructor.getElements();
}
public Cs.ClassDeclaration withPrimaryConstructor(@Nullable List primaryConstructor) {
return getPadding().withPrimaryConstructor(JContainer.withElementsNullable(this.primaryConstructor, primaryConstructor));
}
@Nullable
JLeftPadded extendings;
public @Nullable TypeTree getExtendings() {
return extendings == null ? null : extendings.getElement();
}
public Cs.ClassDeclaration withExtendings(@Nullable TypeTree extendings) {
return getPadding().withExtendings(JLeftPadded.withElement(this.extendings, extendings));
}
@Nullable
JContainer implementings;
public @Nullable List getImplementings() {
return implementings == null ? null : implementings.getElements();
}
public Cs.ClassDeclaration withImplementings(@Nullable List implementings) {
return getPadding().withImplementings(JContainer.withElementsNullable(this.implementings, implementings));
}
@With
@Getter
@Nullable
Block body;
@Nullable
JContainer typeParameterConstraintClauses;
@Nullable
public List getTypeParameterConstraintClauses() {
return typeParameterConstraintClauses == null ? null : typeParameterConstraintClauses.getElements();
}
public Cs.ClassDeclaration withTypeParameterConstraintClauses(@Nullable List typeParameterConstraintClauses) {
return getPadding().withTypeParameterConstraintClauses(JContainer.withElementsNullable(this.typeParameterConstraintClauses, typeParameterConstraintClauses));
}
@Getter
JavaType.@Nullable FullyQualified type;
@SuppressWarnings("unchecked")
@Override
public Cs.ClassDeclaration withType(@Nullable JavaType type) {
if (type == this.type) {
return this;
}
if (type != null && !(type instanceof JavaType.FullyQualified)) {
throw new IllegalArgumentException("A class can only be type attributed with a fully qualified type name");
}
return new Cs.ClassDeclaration(id, prefix, markers, attributeList, modifiers, kind, name, typeParameters, primaryConstructor, extendings, implementings, body, typeParameterConstraintClauses, (JavaType.FullyQualified) type);
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitClassDeclaration(this, p);
}
@Override
@Transient
public CoordinateBuilder.ClassDeclaration getCoordinates() {
//todo: Setup coordinate builder - atm it's private
// return new CoordinateBuilder.ClassDeclaration(this);
return null;
}
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 Cs.ClassDeclaration t;
public @Nullable JContainer getPrimaryConstructor() {
return t.primaryConstructor;
}
public Cs.ClassDeclaration withPrimaryConstructor(@Nullable JContainer primaryConstructor) {
return t.primaryConstructor == primaryConstructor ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type);
}
public @Nullable JLeftPadded getExtendings() {
return t.extendings;
}
public Cs.ClassDeclaration withExtendings(@Nullable JLeftPadded extendings) {
return t.extendings == extendings ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type);
}
public @Nullable JContainer getImplementings() {
return t.implementings;
}
public Cs.ClassDeclaration withImplementings(@Nullable JContainer implementings) {
return t.implementings == implementings ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, implementings, t.body, t.typeParameterConstraintClauses, t.type);
}
public J.ClassDeclaration.Kind getKind() {
return t.kind;
}
public Cs.ClassDeclaration withKind(J.ClassDeclaration.Kind kind) {
return t.kind == kind ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type);
}
public @Nullable JContainer getTypeParameters() {
return t.typeParameters;
}
public Cs.ClassDeclaration withTypeParameters(@Nullable JContainer typeParameters) {
return t.typeParameters == typeParameters ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, t.typeParameterConstraintClauses, t.type);
}
public @Nullable JContainer getTypeParameterConstraintClauses() {
return t.typeParameterConstraintClauses;
}
public Cs.ClassDeclaration withTypeParameterConstraintClauses(@Nullable JContainer typeParameterConstraintClauses) {
return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.ClassDeclaration(t.id, t.prefix, t.markers, t.attributeList, t.modifiers, t.kind, t.name, t.typeParameters, t.primaryConstructor, t.extendings, t.implementings, t.body, typeParameterConstraintClauses, t.type);
}
}
}
// CS specific method exists to allow for modelling for the following not possible in J version:
// - implicit interface implementations
// - Cs.AttributeList that may appear before any of the type variables
// - generics constraints that appear on the end of the method declaration
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class MethodDeclaration implements Cs, Statement, TypedTree {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Getter
List attributes;
@With
@Getter
List modifiers;
@Nullable
JContainer typeParameters;
@With
@Getter
TypeTree returnTypeExpression;
@Nullable
JRightPadded explicitInterfaceSpecifier;
public TypeTree getExplicitInterfaceSpecifier() {
return explicitInterfaceSpecifier.getElement();
}
public Cs.MethodDeclaration withExplicitInterfaceSpecifier(TypeTree explicitInterfaceSpecifier) {
return getPadding().withExplicitInterfaceSpecifier(this.explicitInterfaceSpecifier.withElement(explicitInterfaceSpecifier));
}
@With
@Getter
Identifier name;
JContainer parameters;
public List getParameters() {
return parameters.getElements();
}
public Cs.MethodDeclaration withParameters(List parameters) {
return getPadding().withParameters(JContainer.withElements(this.parameters, parameters));
}
/**
* Null for abstract method declarations and interface method declarations.
*/
@With
@Getter
@Nullable
Block body;
@Getter
JavaType.@Nullable Method methodType;
public Cs.MethodDeclaration withMethodType(JavaType.@Nullable Method type) {
if (type == this.methodType) {
return this;
}
return new Cs.MethodDeclaration(id, prefix, markers, attributes, modifiers, typeParameters, returnTypeExpression, explicitInterfaceSpecifier, name, parameters, body, type, typeParameterConstraintClauses);
}
JContainer typeParameterConstraintClauses;
public List getTypeParameterConstraintClauses() {
return typeParameterConstraintClauses.getElements();
}
public Cs.MethodDeclaration withTypeParameterConstraintClauses(List typeParameterConstraintClauses) {
return getPadding().withTypeParameterConstraintClauses(JContainer.withElementsNullable(this.typeParameterConstraintClauses, typeParameterConstraintClauses));
}
@Override
public JavaType getType() {
return methodType == null ? null : methodType.getReturnType();
}
@SuppressWarnings("unchecked")
@Override
public Cs.MethodDeclaration withType(@Nullable JavaType type) {
throw new UnsupportedOperationException("To change the return type of this method declaration, use withMethodType(..)");
}
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitMethodDeclaration(this, p);
}
@Override
@Transient
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 Cs.MethodDeclaration t;
public JContainer getParameters() {
return t.parameters;
}
public Cs.MethodDeclaration withParameters(JContainer parameters) {
return t.parameters == parameters ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, parameters, t.body, t.methodType, t.typeParameterConstraintClauses);
}
@Nullable
public JRightPadded getExplicitInterfaceSpecifier() {
return t.explicitInterfaceSpecifier;
}
public Cs.MethodDeclaration withExplicitInterfaceSpecifier(JRightPadded explicitInterfaceSpecifier) {
return t.explicitInterfaceSpecifier == explicitInterfaceSpecifier ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, t.typeParameterConstraintClauses);
}
public @Nullable JContainer getTypeParameters() {
return t.typeParameters;
}
public Cs.MethodDeclaration withTypeParameters(@Nullable JContainer typeParameters) {
return t.typeParameters == typeParameters ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, t.typeParameterConstraintClauses);
}
public @Nullable JContainer getTypeParameterConstraintClauses() {
return t.typeParameterConstraintClauses;
}
public Cs.MethodDeclaration withTypeParameterConstraintClauses(@Nullable JContainer typeParameterConstraintClauses) {
return t.typeParameterConstraintClauses == typeParameterConstraintClauses ? t : new Cs.MethodDeclaration(t.id, t.prefix, t.markers, t.attributes, t.modifiers, t.typeParameters, t.returnTypeExpression, t.explicitInterfaceSpecifier, t.name, t.parameters, t.body, t.methodType, typeParameterConstraintClauses);
}
}
}
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class UsingStatement implements Cs, Statement {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
@With
@Nullable
@Getter
Keyword awaitKeyword;
JLeftPadded expression;
public Expression getExpression() {
return expression.getElement();
}
public UsingStatement withExpression(Expression expression) {
return getPadding().withExpression(this.expression.withElement(expression));
}
/**
* The block is null for using declaration form.
*/
@With
@Getter
Statement statement;
@Override
public J acceptCSharp(CSharpVisitor
v, P p) {
return v.visitUsingStatement(this, p);
}
@Override
@Transient
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 UsingStatement t;
public JLeftPadded getExpression() {
return t.expression;
}
public UsingStatement withExpression(JLeftPadded expression) {
return t.expression == expression ? t : new UsingStatement(t.id, t.prefix, t.markers, t.awaitKeyword, expression, t.statement);
}
}
}
//endregion
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
final class TypeParameterConstraintClause implements Cs {
@Nullable
@NonFinal
transient WeakReference padding;
@With
@EqualsAndHashCode.Include
@Getter
UUID id;
@With
@Getter
Space prefix;
@With
@Getter
Markers markers;
/**
* class A<T> where