Java Code Examples for org.eclipse.xtext.common.types.JvmGenericType#setPackageName()

The following examples show how to use org.eclipse.xtext.common.types.JvmGenericType#setPackageName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testJvmTypeSimple_Issue145() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	expected.setPackageName("package.name");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName");
	assertEquals(expected, actual);
	resource.getContents().remove(expected);
	((InternalEObject)expected).eSetProxyURI(EcoreUtil.getURI(expected));
	JvmGenericType expected2 = TypesFactory.eINSTANCE.createJvmGenericType();
	expected2.setSimpleName("SimpleName");
	expected2.setPackageName("package.name");
	resource.getContents().add(expected2);
	JvmType actual2 = getTypeProvider().findTypeByName("package.name.SimpleName");
	assertEquals(expected2, actual2);
}
 
Example 2
protected JvmGenericType createJvmGenericType(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name) {
	if (sourceElement == null || name == null)
		return null;
	Pair<String, String> fullName = splitQualifiedName(name);
	final JvmGenericType result = typesFactory.createJvmGenericType();
	result.setSimpleName(fullName.getSecond());
	if (fullName.getFirst() != null)
		result.setPackageName(fullName.getFirst());
	result.setVisibility(JvmVisibility.PUBLIC);
	return result;
}
 
Example 3
@Test public void testGetElementByInstance_01() {
	JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
	JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType();
	type.setPackageName("java.lang");
	type.setSimpleName("Object");
	constructor.setSimpleName("Object");
	type.getMembers().add(constructor);
	IEObjectDescription element = getConstructorScope().getSingleElement(constructor);
	assertNotNull(element);
	assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName());
	assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName());
}
 
Example 4
@Test
public void testJvmTypeSimple() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	expected.setPackageName("package.name");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName");
	assertEquals(expected, actual);
}
 
Example 5
@Test
public void testJvmTypeNestedClass() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName$Child");
	assertEquals(expected, actual);
}
 
Example 6
@Test
public void testJvmTypeNestedClassWithDot_01() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", false);
	assertEquals(expected, actual);
}
 
Example 7
@Test
public void testJvmTypeNestedClassWithDot_02() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", true);
	assertNull(actual);
}
 
Example 8
@Test
public void testJvmTypeArray() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	expected.setPackageName("package.name");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName[]");
	assertTrue(actual instanceof JvmArrayType);
	assertEquals(expected, ((JvmArrayType) actual).getComponentType());
}
 
Example 9
@Test
public void testJvmTypeSimple() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	expected.setPackageName("package.name");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName");
	assertEquals(expected, actual);
}
 
Example 10
@Test
public void testJvmTypeNestedClass() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName$Child");
	assertEquals(expected, actual);
}
 
Example 11
@Test
public void testJvmTypeNestedClassWithDot_01() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", false);
	assertEquals(expected, actual);
}
 
Example 12
@Test
public void testJvmTypeNestedClassWithDot_02() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType container = TypesFactory.eINSTANCE.createJvmGenericType();
	container.setSimpleName("SimpleName");
	container.setPackageName("package.name");
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("Child");
	container.getMembers().add(expected);
	resource.getContents().add(container);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName.Child", true);
	assertNull(actual);
}
 
Example 13
@Test
public void testJvmTypeArray() {
	Resource resource = resourceSet.createResource(URI.createURI("foo.typesRefactoring"));
	JvmGenericType expected = TypesFactory.eINSTANCE.createJvmGenericType();
	expected.setSimpleName("SimpleName");
	expected.setPackageName("package.name");
	resource.getContents().add(expected);
	JvmType actual = getTypeProvider().findTypeByName("package.name.SimpleName[]");
	assertTrue(actual instanceof JvmArrayType);
	assertEquals(expected, ((JvmArrayType) actual).getComponentType());
}
 
Example 14
@Test
public void testInterfaceDescription_01() {
	JvmGenericType interfaceType = TypesFactory.eINSTANCE.createJvmGenericType();
	interfaceType.setInterface(true);
	interfaceType.setPackageName("foo");
	interfaceType.setSimpleName("MyType");
	List<IEObjectDescription> list = new ArrayList<>();
	descriptionStrategy.createEObjectDescriptions(interfaceType, it -> list.add(it));
	Assert.assertTrue(
			list.stream().anyMatch(it -> "true".equals(it.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE))));
}
 
Example 15
@Test
public void testInterfaceDescription_02() {
	JvmGenericType interfaceType = TypesFactory.eINSTANCE.createJvmGenericType();
	interfaceType.setInterface(false);
	interfaceType.setPackageName("foo");
	interfaceType.setSimpleName("MyType");
	List<IEObjectDescription> list = new ArrayList<>();
	descriptionStrategy.createEObjectDescriptions(interfaceType, it -> list.add(it));
	Assert.assertFalse(list.stream().anyMatch(
			it -> "true".equals(it.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE))));
}
 
Example 16
@Test public void testGetElementByInstance_01() {
	JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
	JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType();
	type.setPackageName("java.lang");
	type.setSimpleName("Object");
	constructor.setSimpleName("Object");
	type.getMembers().add(constructor);
	IEObjectDescription element = getConstructorScope().getSingleElement(constructor);
	assertNotNull(element);
	assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getName());
	assertEquals(new IQualifiedNameConverter.DefaultImpl().toQualifiedName("java.lang.Object"), element.getQualifiedName());
}
 
Example 17
Source Project: sarl   File: PyGenerator.java    License: Apache License 2.0 5 votes vote down vote up
/** Create a JvmType for a Python type.
 *
 * @param pythonName the python type name.
 * @return the type.
 */
@SuppressWarnings("static-method")
protected JvmType newType(String pythonName) {
	final JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType();
	final int index = pythonName.indexOf("."); //$NON-NLS-1$
	if (index <= 0) {
		type.setSimpleName(pythonName);
	} else {
		type.setPackageName(pythonName.substring(0, index - 1));
		type.setSimpleName(pythonName.substring(index + 1));
	}
	return type;
}
 
Example 18
Source Project: sarl   File: Bug92Test.java    License: Apache License 2.0 4 votes vote down vote up
protected static JvmType createType(Class<?> t) {
	JvmGenericType result = TypesFactory.eINSTANCE.createJvmGenericType();
	result.setSimpleName(t.getSimpleName());
	result.setPackageName(t.getPackage().getName());
	return result;
}