Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[all] Use @generated from javax.
see #311

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 27, 2015
1 parent a6a0ad0 commit 168a40f
Show file tree
Hide file tree
Showing 27 changed files with 1,093 additions and 858 deletions.
Expand Up @@ -33,6 +33,8 @@
import java.util.Set;
import java.util.TreeSet;

import javax.annotation.Generated;

import com.google.common.base.Strings;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.EList;
Expand Down Expand Up @@ -67,7 +69,7 @@
import io.sarl.lang.actionprototype.ActionPrototypeProvider;
import io.sarl.lang.actionprototype.FormalParameterProvider;
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.ecoregenerator.helper.SarlEcoreCode;
import io.sarl.lang.sarl.SarlAction;
import io.sarl.lang.sarl.SarlConstructor;
Expand Down Expand Up @@ -373,7 +375,7 @@ private static String extractDefaultValue(IMethod operation, IAnnotation annot)
String fieldName = Utils.PREFIX_ATTRIBUTE_DEFAULT_VALUE + fieldId;
IField field = operation.getDeclaringType().getField(fieldName);
if (field != null) {
annotation = Jdt2Ecore.getAnnotation(field, Generated.class.getName());
annotation = Jdt2Ecore.getAnnotation(field, SarlSourceCode.class.getName());
if (annotation != null) {
return annotation.getMemberValuePairs()[0].getValue().toString();
}
Expand Down
Expand Up @@ -32,8 +32,9 @@
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see Generated
* @see javax.annotation.Generated
* @see DefaultValueSource
* @see SarlSourceCode
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Expand Up @@ -33,8 +33,9 @@
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see Generated
* @see javax.annotation.Generated
* @see DefaultValue
* @see SarlSourceCode
*/
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Expand Up @@ -32,8 +32,9 @@
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see Generated
* @see javax.annotation.Generated
* @see DefaultValue
* @see SarlSourceCode
*/
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR })
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Expand Up @@ -35,7 +35,9 @@
* @mavenartifactid $ArtifactId$
* @see DefaultValueSource
* @see DefaultValue
* @deprecated Use the @Generated from the JRE.
*/
@Deprecated
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Generated {
Expand Down
@@ -0,0 +1,52 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2015 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.annotation;

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

/** Annotation for marking a JvmElement with the original SARL code
* that is the cause of the generation.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see DefaultValueSource
* @see DefaultValue
*/
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface SarlSourceCode {

/** Replies the SARL code that is the cause of the generation.
*
* <p>The value may be an empty string if the SARL code is unknown or too long to
* be stored in the annotation.
*
* @return the SARL code at the source of the generated code.
*/
String value() default "";

}
Expand Up @@ -27,6 +27,8 @@
import java.util.Set;
import java.util.TreeSet;

import javax.annotation.Generated;

import com.google.common.base.Strings;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -41,6 +43,7 @@
import org.eclipse.xtext.common.types.JvmType;
import org.eclipse.xtext.common.types.JvmTypeParameter;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.common.types.JvmVisibility;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.tasks.TaskTags;
Expand All @@ -59,8 +62,8 @@
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.EarlyExit;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.annotation.ImportedCapacityFeature;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.sarl.SarlScript;
import io.sarl.lang.ui.quickfix.SARLQuickfixProvider;
import io.sarl.lang.util.Utils;
Expand Down Expand Up @@ -137,7 +140,7 @@ private void addMissedFunctions(
appendable.increaseIndentation();
}
Set<String> hiddenAnnotations = new TreeSet<>();
for (Class<?> type : Arrays.asList(Generated.class, DefaultValueUse.class, DefaultValue.class,
for (Class<?> type : Arrays.asList(Generated.class, SarlSourceCode.class, DefaultValueUse.class, DefaultValue.class,
DefaultValueSource.class, FiredEvent.class, EarlyExit.class, ImportedCapacityFeature.class)) {
hiddenAnnotations.add(type.getName());
}
Expand All @@ -157,27 +160,47 @@ private void addMissedFunctions(
}
}
// Modifiers
switch (operation.getVisibility()) {
case PRIVATE:
appendable.append("private "); //$NON-NLS-1$
break;
case PROTECTED:
appendable.append("protected "); //$NON-NLS-1$
break;
case PUBLIC:
// Default visibility
//appendable.append("public "); //$NON-NLS-1$
break;
case DEFAULT:
default:
appendable.append("package "); //$NON-NLS-1$
break;
JvmVisibility visibility = container.getDeclaredVisibility();
if (visibility != null) {
switch (visibility) {
case PRIVATE:
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getPrivateKeyword_1().getValue())
.append(" "); //$NON-NLS-1$
break;
case PROTECTED:
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getProtectedKeyword_2().getValue())
.append(" "); //$NON-NLS-1$
break;
case PUBLIC:
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getPublicKeyword_0().getValue())
.append(" "); //$NON-NLS-1$
break;
case DEFAULT:
default:
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getPackageKeyword_3().getValue())
.append(" "); //$NON-NLS-1$
break;
}
}
if (operation.isStrictFloatingPoint()) {
appendable.append("strictfp "); //$NON-NLS-1$
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getStrictfpKeyword_8().getValue())
.append(" "); //$NON-NLS-1$
}
if (operation.isSynchronized()) {
appendable.append("synchronized "); //$NON-NLS-1$
appendable.append(
getTools().getGrammarAccess().getXtendGrammarAccess()
.getCommonModifierAccess().getSynchronizedKeyword_11().getValue())
.append(" "); //$NON-NLS-1$
}
// Type parameters
if (!operation.getTypeParameters().isEmpty()) {
Expand Down Expand Up @@ -265,10 +288,10 @@ private void addMissedFunctions(
while (defaultValue == null && iterator.hasNext()) {
JvmField field = iterator.next();
if (fieldName.equals(field.getSimpleName())) {
String value = Utils.annotationString(field, Generated.class);
if (value != null) {
String value = Utils.annotationString(field, SarlSourceCode.class);
if (!Strings.isNullOrEmpty(value)) {
value = value.trim();
if (!value.isEmpty()) {
if (!Strings.isNullOrEmpty(value)) {
defaultValue = value;
}
}
Expand Down
Expand Up @@ -69,7 +69,7 @@
import io.sarl.lang.actionprototype.ActionPrototypeProvider;
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.annotation.SarlSourceCode;
import io.sarl.lang.sarl.SarlAction;
import io.sarl.lang.sarl.SarlAgent;
import io.sarl.lang.sarl.SarlAnnotationType;
Expand Down Expand Up @@ -874,7 +874,10 @@ private String findDefaultValue(JvmDeclaredType container, String typeName, Stri
if (type instanceof JvmDeclaredType) {
for (JvmField field : ((JvmDeclaredType) type).getDeclaredFields()) {
if (field.getSimpleName().equals(dfName)) {
return Utils.annotationString(field, Generated.class);
String value = Utils.annotationString(field, SarlSourceCode.class);
if (!Strings.isNullOrEmpty(value)) {
return value;
}
}
}
}
Expand All @@ -895,7 +898,10 @@ private String findDefaultValue(JvmDeclaredType container, String name) {
}
for (JvmField field : container.getDeclaredFields()) {
if (field.getSimpleName().equals(dfName)) {
return Utils.annotationString(field, Generated.class);
String value = Utils.annotationString(field, SarlSourceCode.class);
if (!Strings.isNullOrEmpty(value)) {
return value;
}
}
}
}
Expand Down

0 comments on commit 168a40f

Please sign in to comment.