Skip to content

Commit

Permalink
JvmGenericClass
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Dec 21, 2023
1 parent 68eabb5 commit 1a84600
Show file tree
Hide file tree
Showing 13 changed files with 831 additions and 6 deletions.
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class JvmGenericTypeTest extends JvmDeclaredTypeTest {

private JvmGenericType genericType;
protected JvmGenericType genericType;

@Before
public void setUp() throws Exception {
Expand Down Expand Up @@ -52,7 +52,7 @@ protected JvmGenericType getObjectUnderTest() {
assertTrue(Iterables.isEmpty(interfaces));
}

private JvmTypeReference createReferenceTo(JvmType type) {
protected JvmTypeReference createReferenceTo(JvmType type) {
JvmParameterizedTypeReference result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
result.setType(type);
return result;
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ public interface TypesFactory extends EFactory
*/
JvmInnerTypeReference createJvmInnerTypeReference();

/**
* Returns a new object of class '<em>Jvm Generic Class</em>'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return a new object of class '<em>Jvm Generic Class</em>'.
* @generated
*/
JvmGenericClass createJvmGenericClass();

/**
* Returns the package supported by this factory.
* <!-- begin-user-doc -->
Expand Down
Loading

0 comments on commit 1a84600

Please sign in to comment.