Skip to content

Commit

Permalink
De-emphasize type reachable in the ConfigurationCondition API
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed Nov 4, 2024
1 parent 8aa0c6d commit e679196
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@

/**
* A condition that describes if a reflectively-accessed element in Native Image is visible by the
* user.
* user at run time.
* <p>
* Currently, there is only one type of condition (<code>typeReached</code>) so this is a final
* class instead of the class hierarchy. The {@link ConfigurationCondition#type} represents the
* {@link Class<>} that needs to be reached by analysis in order for an element to be visible.
* Currently, there is only two types of condition:
* <li><code>typeReached</code> (the default) that signifies that the type must be both reachable by
* static analysis at build time, and reached at run time. A type is reached at run time, right
* before the class-initialization routine starts for that type, or any of the type's subtypes are
* reached.</li>
* <li><code>typeReachable</code> (legacy) that signifies that the type must be reachable by static
* analysis at build time.</li>
* <p>
* When {@link ConfigurationCondition#runtimeChecked} is <code>true</code> denotes that this is a
* <code>typeReached</code> condition.
*/
public final class ConfigurationCondition {

Expand All @@ -63,6 +70,25 @@ public static ConfigurationCondition alwaysTrue() {

private final boolean runtimeChecked;

/**
* Creates the default type-reached condition that is satisfied when the type is reached at
* runtime.
*
* @param type that has to be reached for this condition to be satisfied
* @return instance of the condition
*/
public static ConfigurationCondition create(Class<?> type) {
return create(type, true);
}

/**
* Creates either a type-reached condition ({@code runtimeChecked = true}) or a type-reachable
* condition.
*
* @param type that has to be reached (or reachable) for this condition to be satisfied
* @param runtimeChecked makes this a type-reachable condition when false
* @return instance of the condition
*/
public static ConfigurationCondition create(Class<?> type, boolean runtimeChecked) {
Objects.requireNonNull(type);
if (JAVA_LANG_OBJECT_REACHED.getType().equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public final class UnresolvedConfigurationCondition implements Comparable<Unreso
private final String typeName;
private final boolean runtimeChecked;

public static UnresolvedConfigurationCondition create(String typeName) {
return create(typeName, true);
}

public static UnresolvedConfigurationCondition create(String typeName, boolean runtimeChecked) {
Objects.requireNonNull(typeName);
if (JAVA_LANG_OBJECT_REACHED.getTypeName().equals(typeName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private ConfigurationSet deduceConditionalConfiguration(Map<MethodInfo, List<Met
for (List<MethodCallNode> value : methodCallNodes.values()) {
for (MethodCallNode node : value) {
String className = node.methodInfo.getJavaDeclaringClassName();
UnresolvedConfigurationCondition condition = UnresolvedConfigurationCondition.create(className, true);
UnresolvedConfigurationCondition condition = UnresolvedConfigurationCondition.create(className);
var resolvedCondition = ConfigurationConditionResolver.identityResolver().resolveCondition(condition);
addConfigurationWithCondition(configurationSet, node.configuration, resolvedCondition.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected UnresolvedConfigurationCondition parseCondition(EconomicMap<String, Ob
var condition = parseTypeContents(object);
if (condition.isPresent()) {
String className = ((NamedConfigurationTypeDescriptor) condition.get()).name();
return UnresolvedConfigurationCondition.create(className, true);
return UnresolvedConfigurationCondition.create(className);
}
} else if (conditionObject.containsKey(TYPE_REACHABLE_KEY)) {
if (runtimeCondition && !TreatAllTypeReachableConditionsAsTypeReached.getValue()) {
Expand Down

0 comments on commit e679196

Please sign in to comment.