Skip to content

Commit

Permalink
Merge pull request #391 from guillermocalvo/implemented-interface-cor…
Browse files Browse the repository at this point in the history
…responding-class

Initialize the corresponding class of a NEW implemented interface
  • Loading branch information
siom79 authored Mar 11, 2024
2 parents f4831bc + 87b4263 commit 59467d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ private void checkIfSuperclassesOrInterfacesChangedIncompatible(final JApiClass
if (interfaceClass == null) {
interfaceClass = loadClass(implementedInterface.getFullyQualifiedName(), EnumSet.allOf(Classpath.class));
}
implementedInterface.setJApiClass(interfaceClass);
if (implementedInterface.getChangeStatus() == JApiChangeStatus.MODIFIED || implementedInterface.getChangeStatus() == JApiChangeStatus.UNCHANGED) {
implementedInterface.setJApiClass(interfaceClass);
checkIfMethodsHaveChangedIncompatible(interfaceClass, classMap);
checkIfFieldsHaveChangedIncompatible(interfaceClass, classMap);
} else if (implementedInterface.getChangeStatus() == JApiChangeStatus.NEW) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public void setJApiClass(JApiClass jApiClass) {
this.correspondingJApiClass = Optional.of(jApiClass);
}

public Optional<JApiClass> getCorrespondingJApiClass() {
return correspondingJApiClass;
}

@XmlTransient
public CtClass getCtClass() {
return ctClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static japicmp.util.Helper.*;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -2292,6 +2293,10 @@ public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
JApiClass jApiClass = getJApiClass(jApiClasses, "com.acme.japicmp.NewOperator");
assertThat(jApiClass.getCompatibilityChanges(), hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.INTERFACE_ADDED)));
assertThat(jApiClass.getCompatibilityChanges(), not(hasItem(new JApiCompatibilityChange(JApiCompatibilityChangeType.METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE))));
JApiImplementedInterface implementedInterface = jApiClass.getInterfaces().stream().filter(i -> i.getFullyQualifiedName().equals("java.util.function.UnaryOperator")).findFirst().orElse(null);
assertThat(implementedInterface, notNullValue());
assertThat(implementedInterface.getCorrespondingJApiClass().isPresent(), is(true));
assertThat(implementedInterface.getCorrespondingJApiClass().get().getFullyQualifiedName(), is("java.util.function.UnaryOperator"));
}

@Test
Expand Down

0 comments on commit 59467d2

Please sign in to comment.