diff --git a/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java b/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java index 6d7ebfeee2e4..8d3ed8b4ce7c 100644 --- a/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java +++ b/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.javac; import org.jetbrains.annotations.NotNull; @@ -63,7 +63,11 @@ public final class Iterators { public interface Function { T fun(S s); } - + + public interface BiFunction { + T fun(S1 s1, S2 s2); + } + public interface BooleanFunction { boolean fun(T t); } @@ -368,12 +372,21 @@ public final class Iterators { } public static boolean equals(Iterable s1, Iterable s2) { + return equals(s1, s2, new BiFunction() { + @Override + public Boolean fun(T t1, T t2) { + return t1.equals(t2); + } + }); + } + + public static boolean equals(Iterable s1, Iterable s2, BiFunction comparator) { Iterator it2 = s2.iterator(); for (T elem : s1) { if (!it2.hasNext()) { return false; } - if (!elem.equals(it2.next())) { + if (!comparator.fun(elem, it2.next())) { return false; } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JvmDifferentiateStrategyImpl.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JvmDifferentiateStrategyImpl.java index 2a77c1423f86..4c56becea3df 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JvmDifferentiateStrategyImpl.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/JvmDifferentiateStrategyImpl.java @@ -56,7 +56,7 @@ public abstract class JvmDifferentiateStrategyImpl implements JvmDifferentiateSt else { context.affectUsage(usageFactory.apply(id)); } - debug("Affect ", usageKind, " usage owned by node ", id.getNodeName()); + debug("Affect ", usageKind, " usage owned by node '", id.getNodeName(), "'"); } } diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/KotlinMeta.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/KotlinMeta.java index 96ae55adad5f..ce9fa67c1386 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/java/KotlinMeta.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/java/KotlinMeta.java @@ -151,6 +151,11 @@ public final class KotlinMeta implements JvmMetadata getTypeParameters() { + KmDeclarationContainer container = getDeclarationContainer(); + return container instanceof KmClass? ((KmClass)container).getTypeParameters() : Collections.emptyList(); + } + @Nullable public KmDeclarationContainer getDeclarationContainer() { KotlinClassMetadata clsMeta = getClassMetadata(); @@ -192,7 +197,7 @@ public final class KotlinMeta implements JvmMetadata p1.getVariance() == p2.getVariance()); + } + public Specifier functions() { return myFunctionsDiff.get(); } diff --git a/jps/jps-builders/src/org/jetbrains/jps/dependency/kotlin/KotlinAwareJavaDifferentiateStrategy.java b/jps/jps-builders/src/org/jetbrains/jps/dependency/kotlin/KotlinAwareJavaDifferentiateStrategy.java index 2539dccafd15..ad8a9245239a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/dependency/kotlin/KotlinAwareJavaDifferentiateStrategy.java +++ b/jps/jps-builders/src/org/jetbrains/jps/dependency/kotlin/KotlinAwareJavaDifferentiateStrategy.java @@ -32,9 +32,8 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate if (!addedClass.isPrivate()) { // calls to newly added class' constructors may shadow calls to functions named similarly - String ktName = getKotlinName(addedClass); - debug("Affecting lookup usages for added class ", ktName); - affectLookupUsages(context, asIterable(new JvmNodeReferenceID(addedClass.getPackageName())), ktName != null? JvmClass.getShortName(ktName) : addedClass.getShortName(), future, null); + debug("Affecting lookup usages for added class ", addedClass.getName()); + affectClassLookupUsages(context, addedClass, future); } return true; @@ -50,9 +49,8 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate // this will affect all imports of this class in kotlin sources KmDeclarationContainer container = getDeclarationContainer(removedClass); if (container == null /*is non-kotlin node*/ || container instanceof KmClass) { - String clsName = container != null? ((KmClass)container).getName() : removedClass.getName(); - debug("Affecting lookup usages for removed class ", clsName); - affectLookupUsages(context, asIterable(new JvmNodeReferenceID(removedClass.getPackageName())), JvmClass.getShortName(clsName), present, null); + debug("Affecting lookup usages for removed class ", removedClass.getName()); + affectClassLookupUsages(context, removedClass, present); } } @@ -127,6 +125,11 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate for (Difference.Change metaChange : diff.metadata(KotlinMeta.class).changed()) { KotlinMeta.Diff metaDiff = metaChange.getDiff(); + if (metaDiff.typeParametersVarianceChanged()) { + debug("Kotlin class' type parameters' variance changed; affecting class usage ", changedClass.getName()); + affectSubclasses(context, future, change.getNow().getReferenceID(), true); + } + for (Difference.Change funChange : metaDiff.functions().changed()) { KmFunction changedKmFunction = funChange.getPast(); Visibility visibility = Attributes.getVisibility(changedKmFunction); @@ -272,11 +275,16 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate if (clsMethod.isPrivate()) { return; } - Set targets = collect( - flat(utils.allSupertypes(cls.getReferenceID()), utils.collectSubclassesWithoutMethod(cls.getReferenceID(), clsMethod)), new SmartHashSet<>() - ); - targets.add(cls.getReferenceID()); - affectLookupUsages(context, targets, getMethodKotlinName(cls, clsMethod), utils, constraint); + if (clsMethod.isConstructor()) { + affectClassLookupUsages(context, cls, utils); + } + else { + Set targets = collect( + flat(utils.allSupertypes(cls.getReferenceID()), utils.collectSubclassesWithoutMethod(cls.getReferenceID(), clsMethod)), new SmartHashSet<>() + ); + targets.add(cls.getReferenceID()); + affectLookupUsages(context, targets, getMethodKotlinName(cls, clsMethod), utils, constraint); + } } private static final class PropertyDescriptor{ @@ -350,6 +358,11 @@ public final class KotlinAwareJavaDifferentiateStrategy extends JvmDifferentiate return !iterator.hasNext(); } + private void affectClassLookupUsages(DifferentiateContext context, JvmClass cls, Utils utils) { + String ktName = getKotlinName(cls); + affectLookupUsages(context, asIterable(new JvmNodeReferenceID(cls.getPackageName())), ktName != null? JvmClass.getShortName(ktName) : cls.getShortName(), utils, null); + } + private void affectMemberLookupUsages(DifferentiateContext context, JvmClass cls, String name, Utils utils) { affectLookupUsages(context, filter(map(utils.withAllSubclasses(cls.getReferenceID()), id -> id instanceof JvmNodeReferenceID? ((JvmNodeReferenceID)id) : null), Objects::nonNull), name, utils, null); }