JPS mappings for incremental compilation refactoring: support changes in Kotlin inline methods with lookup-based usage rules

GitOrigin-RevId: e7b833d505ff5f1155c79607acb3a23316cbe5e4
This commit is contained in:
Eugene Zhuravlev
2024-02-28 13:10:31 +01:00
committed by intellij-monorepo-bot
parent d52c5f8435
commit 1fa85d13e7
17 changed files with 46 additions and 53 deletions

View File

@@ -190,11 +190,13 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate
JvmMethod changedMethod = methodChange.getPast();
JvmNodeReferenceID clsId = changedClass.getReferenceID();
if (isKotlinNode(changedClass) && methodChange.getDiff().valueChanged()) {
debug("Method was inlineable, or has become inlineable or a body of inline method has changed; affecting method usages ", changedMethod);
affectMemberUsages(context, clsId, changedMethod, future.collectSubclassesWithoutMethod(clsId, changedMethod));
if (methodChange.getDiff().valueChanged()) {
KmFunction kmFunction = getKmFunction(changedClass, changedMethod);
if (kmFunction != null) {
debug("Method was inlineable, or has become inlineable or a body of inline method has changed; affecting method usages ", changedMethod);
affectLookupUsages(context, flat(asIterable(clsId), future.collectSubclassesWithoutMethod(clsId, changedMethod)), kmFunction.getName(), future);
}
}
return true;
}
@@ -296,6 +298,13 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate
return !iterator.hasNext();
}
private void affectLookupUsages(DifferentiateContext context, Iterable<JvmNodeReferenceID> symbolOwners, String symbolName, Utils utils) {
affectUsages(context, "lookup usage", symbolOwners, id -> {
String kotlinName = getKotlinName(id, utils);
return new LookupNameUsage(kotlinName != null ? new JvmNodeReferenceID(kotlinName) : id, symbolName);
}, null);
}
private static KmFunction getKmFunction(JvmClass cls, JvmMethod method) {
JvmMethodSignature methodSignature = new JvmMethodSignature(method.getName(), method.getDescriptor());
return find(allKmFunctions(cls), f -> methodSignature.equals(JvmExtensionsKt.getSignature(f)));
@@ -310,6 +319,23 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate
return meta != null? meta.getKmFunctions() : Collections.emptyList();
}
@Nullable
private static String getKotlinName(JvmNodeReferenceID cls, Utils utils) {
return find(map(utils.getNodes(cls, JvmClass.class), c -> getKotlinName(c)), Objects::nonNull);
}
@Nullable
private static String getKotlinName(JvmClass cls) {
KmDeclarationContainer container = getDeclarationContainer(cls);
if (container instanceof KmPackage) {
return cls.getPackageName();
}
if (container instanceof KmClass) {
return ((KmClass)container).getName();
}
return null;
}
private static KmDeclarationContainer getDeclarationContainer(Node<?, ?> node) {
KotlinMeta meta = getKotlinMeta(node);
return meta != null? meta.getDeclarationContainer() : null;

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,10 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
src/topLevelUsage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/Usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module

View File

@@ -7,9 +7,7 @@ End of files
Compiling files:
src/inline.kt
End of files
After build round. Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
Exit code: OK
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module