← Back to Pull requests

review: feature: Implementation for Jigsaw modules(Java 9) with support for shadow modules #4751

Open
Auties00 opened this pull request with 1129 lines diff across 36 files
View on GitHub
Auties00 Auties00 commented on Jun 16, 2022 21:54 UTC
Author

Linked issue: https://github.com/INRIA/spoon/issues/4746

In Java 9 modules were introduced. This PR aims to add support for shadow modules and fix some inconsistencies about the existing module model without any breaking changes.

A list of changes in short:
1. Added public method getDeclaringModule inside CtElement, moved from CtPackage. The reason for this change is that it's important for a type to be easily traceable to its parent module. (Module awareness)
!image

2. CtModule now extends the CtShadowable interface which means that the entire language is supported by shadow models. The getPackage(String) and getAllPackages() methods were also added to the same interface to easily find a package by its fully qualified name or all packages inside a module. (module awareness)

3. Added all the properties defined in a [module descriptor] (https://docs.oracle.com/javase/17/docs/api/java/lang/module/ModuleDescriptor.html) by the JLS (Module model completeness)
!image

4. Added method createPackage(CtModule) to Factory and CoreFactory to create a package inside a module. Now createPackage() invokes createPackage(CtModule) using the unnamed module as an argument(default behaviour of previous versions).
!image

5. EnumFactory, on line 62 there was an erroneous use of the wildcard that wouldn't make the code compile, fixed it. (potentially unrelated)

6. Reworked the internals of ModuleFactory to make the unnamed module a standalone component of the AST(consistency)

7. Reworked the internals of PackageFactory to make packages module aware and create shadow modules if needed.

8. CtElementPathBuilder: changed fromElement method to use the root package of the module more efficiently (implementation)

9. AllMethodsSameSignatureFunction, OverriddenMethodQuery, SubInheritanceHierarchyFunction, Query, JDTBasedSpoonCompiler, SnippetCompilationHelper, SpoonModelTree: these look like big changes(practically most of the PR) but I've just added at most 2 lines of code to check in all modules and not only in the unnamed module(previously the unnamed module contained contained all modules so it was enough)

10. CtInheritanceScanner, added the scanCtShadowable as necessary in visitCtModule

11. Added getModule, addModule and removeModule methods from CtModule for consistency with all other public properties and as it looks like it's required by integration tests.
!image

12. Added methods getPackage(String), getModule(String), addModule(CtModule) and removeModule(CtModule) inside CtModel to allow for the existence of multiple modules instead of making all modules live under the unnamed module(as far as I understand this was the previous implementation, but it's objectively erroneous for the model to not divide modules)

13. Reworked CtModelImpl internals to work with the new module structure and decoupled CtRootPackage, consistent with CtUnnamedModule.

14. CtElementImpl replaced factory calls with getFactory()

15. ElementNameMap added null checks to accommodate for modules having a null parent

16. JavaReflectionTreeBuilder, JavaReflectionVisitor, JavaReflectionVisitorImpl, ModuleRuntimeBuilderContext: needed for shadow module construction. No logical changes

17. Changed SetParentTest to check new contract(aka modules have no parent)

New hierarchy in short:
!image

Diff: 1129 lines (+722 / -407) across 36 files Reviewer: Auties00 Review duration: 2305400m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.93) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.93 · 1129 lines diff across 36 files
0.93
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 5 substantive comment(s)
0.93
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
82%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Self Review self_review
0.140
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
27 items
Auties00 Auties00 commented on code on Jun 16, 2022 21:56 UTC
Code Review
src/main/java/spoon/support/reflect/declaration/CtClassImpl.java:1
@@ -289,4 +290,14 @@ public Collection<CtExecutableReference<?>> getAllExecutables() {
 		}
 		return l;
 	}
+
+	// FIXME: 16/06/2022 This is a workaround

First fixme

Auties00 Auties00 commented on code on Jun 16, 2022 21:57 UTC
Code Review
src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java:1
@@ -251,11 +172,149 @@ public boolean isEmpty() {
 		return getPackages().isEmpty() && getTypes().isEmpty();
 	}
 
