Skip to content

Commit

Permalink
fixed a few Xtend type tests
Browse files Browse the repository at this point in the history
using Stubbed types
  • Loading branch information
LorenzoBettini committed May 14, 2024
1 parent 9057ca6 commit f168b21
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
package org.eclipse.xtend.core.tests.resource

import com.google.inject.Inject
import java.util.Comparator
import org.eclipse.xtend.core.tests.AbstractXtendTestCase
import org.eclipse.xtext.resource.IResourceDescription
import org.junit.Test
import org.junit.Assert
import java.util.Arrays
import java.util.Comparator
import org.junit.Test

class ImportedNamesTest extends AbstractXtendTestCase {
@Inject
Expand Down Expand Up @@ -138,37 +137,37 @@ class ImportedNamesTest extends AbstractXtendTestCase {
import java.util.AbstractMap.*;
class C {
val list = new java.util.ArrayList<Map.Entry>
val list = new testdata.stubs.StubbedArrayList<Map.Entry>
val entry = new SimpleEntry(null, null)
val int i = 0
}
''', true)
val description = resourceDescriptionManager.getResourceDescription(file.eResource)
val importedNames = description.importedNames
Assert.assertEquals(Arrays.asList(
"java.io.serializable",
"java.lang.cloneable",
"java.lang.iterable",
"java.lang.java$util$arraylist",
"java.lang.object",
"java.util.abstractcollection",
"java.util.abstractlist",
"java.util.abstractmap",
"java.util.abstractmap.java$util$arraylist",
"java.util.abstractmap.simpleentry",
"java.util.abstractmap$java$util$arraylist",
"java.util.abstractmap$simpleentry",
"java.util.arraylist",
"java.util.collection",
"java.util.list",
"java.util.map",
"java.util.map$entry",
"java.util.randomaccess",
"java.util$abstractmap$java$util$arraylist",
"java$util$abstractmap$java$util$arraylist",
"my.pack.c",
"my.pack.java$util$arraylist",
"org.eclipse.xtext.xbase.lib.java$util$arraylist").join("\n"),
Assert.assertEquals('''
java.io.serializable
java.lang.cloneable
java.lang.iterable
java.lang.object
java.lang.testdata$stubs$stubbedarraylist
java.util.abstractcollection
java.util.abstractmap
java.util.abstractmap.simpleentry
java.util.abstractmap.testdata$stubs$stubbedarraylist
java.util.abstractmap$simpleentry
java.util.abstractmap$testdata$stubs$stubbedarraylist
java.util.collection
java.util.map
java.util.map$entry
java.util.randomaccess
java.util$abstractmap$testdata$stubs$stubbedarraylist
java$util$abstractmap$testdata$stubs$stubbedarraylist
my.pack.c
my.pack.testdata$stubs$stubbedarraylist
org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedarraylist
testdata.stubs.stubbedabstractlist
testdata.stubs.stubbedarraylist
testdata.stubs.stubbedlist'''.toString.replace("\r", ""),
importedNames.toList.sortWith(Comparator.naturalOrder).join("\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.google.inject.Inject
import java.io.Serializable
import java.util.Collection
import java.util.Collections
import java.util.List
import org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations
import org.eclipse.xtext.util.JavaRuntimeVersion
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference
import org.junit.Ignore
import org.junit.Test
import org.eclipse.xtext.util.JavaRuntimeVersion
import testdata.stubs.StubbedList

/**
* @author Sebastian Zarnekow
Expand Down Expand Up @@ -167,12 +167,12 @@ class SuperTypesTest extends AbstractSuperTypesTest {

@Test
override void testRawList() {
typeof(List).assertSuperTypes("Collection")
typeof(StubbedList).assertSuperTypes("Collection")
}

@Test
override void testStringList() {
"java.util.List<String>".assertSuperTypes("Collection<String>")
"testdata.stubs.StubbedList<String>".assertSuperTypes("Collection<String>")
}

@Test
Expand Down Expand Up @@ -277,23 +277,23 @@ class AllSuperTypesTest extends AbstractSuperTypesTest {

@Test
override void testRawList() {
typeof(List).assertSuperTypes("Collection", "Iterable", "Object")
typeof(StubbedList).assertSuperTypes("Collection", "Iterable", "Object")
}

@Test
override void testStringList() {
"java.util.List<String>".assertSuperTypes("Collection<String>", "Iterable<String>", "Object")
"testdata.stubs.StubbedList<String>".assertSuperTypes("Collection<String>", "Iterable<String>", "Object")
}

@Test
override void testStringArrayArrayList() {
"java.util.ArrayList<? extends String[]>".assertSuperTypes(
"AbstractList<? extends String[]>",
"testdata.stubs.StubbedArrayList<? extends String[]>".assertSuperTypes(
"StubbedAbstractList<? extends String[]>",
"RandomAccess",
"Cloneable",
"Serializable",
"AbstractCollection<? extends String[]>",
"List<? extends String[]>",
"StubbedList<? extends String[]>",
"Collection<? extends String[]>",
"Iterable<? extends String[]>",
"Object")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini 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 testdata.stubs;

import java.util.AbstractCollection;

/**
* A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see,
* e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html).
*
* @author Lorenzo Bettini - Initial contribution and API
*/
public abstract class StubbedAbstractList<E> extends AbstractCollection<E> implements StubbedList<E> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini 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 testdata.stubs;

import java.util.Iterator;
import java.util.RandomAccess;

/**
* A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see,
* e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html).
*
* @author Lorenzo Bettini - Initial contribution and API
*/
@SuppressWarnings("serial")
public class StubbedArrayList<E> extends StubbedAbstractList<E>
implements RandomAccess, Cloneable, java.io.Serializable {

@Override
public Iterator<E> iterator() {
return null;
}

@Override
public int size() {
return 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini 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 testdata.stubs;

import java.util.Collection;

/**
* A stub type to use instead of relying on Java API like AbstractList, whose methods and supertypes might change in newer versions (see,
* e.g., https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/SequencedCollection.html).
*
* @author Lorenzo Bettini - Initial contribution and API
*/
public interface StubbedList<E> extends Collection<E> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.eclipse.xtend.core.tests.resource;

import com.google.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -267,7 +266,7 @@ public void testExhaustiveList() {
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("val list = new java.util.ArrayList<Map.Entry>");
_builder.append("val list = new testdata.stubs.StubbedArrayList<Map.Entry>");
_builder.newLine();
_builder.append("\t");
_builder.append("val entry = new SimpleEntry(null, null)");
Expand All @@ -280,31 +279,53 @@ public void testExhaustiveList() {
final XtendFile file = this.file(_builder.toString(), true);
final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
final Iterable<QualifiedName> importedNames = description.getImportedNames();
Assert.assertEquals(
IterableExtensions.join(Arrays.<String>asList(
"java.io.serializable",
"java.lang.cloneable",
"java.lang.iterable",
"java.lang.java$util$arraylist",
"java.lang.object",
"java.util.abstractcollection",
"java.util.abstractlist",
"java.util.abstractmap",
"java.util.abstractmap.java$util$arraylist",
"java.util.abstractmap.simpleentry",
"java.util.abstractmap$java$util$arraylist",
"java.util.abstractmap$simpleentry",
"java.util.arraylist",
"java.util.collection",
"java.util.list",
"java.util.map",
"java.util.map$entry",
"java.util.randomaccess",
"java.util$abstractmap$java$util$arraylist",
"java$util$abstractmap$java$util$arraylist",
"my.pack.c",
"my.pack.java$util$arraylist",
"org.eclipse.xtext.xbase.lib.java$util$arraylist"), "\n"),
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("java.io.serializable");
_builder_1.newLine();
_builder_1.append("java.lang.cloneable");
_builder_1.newLine();
_builder_1.append("java.lang.iterable");
_builder_1.newLine();
_builder_1.append("java.lang.object");
_builder_1.newLine();
_builder_1.append("java.lang.testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("java.util.abstractcollection");
_builder_1.newLine();
_builder_1.append("java.util.abstractmap");
_builder_1.newLine();
_builder_1.append("java.util.abstractmap.simpleentry");
_builder_1.newLine();
_builder_1.append("java.util.abstractmap.testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("java.util.abstractmap$simpleentry");
_builder_1.newLine();
_builder_1.append("java.util.abstractmap$testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("java.util.collection");
_builder_1.newLine();
_builder_1.append("java.util.map");
_builder_1.newLine();
_builder_1.append("java.util.map$entry");
_builder_1.newLine();
_builder_1.append("java.util.randomaccess");
_builder_1.newLine();
_builder_1.append("java.util$abstractmap$testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("java$util$abstractmap$testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("my.pack.c");
_builder_1.newLine();
_builder_1.append("my.pack.testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("org.eclipse.xtext.xbase.lib.testdata$stubs$stubbedarraylist");
_builder_1.newLine();
_builder_1.append("testdata.stubs.stubbedabstractlist");
_builder_1.newLine();
_builder_1.append("testdata.stubs.stubbedarraylist");
_builder_1.newLine();
_builder_1.append("testdata.stubs.stubbedlist");
Assert.assertEquals(_builder_1.toString().replace("\r", ""),
IterableExtensions.join(IterableExtensions.<QualifiedName>sortWith(IterableExtensions.<QualifiedName>toList(importedNames), Comparator.<QualifiedName>naturalOrder()), "\n"));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
package org.eclipse.xtend.core.tests.typesystem;

import java.util.Collection;
import java.util.List;
import org.eclipse.xtext.util.JavaRuntimeVersion;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference;
import org.junit.Ignore;
import org.junit.Test;
import testdata.stubs.StubbedList;

/**
* @author Sebastian Zarnekow
Expand Down Expand Up @@ -75,25 +75,25 @@ public void testPrimitiveArray() {
@Test
@Override
public void testRawList() {
this.assertSuperTypes(List.class, "Collection", "Iterable", "Object");
this.assertSuperTypes(StubbedList.class, "Collection", "Iterable", "Object");
}

@Test
@Override
public void testStringList() {
this.assertSuperTypes("java.util.List<String>", "Collection<String>", "Iterable<String>", "Object");
this.assertSuperTypes("testdata.stubs.StubbedList<String>", "Collection<String>", "Iterable<String>", "Object");
}

@Test
@Override
public void testStringArrayArrayList() {
this.assertSuperTypes("java.util.ArrayList<? extends String[]>",
"AbstractList<? extends String[]>",
this.assertSuperTypes("testdata.stubs.StubbedArrayList<? extends String[]>",
"StubbedAbstractList<? extends String[]>",
"RandomAccess",
"Cloneable",
"Serializable",
"AbstractCollection<? extends String[]>",
"List<? extends String[]>",
"StubbedList<? extends String[]>",
"Collection<? extends String[]>",
"Iterable<? extends String[]>",
"Object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
package org.eclipse.xtend.core.tests.typesystem;

import java.util.Collection;
import java.util.List;
import org.eclipse.xtext.util.JavaRuntimeVersion;
import org.eclipse.xtext.xbase.lib.Pair;
import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference;
import org.junit.Ignore;
import org.junit.Test;
import testdata.stubs.StubbedList;

/**
* @author Sebastian Zarnekow
Expand Down Expand Up @@ -75,13 +75,13 @@ public void testPrimitiveArray() {
@Test
@Override
public void testRawList() {
this.assertSuperTypes(List.class, "Collection");
this.assertSuperTypes(StubbedList.class, "Collection");
}

@Test
@Override
public void testStringList() {
this.assertSuperTypes("java.util.List<String>", "Collection<String>");
this.assertSuperTypes("testdata.stubs.StubbedList<String>", "Collection<String>");
}

@Test
Expand Down

0 comments on commit f168b21

Please sign in to comment.