-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68eabb5
commit 1a84600
Showing
13 changed files
with
831 additions
and
6 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...se.xtext.common.types.tests/tests/org/eclipse/xtext/common/types/JvmGenericClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.xtext.common.types; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author LorenzoBettini - Initial contribution and API | ||
*/ | ||
public class JvmGenericClassTest extends JvmGenericTypeTest { | ||
|
||
private JvmGenericClass genericClass; | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
genericClass = TypesFactory.eINSTANCE.createJvmGenericClass(); | ||
genericType = genericClass; | ||
} | ||
|
||
@Test public void testSetClassToExtendsUpdatesSuperTypes() { | ||
JvmTypeReference classToExtend = createTypeReference(); | ||
genericClass.setClassToExtend(classToExtend); | ||
assertNotNull(genericClass.getClassToExtend()); | ||
assertSame(classToExtend, genericClass.getSuperTypes().get(0)); | ||
// if we unset the class to extend... | ||
genericClass.setClassToExtend(null); | ||
assertNull(genericClass.getClassToExtend()); | ||
// ... it must also be removed from supertypes | ||
assertEquals(0, genericClass.getSuperTypes().size()); | ||
} | ||
|
||
@Test public void testUpdateSuperTypesSetsClassToExtend() { | ||
JvmTypeReference classToExtend = createTypeReference(); | ||
JvmTypeReference anotherType = createTypeReference(); | ||
genericClass.setClassToExtend(classToExtend); | ||
assertNotNull(genericClass.getClassToExtend()); | ||
assertSame(classToExtend, genericClass.getSuperTypes().get(0)); | ||
genericClass.getSuperTypes().add(anotherType); | ||
assertEquals(2, genericClass.getSuperTypes().size()); | ||
// if we remove a super type that is not the class to extend... | ||
genericClass.getSuperTypes().remove(anotherType); | ||
assertEquals(1, genericClass.getSuperTypes().size()); | ||
// ... the extended class is still there | ||
assertNotNull(genericClass.getClassToExtend()); | ||
// ... otherwise ... | ||
genericClass.getSuperTypes().clear(); | ||
// ... the class to extend is unset as well ... | ||
assertNull(genericClass.getClassToExtend()); | ||
} | ||
|
||
@Test public void testUpdateInterfacesToExtendUpdatesSuperTypes() { | ||
JvmTypeReference interface1 = createTypeReference(); | ||
JvmTypeReference interface2 = createTypeReference(); | ||
genericClass.getInterfacesToImplement().addAll(List.of(interface1, interface2)); | ||
assertEquals(2, genericClass.getInterfacesToImplement().size()); | ||
var superTypes = genericClass.getSuperTypes(); | ||
assertEquals(genericClass.getInterfacesToImplement(), superTypes); | ||
// call it twice to make sure it doesn't change | ||
var superTypes2 = genericClass.getSuperTypes(); | ||
assertEquals(genericClass.getInterfacesToImplement(), superTypes2); | ||
// remove from interface to implement ... | ||
genericClass.getInterfacesToImplement().remove(0); | ||
assertEquals(1, genericClass.getInterfacesToImplement().size()); | ||
var superTypes3 = genericClass.getSuperTypes(); | ||
assertEquals(genericClass.getInterfacesToImplement(), superTypes3); | ||
} | ||
|
||
private JvmTypeReference createTypeReference() { | ||
return createReferenceTo( | ||
TypesFactory.eINSTANCE.createJvmGenericType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
org.eclipse.xtext.common.types/emf-gen/org/eclipse/xtext/common/types/JvmGenericClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) 2011-2020 itemis AG (http://www.itemis.eu) and others. | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.xtext.common.types; | ||
|
||
import org.eclipse.emf.common.util.EList; | ||
|
||
/** | ||
* <!-- begin-user-doc --> | ||
* A representation of the model object '<em><b>Jvm Generic Class</b></em>'. | ||
* <!-- end-user-doc --> | ||
* | ||
* <p> | ||
* The following features are supported: | ||
* </p> | ||
* <ul> | ||
* <li>{@link org.eclipse.xtext.common.types.JvmGenericClass#getClassToExtend <em>Class To Extend</em>}</li> | ||
* <li>{@link org.eclipse.xtext.common.types.JvmGenericClass#getInterfacesToImplement <em>Interfaces To Implement</em>}</li> | ||
* </ul> | ||
* | ||
* @see org.eclipse.xtext.common.types.TypesPackage#getJvmGenericClass() | ||
* @model | ||
* @generated | ||
*/ | ||
public interface JvmGenericClass extends JvmGenericType | ||
{ | ||
/** | ||
* Returns the value of the '<em><b>Class To Extend</b></em>' reference. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>Class To Extend</em>' reference. | ||
* @see #setClassToExtend(JvmTypeReference) | ||
* @see org.eclipse.xtext.common.types.TypesPackage#getJvmGenericClass_ClassToExtend() | ||
* @model | ||
* @generated | ||
*/ | ||
JvmTypeReference getClassToExtend(); | ||
|
||
/** | ||
* Sets the value of the '{@link org.eclipse.xtext.common.types.JvmGenericClass#getClassToExtend <em>Class To Extend</em>}' reference. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @param value the new value of the '<em>Class To Extend</em>' reference. | ||
* @see #getClassToExtend() | ||
* @generated | ||
*/ | ||
void setClassToExtend(JvmTypeReference value); | ||
|
||
/** | ||
* Returns the value of the '<em><b>Interfaces To Implement</b></em>' reference list. | ||
* The list contents are of type {@link org.eclipse.xtext.common.types.JvmTypeReference}. | ||
* <!-- begin-user-doc --> | ||
* <!-- end-user-doc --> | ||
* @return the value of the '<em>Interfaces To Implement</em>' reference list. | ||
* @see org.eclipse.xtext.common.types.TypesPackage#getJvmGenericClass_InterfacesToImplement() | ||
* @model resolveProxies="false" | ||
* @generated | ||
*/ | ||
EList<JvmTypeReference> getInterfacesToImplement(); | ||
|
||
} // JvmGenericClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.