Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jun 22, 2023
2 parents 0c41aa7 + abc6255 commit 3c6dc28
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 78 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ jobs:
- name: set branchname to next version
run: echo "BRANCH_NAME=release/$NEXT_VERSION" >> $GITHUB_ENV
- name: Set release version
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
run: |
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_VERSION -DprocessAllModules
- name: Commit & Push changes
run: |
git checkout -b ${{env.BRANCH_NAME}}
Expand All @@ -78,7 +81,7 @@ jobs:
# Now we can run the release
- name: Stage release
run: mvn --no-transfer-progress --batch-mode -Pjreleaser clean deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy
run: mvn -f spoon-pom --no-transfer-progress --batch-mode -Pjreleaser clean deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy
- name: Print next version
run: mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//'
- name: Run JReleaser
Expand All @@ -101,7 +104,10 @@ jobs:
echo "NEXT_RELEASE_VERSION=$(semver next patch $NEXT_VERSION)-SNAPSHOT" >> $GITHUB_ENV
echo "NEXT_RELEASE_VERSION_WITHOUT_SNAPSHOT=$(semver next patch $NEXT_VERSION)" >> $GITHUB_ENV
- name: Set release version
run: mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
run: |
mvn -f spoon-pom --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
mvn --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
mvn -f spoon-javadoc --no-transfer-progress --batch-mode versions:set -DnewVersion=$NEXT_RELEASE_VERSION -DprocessAllModules
# Commit and push changes
- name: Commit & Push changes
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
with:
fetch-depth: 0
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@47c262ae41cc8c13cbc5d349cce1ffb2578ed25c # v2023.1.4
uses: JetBrains/qodana-action@54d3fc653c515607d6b1599201a383e9e07649b1 # v2023.1.5
with:
args: --source-directory,./src/main/java , --fail-threshold, 0
post-pr-comment: "false"
- uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2
- uses: github/codeql-action/upload-sarif@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
code-quality-spoon-javadoc:
Expand All @@ -33,10 +33,10 @@ jobs:
with:
fetch-depth: 0
- name: 'Qodana Scan (spoon-javadoc)'
uses: JetBrains/qodana-action@47c262ae41cc8c13cbc5d349cce1ffb2578ed25c # v2023.1.4
uses: JetBrains/qodana-action@54d3fc653c515607d6b1599201a383e9e07649b1 # v2023.1.5
with:
args: --source-directory,./spoon-javadoc/src/main/java , --fail-threshold, 0
post-pr-comment: "false"
- uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2
- uses: github/codeql-action/upload-sarif@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2.20.0
uses: github/codeql-action/upload-sarif@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2.20.1
with:
sarif_file: results.sarif
5 changes: 3 additions & 2 deletions jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ project:
homepage: https://spoon.gforge.inria.fr/
java:
groupId: fr.inria.gforge.spoon
version: 11
inceptionYear: 2015
version: "11"
inceptionYear: "2015"