-	void updateTypeName(CtType<?> newType, String oldName) {
+	@Override
+	public CtModule getDeclaringModule() {
+		return declaringModule;
+	}
+
+	@Override
+	public CtPackage getDeclaringPackage() {
+		return getParent(CtPackage.class);
+	}
+
+	@Override
+	public CtPackage getPackage(String name) {
+		return factory.getModel()
+				.getPackage(getQualifiedName() + CtPackage.PACKAGE_SEPARATOR_CHAR + name);
+	}
+
+	@Override
+	public Set<CtPackage> getPackages() {
+		return Set.copyOf(packs.values());
+	}
+
+	@Override
+	public <T extends CtNamedElement> T setSimpleName(String simpleName) {
+		String oldName = getSimpleName();
+		super.setSimpleName(simpleName);
+
+		if (parent instanceof CtPackageImpl) {
+			((CtPackageImpl) parent).updatePackageName(this, oldName);
+		}
+
+		return (T) this;
+	}
+
+	@Override
+	public <E extends CtElement> E setParent(CtElement newParent) {
+		if(newParent == null){
+			return super.setParent(null);
+		}
+
+		if(parent instanceof CtPackage){
+			CtPackage oldPackage = (CtPackage) parent;
+			oldPackage.removePackage(this);
+		}
+
+		if(newParent instanceof CtPackageImpl){
+			CtPackageImpl newPackage = (CtPackageImpl) newParent;
+			newPackage.getPackagesImpl()
+					.getBacking()
+					.put(getSimpleName(), this);
+		}
+
+		return super.setParent(newParent);
+	}
+
+	private Packages getPackagesImpl(){
+		return packs;
+	}
+
+	protected void setDeclaringModule(CtModule declaringModule) {
+		this.declaringModule = declaringModule;
+	}
+
+	protected void updateTypeName(CtType<?> newType, String oldName) {
 		types.updateKey(oldName, newType.getSimpleName());
 	}
 
-	void updatePackageName(CtPackage newPackage, String oldName) {
+	protected void updatePackageName(CtPackage newPackage, String oldName) {
 		packs.updateKey(oldName, newPackage.getSimpleName());
 	}
+
+	// FIXME: 16/06/2022 This is a workaround
+	@Override
+	public CtRole getRoleInParent() {

Second fixme

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/support/reflect/declaration/CtPackageImpl.java:1
@@ -251,11 +172,149 @@
 		return getPackages().isEmpty() && getTypes().isEmpty();
 	}
 
-	void updateTypeName(CtType<?> newType, String oldName) {
+	@Override
+	public CtModule getDeclaringModule() {
+		return declaringModule;
+	}
+
+	@Override
+	public CtPackage getDeclaringPackage() {
+		return getParent(CtPackage.class);
+	}
+
+	@Override
+	public CtPackage getPackage(String name) {
+		return factory.getModel()
+				.getPackage(getQualifiedName() + CtPackage.PACKAGE_SEPARATOR_CHAR + name);
+	}
+
+	@Override
+	public Set<CtPackage> getPackages() {
+		return Set.copyOf(packs.values());
+	}
+
+	@Override
+	public <T extends CtNamedElement> T setSimpleName(String simpleName) {
+		String oldName = getSimpleName();
+		super.setSimpleName(simpleName);
+
+		if (parent instanceof CtPackageImpl) {
+			((CtPackageImpl) parent).updatePackageName(this, oldName);
+		}
+
+		return (T) this;
+	}
+
+	@Override
+	public <E extends CtElement> E setParent(CtElement newParent) {
+		if(newParent == null){
+			return super.setParent(null);
+		}
+
+		if(parent instanceof CtPackage){
+			CtPackage oldPackage = (CtPackage) parent;
+			oldPackage.removePackage(this);
+		}
+
+		if(newParent instanceof CtPackageImpl){
+			CtPackageImpl newPackage = (CtPackageImpl) newParent;
+			newPackage.getPackagesImpl()
+					.getBacking()
+					.put(getSimpleName(), this);
+		}
+
+		return super.setParent(newParent);
+	}
+
+	private Packages getPackagesImpl(){
+		return packs;
+	}
+
+	protected void setDeclaringModule(CtModule declaringModule) {
+		this.declaringModule = declaringModule;
+	}
+
+	protected void updateTypeName(CtType<?> newType, String oldName) {
 		types.updateKey(oldName, newType.getSimpleName());
 	}
 
-	void updatePackageName(CtPackage newPackage, String oldName) {
+	protected void updatePackageName(CtPackage newPackage, String oldName) {
 		packs.updateKey(oldName, newPackage.getSimpleName());
 	}
+
+	// FIXME: 16/06/2022 This is a workaround
+	@Override
+	public CtRole getRoleInParent() {
+		if(getParent() instanceof CtRootPackageImpl){
+			return null;

Return of 'null'

Return of 'null'

Show more details

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/support/reflect/declaration/CtClassImpl.java:1
@@ -289,4 +290,14 @@
 		}
 		return l;
 	}
+
+	// FIXME: 16/06/2022 This is a workaround
+	@Override
+	public CtRole getRoleInParent() {
+		if(getParent() instanceof CtRootPackageImpl){
+			return null;

Return of 'null'

Return of 'null'

Show more details

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/reflect/CtModelImpl.java:1
@@ -137,10 +145,33 @@
 		return this.buildModelFinished;
 	}
 
+	@Override
+	public <T extends CtModel> T addModule(CtModule module) {
+		modules.put(module.getSimpleName(), module);
+		return (T) this;
+	}
+
+	@Override
+	public <T extends CtModel> T removeModule(CtModule module) {
+		modules.remove(module.getSimpleName());
+		return (T) this;
+	}
+
 	@Override
 	public <T extends CtModel> T setBuildModelIsFinished(boolean buildModelFinished) {
 		this.buildModelFinished = buildModelFinished;
 		return (T) this;
 	}
 
+	private static class Modules extends ElementNameMap<CtModule>{
+		@Override
+		protected CtElement getOwner() {
+			return null;

Return of 'null'

Return of 'null'

Show more details

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/support/reflect/declaration/CtModuleImpl.java:1
@@ -429,9 +473,43 @@
 		return (T) this;
 	}
 
+	@Override
+	public Collection<CtPackage> getAllPackages() {
+		return getAllPackages(getRootPackage());
+	}
+
+	private List<CtPackage> getAllPackages(CtPackage source) {
+		List<CtPackage> results = new ArrayList<>();
+		results.add(source);
+		source.getPackages().forEach(entry -> {
+			results.add(entry);
+			entry.getPackages()
+					.stream()
+					.map(this::getAllPackages)
+					.forEach(results::addAll);
+		});
+
+		return results;
+	}
+
+	@Override
+	public CtModule getDeclaringModule() {
+		return this;
+	}
+
 	@Override
 	@DerivedProperty
 	public CtElement getParent() {
-		return getFactory().getModel().getUnnamedModule();
+		return null;

Return of 'null'

Return of 'null'

Show more details

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/support/visitor/java/JavaReflectionTreeBuilder.java:1
@@ -88,49 +50,142 @@
 
 	/** 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());
+			CtType<?> ctEnclosingClass = factory.Type().get(clazz.getEnclosingClass());
 			return ctEnclosingClass.getNestedType(clazz.getSimpleName());
 		} else {
-			if (clazz.getPackage() == null) {
-				ctPackage = factory.Package().getRootPackage();
-			} else {
-				ctPackage = factory.Package().getOrCreate(clazz.getPackage().getName());
-			}
-			if (contexts.isEmpty()) {
-				enter(new PackageRuntimeBuilderContext(ctPackage));
+			CtPackage ctPackage = clazz.getPackage() != null ? factory.Package().getOrCreate(clazz.getPackage().getName())
+					: factory.Package().getRootPackage();
+			if(contexts.isEmpty()){
+				contexts.add(new PackageRuntimeBuilderContext(ctPackage));
 			}
-			boolean visited = false;
+
 			if (clazz.isAnnotation()) {
-				visited = true;
 				visitAnnotationClass((Class<Annotation>) clazz);
-			}
-			if (clazz.isInterface() && !visited) {
-				visited = true;
+			}else if (clazz.isInterface()) {
 				visitInterface(clazz);
-			}
-			if (clazz.isEnum() && !visited) {
-				visited = true;
+			}else if (clazz.isEnum()) {
 				visitEnum(clazz);
-			}
-			if (MethodHandleUtils.isRecord(clazz) && !visited) {
-				visited = true;
+			}else if (MethodHandleUtils.isRecord(clazz)) {
 				visitRecord(clazz);
-			}
-			if (!visited) {
+			}else {
 				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;
 		}
 	}
 
+	@Override
+	public void visitModule(Module module) {
+		CtModule know = factory.Module().getModule(module.getName());
+		if (know != null && know.isAttributed()) {
+			return;
+		}
+
+		CtModule fresh = know != null ? know : factory.Module().getOrCreate(module.getName());
+		ModuleDescriptor descriptor = module.getDescriptor();
+		if(descriptor != null){
+			attributeModule(fresh, descriptor);
+		}
+
+		fresh.setIsAttributed(true);
+		enter(new ModuleRuntimeBuilderContext(fresh));
+		super.visitModule(module);
+		exit();
+	}
+
+	private void attributeModule(CtModule fresh, ModuleDescriptor descriptor) {
+		fresh.setIsOpenModule(descriptor.isOpen());
+		fresh.setIsAutomatic(descriptor.isAutomatic());
+
+		List<CtModuleRequirement> requires = descriptor.requires()
+				.stream()
+				.map(this::createRequires)
+				.collect(Collectors.toUnmodifiableList());
+		fresh.setRequiredModules(requires);
+
+		List<CtPackageExport> exports = descriptor.exports()
+				.stream()
+				.map(instruction -> createExport(instruction.source(), instruction.targets(), false))
+				.collect(Collectors.toUnmodifiableList());
+		fresh.setExportedPackages(exports);
+
+		List<CtPackageExport> opens = descriptor.opens()
+				.stream()
+				.map(instruction -> createExport(instruction.source(), instruction.targets(), true))
+				.collect(Collectors.toUnmodifiableList());
+		fresh.setOpenedPackages(opens);
+
+		List<CtProvidedService> provides = descriptor.provides()
+				.stream()
+				.map(this::createProvides)
+				.collect(Collectors.toUnmodifiableList());
+		fresh.setProvidedServices(provides);
+
+		List<CtUsedService> uses = descriptor.uses()
+				.stream()
+				.map(this::createUses)
+				.collect(Collectors.toUnmodifiableList());
+		fresh.setUsedServices(uses);
+	}
+
+	private CtModuleRequirement createRequires(ModuleDescriptor.Requires instruction) {
+		CtModuleReference requiredModule = factory.Module().createReference(instruction.name());
+		Set<CtModuleRequirement.RequiresModifier> modifiers = new HashSet<>();

'Set' can be replaced with 'EnumSet'

'HashSet<>' can be replaced with 'EnumSet'

Show more details

github-advanced-security[bot] github-advanced-security[bot] commented on code on Jun 17, 2022 06:45 UTC
Code Review
src/main/java/spoon/reflect/visitor/filter/AllMethodsSameSignatureFunction.java:1
@@ -114,62 +115,67 @@
 		targetMethods.add(targetMethod);
 		CtType<?> declaringType = targetMethod.getDeclaringType();
 		lambdaFilter.addImplementingInterface(declaringType);
-		//search for all declarations and implementations of this method in sub and super classes and interfaces of all related hierarchies.
-		class Context {
-			boolean haveToSearchForSubtypes;
-		}
-		final Context context = new Context();
-		//at the beginning we know that we have to always search for sub types too.
-		context.haveToSearchForSubtypes = true;
-		//Sub inheritance hierarchy function, which remembers visited sub types and does not returns/visits them again
-		final SubInheritanceHierarchyResolver subHierarchyFnc = new SubInheritanceHierarchyResolver(declaringType.getFactory().getModel().getRootPackage());
-		//add hierarchy of `targetMethod` as to be checked for sub types of declaring type
-		subHierarchyFnc.addSuperType(declaringType);
-		//unique names of all types whose super inheritance hierarchy was searched for rootType
-		Set<String> typesCheckedForRootType = new HashSet<>();
-		//list of sub types whose inheritance hierarchy has to be checked
-		final List<CtType<?>> toBeCheckedSubTypes = new ArrayList<>();
-		//add hierarchy of `targetMethod` as to be checked for super types of declaring type
-		toBeCheckedSubTypes.add(declaringType);
-		while (!toBeCheckedSubTypes.isEmpty()) {
-			for (CtType<?> subType : toBeCheckedSubTypes) {
-				TypeAdaptor typeAdaptor = new TypeAdaptor(subType);
-				//search for first target method from the same type inheritance hierarchy
-				targetMethod = getTargetMethodOfHierarchy(targetMethods, typeAdaptor);
-				//search for all methods with same signature in inheritance hierarchy of `subType`
-				forEachOverridenMethod(typeAdaptor, targetMethod, typesCheckedForRootType, new CtConsumer<CtMethod<?>>() {
-					@Override
-					public void accept(CtMethod<?> overriddenMethod) {
-						targetMethods.add(overriddenMethod);
-						outputConsumer.accept(overriddenMethod);
-						CtType<?> type = overriddenMethod.getDeclaringType();
-						lambdaFilter.addImplementingInterface(type);
-						subHierarchyFnc.addSuperType(type);
-						//mark that new super type was added, so we have to search for sub types again
-						context.haveToSearchForSubtypes = true;
+
+		for(CtModule ctModule : declaringType.getFactory().getModel().getAllModules()) {
+			//search for all declarations and implementations of this method in sub and super classes and interfaces of all related hierarchies.
+			class Context {
+				boolean haveToSearchForSubtypes;
+			}
+			final Context context = new Context();
+			//at the beginning we know that we have to always search for sub types too.
+			context.haveToSearchForSubtypes = true;
+
+
+			//Sub inheritance hierarchy function, which remembers visited sub types and does not returns/visits them again
+			final SubInheritanceHierarchyResolver subHierarchyFnc = new SubInheritanceHierarchyResolver(ctModule.getRootPackage());
+			//add hierarchy of `targetMethod` as to be checked for sub types of declaring type
+			subHierarchyFnc.addSuperType(declaringType);
+			//unique names of all types whose super inheritance hierarchy was searched for rootType
+			Set<String> typesCheckedForRootType = new HashSet<>();
+			//list of sub types whose inheritance hierarchy has to be checked
+			final List<CtType<?>> toBeCheckedSubTypes = new ArrayList<>();
+			//add hierarchy of `targetMethod` as to be checked for super types of declaring type
+			toBeCheckedSubTypes.add(declaringType);
+			while (!toBeCheckedSubTypes.isEmpty()) {
+				for (CtType<?> subType : toBeCheckedSubTypes) {
+					TypeAdaptor typeAdaptor = new TypeAdaptor(subType);
+					//search for first target method from the same type inheritance hierarchy
+					targetMethod = getTargetMethodOfHierarchy(targetMethods, typeAdaptor);
+					//search for all methods with same signature in inheritance hierarchy of `subType`
+					forEachOverridenMethod(typeAdaptor, targetMethod, typesCheckedForRootType, new CtConsumer<CtMethod<?>>() {
+						@Override
+						public void accept(CtMethod<?> overriddenMethod) {
+							targetMethods.add(overriddenMethod);
+							outputConsumer.accept(overriddenMethod);
+							CtType<?> type = overriddenMethod.getDeclaringType();
+							lambdaFilter.addImplementingInterface(type);
+							subHierarchyFnc.addSuperType(type);
+							//mark that new super type was added, so we have to search for sub types again
+							context.haveToSearchForSubtypes = true;
+						}
+					});
+					if (query.isTerminated()) {
+						return;
 					}
-				});
-				if (query.isTerminated()) {
-					return;
+				}
+				toBeCheckedSubTypes.clear();
+				if (context.haveToSearchForSubtypes) {
+					context.haveToSearchForSubtypes = false;
+					//there are some new super types, whose sub inheritance hierarchy has to be checked
+					//search their inheritance hierarchy for sub types
+					subHierarchyFnc.forEachSubTypeInPackage(new CtConsumer<CtType<?>>() {

Anonymous type can be replaced with method reference

Anonymous new CtConsumer>() can be replaced with method reference

Show more details

MartinWitt MartinWitt commented on Jun 20, 2022 14:06 UTC
Contributor

I took a quick glance at your pull request. We try to create small PRs that only fix the issue and do not include unrelated changes at spoon. Your code style changes are fine, but they should not be included in this PR. Can you change this so that only changes relevant to the bug fix are included?

Auties00 Auties00 commented on Jun 20, 2022 16:40 UTC
Author

I took a quick glance at your pull request. We try to create small PRs that only fix the issue and do not include unrelated changes at spoon. Your code style changes are fine, but they should not be included in this PR. Can you change this so that only changes relevant to the bug fix are included?

Sure, no problem. It was accidental as intellij automatically styles the code I write in that way. Also can you help me with the issue i mentioned? It should be quite easy to fix but I haven't had time to look into it these last days

flacocobot flacocobot commented on Jun 21, 2022 13:50 UTC
Contributor

flacoco flags 5 suspicious lines as the potential root cause of the test failure.

The line 92 of the file src/test/java/spoon/LauncherTest.java has been identified with a suspiciousness value of 92.43%.

The line 93 of the file src/test/java/spoon/LauncherTest.java has been identified with a suspiciousness value of 92.43%.

The line 98 of the file src/test/java/spoon/LauncherTest.java has been identified with a suspiciousness value of 92.43%.

The line 11 of the file src/main/java/spoon/support/reflect/declaration/CtUnnamedModuleImpl.java has been identified with a suspiciousness value of 89.65%.

The line 12 of the file src/main/java/spoon/support/reflect/declaration/CtUnnamedModuleImpl.java has been identified with a suspiciousness value of 89.65%.

MartinWitt MartinWitt commented on Jun 21, 2022 16:54 UTC
Contributor

Can you point me to a test case which produces your problem?

Auties00 Auties00 commented on Jun 22, 2022 11:15 UTC
Author

Can you point me to a test case which produces your problem?

I've fixed them myself just now. Is there a way though to automatically generate ModelRoleHandlers or should I implement them manually?

Auties00 Auties00 commented on Jun 26, 2022 15:34 UTC
Author

It should be ready for review. The only thing that I don't really like is how I check if a module was attributed in JavaReflectionTreeBuilder, but having a property only in the implementation seems to break some tests. If a maintainer can check that, it would be great.

MartinWitt MartinWitt commented on Jul 02, 2022 14:12 UTC
Contributor

Your pull request is still really noise and has unrelated changes like the conversion of imports to package imports. Could you clean it up a bit? This helps a lot in the review process.
Edit: There are also 95 checkstyle error.

Auties00 Auties00 commented on Jul 03, 2022 21:00 UTC
Author

Your pull request is still really noise and has unrelated changes like the conversion of imports to package imports. Could you clean it up a bit? This helps a lot in the review process. Edit: There are also 95 checkstyle error.

I've fixed all of the styling problems. Sorry, but I didn't actually notice that my IDE was continuing to apply my default styling also here. Now it should be fixed. For the checkstyle errors I've tried to run qodana locally but I cannot seem to make it analyze only a particular commit or branch

I-Al-Istannen I-Al-Istannen commented on Jul 04, 2022 20:25 UTC
Contributor

For the checkstyle errors I've tried to run qodana locally but I cannot seem to make it analyze only a particular commit or branch

You probably want to run mvn checkstyle:check instead?

Auties00 Auties00 commented on Jul 08, 2022 12:00 UTC
Author

> For the checkstyle errors I've tried to run qodana locally but I cannot seem to make it analyze only a particular commit or branch

> You probably want to run mvn checkstyle:check instead?

Yeah that's probably it. I'm currently on vacation, I'll do it asap

Auties00 Auties00 commented on Jul 26, 2022 20:13 UTC
Author

It's becoming a challenge to make this ready :/
Fixed all the tests again.
It would be nice if I could run the CI myself because I can't check if it passes except for the integration tests which wastes a bunch of weeks

I-Al-Istannen I-Al-Istannen commented on Jul 26, 2022 20:51 UTC
Contributor

It would be nice if I could run the CI myself because I can't check if it passes except for the integration tests which wastes a bunch of weeks

That is sadly a Github setting we (AFAIK) won't get around until you've merged a PR.

----

About your PR


First up, thanks for your changes! I hope the rest is not too discouraging :)

I was looking at it here and there, but your PR changes multiple different and unrelated things at once. This makes reviewing it quite a chore.

You are at least:

  • Updating the readme

  • Updating plugin versions

  • Reworking how modules are handled internally which might break existing assumptions in some places or downstream consumers (i.e. it might be breaking?). This change also has a huge surface area, necessitating careful review.

  • - This also seems to make a lot more places module-aware than before.
  • Adding new public APIs to work with modules at the CtModel level (I am not sure what exactly we want to allow here)

  • Actually build shadow modules

  • Performing some completely unrelated changes AFAICT in CtElementImpl

  • Reworks how packages are structured internally (or maybe just refactors some things, I am not sure)

  • Adds some unexplained null checks in the ElementNameMap, which warrant a comment

  • Fiddles with the termination and duplication conditions of the JavaReflectionTreeBuilder
  • And maybe more I missed. While some of them certainly could be bundled together, it currently does way too many things IMHO. I am not smart enough to keep the whole thing paged in main memory and don't have the time to detangle all this into different changesets to properly understand what and why you changed things.

    My humble request


    I can't speak for anybody else on the project and especially not the integrators, but the PR in its current form is a bit of a hard pill to swallow. I'd greatly appreciate if you could split it along at least a few of the points I outlined above (or, even better: You find your own independent changes, as you are probably better at it than I am). Merging some of the smaller ones would also allow you to run workflows, as a nice side effect.

    Auties00 Auties00 commented on Jul 26, 2022 21:47 UTC
    Author

    Updating the readme

    Updating plugin versions

    I'm not changing those, I was working out the merge conflicts between my upstream and the main one as it looks like there were some changes in previous commits that I didn't merge correctly the first time around. It should be fixed in the latest commit, sorry about that.

    Reworking how modules are handled internally which might break existing assumptions in some places or downstream consumers (i.e. it might be breaking?). This change also has a huge surface area, necessitating careful review.

    Actually build shadow modules

    This PR adds support for shadow modules so it makes sense to make every component module aware while the opportunity is there in my opinion. Previously modules were supported, but you couldn't really do anything useful with them because of the lack of module awareness and shadow support. Talking about backwards compatibility, everything should continue to work and nothing should break except that the parent of a named module is no longer the unnamed module as I explained in the introduction, but no element as they are by definition standalone containers. In practice, this means that old code which checks the parent of a module and expects the unnamed will not work. Though, this is practically a non-issue as previously only the unnamed module had any presence in the various components of the AST so I don't see who is going to check if the parent of the unnamed module is the unnamed module(which doesn't even make sense logically but that's beside the point). If it's necessary to keep this condition in, I can definitely revert it, but it breaks quite clearly the JLS which is an issue that someday will need to be addressed in my opinion. I think that it's better to do it now, before shadow modules are introduced as doing it later may actually break some code.

    Adding new public APIs to work with modules at the CtModel level (I am not sure what exactly we want to allow here)

    I added those methods for consistency with the model overall and as some tests even depend on the existence of getters and setters for public fields of the meta-model, unless marked explicitly with @Unsettable for the latter.

    Performing some completely unrelated changes AFAICT in CtElementImpl

    The changes in CtElementImpl are actually related. Considering that the parent of a module is null, which was previously not true as explained in the previous points, the get parent and get factory methods need to take that into account.

    Reworks how packages are structured internally (or maybe just refactors some things, I am not sure)

    I've changed how packages are handled internally to make packages module aware while not sacrificing performance, so I'd say that it's relevant. Btw it doesn't break anything and the implementation is practically identical(no checks have been changed).

    Adds some unexplained null checks in the ElementNameMap, which warrant a comment

    This is related to the previous point. A module doesn't have an owner which needs to be taken into account. I can definitely add a comment btw

    Fiddles with the termination and duplication conditions of the JavaReflectionTreeBuilder

    Practically nothing has changed there except for the fact that modules are also analyzed

    I can't speak for anybody else on the project and especially not the integrators, but the PR in its current form is a bit of a hard pill to swallow. I'd greatly appreciate if you could split it along at least a few of the points I outlined above (or, even better: You find your own independent changes, as you are probably better at it than I am). Merging some of the smaller ones would also allow you to run workflows, as a nice side effect.

    If it's necessary, I can divide the PR into a rework of the module system and package system for better module awareness and the addition of shadow modules, though in practice practically nothing will change as the changes will still need to be reviewed. If you want I can add a commit message explaining all the changes file per file which should make it very easy to review which I think is better. Though I'm open to accepting any option that is preferable for the project

    EDIT: I've reviewed all of my code to remove any unnecessary change and updated this PR to contain all changes

    Auties00 Auties00 commented on Aug 07, 2022 10:37 UTC
    Author

    Oh well looks like there is a single test failing right now. I'll look into it

    Auties00 Auties00 commented on Sep 06, 2022 17:39 UTC
    Author

    Ready for review. @I-Al-Istannen sorry for the tag, but can you please run the CI?

    Auties00 Auties00 commented on Sep 07, 2022 22:56 UTC
    Author

    Fixed the checkstyle

    Auties00 Auties00 commented on Sep 12, 2022 18:54 UTC
    Author

    For the maintainers: should I fix the Javadoc? I really didn't change anything there. The PR should be ready as it passes all integration tests apart from that

    slarse slarse commented on Sep 17, 2022 08:26 UTC
    Contributor

    I have no context on this whole topic so I can't make specific comments on the code, but I can answer some of the outstanding questions.

    For the maintainers: should I fix the Javadoc? I really didn't change anything there.

    You're failing a check that's part of our ongoing effort to improve upon Spoon's API documentation (see #3923). Specifically, you've added public methods without documenting e.g. type and method parameters. A script checks before/after and fails if the amount of Checkstyle violations for Javadoc increases. You can run the script locally, run python3 chore/check-javadoc-regressions.py --help to see how to use it. The short of it is that for any new public method, you need to _fully_ document it.

    If it's necessary, I can divide the PR into a rework of the module system and package system for better module awareness and the addition of shadow modules, though in practice practically nothing will change as the changes will still need to be reviewed.

    Yes, I would say it is necessary. The integrators of Spoon do not merge something we don't understand fully, and understanding this large a change fully in one go is a lot to ask. A smaller change is also easier to debug if there is significant breakage in post-merge tests. So by all means, this needs to be broken down into smaller pieces. @I-Al-Istannen feel free to weigh in.

    That goes double for the changes to the public API, which we are very conservative in changing. Every single method has to be carefully justified, reviewed and reasoned about. A single PR adding more than a single new method is therefore just on that account asking a whole lot of reviewers.

    I just want to make clear that I'm in no way trying to discourage you from contributing Spoon. It's _great_ that you want to contribute, without people like you we would not have Spoon. I can tell you've put a lot of effort into this and for that I salute you, but the unfortunate reality is that with all of that effort you've created something too large for us to take in in one go.

    Reviewers
    Assignees
    Auties00 Auties00
    Labels
    risk: low confidence: 82.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 92.5% (HIGH) · Higher = larger blast radius
    92.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 82.8% · Lower = rushed or shallow review
    82.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%
    Repository