Skip to content

Commit

Permalink
[all] Remove references to Generated annotation class that is differe…
Browse files Browse the repository at this point in the history
…nt between 8 and 11.

see #955

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 1, 2020
1 parent 0e6c1d4 commit 3447a14
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Expand Up @@ -69,7 +69,6 @@

import io.sarl.eclipse.SARLEclipsePlugin;
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.annotation.SyntheticMember;
import io.sarl.lang.codebuilder.builders.IBlockExpressionBuilder;
Expand Down Expand Up @@ -97,6 +96,8 @@
@SuppressWarnings({"static-method", "checkstyle:classfanoutcomplexity"})
public class Jdt2Ecore {

private static final String GENERATED_NAME = "Generated"; //$NON-NLS-0$

@Inject
private TypeReferences typeReferences;

Expand Down Expand Up @@ -322,7 +323,7 @@ && isVisible(typeFinder, type, field)) {
*/
public boolean isGeneratedOperation(IMethod method) {
return getAnnotation(method, SyntheticMember.class.getName()) != null
|| getAnnotation(method, Generated.class.getName()) != null;
|| getAnnotation(method, GENERATED_NAME) != null;
}

/** Replies the annotation with the given qualified name.
Expand Down
Expand Up @@ -65,7 +65,6 @@
import org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters;

import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.annotation.SyntheticMember;
import io.sarl.lang.jvmmodel.SarlJvmModelAssociations;
import io.sarl.lang.sarl.actionprototype.FormalParameterProvider;
Expand All @@ -89,6 +88,8 @@
@SuppressWarnings("checkstyle:classfanoutcomplexity")
public final class MissedMethodAddModification extends SARLSemanticModification {

private static final String GENERATED_NAME = "Generated"; //$NON-NLS-1$

@Inject
private SarlJvmModelAssociations associations;

Expand Down Expand Up @@ -234,8 +235,11 @@ public void apply(EObject element, IModificationContext context) throws Exceptio
*/
public static boolean isGeneratedOperation(JvmOperation method) {
for (final JvmAnnotationReference annotation : method.getAnnotations()) {
if (Objects.equals(SyntheticMember.class.getName(), annotation.getAnnotation().getIdentifier())
|| Objects.equals(Generated.class.getName(), annotation.getAnnotation().getIdentifier())) {
if (Objects.equals(SyntheticMember.class.getName(), annotation.getAnnotation().getIdentifier())) {
return true;
}
final String simpleName = annotation.getAnnotation().getSimpleName();
if (Objects.equals(GENERATED_NAME, simpleName)) {
return true;
}
}
Expand Down
Expand Up @@ -222,6 +222,8 @@ public class SARLJvmModelInferrer extends XtendJvmModelInferrer {

private static final String SERIAL_FIELD_NAME = "serialVersionUID"; //$NON-NLS-1$

private static final String GENERATED_NAME = Generated.class.getName();

/** See the filter in the super class.
*/
private static final Predicate<JvmAnnotationReference> ANNOTATION_TRANSLATION_FILTER = annotation -> {
Expand Down Expand Up @@ -391,6 +393,33 @@ private JvmAnnotationReference addAnnotationSafe(JvmAnnotationTarget target, Cla
return null;
}

/** Add annotation safely.
*
* <p>This function creates an annotation reference. If the type for the annotation is not found;
* no annotation is added.
*
* @param target the receiver of the annotation.
* @param annotationType the type of the annotation.
* @param values the annotations values.
* @return the annotation reference or {@code null} if the annotation cannot be added.
* @since 0.12
*/
private JvmAnnotationReference addAnnotationSafe(JvmAnnotationTarget target, String annotationType, String... values) {
assert target != null;
assert annotationType != null;
try {
final JvmAnnotationReference annotationRef = this._annotationTypesBuilder.annotationRef(annotationType, values);
if (annotationRef != null) {
if (target.getAnnotations().add(annotationRef)) {
return annotationRef;
}
}
} catch (IllegalArgumentException exception) {
// Ignore
}
return null;
}

/** Add annotation safely.
*
* <p>This function creates an annotation reference. If the type for the annotation is not found;
Expand Down Expand Up @@ -1882,7 +1911,7 @@ protected void transform(final XtendFunction source, final JvmGenericType contai
&& !EarlyExit.class.getName().equals(id)
&& !FiredEvent.class.getName().equals(id)
&& !Inline.class.getName().equals(id)
&& !Generated.class.getName().equals(id)) {
&& !GENERATED_NAME.equals(id)) {
try {
final JvmAnnotationReference clone = SARLJvmModelInferrer.this._annotationTypesBuilder
.annotationRef(id);
Expand Down Expand Up @@ -2473,7 +2502,7 @@ protected final void appendGeneratedAnnotation(JvmAnnotationTarget target, Gener
protected void appendGeneratedAnnotation(JvmAnnotationTarget target, GenerationContext context, String sarlCode) {
final GeneratorConfig config = context.getGeneratorConfig();
if (config.isGenerateGeneratedAnnotation()) {
addAnnotationSafe(target, Generated.class, getClass().getName());
addAnnotationSafe(target, GENERATED_NAME, getClass().getName());
}

if (target instanceof JvmFeature) {
Expand Down

0 comments on commit 3447a14

Please sign in to comment.