Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1396 from eclipse/cd_afterJava11cleanup
Browse files Browse the repository at this point in the history
clean java 11 guards in tests
  • Loading branch information
cdietrich authored Nov 1, 2022
2 parents c4a83d7 + f694ee5 commit 8f6d3e4
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 422 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2013, 2022 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.
Expand All @@ -11,7 +11,6 @@ package org.eclipse.xtend.core.tests.compiler
import org.eclipse.xtend.core.tests.SingletonGeneratorConfigRuntimeInjectorProvider
import org.eclipse.xtext.testing.InjectWith
import org.junit.Test
import org.eclipse.xtext.util.JavaRuntimeVersion

/**
* @author Sebastian Zarnekow - Initial contribution and API
Expand Down Expand Up @@ -169,11 +168,6 @@ class ConfiguredCompilerTest extends AbstractXtendCompilerTest {
'''
package foo;
«IF !JavaRuntimeVersion.isJava11OrLater»
import javax.annotation.Generated;
@Generated("org.eclipse.xtend.core.compiler.XtendGenerator")
«ENDIF»
public class Bar {
}
''')
Expand All @@ -195,11 +189,6 @@ class ConfiguredCompilerTest extends AbstractXtendCompilerTest {
'''
package foo;
«IF !JavaRuntimeVersion.isJava11OrLater»
import javax.annotation.Generated;
@Generated(value = "org.eclipse.xtend.core.compiler.XtendGenerator", comments = "Source: Bar.xtend")
«ENDIF»
public class Bar {
}
''')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2012, 2022 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.
Expand All @@ -21,10 +21,8 @@ import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.logging.LoggingTester
import org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest
import org.eclipse.xtext.util.JavaRuntimeVersion
import org.junit.After
import org.junit.AfterClass
import org.junit.Assume
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
Expand Down Expand Up @@ -496,38 +494,6 @@ class TestBatchCompiler {
assertFalse((OUTPUT_DIRECTORY + "/XtendA.java").contents.contains("@SuppressWarnings"))
}

@Test
def void testGeneratedAnnotation() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater)
batchCompiler.generateGeneratedAnnotation = true
batchCompiler.sourcePath = "./batch-compiler-data/xtendClass"
assertTrue(batchCompiler.compile)
assertTrue((OUTPUT_DIRECTORY + "/XtendA.java").contents.contains("@Generated"))
}

@Test
def void testGeneratedAnnotationComment() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater)
batchCompiler.generateGeneratedAnnotation = true
batchCompiler.generatedAnnotationComment = "FooComment"
batchCompiler.sourcePath = "./batch-compiler-data/xtendClass"
assertTrue(batchCompiler.compile)
val generated = (OUTPUT_DIRECTORY + "/XtendA.java").contents
assertTrue(generated.contains("@Generated"))
assertTrue(generated.contains("FooComment"))
}

@Test
def void testGeneratedAnnotationDate1() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater)
batchCompiler.generateGeneratedAnnotation = true
batchCompiler.includeDateInGeneratedAnnotation = true
batchCompiler.sourcePath = "./batch-compiler-data/xtendClass"
assertTrue(batchCompiler.compile)
val generated = (OUTPUT_DIRECTORY + "/XtendA.java").contents
assertTrue(generated.contains("@Generated"))
assertTrue(generated.contains("date ="))
}

@Test
def void testJavaVersion5() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2013, 2022 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.
Expand All @@ -16,8 +16,6 @@ import org.eclipse.xtext.util.TextRegion
import org.eclipse.xtext.xbase.imports.ImportsAcceptor.DefaultImportsAcceptor
import org.eclipse.xtext.xbase.imports.ImportsCollector
import org.junit.Test
import org.junit.Assume
import org.eclipse.xtext.util.JavaRuntimeVersion

/**
* @author Dennis Huebner - Initial contribution and API
Expand Down Expand Up @@ -307,16 +305,15 @@ class ImportsCollectorTests extends AbstractXtendTestCase {
@Test
def void testEnum_01() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater)
'''
import javax.annotation.Resource
import static javax.annotation.Resource.AuthenticationType.*
import testdata.ClassWithEnum
import static testdata.ClassWithEnum.MyEnum.*
class C {
|val en = CONTAINER
var en2 = Resource.AuthenticationType.APPLICATION|
|val en = A
var en2 = ClassWithEnum.MyEnum.B|
}
'''.assertTypeImport('javax.annotation.Resource').assertStaticImport(
'javax.annotation.Resource.AuthenticationType.CONTAINER').assertExtensionImport
'''.assertTypeImport('testdata.ClassWithEnum').assertStaticImport(
'testdata.ClassWithEnum.MyEnum.A').assertExtensionImport
}
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2012, 2022 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.
Expand Down Expand Up @@ -441,27 +441,15 @@ class BoundTypeArgumentMergerTest extends AbstractTestingTypeReferenceOwner {
}

@Test def void testMergeMultiType_01() {
if (JavaRuntimeVersion.isJava11OrLater) {
merge('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT).to('AbstractStringBuilder & Serializable & Comparable<?>', INVARIANT)
} else {
merge('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT).to('AbstractStringBuilder & Serializable', INVARIANT)
}
merge('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT).to('AbstractStringBuilder & Serializable & Comparable<?>', INVARIANT)
}

@Test def void testMergeMultiType_02() {
if (JavaRuntimeVersion.isJava11OrLater) {
mergeSuccessive('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT, 'StringBuilder'->OUT->OUT).to('AbstractStringBuilder & Serializable & Comparable<?>', INVARIANT)
} else {
mergeSuccessive('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT, 'StringBuilder'->OUT->OUT).to('AbstractStringBuilder & Serializable', INVARIANT)
}
mergeSuccessive('StringBuilder'->OUT->OUT, 'StringBuffer'->OUT->OUT, 'StringBuilder'->OUT->OUT).to('AbstractStringBuilder & Serializable & Comparable<?>', INVARIANT)
}

@Test def void testMergeMultiType_03() {
if (JavaRuntimeVersion.isJava11OrLater) {
merge('StringBuilder'->OUT->INVARIANT, 'StringBuffer'->OUT->INVARIANT, 'String'->OUT->INVARIANT).to('Serializable & Comparable<?> & CharSequence', INVARIANT)
} else {
merge('StringBuilder'->OUT->INVARIANT, 'StringBuffer'->OUT->INVARIANT, 'String'->OUT->INVARIANT).to('Serializable & CharSequence', INVARIANT)
}
merge('StringBuilder'->OUT->INVARIANT, 'StringBuffer'->OUT->INVARIANT, 'String'->OUT->INVARIANT).to('Serializable & Comparable<?> & CharSequence', INVARIANT)
}

@Test def void testMergeMultiType_04() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2012, 2022 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.
Expand Down Expand Up @@ -92,11 +92,7 @@ class CommonSuperTypeTest extends AbstractTestingTypeReferenceOwner {

@Test
def void testCommonSuperType_01() {
if (JavaRuntimeVersion.isJava11OrLater) {
"Serializable & Comparable<?> & CharSequence".isSuperTypeOf("String", "StringBuilder")
} else {
"Serializable & CharSequence".isSuperTypeOf("String", "StringBuilder")
}
"Serializable & Comparable<?> & CharSequence".isSuperTypeOf("String", "StringBuilder")
}

@Test
Expand Down Expand Up @@ -126,11 +122,7 @@ class CommonSuperTypeTest extends AbstractTestingTypeReferenceOwner {

@Test
def void testCommonSuperType_07() {
if (JavaRuntimeVersion.isJava11OrLater) {
"Comparable<?> & Appendable & CharSequence".isSuperTypeOf("StringBuilder", "java.nio.CharBuffer")
} else {
"Appendable & CharSequence".isSuperTypeOf("StringBuilder", "java.nio.CharBuffer")
}
"Comparable<?> & Appendable & CharSequence".isSuperTypeOf("StringBuilder", "java.nio.CharBuffer")
}

@Test
Expand Down Expand Up @@ -168,11 +160,7 @@ class CommonSuperTypeTest extends AbstractTestingTypeReferenceOwner {

@Test
def void testCommonSuperType_13() {
if (JavaRuntimeVersion.isJava11OrLater) {
"AbstractStringBuilder & Serializable & Comparable<?>".isSuperTypeOf("StringBuilder", "StringBuffer")
} else {
"AbstractStringBuilder & Serializable".isSuperTypeOf("StringBuilder", "StringBuffer")
}
"AbstractStringBuilder & Serializable & Comparable<?>".isSuperTypeOf("StringBuilder", "StringBuffer")
}

@Test
Expand Down Expand Up @@ -231,11 +219,7 @@ class CommonSuperTypeTest extends AbstractTestingTypeReferenceOwner {

@Test
def void testCommonSuperType_24() {
if (JavaRuntimeVersion.isJava11OrLater) {
"Collection<? extends AbstractStringBuilder & Serializable & Comparable<?>>".isSuperTypeOf("java.util.List<StringBuilder>", "java.util.Set<StringBuffer>")
} else {
"Collection<? extends AbstractStringBuilder & Serializable>".isSuperTypeOf("java.util.List<StringBuilder>", "java.util.Set<StringBuffer>")
}
"Collection<? extends AbstractStringBuilder & Serializable & Comparable<?>>".isSuperTypeOf("java.util.List<StringBuilder>", "java.util.Set<StringBuffer>")
}

@Test
Expand Down
20 changes: 20 additions & 0 deletions org.eclipse.xtend.core.tests/testdata/testdata/ClassWithEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2022 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 testdata;

/**
* @author cdietrich - Initial contribution and API
*/
public class ClassWithEnum {

public static enum MyEnum {
A,B,C
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2013, 2022 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.
Expand All @@ -11,7 +11,6 @@
import org.eclipse.xtend.core.tests.SingletonGeneratorConfigRuntimeInjectorProvider;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.util.JavaRuntimeVersion;
import org.eclipse.xtext.xbase.compiler.GeneratorConfig;
import org.junit.Test;

Expand Down Expand Up @@ -269,17 +268,6 @@ public void testGeneratedAnnotation_01() {
_builder_1.append("package foo;");
_builder_1.newLine();
_builder_1.newLine();
{
boolean _isJava11OrLater = JavaRuntimeVersion.isJava11OrLater();
boolean _not = (!_isJava11OrLater);
if (_not) {
_builder_1.append("import javax.annotation.Generated;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@Generated(\"org.eclipse.xtend.core.compiler.XtendGenerator\")");
_builder_1.newLine();
}
}
_builder_1.append("public class Bar {");
_builder_1.newLine();
_builder_1.append("}");
Expand All @@ -305,17 +293,6 @@ public void testGeneratedAnnotation_02() {
_builder_1.append("package foo;");
_builder_1.newLine();
_builder_1.newLine();
{
boolean _isJava11OrLater = JavaRuntimeVersion.isJava11OrLater();
boolean _not = (!_isJava11OrLater);
if (_not) {
_builder_1.append("import javax.annotation.Generated;");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@Generated(value = \"org.eclipse.xtend.core.compiler.XtendGenerator\", comments = \"Source: Bar.xtend\")");
_builder_1.newLine();
}
}
_builder_1.append("public class Bar {");
_builder_1.newLine();
_builder_1.append("}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012, 2016 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2012, 2022 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.
Expand All @@ -26,7 +26,6 @@
import org.eclipse.xtext.testing.logging.LoggingTester;
import org.eclipse.xtext.testing.smoketest.IgnoredBySmokeTest;
import org.eclipse.xtext.util.Files;
import org.eclipse.xtext.util.JavaRuntimeVersion;
import org.eclipse.xtext.workspace.FileProjectConfig;
import org.eclipse.xtext.workspace.FileSourceFolder;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
Expand All @@ -40,7 +39,6 @@
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -730,39 +728,6 @@ public void testNoSuppressWarningsAnnotations() {
Assert.assertFalse(this.getContents((TestBatchCompiler.OUTPUT_DIRECTORY + "/XtendA.java")).contains("@SuppressWarnings"));
}

@Test
public void testGeneratedAnnotation() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater());
this.batchCompiler.setGenerateGeneratedAnnotation(true);
this.batchCompiler.setSourcePath("./batch-compiler-data/xtendClass");
Assert.assertTrue(this.batchCompiler.compile());
Assert.assertTrue(this.getContents((TestBatchCompiler.OUTPUT_DIRECTORY + "/XtendA.java")).contains("@Generated"));
}

@Test
public void testGeneratedAnnotationComment() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater());
this.batchCompiler.setGenerateGeneratedAnnotation(true);
this.batchCompiler.setGeneratedAnnotationComment("FooComment");
this.batchCompiler.setSourcePath("./batch-compiler-data/xtendClass");
Assert.assertTrue(this.batchCompiler.compile());
final String generated = this.getContents((TestBatchCompiler.OUTPUT_DIRECTORY + "/XtendA.java"));
Assert.assertTrue(generated.contains("@Generated"));
Assert.assertTrue(generated.contains("FooComment"));
}

@Test
public void testGeneratedAnnotationDate1() {
Assume.assumeFalse(JavaRuntimeVersion.isJava11OrLater());
this.batchCompiler.setGenerateGeneratedAnnotation(true);
this.batchCompiler.setIncludeDateInGeneratedAnnotation(true);
this.batchCompiler.setSourcePath("./batch-compiler-data/xtendClass");
Assert.assertTrue(this.batchCompiler.compile());
final String generated = this.getContents((TestBatchCompiler.OUTPUT_DIRECTORY + "/XtendA.java"));
Assert.assertTrue(generated.contains("@Generated"));
Assert.assertTrue(generated.contains("date ="));
}

@Test
public void testJavaVersion5() {
this.batchCompiler.setJavaSourceVersion("1.5");
Expand Down
Loading

0 comments on commit 8f6d3e4

Please sign in to comment.