Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for CtReceiverParameter in spoon model. #5674

Merged
merged 53 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f2510bf
Add support for CtReceiverParameter in spoon model.
MartinWitt Jan 30, 2024
1064eec
Update copyright headers in multiple files
MartinWitt Feb 17, 2024
abd67a5
Add receiver parameter visitation methods
MartinWitt Mar 10, 2024
3cdeccf
Update flake.lock file
MartinWitt Mar 10, 2024
54dd707
Implement CtReceiverParameter methods and add to DefaultCoreFactory
MartinWitt Mar 10, 2024
15a041b
lets try to not have a CtNamedElement
MartinWitt Mar 10, 2024
ac00804
Refactor ReceiverParameter setting and scanning
MartinWitt Mar 10, 2024
1c6dce8
Update ReceiverParameter handling and tests
MartinWitt Mar 10, 2024
9b1c37c
Add CtCasePattern, CtReceiverParameter and CtRecordPattern assert cla…
MartinWitt Mar 25, 2024
9759ed2
Improve ReceiverParameter handling in tests
MartinWitt Mar 25, 2024
703d9dd
Merge branch 'java17' into feat/java17/receiverparameter
MartinWitt Mar 25, 2024
168b08e
Refactor and clean-up the Spoon library classes
MartinWitt Mar 25, 2024
ac899ce
Add ReceiverParameter to CtExecutable and documentation
MartinWitt Mar 25, 2024
ec62d96
Update handling of CtReceiverParameter and implement code refactoring
MartinWitt Mar 25, 2024
f85b7d9
doc
MartinWitt Mar 25, 2024
2a3c052
doc
MartinWitt Mar 25, 2024
eedbdc9
maybe I am too stupid to read
MartinWitt Mar 25, 2024
25a2324
meta meta meta
MartinWitt Mar 25, 2024
445af0b
Update expected counts in CtScannerTest
MartinWitt Mar 26, 2024
1c0806e
Merge remote-tracking branch 'origin/java17' into feat/java17/receive…
MartinWitt Mar 26, 2024
6fc0a88
Normalize indentation in CtReceiverParameter.java
MartinWitt Mar 26, 2024
ad7c08a
up
MartinWitt Mar 26, 2024
5e0e872
up
MartinWitt Mar 26, 2024
2e56738
imports
MartinWitt Mar 28, 2024
b6b55de
Reorganize import statements across multiple files
MartinWitt Mar 28, 2024
b41e419
up
MartinWitt Mar 28, 2024
d383721
up
MartinWitt Mar 28, 2024
db9f45b
up
MartinWitt Mar 28, 2024
d86eb00
up
MartinWitt Mar 28, 2024
725e168
up
MartinWitt Mar 28, 2024
2ce4544
up
MartinWitt Mar 29, 2024
994d8f5
Update CtMethod.java
MartinWitt Mar 29, 2024
e6e4b7e
Update ExecutableFactory.java
MartinWitt Mar 29, 2024
b1a8574
Update DefaultJavaPrettyPrinter.java
MartinWitt Mar 29, 2024
cfd2f69
Update ParentExiter.java
MartinWitt Mar 29, 2024
a7900af
Update CtMethodImpl.java
MartinWitt Mar 29, 2024
f8f4b52
Update ExecutableFactory.java
MartinWitt Mar 29, 2024
fcb14f7
date import statements and optimize argument naming
MartinWitt Mar 29, 2024
6fdde39
Add inner class handling in receiver parameter test
MartinWitt Apr 1, 2024
ece9340
Reorganize import statements in Metamodel.java
MartinWitt Apr 1, 2024
59aaa76
Reorganize import statements in Metamodel.java
MartinWitt Apr 1, 2024
f771d56
Reorganize import statements in Metamodel.java
MartinWitt Apr 1, 2024
861fab5
up
MartinWitt Apr 1, 2024
71ea27b
Update src/main/java/spoon/reflect/visitor/ElementPrinterHelper.java
MartinWitt Apr 1, 2024
3e4112b
Update src/main/java/spoon/reflect/declaration/CtReceiverParameter.java
MartinWitt Apr 1, 2024
e8edd5d
Update SimpleReceiverParameter.java
MartinWitt Apr 1, 2024
7334c5e
Update InnerClassCtor.java
MartinWitt Apr 1, 2024
2abac1f
Update src/main/java/spoon/support/compiler/jdt/ParentExiter.java
MartinWitt Apr 1, 2024
f2848be
Update src/test/java/spoon/test/receiverparameter/ReceiverParameterTe…
MartinWitt Apr 1, 2024
184c2db
Update src/test/java/spoon/test/receiverparameter/ReceiverParameterTe…
MartinWitt Apr 1, 2024
42d5483
Update src/main/java/spoon/support/reflect/declaration/CtExecutableIm…
MartinWitt Apr 1, 2024
6f7d663
to tabs
MartinWitt Apr 1, 2024
0143126
Update src/test/java/spoon/test/receiverparameter/ReceiverParameterTe…
MartinWitt Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/java/spoon/metamodel/Metamodel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@
*/
package spoon.metamodel;

import java.io.File;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jspecify.annotations.Nullable;

import spoon.Launcher;
import spoon.SpoonException;
import spoon.reflect.annotations.PropertyGetter;
Expand All @@ -33,6 +20,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,11 +30,23 @@
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;

import java.io.File;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Represents the Spoon metamodel (incl. at runtime)
*/
Expand Down Expand Up @@ -195,6 +195,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();
}
1 change: 0 additions & 1 deletion src/main/java/spoon/reflect/declaration/CtMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ public interface CtMethod<T> extends CtExecutable<T>, CtFormalTypeDeclarer, CtSh
* If you want to rename the new method, use {@link Refactoring#changeMethodName(CtMethod, String)} (and not {@link #setSimpleName(String)}, which does not update the references)
*/
CtMethod<?> copyMethod();

}
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>
* // Foo this is a receiver parameter
* class Foo {
* void bar(Foo this) {
* }
* }
* </pre>
MartinWitt marked this conversation as resolved.
Show resolved Hide resolved
*/
public interface CtReceiverParameter extends CtTypedElement<Object>, CtShadowable, CtElement {

@Override
CtTypeReference<Object> getType();

@Override
CtReceiverParameter clone();

}
21 changes: 14 additions & 7 deletions src/main/java/spoon/reflect/factory/CoreFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
package spoon.reflect.factory;

import java.lang.annotation.Annotation;

import spoon.reflect.code.CtAnnotationFieldAccess;
import spoon.reflect.code.CtArrayRead;
import spoon.reflect.code.CtArrayWrite;
Expand Down Expand Up @@ -78,27 +76,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 All @@ -107,6 +106,8 @@
import spoon.reflect.reference.CtUnboundVariableReference;
import spoon.reflect.reference.CtWildcardReference;

import java.lang.annotation.Annotation;

/**
* This interface defines the core creation methods for the meta-model (to be
* implemented so that Spoon can manipulate other meta-model implementations).
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();
}
1 change: 0 additions & 1 deletion src/main/java/spoon/reflect/factory/ExecutableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,4 @@ public <T> CtExecutableReference<T> createReference(String signature) {
executableRef.setParameters(params);
return executableRef;
}

}
Loading
Loading