This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
chore: Handle forward references, repeatable annotations, and use str enums #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, we eagerly compile the class as soon as
@planning_entity
or@planning_solution
is reached. This cause problem if the class contains forward references, since:The referenced class does not exist when
@planning_entity
or@planning_solution
is reached, since it is defined later.This causes
get_type_hints
to raise a NameError, since it cannot find the type name in locals or globalsNow, the classes are compiled when the SolverConfig is read (and
thus, all the referenced classes should be defined).
In order to handle forward references in annotations and the class translator, usage of getJavaClass (which may throw an exception if the class is in the middle of being defined) need to be changed to getJavaClassInternalName (which will never throw). Thus:
ArgumentSpec now take the return type and parameters of a function as String instead of their Class. There could be a Class overload that calls the String version, but I decided against it to prevent the temptation to pass getJavaClass to it.
PythonDefaultArgumentImplementor now sets its constants inside , which means ArgumentSpec must store itself in a static field so clinit can access it. This is because if a Class cannot be loaded until all the Classes it references are defined (and thus, we cannot set the field values from Java, since PythonDefaultArgumentImplementor might reference a class still being defined).
AnnotationMetadata now store Class values as Type instead of Class.
In order for Timefold to discover the "true" type of annotated getters, we remove NoneType from the Union of the getter return type (but keep it in the actual field type). That is, if a type is annotated
Value | None
, the getter type will beValue
, and the field type will beget_common_ancestor(Value, NoneType) = object
.Use PythonClassWriter instead of ClassWriter in the ClassTranslator, so ASM will not complain about missing classes when computing frames.
In order to properly visit a repeatable annotation, we need to group the repeated annotation by type and put them as the value of their container annotation class.
Make VersionMapping throw an exception if it gets a null version mapping (otherwise, an undescriptive NPE will happen if the unsupported opcode is in the bytecode).
Added the missing PreviousElementShadowVariable and NextElementShadowVariable annotations.
Use str enums, so the enum serializes to their names instead of a number.