Skip to content

Commit

Permalink
Revert "check valid usage depending on interface/class"
Browse files Browse the repository at this point in the history
This reverts commit f2521d8.

The check would break code that scans all the features, e.g.,
org.eclipse.xtext.findReferences.ReferenceFinder.findLocalReferencesFromElement(Predicate<URI>,
EObject, Resource, Acceptor)
  • Loading branch information
LorenzoBettini committed Dec 23, 2023
1 parent f2521d8 commit d3ab99d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ public JvmType apply(JvmTypeReference from) {
}

@Test public void testUpdateInterfacesToExtendUpdatesSuperTypes() {
genericType.setInterface(true);
JvmTypeReference interface1 = createTypeReference();
JvmTypeReference interface2 = createTypeReference();
genericType.getInterfacesToExtend().addAll(List.of(interface1, interface2));
Expand All @@ -228,7 +227,6 @@ public JvmType apply(JvmTypeReference from) {
}

@Test public void testUpdateSuperTypesUpdatesInterfacesToExtend() {
genericType.setInterface(true);
JvmTypeReference interface1 = createTypeReference();
JvmTypeReference interface2 = createTypeReference();
JvmTypeReference anotherType = createTypeReference();
Expand All @@ -250,26 +248,6 @@ public JvmType apply(JvmTypeReference from) {
assertEquals(0, genericType.getInterfacesToExtend().size());
}

@Test public void testWrongUsageInClass() {
IllegalStateException thrown = assertThrows(IllegalStateException.class, () ->
genericType.getInterfacesToExtend());
assertEquals("interfacesToExtend can only be used in interfaces", thrown.getMessage());
}

@Test public void testWrongUsageInInterface() {
genericType.setInterface(true);
var expectedMessage = "classToExtend/interfacesToImplement can only be used in classes";
var thrown = assertThrows(IllegalStateException.class, () ->
genericType.getClassToExtend());
assertEquals(expectedMessage, thrown.getMessage());
thrown = assertThrows(IllegalStateException.class, () ->
genericType.setClassToExtend(null));
assertEquals(expectedMessage, thrown.getMessage());
thrown = assertThrows(IllegalStateException.class, () ->
genericType.getInterfacesToImplement());
assertEquals(expectedMessage, thrown.getMessage());
}

private JvmTypeReference createTypeReference() {
return createReferenceTo(
TypesFactory.eINSTANCE.createJvmGenericType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public boolean isAnonymous() {
@Override
public void setClassToExtend(JvmTypeReference newClassToExtend) {
checkPendingInitialization();
checkValidUsage(false);
JvmTypeReference oldClassToExtend = classToExtend;
super.setClassToExtend(newClassToExtend);
super.getSuperTypes().remove(oldClassToExtend);
Expand All @@ -81,7 +80,6 @@ public void setClassToExtend(JvmTypeReference newClassToExtend) {
@Override
public JvmTypeReference getClassToExtend() {
checkPendingInitialization();
checkValidUsage(false);
if (!super.getSuperTypes().contains(classToExtend)) {
// some one else removed it via superTypes API
super.setClassToExtend(null);
Expand Down Expand Up @@ -121,7 +119,6 @@ public EList<JvmTypeReference> getSuperTypes() {
@Override
public EList<JvmTypeReference> getInterfacesToImplement() {
checkPendingInitialization();
checkValidUsage(false);
var origInterfacesToImplement = super.getInterfacesToImplement();
var origSuperTypes = super.getSuperTypes();
if (!superTypesSnapshot.equals(origSuperTypes)) {
Expand All @@ -138,7 +135,6 @@ public EList<JvmTypeReference> getInterfacesToImplement() {
@Override
public EList<JvmTypeReference> getInterfacesToExtend() {
checkPendingInitialization();
checkValidUsage(true);
var origInterfacesToExtend = super.getInterfacesToExtend();
var origSuperTypes = super.getSuperTypes();
if (!superTypesSnapshot.equals(origSuperTypes)) {
Expand All @@ -152,14 +148,6 @@ public EList<JvmTypeReference> getInterfacesToExtend() {
return origInterfacesToExtend;
}

private void checkValidUsage(boolean expectInterface) {
var interf = isInterface();
if (expectInterface && !interf)
throw new IllegalStateException("interfacesToExtend can only be used in interfaces");
if (!expectInterface && interf)
throw new IllegalStateException("classToExtend/interfacesToImplement can only be used in classes");
}

private List<JvmTypeReference> createSnapshot(EList<JvmTypeReference> origList) {
return new ArrayList<>(origList);
}
Expand Down

0 comments on commit d3ab99d

Please sign in to comment.