Skip to content

Commit

Permalink
feat: Add support for CtReceiverParameter in spoon model. (#5674)
Browse files Browse the repository at this point in the history
Co-authored-by: I-Al-Istannen <[email protected]>
  • Loading branch information
MartinWitt and I-Al-Istannen committed Apr 3, 2024
1 parent 144d7d7 commit 1dc595a
Show file tree
Hide file tree
Showing 39 changed files with 560 additions and 90 deletions.
6 changes: 6 additions & 0 deletions spoon-smpl/src/main/java/spoon/smpl/Substitutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.declaration.CtRecord;
import spoon.reflect.declaration.CtRecordComponent;
import spoon.reflect.declaration.CtTypeParameter;
Expand Down Expand Up @@ -710,4 +711,9 @@ public void visitCtCasePattern(CtCasePattern casePattern) {
public void visitCtRecordPattern(CtRecordPattern recordPattern) {
throw new NotImplementedException("Not implemented");
}

@Override
public void visitCtReceiverParameter(CtReceiverParameter receiverParameter) {
throw new NotImplementedException("Not implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.declaration.CtRecord;
import spoon.reflect.declaration.CtRecordComponent;
import spoon.reflect.declaration.CtTypeParameter;
Expand Down Expand Up @@ -851,6 +852,10 @@ public void visitCtRecordPattern(CtRecordPattern recordPattern) {
throw new NotImplementedException("Not implemented");
}

@Override
public void visitCtReceiverParameter(CtReceiverParameter receiverParameter) {
throw new NotImplementedException("Not implemented");
}

/**
* Parameter identifiers.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/spoon/metamodel/Metamodel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import spoon.reflect.declaration.CtModuleDirective;
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.declaration.CtRecord;
import spoon.reflect.declaration.CtRecordComponent;
import spoon.reflect.declaration.CtType;
Expand All @@ -42,9 +43,9 @@
import spoon.reflect.reference.CtTypeReference;
import spoon.reflect.visitor.filter.AllTypeMembersFunction;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.support.adaption.TypeAdaptor;
import spoon.support.DefaultCoreFactory;
import spoon.support.StandardEnvironment;
import spoon.support.adaption.TypeAdaptor;
import spoon.support.compiler.FileSystemFolder;

/**
Expand Down Expand Up @@ -195,6 +196,7 @@ public static Set<CtType<?>> getAllMetamodelInterfaces() {
result.add(factory.Type().get(CtModuleDirective.class));
result.add(factory.Type().get(CtRecordComponent.class));
result.add(factory.Type().get(CtRecord.class));
result.add(factory.Type().get(CtReceiverParameter.class));
return result;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/spoon/reflect/code/CtLambda.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
package spoon.reflect.code;

import org.jspecify.annotations.Nullable;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.DerivedProperty;
import spoon.reflect.annotations.PropertyGetter;
Expand Down Expand Up @@ -77,4 +79,11 @@ public interface CtLambda<T> extends CtExpression<T>, CtExecutable<T> {
@Override
@UnsettableProperty
<T1 extends CtExecutable<T>> T1 setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes);

@UnsettableProperty
CtExecutable<?> setReceiverParameter(CtReceiverParameter receiverParameter);

@UnsettableProperty
@Nullable
CtReceiverParameter getReceiverParameter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package spoon.reflect.declaration;

import org.jspecify.annotations.Nullable;
import spoon.reflect.code.CtBodyHolder;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtStatement;
Expand Down Expand Up @@ -54,4 +55,10 @@ public interface CtAnnotationMethod<T> extends CtMethod<T> {
@Override
@UnsettableProperty
<T1 extends CtExecutable<T>> T1 setParameters(List<CtParameter<?>> parameters);
@UnsettableProperty
CtExecutable<?> setReceiverParameter(CtReceiverParameter receiverParameter);

@UnsettableProperty
@Nullable
CtReceiverParameter getReceiverParameter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package spoon.reflect.declaration;

import org.jspecify.annotations.Nullable;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.UnsettableProperty;

Expand Down Expand Up @@ -50,4 +51,12 @@ public interface CtAnonymousExecutable extends CtExecutable<Void>, CtTypeMember
@UnsettableProperty
<T extends CtExecutable<Void>> T addThrownType(CtTypeReference<? extends Throwable> throwType);


@UnsettableProperty
CtExecutable<?> setReceiverParameter(CtReceiverParameter receiverParameter);

@UnsettableProperty
@Nullable
CtReceiverParameter getReceiverParameter();

}
9 changes: 9 additions & 0 deletions src/main/java/spoon/reflect/declaration/CtExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*/
package spoon.reflect.declaration;

import org.jspecify.annotations.Nullable;
import spoon.reflect.annotations.PropertyGetter;
import spoon.reflect.annotations.PropertySetter;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtBodyHolder;
import spoon.reflect.path.CtRole;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;
import spoon.support.DerivedProperty;
Expand Down Expand Up @@ -140,4 +142,11 @@ public interface CtExecutable<R> extends CtNamedElement, CtTypedElement<R>, CtBo

@Override
CtExecutable<R> clone();

@PropertySetter(role = CtRole.RECEIVER_PARAMETER)
CtExecutable<?> setReceiverParameter(CtReceiverParameter receiverParameter);

@PropertyGetter(role = CtRole.RECEIVER_PARAMETER)
@Nullable
CtReceiverParameter getReceiverParameter();
}
31 changes: 31 additions & 0 deletions src/main/java/spoon/reflect/declaration/CtReceiverParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: (MIT OR CECILL-C)
*
* Copyright (C) 2006-2023 INRIA and contributors
*
* Spoon is available either under the terms of the MIT License (see LICENSE-MIT.txt) or the Cecill-C License (see LICENSE-CECILL-C.txt). You as the user are entitled to choose the terms under which to adopt Spoon.
*/
package spoon.reflect.declaration;


import spoon.reflect.reference.CtTypeReference;
/**
* This element represents a class declaration.
*
* <pre>{@code
* class Foo {
* // this is a receiver parameter
* void bar(Foo this) {
* }
* }}
* </pre>
*/
public interface CtReceiverParameter extends CtTypedElement<Object>, CtShadowable, CtElement {

@Override
CtTypeReference<Object> getType();

@Override
CtReceiverParameter clone();

}
17 changes: 12 additions & 5 deletions src/main/java/spoon/reflect/factory/CoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,28 @@
import spoon.reflect.declaration.CtEnum;
import spoon.reflect.declaration.CtEnumValue;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtImport;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtModule;
import spoon.reflect.declaration.CtModuleRequirement;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtPackageDeclaration;
import spoon.reflect.declaration.CtPackageExport;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtProvidedService;
import spoon.reflect.declaration.CtReceiverParameter;
import spoon.reflect.declaration.CtRecord;
import spoon.reflect.declaration.CtRecordComponent;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtPackageDeclaration;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.declaration.CtTypeParameter;
import spoon.reflect.declaration.CtUsedService;
import spoon.reflect.reference.CtArrayTypeReference;
import spoon.reflect.reference.CtCatchVariableReference;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtFieldReference;
import spoon.reflect.declaration.CtImport;
import spoon.reflect.reference.CtIntersectionTypeReference;
import spoon.reflect.reference.CtLocalVariableReference;
import spoon.reflect.reference.CtModuleReference;
import spoon.reflect.declaration.CtModuleRequirement;
import spoon.reflect.reference.CtPackageReference;
import spoon.reflect.reference.CtParameterReference;
import spoon.reflect.reference.CtTypeMemberWildcardImportReference;
Expand Down Expand Up @@ -653,4 +654,10 @@ BodyHolderSourcePosition createBodyHolderSourcePosition(
* {@return a record pattern}
*/
CtRecordPattern createRecordPattern();

/**
* Creates a receiver parameter.
* @return the created receiver parameter.
*/
CtReceiverParameter createReceiverParameter();
}
Loading

0 comments on commit 1dc595a

Please sign in to comment.