Skip to content

Commit

Permalink
deal with List changes in Java 21 and fixed bug in publicNativeMethod
Browse files Browse the repository at this point in the history
The test publicNativeMethod was indeed testing "publicStrictFpMethod":
copy and paste error?
  • Loading branch information
LorenzoBettini committed May 14, 2024
1 parent 27f2cf3 commit 57e8d52
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,13 @@ public void testFindTypeByName_javaUtilList_07() {
assertEquals(1, type.getSuperTypes().size());
JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0);
assertFalse(superType.getType().eIsProxy());
assertEquals("java.util.Collection<E>", superType.getIdentifier());
// in Java 21 List extends SequencedCollection
// but this test relies on sources so we cannot use stubbed classes
// like in xtext.java.tests or common.types.tests
// so we remove "Sequenced" from the super type
// Lorenzo: that's the best and simplest solution I could find
assertEquals("java.util.Collection<E>",
superType.getIdentifier().replace("Sequenced", ""));
assertEquals(1, type.getTypeParameters().size());
JvmType rawType = superType.getType();
assertFalse(rawType.eIsProxy());
Expand Down Expand Up @@ -2016,14 +2022,14 @@ public void testMethods_publicStrictFpMethod_01() {
public void publicNativeMethod() {
String typeName = Methods.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()");
assertSame(type, method.getDeclaringType());
assertFalse(method.isAbstract());
assertFalse(method.isFinal());
assertFalse(method.isStatic());
assertFalse(method.isSynchronized());
assertTrue(method.isStrictFloatingPoint());
assertFalse(method.isNative());
assertFalse(method.isStrictFloatingPoint());
assertTrue(method.isNative());
assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
JvmType methodType = method.getReturnType().getType();
assertEquals("void", methodType.getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* 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;

import java.util.Collection;
import java.util.List;

/**
* To avoid breaking our tests with new Java API (e.g., in Java 21,
* {@link List} extends SequencedCollection instead of Collection.
*
* @author Lorenzo Bettini
*
*/
public interface MyStubbedList<E> extends Collection<E> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import testdata.MyStubbedList;

/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
Expand Down Expand Up @@ -471,7 +473,7 @@ public void testFindTypeByName_javaUtilList_06() {

@Test
public void testFindTypeByName_javaUtilList_07() {
String typeName = List.class.getName();
String typeName = MyStubbedList.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
assertEquals(1, type.getSuperTypes().size());
JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0);
Expand Down Expand Up @@ -2038,14 +2040,14 @@ public void testMethods_publicStrictFpMethod_01() {
public void publicNativeMethod() {
String typeName = Methods.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()");
assertSame(type, method.getDeclaringType());
assertFalse(method.isAbstract());
assertFalse(method.isFinal());
assertFalse(method.isStatic());
assertFalse(method.isSynchronized());
assertTrue(method.isStrictFloatingPoint());
assertFalse(method.isNative());
assertFalse(method.isStrictFloatingPoint());
assertTrue(method.isNative());
assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
JvmType methodType = method.getReturnType().getType();
assertEquals("void", methodType.getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import org.eclipse.xtext.common.types.testSetups.TestEnum;
import org.eclipse.xtext.common.types.testSetups.TypeWithInnerAnnotation;
import org.eclipse.xtext.common.types.testSetups.TypeWithInnerEnum;
import org.eclipse.xtext.java.tests.MyStubbedList;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -472,7 +473,7 @@ public void testFindTypeByName_javaUtilList_06() {

@Test
public void testFindTypeByName_javaUtilList_07() {
String typeName = List.class.getName();
String typeName = MyStubbedList.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
assertEquals(1, type.getSuperTypes().size());
JvmParameterizedTypeReference superType = (JvmParameterizedTypeReference) type.getSuperTypes().get(0);
Expand Down Expand Up @@ -2039,14 +2040,14 @@ public void testMethods_publicStrictFpMethod_01() {
public void publicNativeMethod() {
String typeName = Methods.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
JvmOperation method = getMethodFromType(type, Methods.class, "publicNativeMethod()");
assertSame(type, method.getDeclaringType());
assertFalse(method.isAbstract());
assertFalse(method.isFinal());
assertFalse(method.isStatic());
assertFalse(method.isSynchronized());
assertTrue(method.isStrictFloatingPoint());
assertFalse(method.isNative());
assertFalse(method.isStrictFloatingPoint());
assertTrue(method.isNative());
assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
JvmType methodType = method.getReturnType().getType();
assertEquals("void", methodType.getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* 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 org.eclipse.xtext.java.tests;

import java.util.Collection;
import java.util.List;

/**
* To avoid breaking our tests with new Java API (e.g., in Java 21,
* {@link List} extends SequencedCollection instead of Collection.
*
* @author Lorenzo Bettini
*
*/
public interface MyStubbedList<E> extends Collection<E> {

}

0 comments on commit 57e8d52

Please sign in to comment.