Skip to content

Commit

Permalink
JPS mappings for incremental compilation refactoring: adjusted affect…
Browse files Browse the repository at this point in the history
…ion scope for Kotlin extension functions

GitOrigin-RevId: dbfa8a201fee9d8c1b2386c29fca657eefcc70b3
  • Loading branch information
Eugene Zhuravlev authored and intellij-monorepo-bot committed Nov 27, 2023
1 parent 89ce08a commit 9464787
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected boolean processMethodArgumentBecameLambdaTarget(DifferentiateContext c
if (!super.processMethodArgumentBecameLambdaTarget(context, cls, clsMethod, argSAMType, future, present)) {
return false;
}
context.affectUsage(new AffectionScopeMetaUsage(cls.getReferenceID()));
affectConflictingExtensionMethods(context, cls, clsMethod, future);
return true;
}
Expand All @@ -82,22 +81,33 @@ protected boolean processAddedMethod(DifferentiateContext context, JvmClass chan
}

private static void affectConflictingExtensionMethods(DifferentiateContext context, JvmClass cls, JvmMethod clsMethod, Utils utils) {
TypeRepr.ClassType firstArgType = new TypeRepr.ClassType(cls.getName()); // the first arg is always the class being extended
// the first arg is always the class being extended
Set<String> firstArgTypes = collect(
map(flat(utils.allSupertypes(cls.getReferenceID()), utils.collectSubclassesWithoutMethod(cls.getReferenceID(), clsMethod)), id -> id.getNodeName()), new HashSet<>()
);
firstArgTypes.add(cls.getName());
for (String clsName : firstArgTypes) {
context.affectUsage(new AffectionScopeMetaUsage(new JvmNodeReferenceID(clsName)));
}
context.affectUsage((n, u) -> {
if (!(u instanceof MethodUsage) || !(n instanceof JvmClass)) {
return false;
}
MethodUsage methodUsage = (MethodUsage)u;
JvmClass contextCls = (JvmClass)n;
if (Objects.equals(methodUsage.getElementOwner(), cls.getReferenceID()) || !Objects.equals(methodUsage.getName(), clsMethod.getName())) {
if (firstArgTypes.contains(methodUsage.getElementOwner().getNodeName()) || !Objects.equals(methodUsage.getName(), clsMethod.getName())) {
return false;
}
Type calledMethodType = Type.getType(methodUsage.getDescriptor());
if (!Objects.equals(clsMethod.getType(), TypeRepr.getType(calledMethodType.getReturnType()))) {
return false;
}
Iterator<TypeRepr> args = map(Arrays.asList(calledMethodType.getArgumentTypes()), TypeRepr::getType).iterator();
if (!args.hasNext() || !firstArgType.equals(args.next())) {
if (!args.hasNext()) {
return false;
}
TypeRepr firstArgType = args.next();
if (!(firstArgType instanceof TypeRepr.ClassType) || !firstArgTypes.contains(((TypeRepr.ClassType)firstArgType).getJvmName())) {
return false;
}
for (TypeRepr expectedArgType : clsMethod.getArgTypes()) {
Expand Down

0 comments on commit 9464787

Please sign in to comment.