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

The following examples show how to use org.eclipse.xtext.common.types.JvmGenericType#getSuperTypes() . 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
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testInterfaceCreation() {
  try {
    final XExpression e = this.expression("\'foo\'");
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this._jvmTypeReferenceBuilder.typeRef(Iterable.class);
      this._jvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType anno = this._jvmTypesBuilder.toInterface(e, "foo.bar.MyAnnotation", _function);
    Assert.assertTrue(anno.isInterface());
    Assert.assertEquals("foo.bar", anno.getPackageName());
    Assert.assertEquals("MyAnnotation", anno.getSimpleName());
    Assert.assertEquals(1, anno.getSuperTypes().size());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testImplements() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      it.setAbstract(true);
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this.typeRef(expression, Iterable.class, String.class);
      this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiled = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testExtends() {
  try {
    final XExpression expression = this.expression("null", false);
    final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> {
      it.setAbstract(true);
      EList<JvmTypeReference> _superTypes = it.getSuperTypes();
      JvmTypeReference _typeRef = this.typeRef(expression, AbstractList.class, String.class);
      this.builder.<JvmTypeReference>operator_add(_superTypes, _typeRef);
    };
    final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function);
    final Class<?> compiled = this.compile(expression.eResource(), clazz);
    Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
    Assert.assertTrue(AbstractList.class.isAssignableFrom(compiled));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean hasCycleInHierarchy(JvmGenericType type, Set<JvmGenericType> processedSuperTypes) {
	JvmDeclaredType container = type;
	do {
		if (processedSuperTypes.contains(container))
			return true;
		container = container.getDeclaringType();
	} while (container != null);
	processedSuperTypes.add(type);
	for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
		if (superTypeRef.getType() instanceof JvmGenericType) {
			if (hasCycleInHierarchy((JvmGenericType) superTypeRef.getType(), processedSuperTypes))
				return true;
		}
	}
	processedSuperTypes.remove(type);
	return false;
}
 
Example 5
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRawIterable_01() {
	String typeName = RawIterable.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	List<JvmTypeReference> superTypes = type.getSuperTypes();
	JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1);
	assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier());
	assertTrue(iterableSuperType.getArguments().isEmpty());
}
 
Example 6
Source File: AbstractTypeProviderTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRawIterable_01() {
	String typeName = RawIterable.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	List<JvmTypeReference> superTypes = type.getSuperTypes();
	JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1);
	assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier());
	assertTrue(iterableSuperType.getArguments().isEmpty());
}
 
Example 7
Source File: AbstractTypeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRawIterable_01() {
	String typeName = RawIterable.class.getName();
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	List<JvmTypeReference> superTypes = type.getSuperTypes();
	JvmParameterizedTypeReference iterableSuperType = (JvmParameterizedTypeReference) superTypes.get(1);
	assertEquals("java.lang.Iterable", iterableSuperType.getIdentifier());
	assertTrue(iterableSuperType.getArguments().isEmpty());
}
 
Example 8
Source File: DispatchRenameSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean addDispatcher(
		JvmGenericType type, 
		DispatchHelper.DispatchSignature signature,
		final IAcceptor<JvmOperation> acceptor,
		final Set<JvmGenericType> processedTypes,
		ResourceSet tempResourceSet) {
	if (processedTypes.contains(type))
		return false;
	processedTypes.add(type);
	boolean needProcessSubclasses = false;
	JvmOperation dispatcher = dispatchHelper.getDispatcherOperation(type, signature);
	if (dispatcher != null) {
		needProcessSubclasses = true;
		acceptor.accept(dispatcher);
	}
		
	for (JvmOperation dispatchCase : dispatchHelper.getLocalDispatchCases(type, signature)) {
		needProcessSubclasses = true;
		acceptor.accept(dispatchCase);
	}
	for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
		JvmType superType = superTypeRef.getType();
		if (superType instanceof JvmGenericType)
			needProcessSubclasses |= addDispatcher((JvmGenericType) superType, signature, acceptor, processedTypes, tempResourceSet);
	}
	if (needProcessSubclasses) {
		for (JvmGenericType subType : getSubTypes(type, tempResourceSet))
			needProcessSubclasses |= addDispatcher(subType, signature, acceptor, processedTypes, tempResourceSet);
	}
	return needProcessSubclasses;
}
 
Example 9
Source File: RegisterGlobalsContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void registerClass(final String qualifiedName) throws IllegalArgumentException {
  final JvmGenericType newType = TypesFactory.eINSTANCE.createJvmGenericType();
  newType.setVisibility(JvmVisibility.PUBLIC);
  EList<JvmTypeReference> _superTypes = newType.getSuperTypes();
  JvmTypeReference _typeForName = this.compilationUnit.getTypeReferences().getTypeForName(Object.class, this.compilationUnit.getXtendFile());
  _superTypes.add(_typeForName);
  this.setNameAndAccept(newType, qualifiedName);
}
 
Example 10
Source File: MissedMethodAddModification.java    From sarl with Apache License 2.0 5 votes vote down vote up
private Map<String, JvmTypeReference> buildTypeParameterMapping(XtendTypeDeclaration container) {
	final Map<String, JvmTypeReference> map = new TreeMap<>();
	final EObject obj = this.associations.getPrimaryJvmElement(container);
	if (obj instanceof JvmGenericType) {
		final JvmGenericType genType = (JvmGenericType) obj;

		final Set<String> encounteredTypes = new TreeSet<>();

		final LinkedList<JvmGenericType> expectedReferences = new LinkedList<>();
		expectedReferences.add(genType);

		final String objectId = Object.class.getName();

		while (!expectedReferences.isEmpty()) {
			final JvmGenericType type = expectedReferences.removeFirst();
			if (encounteredTypes.add(type.getIdentifier())) {

				for (final JvmTypeReference superType : type.getSuperTypes()) {
					if (!objectId.equals(superType.getIdentifier()) && superType instanceof JvmParameterizedTypeReference) {
						final JvmParameterizedTypeReference parametizedReference = (JvmParameterizedTypeReference) superType;
						if (!parametizedReference.getArguments().isEmpty()) {
							final JvmGenericType genericSuperType = (JvmGenericType) parametizedReference.getType();
							int i = 0;
							for (final JvmTypeReference refInstance : parametizedReference.getArguments()) {
								final JvmTypeParameter typeParameter = genericSuperType.getTypeParameters().get(i);
								map.put(
										typeParameterId(typeParameter, genericSuperType.getQualifiedName()),
										refInstance);
								++i;
							}
							expectedReferences.add((JvmGenericType) parametizedReference.getType());
						}
					}
				}

			}
		}
	}
	return map;
}