Skip to content

Commit

Permalink
StubbedSuppressWarnings
Browse files Browse the repository at this point in the history
A stub type to use instead of relying on Java API, which, in Java 21 has
lost the java.lang.annotation.Target} specification.
  • Loading branch information
LorenzoBettini committed Apr 9, 2024
1 parent 51a4ae2 commit 2791444
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeclarationsTest extends AbstractXtendTestCase {

@Test def testAnnotation() {
validFile('''
@SuppressWarnings("unused")
@testdata.stubs.StubbedSuppressWarnings("unused")
class MyClass {
@com.google.inject.Inject(optional=true) MyClass foo
}
Expand All @@ -44,7 +44,7 @@ class DeclarationsTest extends AbstractXtendTestCase {
assertEquals('MyClass', clazz.qualifiedName)
val suppressWarning = clazz.annotations.head
val supressWarningsDeclaration = suppressWarning.annotationTypeDeclaration
assertEquals('java.lang.SuppressWarnings', supressWarningsDeclaration.qualifiedName)
assertEquals('testdata.stubs.StubbedSuppressWarnings', supressWarningsDeclaration.qualifiedName)
assertEquals('unused', suppressWarning.getStringArrayValue('value').get(0))

val annotations = supressWarningsDeclaration.annotations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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 static java.lang.annotation.ElementType.*;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* A stub type to use instead of relying on Java API {@link SuppressWarnings}, which, in Java 21 has lost the
* {@link java.lang.annotation.Target} specification.
*
* @author Lorenzo Bettini - Initial contribution and API
*/
@Target({ TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, MODULE })
@Retention(RetentionPolicy.SOURCE)
public @interface StubbedSuppressWarnings {
String[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class DeclarationsTest extends AbstractXtendTestCase {
@Test
public void testAnnotation() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("@SuppressWarnings(\"unused\")");
_builder.append("@testdata.stubs.StubbedSuppressWarnings(\"unused\")");
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
Expand All @@ -78,7 +78,7 @@ public void testAnnotation() {
Assert.assertEquals("MyClass", clazz.getQualifiedName());
final AnnotationReference suppressWarning = IterableExtensions.head(clazz.getAnnotations());
final AnnotationTypeDeclaration supressWarningsDeclaration = suppressWarning.getAnnotationTypeDeclaration();
Assert.assertEquals("java.lang.SuppressWarnings", supressWarningsDeclaration.getQualifiedName());
Assert.assertEquals("testdata.stubs.StubbedSuppressWarnings", supressWarningsDeclaration.getQualifiedName());
Assert.assertEquals("unused", suppressWarning.getStringArrayValue("value")[0]);
final Iterable<? extends AnnotationReference> annotations = supressWarningsDeclaration.getAnnotations();
final Function1<AnnotationReference, AnnotationTypeDeclaration> _function_1 = (AnnotationReference it_1) -> {
Expand Down

0 comments on commit 2791444

Please sign in to comment.