JPS: support java16 instanceof pattern matching

GitOrigin-RevId: 5a2777c4234e63621c1daf4bc11da402edaae8f5
This commit is contained in:
Eugene Zhuravlev
2024-07-05 15:58:16 +02:00
committed by intellij-monorepo-bot
parent 7ffc3f8f8b
commit 40bbc9947b
10 changed files with 52 additions and 6 deletions

View File

@@ -5,10 +5,12 @@ Compiling files:
src/Super.java
End of files
Cleaning output files:
out/production/AddImplements/Client.class
out/production/AddImplements/Client2.class
out/production/AddImplements/Client3.class
End of files
Compiling files:
src/Client.java
src/Client2.java
src/Client3.java
End of files
End of files

View File

@@ -0,0 +1,14 @@
Cleaning output files:
out/production/AddImplementsPatternMatching/I2.class
End of files
Compiling files:
src/I2.java
End of files
Cleaning output files:
out/production/AddImplementsPatternMatching/I3.class
out/production/AddImplementsPatternMatching/Main.class
End of files
Compiling files:
src/I3.java
src/Main.java
End of files

View File

@@ -0,0 +1,2 @@
public interface I2 extends I1 {
}

View File

@@ -0,0 +1,2 @@
public interface I3 extends I2 {
}

View File

@@ -0,0 +1,7 @@
public class Main {
void foo(I3 param) {
if (param instanceof I1 asI1) {
// process
}
}
}

View File

@@ -1963,12 +1963,10 @@ public class Mappings {
debug("Signature changed ", signatureChanged);
final boolean extendsChanged = superClassChanged && !diff.extendsAdded();
final boolean interfacesRemoved = interfacesChanged && !diff.interfaces().removed().isEmpty();
debug("Extends changed: ", extendsChanged);
debug("Interfaces removed: ", interfacesRemoved);
myFuture.affectSubclasses(changedClass.name, myAffectedFiles, state.myAffectedUsages, state.myDependants, extendsChanged || interfacesRemoved || signatureChanged, myCompiledFiles, null);
myFuture.affectSubclasses(changedClass.name, myAffectedFiles, state.myAffectedUsages, state.myDependants, extendsChanged || interfacesChanged || signatureChanged, myCompiledFiles, null);
if (extendsChanged && directDeps != null) {
final TypeRepr.ClassType excClass = TypeRepr.createClassType(myContext, changedClass.name);

View File

@@ -101,7 +101,7 @@ public final class JavaDifferentiateStrategy extends JvmDifferentiateStrategyImp
if (classDiff.superClassChanged() || classDiff.signatureChanged() || !classDiff.interfaces().unchanged()) {
boolean extendsChanged = classDiff.superClassChanged() && !classDiff.extendsAdded();
boolean affectUsages = classDiff.signatureChanged() || extendsChanged || !isEmpty(classDiff.interfaces().removed());
boolean affectUsages = classDiff.signatureChanged() || extendsChanged || !classDiff.interfaces().unchanged();
affectSubclasses(context, future, change.getNow().getReferenceID(), affectUsages);
if (extendsChanged) {

View File

@@ -1,14 +1,27 @@
// 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.ether;
import org.jetbrains.jps.builders.java.JavaBuilderUtil;
import org.jetbrains.jps.model.JpsModuleRootModificationUtil;
import org.jetbrains.jps.model.module.JpsModule;
import java.util.Set;
public class ClassPropertyTest extends IncrementalTestCase {
private static final Set<String> GRAPH_ONLY_TESTS = Set.of("addImplementsPatternMatching");
public ClassPropertyTest() {
super("classProperties");
}
@Override
protected boolean shouldRunTest() {
if (JavaBuilderUtil.isDepGraphEnabled()) {
return super.shouldRunTest();
}
return !GRAPH_ONLY_TESTS.contains(getTestName(true));
}
public void testAddExtends() {
doTest();
}
@@ -17,6 +30,10 @@ public class ClassPropertyTest extends IncrementalTestCase {
doTest();
}
public void testAddImplementsPatternMatching() {
doTest();
}
public void testChangeExtends() {
doTest();
}