release:
github:
owner: INRIA
changelog:
formatted: ALWAYS
preset: conventional-commits
format: '- {{commitShortHash}} {{commitTitle}}'
contributors:
format: '- {{contributorName}} ({{contributorUsernameAsLink}})'
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/spoon/reflect/factory/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public class TypeFactory extends SubFactory {
public final CtTypeReference<Enum> ENUM = createReference(Enum.class);
public final CtTypeReference<?> OMITTED_TYPE_ARG_TYPE = createReference(CtTypeReference.OMITTED_TYPE_ARG_NAME);

private final Map<Class<?>, CtType<?>> shadowCache = new ConcurrentHashMap<>();
// This map MUST provide a useful computeIfAbsent method in the face of concurrency.
// Therefore, we declare it as a ConcurrentHashMap directly.
private final ConcurrentHashMap<Class<?>, CtType<?>> shadowCache = new ConcurrentHashMap<>();

/**
* Returns a reference on the null type (type of null).
Expand Down Expand Up @@ -555,37 +557,35 @@ private void addNestedType(List<CtType<?>> list, CtType<?> t) {
public <T> CtType<T> get(Class<?> cl) {
final CtType<T> aType = get(cl.getName());
if (aType == null) {
final CtType<T> shadowClass = (CtType<T>) this.shadowCache.get(cl);
if (shadowClass == null) {
CtType<T> newShadowClass;
try {
newShadowClass = new JavaReflectionTreeBuilder(getShadowFactory()).scan((Class<T>) cl);
} catch (Throwable e) {
Launcher.LOGGER.warn("cannot create shadow class: {}", cl.getName(), e);

newShadowClass = getShadowFactory().Core().createClass();
newShadowClass.setSimpleName(cl.getSimpleName());
newShadowClass.setShadow(true);
getShadowFactory().Package().getOrCreate(cl.getPackage().getName()).addType(newShadowClass);
}
newShadowClass.setFactory(factory);
newShadowClass.accept(new CtScanner() {
@Override
public void scan(CtElement element) {
if (element != null) {
element.setFactory(factory);
}
}
});
this.shadowCache.put(cl, newShadowClass);
return newShadowClass;
} else {
return shadowClass;
}
return (CtType<T>) this.shadowCache.computeIfAbsent(cl, this::buildNewShadowClass);
}
return aType;
}

private CtType<?> buildNewShadowClass(Class<?> cl) {
CtType<?> newShadowClass;
try {
newShadowClass = new JavaReflectionTreeBuilder(getShadowFactory()).scan(cl);
} catch (Throwable e) {
Launcher.LOGGER.warn("cannot create shadow class: {}", cl.getName(), e);

newShadowClass = getShadowFactory().Core().createClass();
newShadowClass.setSimpleName(cl.getSimpleName());
newShadowClass.setShadow(true);
getShadowFactory().Package().getOrCreate(cl.getPackage().getName()).addType(newShadowClass);
}
newShadowClass.setFactory(factory);
newShadowClass.accept(new CtScanner() {
@Override
public void scan(CtElement element) {
if (element != null) {
element.setFactory(factory);
}
}
});
return newShadowClass;
}

private transient Factory shadowFactory;
private Factory getShadowFactory() {
if (shadowFactory == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@
* element comes from the reflection api, use {@link spoon.reflect.declaration.CtShadowable#isShadow()}.
*/
public class JavaReflectionTreeBuilder extends JavaReflectionVisitorImpl {
private Deque<RuntimeBuilderContext> contexts = new ArrayDeque<>();
private Factory factory;
private final Deque<RuntimeBuilderContext> contexts;
private final Factory factory;

public JavaReflectionTreeBuilder(Factory factory) {
this.factory = factory;
this.contexts = new ArrayDeque<>();
}

private void enter(RuntimeBuilderContext context) {
Expand All @@ -87,46 +88,53 @@ private RuntimeBuilderContext exit() {

/** transforms a java.lang.Class into a CtType (ie a shadow type in Spoon's parlance) */
public <T, R extends CtType<T>> R scan(Class<T> clazz) {
CtPackage ctPackage;
CtType<?> ctEnclosingClass;
if (clazz.getEnclosingClass() != null && !clazz.isAnonymousClass()) {
ctEnclosingClass = factory.Type().get(clazz.getEnclosingClass());
return ctEnclosingClass.getNestedType(clazz.getSimpleName());
} else {
if (clazz.getPackage() == null) {
ctPackage = factory.Package().getRootPackage();
// We modify and query our modified model in this part. If another thread were to do the same
// on the same model, things will explode (e.g. with a ParentNotInitialized exception).
// We only synchronize in the main entrypoint, as that should be enough for normal consumers.
// The shadow factory should not be modified in other places and nobody should be directly calling
// the visit methods.
synchronized (factory) {
CtPackage ctPackage;
CtType<?> ctEnclosingClass;
if (clazz.getEnclosingClass() != null && !clazz.isAnonymousClass()) {
ctEnclosingClass = factory.Type().get(clazz.getEnclosingClass());
return ctEnclosingClass.getNestedType(clazz.getSimpleName());
} else {
ctPackage = factory.Package().getOrCreate(clazz.getPackage().getName());
}
if (contexts.isEmpty()) {
enter(new PackageRuntimeBuilderContext(ctPackage));
}
boolean visited = false;
if (clazz.isAnnotation()) {
visited = true;
visitAnnotationClass((Class<Annotation>) clazz);
}
if (clazz.isInterface() && !visited) {
visited = true;
visitInterface(clazz);
}
if (clazz.isEnum() && !visited) {
visited = true;
visitEnum(clazz);
}
if (MethodHandleUtils.isRecord(clazz) && !visited) {
visited = true;
visitRecord(clazz);
}
if (!visited) {
visitClass(clazz);
}
exit();
final R type = ctPackage.getType(clazz.getSimpleName());
if (clazz.isPrimitive() && type.getParent() instanceof CtPackage) {
type.setParent(null); // primitive type isn't in a package.
if (clazz.getPackage() == null) {
ctPackage = factory.Package().getRootPackage();
} else {
ctPackage = factory.Package().getOrCreate(clazz.getPackage().getName());
}
if (contexts.isEmpty()) {
enter(new PackageRuntimeBuilderContext(ctPackage));
}
boolean visited = false;
if (clazz.isAnnotation()) {
visited = true;
visitAnnotationClass((Class<Annotation>) clazz);
}
if (clazz.isInterface() && !visited) {
visited = true;
visitInterface(clazz);
}
if (clazz.isEnum() && !visited) {
visited = true;
visitEnum(clazz);
}
if (MethodHandleUtils.isRecord(clazz) && !visited) {
visited = true;
visitRecord(clazz);
}
if (!visited) {
visitClass(clazz);
}
exit();
final R type = ctPackage.getType(clazz.getSimpleName());
if (clazz.isPrimitive() && type.getParent() instanceof CtPackage) {
type.setParent(null); // primitive type isn't in a package.
}
return type;
}
return type;
}
}

Expand Down

0 comments on commit 3c6dc28

Please sign in to comment.