diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml
index 173f4087db..a6a63c123a 100644
--- a/checkstyle/suppressions.xml
+++ b/checkstyle/suppressions.xml
@@ -77,5 +77,11 @@
+
+
+
+
+
+
diff --git a/plugins/io.sarl.eclipse/icons/sarl_new_agent_dialog.png b/plugins/io.sarl.eclipse/icons/sarl_new_agent_dialog.png
index 5f702fc1bb..faec03f110 100644
Binary files a/plugins/io.sarl.eclipse/icons/sarl_new_agent_dialog.png and b/plugins/io.sarl.eclipse/icons/sarl_new_agent_dialog.png differ
diff --git a/plugins/io.sarl.eclipse/icons/sarl_new_behavior_dialog.png b/plugins/io.sarl.eclipse/icons/sarl_new_behavior_dialog.png
index 70ea175b90..54b07ddda6 100644
Binary files a/plugins/io.sarl.eclipse/icons/sarl_new_behavior_dialog.png and b/plugins/io.sarl.eclipse/icons/sarl_new_behavior_dialog.png differ
diff --git a/plugins/io.sarl.eclipse/icons/sarl_new_capacity_dialog.png b/plugins/io.sarl.eclipse/icons/sarl_new_capacity_dialog.png
index 777ba4ad5d..cd0e2e5f7d 100644
Binary files a/plugins/io.sarl.eclipse/icons/sarl_new_capacity_dialog.png and b/plugins/io.sarl.eclipse/icons/sarl_new_capacity_dialog.png differ
diff --git a/plugins/io.sarl.eclipse/icons/sarl_new_event_dialog.png b/plugins/io.sarl.eclipse/icons/sarl_new_event_dialog.png
index 694c263987..ee52dfee32 100644
Binary files a/plugins/io.sarl.eclipse/icons/sarl_new_event_dialog.png and b/plugins/io.sarl.eclipse/icons/sarl_new_event_dialog.png differ
diff --git a/plugins/io.sarl.eclipse/icons/sarl_new_skill_dialog.png b/plugins/io.sarl.eclipse/icons/sarl_new_skill_dialog.png
index 85b264fee9..9846f99b86 100644
Binary files a/plugins/io.sarl.eclipse/icons/sarl_new_skill_dialog.png and b/plugins/io.sarl.eclipse/icons/sarl_new_skill_dialog.png differ
diff --git a/plugins/io.sarl.eclipse/plugin.xml b/plugins/io.sarl.eclipse/plugin.xml
index d7e1683433..cffbbac9b0 100644
--- a/plugins/io.sarl.eclipse/plugin.xml
+++ b/plugins/io.sarl.eclipse/plugin.xml
@@ -13,18 +13,17 @@
%wizard.description.newSarlProject"
@@ -248,7 +247,7 @@
+ value="plugin_customization.ini"/>
@@ -257,15 +256,21 @@
point="org.eclipse.ui.perspectiveExtensions">
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/dialog/SuperAgentSelectionDialog.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/dialog/SuperAgentSelectionDialog.java
index cf1a0138ce..3c3d197d7f 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/dialog/SuperAgentSelectionDialog.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/dialog/SuperAgentSelectionDialog.java
@@ -36,6 +36,8 @@
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.swt.widgets.Shell;
+import com.google.common.annotations.Beta;
+
/** Dialog box for selecting an agent type.
*
* @author $Author: sgalland$
@@ -43,6 +45,7 @@
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
+@Beta
public class SuperAgentSelectionDialog extends OpenTypeSelectionDialog {
/** Creates new instance of SuperInterfaceSelectionDialog.
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/util/Jdt2Ecore.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/util/Jdt2Ecore.java
new file mode 100644
index 0000000000..81f3081543
--- /dev/null
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/util/Jdt2Ecore.java
@@ -0,0 +1,541 @@
+/*
+ * $Id$
+ *
+ * SARL is an general-purpose agent programming language.
+ * More details on http://www.sarl.io
+ *
+ * Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
+ *
+ * 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.eclipse.util;
+
+import io.sarl.lang.annotation.DefaultValue;
+import io.sarl.lang.annotation.Generated;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
+import io.sarl.lang.sarl.Action;
+import io.sarl.lang.sarl.Constructor;
+import io.sarl.lang.sarl.FeatureContainer;
+import io.sarl.lang.sarl.ParameterizedFeature;
+import io.sarl.lang.signature.ActionKey;
+import io.sarl.lang.signature.ActionSignatureProvider;
+import io.sarl.lang.signature.ActionSignatureProvider.FormalParameterProvider;
+import io.sarl.lang.signature.SignatureKey;
+import io.sarl.lang.util.ModelUtil;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.xtext.common.types.JvmConstructor;
+import org.eclipse.xtext.common.types.JvmDeclaredType;
+import org.eclipse.xtext.common.types.JvmFormalParameter;
+import org.eclipse.xtext.common.types.JvmType;
+import org.eclipse.xtext.xbase.XBlockExpression;
+import org.eclipse.xtext.xbase.XExpression;
+import org.eclipse.xtext.xbase.XFeatureCall;
+import org.eclipse.xtext.xbase.XbaseFactory;
+
+import com.google.common.base.Strings;
+
+
+/** Utilities for creating Ecore SARL elements from the JDT model.
+ *
+ * This class extends the {@link ModelUtil} from the io.sarl.lang
project.
+ *
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @see ModelUtil
+ */
+public final class Jdt2Ecore {
+
+ private Jdt2Ecore() {
+ //
+ }
+
+ /** Find the definition of a type in the classpath of the given project.
+ *
+ * @param project - the project to explore.
+ * @param typeName - the name of the type to search for.
+ * @return the type, or null
if the type was not found.
+ * @throws JavaModelException if this project does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public static IType findType(IJavaProject project, String typeName) throws JavaModelException {
+ if (project != null) {
+ return project.findType(typeName);
+ }
+ return null;
+ }
+
+ /** Replies if the given type name is valid for a super-type.
+ *
+ * The type name is valid if it is not empty and not the Object
classname.
+ *
+ * @param typeName - the name of the type to test.
+ * @return true
if the given type name is valid.
+ */
+ protected static boolean isValidSuperType(String typeName) {
+ return !Strings.isNullOrEmpty(typeName) && !"java.lang.Object".equals(typeName); //$NON-NLS-1$
+ }
+
+ /** Replies if the target feature is visible from the type.
+ *
+ * @param fromType - the type from which the feature visibility is tested.
+ * @param target - the feature to test for the visibility.
+ * @return true
if the given type can see the target feature.
+ * @throws JavaModelException if the Java model is invalid.
+ */
+ public static boolean isVisible(IType fromType, IMember target) throws JavaModelException {
+ int flags = target.getFlags();
+ if (Flags.isPublic(flags) || Flags.isProtected(flags)) {
+ return true;
+ }
+ if (Flags.isPrivate(flags)) {
+ return false;
+ }
+ IPackageFragment f1 = target.getDeclaringType().getPackageFragment();
+ IPackageFragment f2 = fromType.getPackageFragment();
+ if (f1.isDefaultPackage()) {
+ return f2.isDefaultPackage();
+ }
+ return f1.getElementName().equals(f2.getElementName());
+ }
+
+ /** Replies the provider of formal parameters for the given operation.
+ *
+ * @param operation - the operation.
+ * @return the provider of formal parameters for the operation.
+ * @throws JavaModelException if the Java model is invalid.
+ */
+ public static FormalParameterProvider getFormalParameterProvider(IMethod operation) throws JavaModelException {
+ return new FormalParameterList(operation);
+ }
+
+ /** Analyzing the type hierarchy of the given element, and
+ * extract any type-related information.
+ *
+ * @param project - the project to explore.
+ * @param finalOperations - filled with the final operations inherited by the element.
+ * @param overridableOperations - filled with the oervrideable operations inherited by the element.
+ * @param inheritedFields - filled with the fields inherited by the element.
+ * @param operationsToImplement - filled with the abstract operations inherited by the element.
+ * @param superConstructors - filled with the construstors of the super type.
+ * @param sarlSignatureProvider - provider of tools related to action signatures.
+ * @param superClass - the name of the super class.
+ * @param superInterfaces - the super interfaces.
+ * @throws JavaModelException if the Java model is invalid.
+ */
+ public static void populateInheritanceContext(
+ IJavaProject project,
+ Map finalOperations,
+ Map overridableOperations,
+ Map inheritedFields,
+ Map operationsToImplement,
+ Map superConstructors,
+ ActionSignatureProvider sarlSignatureProvider,
+ String superClass,
+ List superInterfaces) throws JavaModelException {
+ // Get the operations that must be implemented
+ if (operationsToImplement != null) {
+ Iterator typeIterator = new SuperTypeIterator(project, true, superInterfaces);
+ while (typeIterator.hasNext()) {
+ IType type = typeIterator.next();
+ for (IMethod operation : type.getMethods()) {
+ if (!Flags.isStatic(operation.getFlags())
+ && !Flags.isFinal(operation.getFlags())
+ && !operation.isLambdaMethod()
+ && !operation.isConstructor()) {
+ SignatureKey sig = sarlSignatureProvider.createSignatureID(
+ Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation));
+ ActionKey actionKey = sarlSignatureProvider.createActionID(
+ operation.getElementName(),
+ sig);
+ operationsToImplement.put(actionKey, operation);
+ }
+ }
+ }
+ }
+
+ // Check on the implemented features, inherited from the super type
+ if (isValidSuperType(superClass)) {
+ Iterator typeIterator = new SuperTypeIterator(project, false, superClass);
+ while (typeIterator.hasNext()) {
+ IType type = typeIterator.next();
+ boolean checkForConstructors = (superConstructors != null && type.getFullyQualifiedName().equals(superClass));
+ for (IMethod operation : type.getMethods()) {
+ if (!Flags.isStatic(operation.getFlags())
+ && !operation.isLambdaMethod()
+ && isVisible(type, operation)) {
+ if (!operation.isConstructor()
+ && !ModelUtil.isHiddenAction(operation.getElementName())) {
+ SignatureKey sig = sarlSignatureProvider.createSignatureID(
+ Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation));
+ ActionKey actionKey = sarlSignatureProvider.createActionID(
+ operation.getElementName(), sig);
+ int flags = operation.getFlags();
+ if (Flags.isAbstract(flags)) {
+ if (operationsToImplement != null) {
+ operationsToImplement.put(actionKey, operation);
+ }
+ } else if (Flags.isFinal(flags)) {
+ if (finalOperations != null) {
+ finalOperations.put(actionKey, operation);
+ }
+ if (operationsToImplement != null) {
+ operationsToImplement.remove(actionKey);
+ }
+ } else {
+ if (overridableOperations != null) {
+ overridableOperations.put(actionKey, operation);
+ }
+ if (operationsToImplement != null) {
+ operationsToImplement.remove(actionKey);
+ }
+ }
+ } else if (checkForConstructors && operation.isConstructor() && superConstructors != null) {
+ SignatureKey sig = sarlSignatureProvider.createSignatureID(
+ Flags.isVarargs(operation.getFlags()), getFormalParameterProvider(operation));
+ superConstructors.put(sig, operation);
+ }
+ }
+ }
+
+ if (inheritedFields != null) {
+ for (IField field : type.getFields()) {
+ if (!Flags.isStatic(field.getFlags())
+ && !ModelUtil.isHiddenAttribute(field.getElementName())
+ && isVisible(type, field)) {
+ inheritedFields.put(field.getElementName(), field);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /** Replies if the given method is marked has automatically generated by the SARL compiler.
+ *
+ * @param method - the method to check.
+ * @return true
if the method is annoted with Generated; false
+ * otherwise.
+ */
+ public static boolean isGeneratedOperation(IMethod method) {
+ return getAnnotation(method, Generated.class.getName()) != null;
+ }
+
+ /** Replies the annotation with the given qualified name.
+ *
+ * @param element - the annoted element.
+ * @param qualifiedName - the qualified name of the element.
+ * @return the annotation, or null
if the element is not annoted.
+ */
+ public static IAnnotation getAnnotation(IAnnotatable element, String qualifiedName) {
+ if (element != null) {
+ try {
+ int separator = qualifiedName.lastIndexOf('.');
+ String simpleName;
+ if (separator >= 0 && separator < (qualifiedName.length() - 1)) {
+ simpleName = qualifiedName.substring(separator + 1, qualifiedName.length());
+ } else {
+ simpleName = qualifiedName;
+ }
+ for (IAnnotation annotation : element.getAnnotations()) {
+ String name = annotation.getElementName();
+ if (name.equals(simpleName) || name.equals(qualifiedName)) {
+ return annotation;
+ }
+ }
+ } catch (JavaModelException e) {
+ //
+ }
+ }
+ return null;
+ }
+
+ /** Create the JvmConstructor for the given JDT method.
+ *
+ * @param code - the generated code.
+ * @param constructor - the JDT constructor.
+ * @param context - the context of the constructor.
+ * @return the JvmConstructor
+ * @throws JavaModelException if the Java model is invalid.
+ */
+ public static JvmConstructor getJvmConstructor(GeneratedCode code, IMethod constructor, FeatureContainer context)
+ throws JavaModelException {
+ if (constructor.isConstructor()) {
+ JvmType type = code.getCodeGenerator().getTypeReferences().findDeclaredType(
+ constructor.getDeclaringType().getFullyQualifiedName(),
+ context);
+ if (type instanceof JvmDeclaredType) {
+ JvmDeclaredType declaredType = (JvmDeclaredType) type;
+ ActionSignatureProvider sigProvider = code.getCodeGenerator().getActionSignatureProvider();
+ SignatureKey jdtSignature = sigProvider.createSignatureID(
+ Flags.isVarargs(constructor.getFlags()),
+ Jdt2Ecore.getFormalParameterProvider(constructor));
+ for (JvmConstructor jvmConstructor : declaredType.getDeclaredConstructors()) {
+ SignatureKey jvmSignature = sigProvider.createSignatureIDFromJvmModel(
+ jvmConstructor.isVarArgs(),
+ jvmConstructor.getParameters());
+ if (jvmSignature.equals(jdtSignature)) {
+ return jvmConstructor;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static String extractDefaultValue(IMethod operation, IAnnotation annot)
+ throws JavaModelException, IllegalArgumentException {
+ IAnnotation annotation = annot;
+ Object value = annotation.getMemberValuePairs()[0].getValue();
+ String fieldId = (value == null) ? null : value.toString();
+ if (!Strings.isNullOrEmpty(fieldId)) {
+ String fieldName = ModelUtil.PREFIX_ATTRIBUTE_DEFAULT_VALUE + fieldId;
+ IField field = operation.getDeclaringType().getField(fieldName);
+ if (field != null) {
+ annotation = Jdt2Ecore.getAnnotation(field, Generated.class.getName());
+ if (annotation != null) {
+ return annotation.getMemberValuePairs()[0].getValue().toString();
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Create the formal parameters for the given operation.
+ *
+ * @param code - the generated code.
+ * @param operation - the operation that describes the formal parameters.
+ * @param container - the container of the created formal parameters.
+ * @throws JavaModelException if the Java model is invalid.
+ * @throws IllegalArgumentException if the signature is not syntactically correct.
+ */
+ public static void createFormalParameters(GeneratedCode code, IMethod operation,
+ ParameterizedFeature container) throws JavaModelException, IllegalArgumentException {
+ boolean isVarargs = Flags.isVarargs(operation.getFlags());
+ container.setVarargs(isVarargs);
+ ILocalVariable[] parameters = operation.getParameters();
+ for (int i = 0; i < parameters.length; ++i) {
+ ILocalVariable parameter = parameters[i];
+ IAnnotation annotation = Jdt2Ecore.getAnnotation(parameter, DefaultValue.class.getName());
+ String defaultValue = (annotation != null) ? extractDefaultValue(operation, annotation) : null;
+ String type = Signature.toString(parameter.getTypeSignature());
+ if (isVarargs && i == parameters.length - 1 && type.endsWith("[]")) { //$NON-NLS-1$
+ type = type.substring(0, type.length() - 2);
+ }
+ code.getCodeGenerator().createFormalParameter(code, container,
+ parameter.getElementName(),
+ type,
+ defaultValue,
+ code.getResourceSet());
+ }
+ }
+
+ /** Add the given constructors to the Ecore container.
+ *
+ * @param code - the generated code.
+ * @param superClassConstructors - the constructors defined in the super class.
+ * @param container - the container of the created constructors.
+ * @throws JavaModelException if the Java model is invalid.
+ */
+ public static void createStandardConstructors(GeneratedCode code,
+ Collection superClassConstructors, FeatureContainer container) throws JavaModelException {
+ if (superClassConstructors != null) {
+ for (IMethod constructor : superClassConstructors) {
+ if (!isGeneratedOperation(constructor)) {
+ XBlockExpression block = XbaseFactory.eINSTANCE.createXBlockExpression();
+ //
+ JvmConstructor jvmConstructor = getJvmConstructor(code, constructor, container);
+ XFeatureCall call = XbaseFactory.eINSTANCE.createXFeatureCall();
+ call.setFeature(jvmConstructor);
+ call.setExplicitOperationCall(true);
+ EList arguments = call.getFeatureCallArguments();
+ for (JvmFormalParameter param : jvmConstructor.getParameters()) {
+ XFeatureCall paramRef = XbaseFactory.eINSTANCE.createXFeatureCall();
+ paramRef.setFeature(param);
+ arguments.add(paramRef);
+ }
+ block.getExpressions().add(call);
+ //
+ Constructor cons = code.getCodeGenerator().createConstructor(code, container, block);
+ createFormalParameters(code, constructor, cons);
+ }
+ }
+ }
+ }
+
+ /** Create the operations into the SARL feature container.
+ *
+ * @param code - the generated code.
+ * @param methods - the operations to create.
+ * @param container - the container of the created formal parameters.
+ * @throws JavaModelException if the Java model is invalid.
+ * @throws IllegalArgumentException if the signature is not syntactically correct.
+ */
+ public static void createActions(GeneratedCode code,
+ Collection methods, FeatureContainer container) throws JavaModelException, IllegalArgumentException {
+ if (methods != null) {
+ for (IMethod operation : methods) {
+ if (!isGeneratedOperation(operation)) {
+ Action action = code.getCodeGenerator().createAction(code, container,
+ operation.getElementName(),
+ Signature.toString(operation.getReturnType()),
+ null);
+ createFormalParameters(code, operation, action);
+ }
+ }
+ }
+ }
+
+ /**
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private static class SuperTypeIterator implements Iterator {
+
+ private final IJavaProject project;
+ private final Set encountered = new TreeSet<>();
+ private final Deque queue = new LinkedList<>();
+ private final boolean isInterface;
+ private IType current;
+
+ /**
+ * @param project
+ * @param isInterface
+ * @param typeNames
+ */
+ public SuperTypeIterator(IJavaProject project, boolean isInterface, String... typeNames) {
+ this(project, isInterface, Arrays.asList(typeNames));
+ }
+
+ /**
+ * @param project
+ * @param isInterface
+ * @param typeNames
+ */
+ public SuperTypeIterator(IJavaProject project, boolean isInterface, Collection typeNames) {
+ this.isInterface = isInterface;
+ this.project = project;
+ this.queue.addAll(typeNames);
+ updateCurrent();
+ }
+
+ private void updateCurrent() {
+ this.current = null;
+ while (this.current == null && !this.queue.isEmpty()) {
+ String typeName = this.queue.removeFirst();
+ if (isValidSuperType(typeName) && !this.encountered.contains(typeName)) {
+ try {
+ this.current = findType(this.project, typeName);
+ } catch (JavaModelException e) {
+ this.current = null;
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ return this.current != null;
+ }
+
+ @Override
+ public IType next() {
+ if (this.current == null) {
+ throw new NoSuchElementException();
+ }
+ IType c = this.current;
+ String name = c.getFullyQualifiedName();
+ this.encountered.add(name);
+ try {
+ if (this.isInterface) {
+ this.queue.addAll(Arrays.asList(c.getSuperInterfaceNames()));
+ } else {
+ this.queue.add(c.getSuperclassName());
+ }
+ } catch (JavaModelException _) {
+ //
+ }
+ updateCurrent();
+ return c;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ /**
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ private static class FormalParameterList implements FormalParameterProvider {
+
+ private final ILocalVariable[] parameters;
+
+ /**
+ * @param operation - the operation.
+ * @throws JavaModelException if the parameters cannot be retreived.
+ */
+ public FormalParameterList(IMethod operation) throws JavaModelException {
+ this.parameters = operation.getParameters();
+ }
+
+ @Override
+ public int getFormalParameterCount() {
+ return this.parameters.length;
+ }
+
+ @Override
+ public String getFormalParameterName(int position) {
+ return this.parameters[position].getElementName();
+ }
+
+ @Override
+ public String getFormalParameterType(int position, boolean isVarArgs) {
+ return Signature.toString(this.parameters[position].getTypeSignature());
+ }
+
+ }
+
+}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizard.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizard.java
index 32ffc1610c..8bb49b6ad7 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizard.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizard.java
@@ -82,7 +82,7 @@ public IJavaElement getCreatedElement() {
@Override
public boolean performFinish() {
- final int size = this.page.createType();
+ final int size = this.page.asyncCreateType();
final IResource resource = this.page.getResource();
if (resource != null) {
selectAndReveal(resource);
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizardPage.java
index b3820f14c8..718a7a79ed 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/AbstractNewSarlElementWizardPage.java
@@ -21,16 +21,17 @@
package io.sarl.eclipse.wizards.elements;
import io.sarl.eclipse.SARLEclipsePlugin;
-import io.sarl.lang.SARLKeywords;
+import io.sarl.eclipse.util.Jdt2Ecore;
+import io.sarl.lang.genmodel.SARLCodeGenerator;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.TreeSet;
import javax.inject.Inject;
import javax.inject.Named;
@@ -46,6 +47,8 @@
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.debug.internal.ui.SWTFactory;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
@@ -57,16 +60,22 @@
import org.eclipse.jdt.internal.core.CompilationUnit;
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
import org.eclipse.jdt.internal.core.PackageFragment;
-import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFieldGroup;
import org.eclipse.jdt.ui.wizards.NewTypeWizardPage;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.xtext.Constants;
import org.eclipse.xtext.formatting.IWhitespaceInformationProvider;
+import org.eclipse.xtext.ui.resource.IResourceSetProvider;
import org.eclipse.xtext.ui.resource.IStorage2UriMapper;
import com.google.common.base.Strings;
@@ -89,19 +98,33 @@ public abstract class AbstractNewSarlElementWizardPage extends NewTypeWizardPage
*/
protected static final int COLUMNS = 4;
- private IResource resource;
+ private static final int STEPS = 4;
+ private static final String SETTINGS_CREATECONSTR = "create_constructor"; //$NON-NLS-1$
+ private static final String SETTINGS_CREATEUNIMPLEMENTED = "create_unimplemented"; //$NON-NLS-1$
+ /** The generator for the SALR language.
+ */
@Inject
- private FieldInitializerUtil util;
-
- private String sarlFileExtension;
+ protected SARLCodeGenerator sarlGenerator;
@Inject
- private IWhitespaceInformationProvider whitespaceInformationProvider;
+ private FieldInitializerUtil fieldInitializer;
@Inject
private IStorage2UriMapper storage2UriMapper;
+ @Inject
+ private IResourceSetProvider resourceSetFactory;
+
+ @Inject
+ private IWhitespaceInformationProvider whitespaceInformationProvider;
+
+ private String sarlFileExtension;
+ private IResource resource;
+ private SelectionButtonDialogFieldGroup methodStubsButtons;
+ private boolean isConstructorCreationEnabled;
+ private boolean isInheritedCreationEnabled;
+
/**
* @param typeKind - Signals the kind of the type to be created. Valid kinds are
* {@link NewTypeWizardPage#CLASS_TYPE}, {@link NewTypeWizardPage#INTERFACE_TYPE},
@@ -150,11 +173,6 @@ public void setVisible(boolean visible) {
}
}
- @Override
- public final void createType(IProgressMonitor monitor) throws CoreException, InterruptedException {
- throw new UnsupportedOperationException();
- }
-
@Override
protected void handleFieldChanged(String fieldName) {
super.handleFieldChanged(fieldName);
@@ -287,7 +305,7 @@ protected String getMissedSuperInterfaceErrorMessage() {
* @param selection - the current selection.
*/
protected void init(IStructuredSelection selection) {
- IJavaElement elem = this.util.getSelectedResource(selection);
+ IJavaElement elem = this.fieldInitializer.getSelectedResource(selection);
initContainerPage(elem);
initTypePage(elem);
//
@@ -308,6 +326,12 @@ protected void init(IStructuredSelection selection) {
doStatusUpdate();
}
+ @Override
+ public boolean isAddComments() {
+ // Create the comments
+ return true;
+ }
+
/** Replies if the given type is a subtype of the expected super-type.
* The expected super-type is replied by {@link #getRootSuperType()}.
*
@@ -321,7 +345,7 @@ protected boolean isValidExtendedType(String className) throws JavaModelExceptio
if (!Strings.isNullOrEmpty(className)) {
IType rootType = getRootSuperType();
assert (rootType != null);
- IType type = findType(getJavaProject(), className);
+ IType type = Jdt2Ecore.findType(getJavaProject(), className);
assert (type != null);
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
assert (hierarchy != null);
@@ -344,7 +368,7 @@ protected boolean isValidImplementedType(String className) throws JavaModelExcep
if (!Strings.isNullOrEmpty(className)) {
IType rootType = getRootSuperInterface();
assert (rootType != null);
- IType type = findType(getJavaProject(), className);
+ IType type = Jdt2Ecore.findType(getJavaProject(), className);
assert (type != null);
ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
assert (hierarchy != null);
@@ -404,21 +428,6 @@ private void reinitSuperInterfaces() {
}
}
- /** Find a type in the context of the given project.
- *
- * @param project - the context of the search.
- * @param typeName - the name of the type to search.
- * @return the type or null
.
- * @throws JavaModelException if it is not possible to retreive the type.
- */
- @SuppressWarnings("static-method")
- protected IType findType(IJavaProject project, String typeName) throws JavaModelException {
- if (project.exists()) {
- return project.findType(typeName);
- }
- return null;
- }
-
@Override
protected IStatus superClassChanged() {
IStatus status = super.superClassChanged();
@@ -529,50 +538,32 @@ protected Composite createCommonControls(Composite parent) {
return composite;
}
+ @Override
+ public final void createControl(Composite parent) {
+ Composite composite = createCommonControls(parent);
+ createPageControls(composite);
+ setControl(composite);
+ readSettings();
+ doStatusUpdate();
+ }
+
+ /** Invoked to create the controls in the page.
+ *
+ * @param parent - the container of the controls.
+ */
+ protected abstract void createPageControls(Composite parent);
+
/** Create the type from the data gathered in the wizard.
*
* @return the size of the created file.
*/
- protected int createType() {
+ protected final int asyncCreateType() {
final int[] size = {0};
IRunnableWithProgress op = new WorkspaceModifyOperation() {
- private static final int STEPS = 4;
- @SuppressWarnings("synthetic-access")
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
InterruptedException {
- SubMonitor mon = SubMonitor.convert(monitor, STEPS);
- try {
- // Create the package if not existing
- if (!getPackageFragment().exists()) {
- getPackageFragmentRoot().createPackageFragment(
- getPackageFragment().getElementName(),
- true,
- mon.newChild(1));
- } else {
- mon.worked(1);
- }
- // Create the file
- IResource packageResource = getPackageFragment().getResource();
- IFile sarlFile = ((IFolder) packageResource).getFile(
- getTypeName() + "." //$NON-NLS-1$
- + AbstractNewSarlElementWizardPage.this.sarlFileExtension);
- URI sarlUri = AbstractNewSarlElementWizardPage.this.storage2UriMapper.getUri(sarlFile);
- mon.worked(1);
- // Create the file content
- String content = createContent(mon.newChild(1), sarlFile,
- AbstractNewSarlElementWizardPage.this.whitespaceInformationProvider.
- getIndentationInformation(sarlUri).getIndentString(),
- AbstractNewSarlElementWizardPage.this.whitespaceInformationProvider.
- getLineSeparatorInformation(sarlUri).getLineSeparator());
- size[0] = content.length();
- sarlFile.create(new ByteArrayInputStream(content.getBytes()), true, mon.newChild(1));
- setResource(sarlFile);
- } catch (OperationCanceledException e) {
- throw new InterruptedException();
- } catch (Exception e) {
- throw new InvocationTargetException(e);
- }
+ size[0] = createSARLType(monitor);
}
};
try {
@@ -582,77 +573,203 @@ protected void execute(IProgressMonitor monitor) throws CoreException, Invocatio
return 0;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
+ SARLEclipsePlugin.getDefault().log(realException);
MessageDialog.openError(getShell(), getTitle(), realException.getMessage());
}
return size[0];
}
- /** Invoked to create a stub to a JDT compilation unit.
- * This stub could be used to access to the
- *
- * @return the stub.
- */
- private ICompilationUnit getCompilationUnitStub() {
- String compilationUnitName = getCompilationUnitName(getTypeName());
- return new CompilationUnit((PackageFragment) getPackageFragment(),
- compilationUnitName,
- DefaultWorkingCopyOwner.PRIMARY);
+ @Override
+ public final void createType(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ createSARLType(monitor);
}
- /** Invoked for creating the content of the generated file.
+ /** Create the SARL type.
*
* @param monitor - the progression monitor.
- * @param sarlFile - the filename of the generated file.
- * @param indentation - the identation.
- * @param lineSeparator - the line separator.
- * @return the content of the file.
- * @throws CoreException when the content cannot be generated.
+ * @return the size of the generated code.
+ * @throws CoreException when the creation failed.
+ * @throws InterruptedException when the operation was canceled.
*/
- private String createContent(IProgressMonitor monitor, IFile sarlFile,
- String indentation, String lineSeparator) throws CoreException {
- ICompilationUnit compilationUnit = getCompilationUnitStub();
- String fileComment = getFileComment(compilationUnit, lineSeparator);
- String typeComment = getTypeComment(compilationUnit, lineSeparator);
+ public int createSARLType(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ SubMonitor mon = SubMonitor.convert(monitor, STEPS);
+ try {
+ // Create the package if not existing
+ if (!getPackageFragment().exists()) {
+ getPackageFragmentRoot().createPackageFragment(
+ getPackageFragment().getElementName(),
+ true,
+ mon.newChild(1));
+ } else {
+ mon.worked(1);
+ }
+ // Create the file
+ IResource packageResource = getPackageFragment().getResource();
+ IFolder folder = (IFolder) packageResource;
+ IFile sarlFile = folder.getFile(
+ getTypeName() + "." //$NON-NLS-1$
+ + AbstractNewSarlElementWizardPage.this.sarlFileExtension);
+ URI sarlUri = AbstractNewSarlElementWizardPage.this.storage2UriMapper.getUri(sarlFile);
+ ResourceSet resourceSet = AbstractNewSarlElementWizardPage.this.resourceSetFactory.get(
+ getJavaProject().getProject());
+ Resource ecoreResource = resourceSet.createResource(sarlUri);
+ mon.worked(1);
+
+ // Create the file content
+ ICompilationUnit compilationUnit = getCompilationUnitStub();
+ String lineSeparator = AbstractNewSarlElementWizardPage.this.whitespaceInformationProvider
+ .getLineSeparatorInformation(sarlUri).getLineSeparator();
+ String fileComment = getFileComment(compilationUnit, lineSeparator);
+ String typeComment = getTypeComment(compilationUnit, lineSeparator);
+ getTypeContent(ecoreResource, typeComment);
+ byte[] content;
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ if (!Strings.isNullOrEmpty(fileComment)) {
+ baos.write(fileComment.getBytes());
+ baos.write(lineSeparator.getBytes());
+ }
+ ecoreResource.save(baos, null);
+ content = baos.toByteArray();
+ }
+ mon.worked(1);
- IPackageFragment packageFragment = getPackageFragment();
+ sarlFile.create(new ByteArrayInputStream(content), true, mon.newChild(1));
+ setResource(sarlFile);
- StringBuilder typeContent = new StringBuilder();
- Set imports = new TreeSet<>();
- getTypeContent(packageFragment, typeContent, imports, indentation, lineSeparator);
-
- String packageDeclaration = SarlTypeCreatorUtil.createPackageDeclaration(packageFragment, lineSeparator);
-
- StringBuilder head = new StringBuilder();
- head.append(packageDeclaration);
- head.append(lineSeparator);
- if (!imports.isEmpty()) {
- for (String importElement : imports) {
- if (!Strings.isNullOrEmpty(importElement)
- && !importElement.equals(packageFragment.getElementName())) {
- head.append(SARLKeywords.IMPORT);
- head.append(" "); //$NON-NLS-1$
- head.append(importElement);
- head.append(lineSeparator);
- }
+ saveSettings();
+
+ return content.length;
+ } catch (OperationCanceledException e) {
+ throw new InterruptedException();
+ } catch (CoreException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new CoreException(SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, e));
+ }
+ }
+
+ /** Read the settings of the dialog box.
+ */
+ protected void readSettings() {
+ boolean createConstructors = false;
+ boolean createUnimplemented = true;
+ IDialogSettings dialogSettings = getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section = dialogSettings.getSection(getName());
+ if (section != null) {
+ createConstructors = section.getBoolean(SETTINGS_CREATECONSTR);
+ createUnimplemented = section.getBoolean(SETTINGS_CREATEUNIMPLEMENTED);
}
}
- return StubUtility.getCompilationUnitContent(compilationUnit,
- head.toString(),
- fileComment, typeComment, typeContent.toString(), lineSeparator);
+ setMethodStubSelection(createConstructors, createUnimplemented, true);
+ }
+
+ /** Save the settings of the dialog box.
+ */
+ protected void saveSettings() {
+ IDialogSettings dialogSettings = getDialogSettings();
+ if (dialogSettings != null) {
+ IDialogSettings section = dialogSettings.getSection(getName());
+ if (section == null) {
+ section = dialogSettings.addNewSection(getName());
+ }
+ section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
+ section.put(SETTINGS_CREATEUNIMPLEMENTED, isCreateInherited());
+ }
+ }
+
+ private ICompilationUnit getCompilationUnitStub() {
+ String compilationUnitName = getCompilationUnitName(getTypeName());
+ return new CompilationUnit((PackageFragment) getPackageFragment(), compilationUnitName, DefaultWorkingCopyOwner.PRIMARY);
}
/** Invoked for retreiving the definition of the new type.
*
- * @param packageFragment - the definition of the package fragment in which the content should be generated.
- * @param content - the content of the file. This parameter is filled with the content.
- * @param imports - the list of the imports to inject into the file.
- * @param indentation - the identation.
- * @param lineSeparator - the line separator.
+ * @param ecoreResource - the Ecore resource of the script.
+ * @param typeComment - the comment for the type.
+ * @throws CoreException if an error occurs when creating the content.
*/
- protected abstract void getTypeContent(
- IPackageFragment packageFragment,
- StringBuilder content,
- Set imports,
- String indentation, String lineSeparator);
+ protected abstract void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException;
+
+ /** Create the controls related to the behavior units to generate.
+ *
+ * @param composite - the container of the controls.
+ * @param nColumns - the number of columns.
+ * @param enableConstructors - indicates if the constructor creation is enable.
+ * @param enableInherited - indicates if the inherited operation creation is enable.
+ */
+ protected void createMethodStubControls(Composite composite, int nColumns,
+ boolean enableConstructors, boolean enableInherited) {
+ this.isConstructorCreationEnabled = enableConstructors;
+ this.isInheritedCreationEnabled = enableInherited;
+ String[] buttonNames;
+ if (enableConstructors && enableInherited) {
+ buttonNames = new String[] {
+ Messages.AbstractNewSarlElementWizardPage_0,
+ Messages.AbstractNewSarlElementWizardPage_1,
+ };
+ } else if (enableInherited && !enableConstructors) {
+ buttonNames = new String[] {
+ Messages.AbstractNewSarlElementWizardPage_1,
+ };
+ } else {
+ assert (enableConstructors);
+ buttonNames = new String[] {
+ Messages.AbstractNewSarlElementWizardPage_0,
+ };
+ }
+ this.methodStubsButtons = new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames, 1);
+ this.methodStubsButtons.setLabelText(Messages.AbstractNewSarlElementWizardPage_2);
+
+ Control labelControl = this.methodStubsButtons.getLabelControl(composite);
+ LayoutUtil.setHorizontalSpan(labelControl, nColumns);
+
+ DialogField.createEmptySpace(composite);
+
+ Control buttonGroup = this.methodStubsButtons.getSelectionButtonsGroup(composite);
+ LayoutUtil.setHorizontalSpan(buttonGroup, nColumns - 1);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create Constructors' checkbox.
+ *
+ * @return the selection state of the 'Create Constructors' checkbox
+ */
+ protected boolean isCreateConstructors() {
+ return this.isConstructorCreationEnabled && this.methodStubsButtons.isSelected(0);
+ }
+
+ /**
+ * Returns the current selection state of the 'Create inherited abstract methods'
+ * checkbox.
+ *
+ * @return the selection state of the 'Create inherited abstract methods' checkbox
+ */
+ protected boolean isCreateInherited() {
+ return this.isInheritedCreationEnabled && this.methodStubsButtons.isSelected(
+ this.isConstructorCreationEnabled ? 1 : 0);
+ }
+
+ /**
+ * Sets the selection state of the method stub checkboxes.
+ *
+ * @param createConstructors initial selection state of the 'Create Constructors' checkbox.
+ * @param createInherited initial selection state of the 'Create inherited abstract methods' checkbox.
+ * @param canBeModified if true
the method stub checkboxes can be changed by
+ * the user. If false
the buttons are "read-only"
+ */
+ protected void setMethodStubSelection(boolean createConstructors, boolean createInherited, boolean canBeModified) {
+ if (this.methodStubsButtons != null) {
+ if (this.isConstructorCreationEnabled && this.isInheritedCreationEnabled) {
+ this.methodStubsButtons.setSelection(0, createConstructors);
+ this.methodStubsButtons.setSelection(1, createInherited);
+ } else if (this.isInheritedCreationEnabled && !this.isConstructorCreationEnabled) {
+ this.methodStubsButtons.setSelection(0, createInherited);
+ } else {
+ this.methodStubsButtons.setSelection(0, createConstructors);
+ }
+ this.methodStubsButtons.setEnabled(canBeModified);
+ }
+ }
}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/Messages.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/Messages.java
new file mode 100644
index 0000000000..be8f8b1ef4
--- /dev/null
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/Messages.java
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * SARL is an general-purpose agent programming language.
+ * More details on http://www.sarl.io
+ *
+ * Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
+ *
+ * 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.eclipse.wizards.elements;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+@SuppressWarnings("all")
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "io.sarl.eclipse.wizards.elements.messages"; //$NON-NLS-1$
+ public static String AbstractNewSarlElementWizardPage_0;
+ public static String AbstractNewSarlElementWizardPage_1;
+ public static String AbstractNewSarlElementWizardPage_2;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/SarlTypeCreatorUtil.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/SarlTypeCreatorUtil.java
deleted file mode 100644
index e1eb7bfbcb..0000000000
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/SarlTypeCreatorUtil.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * $Id$
- *
- * SARL is an general-purpose agent programming language.
- * More details on http://www.sarl.io
- *
- * Copyright (C) 2014 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
- *
- * 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.eclipse.wizards.elements;
-
-import io.sarl.lang.SARLKeywords;
-import io.sarl.lang.core.Agent;
-import io.sarl.lang.core.Behavior;
-import io.sarl.lang.core.Capacity;
-import io.sarl.lang.core.Event;
-import io.sarl.lang.core.Skill;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.jdt.core.IPackageFragment;
-
-import com.google.common.base.Strings;
-
-
-/** Utilities for creating SARL elements.
- *
- * This class may extend the XtendTypeCreatorUtil.
- *
- * FIXME: Creating the code from the EMF elements (using a serializer) should be better than this hard-coded version.
- *
- * @author $Author: sgalland$
- * @version $FullVersion$
- * @mavengroupid $GroupId$
- * @mavenartifactid $ArtifactId$
- */
-public final class SarlTypeCreatorUtil {
-
- private SarlTypeCreatorUtil() {
- //
- }
-
- /** Create a package declaration.
- *
- * @param packageFragment - package fragment.
- * @param lineSeparator - line separator.
- * @return the SARL package declaration.
- */
- public static String createPackageDeclaration(IPackageFragment packageFragment, String lineSeparator) {
- StringBuilder sb = new StringBuilder();
- if (!Strings.isNullOrEmpty(packageFragment.getElementName())) {
- sb.append(SARLKeywords.PACKAGE + " "); //$NON-NLS-1$
- sb.append(packageFragment.getElementName());
- sb.append(lineSeparator);
- }
- return sb.toString();
- }
-
- /** Create the SARL code that corresponds to an agent with the given properties.
- *
- * @param packageName - the name of the package where the agent is created.
- * @param agentName - name of the agent type.
- * @param superClass - the name of the super type.
- * @param imports - the list of the types to put into the import section for supporting
- * the generated code. If this parameter is null
, the
- * list is not filled.
- * @param indentation - identation string.
- * @param lineSeparator - line separator.
- * @param generateInitializeHandler - indicates if the handler for the Initialize event should be generated.
- * @return the SARL code for the agent.
- */
- public static String createAgentContent(
- String packageName,
- String agentName, String superClass,
- Set imports,
- String indentation, String lineSeparator,
- boolean generateInitializeHandler) {
- StringBuilder sb = new StringBuilder();
- sb.append(SARLKeywords.AGENT);
- sb.append(' ');
- sb.append(agentName);
-
- if (!Strings.isNullOrEmpty(superClass) && !Agent.class.getName().equals(superClass)) {
- sb.append(' ');
- sb.append(SARLKeywords.EXTENDS);
- sb.append(' ');
- String superClassname = stripPackage(superClass);
- if (agentName.equals(superClassname)) {
- sb.append(superClass);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, superClass);
- }
- }
-
- sb.append(" {"); //$NON-NLS-1$
- sb.append(lineSeparator);
- sb.append(indentation);
- if (generateInitializeHandler) {
- sb.append(SARLKeywords.ON);
- String initializeEvent = "io.sarl.core.Initialize"; //$NON-NLS-1$
- sb.append(' ');
- sb.append(stripPackage(initializeEvent));
- sb.append(" {"); //$NON-NLS-1$
- addImport(packageName, imports, initializeEvent);
- sb.append(lineSeparator);
- sb.append(indentation);
- sb.append(indentation);
- sb.append(lineSeparator);
- sb.append(indentation);
- sb.append("}"); //$NON-NLS-1$
- }
- sb.append(lineSeparator);
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
- return sb.toString();
- }
-
- /** Create the SARL code that corresponds to a behavior with the given properties.
- *
- * @param packageName - the name of the package where the behavior is created.
- * @param behaviorName - name of the behavior type.
- * @param superClass - the name of the super type.
- * @param imports - the list of the types to put into the import section for supporting
- * the generated code. If this parameter is null
, the
- * list is not filled.
- * @param indentation - identation string.
- * @param lineSeparator - line separator.
- * @return the SARL code for the behavior.
- */
- public static String createBehaviorContent(
- String packageName,
- String behaviorName, String superClass,
- Set imports,
- String indentation, String lineSeparator) {
- StringBuilder sb = new StringBuilder();
- sb.append(SARLKeywords.BEHAVIOR);
- sb.append(' ');
- sb.append(behaviorName);
-
- if (!Strings.isNullOrEmpty(superClass) && !Behavior.class.getName().equals(superClass)) {
- sb.append(' ');
- sb.append(SARLKeywords.EXTENDS);
- sb.append(' ');
- String superClassname = stripPackage(superClass);
- if (behaviorName.equals(superClassname)) {
- sb.append(superClass);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, superClass);
- }
- }
-
- sb.append(" {"); //$NON-NLS-1$
- sb.append(lineSeparator);
-
- sb.append(indentation);
- sb.append(SARLKeywords.CONSTRUCTOR);
- sb.append("(owner : "); //$NON-NLS-1$
- String agentType = "io.sarl.lang.core.Agent"; //$NON-NLS-1$
- String agentBasename = stripPackage(agentType);
- if (agentBasename.equals(behaviorName)) {
- sb.append(agentType);
- } else {
- sb.append(agentBasename);
- addImport(packageName, imports, agentType);
- }
- sb.append(") {"); //$NON-NLS-1$
- sb.append(lineSeparator);
- sb.append(indentation);
- sb.append(indentation);
- sb.append("super(owner)"); //$NON-NLS-1$
- sb.append(lineSeparator);
- sb.append(indentation);
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
-
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
- return sb.toString();
- }
-
- /** Create the SARL code that corresponds to a capacity with the given properties.
- *
- * @param packageName - the name of the package where the capacity is created.
- * @param capacityName - name of the capacity type.
- * @param superClass - the name of the super type.
- * @param imports - the list of the types to put into the import section for supporting
- * the generated code. If this parameter is null
, the
- * list is not filled.
- * @param indentation - identation string.
- * @param lineSeparator - line separator.
- * @return the SARL code for the capacity.
- */
- public static String createCapacityContent(
- String packageName,
- String capacityName, String superClass,
- Set imports,
- String indentation, String lineSeparator) {
- StringBuilder sb = new StringBuilder();
- sb.append(SARLKeywords.CAPACITY);
- sb.append(' ');
- sb.append(capacityName);
-
- if (!Strings.isNullOrEmpty(superClass) && !Capacity.class.getName().equals(superClass)) {
- sb.append(' ');
- sb.append(SARLKeywords.EXTENDS);
- sb.append(' ');
- String superClassname = stripPackage(superClass);
- if (capacityName.equals(superClassname)) {
- sb.append(superClass);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, superClass);
- }
- }
-
- sb.append(" {"); //$NON-NLS-1$
- sb.append(lineSeparator);
-
- sb.append(indentation);
- sb.append(lineSeparator);
-
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
- return sb.toString();
- }
-
- /** Create the SARL code that corresponds to an event with the given properties.
- *
- * @param packageName - the name of the package where the event is created.
- * @param eventName - name of the event type.
- * @param superClass - the name of the super type.
- * @param imports - the list of the types to put into the import section for supporting
- * the generated code. If this parameter is null
, the
- * list is not filled.
- * @param indentation - identation string.
- * @param lineSeparator - line separator.
- * @return the SARL code for the event.
- */
- public static String createEventContent(
- String packageName,
- String eventName, String superClass,
- Set imports,
- String indentation, String lineSeparator) {
- StringBuilder sb = new StringBuilder();
- sb.append(SARLKeywords.EVENT);
- sb.append(' ');
- sb.append(eventName);
-
- if (!Strings.isNullOrEmpty(superClass) && !Event.class.getName().equals(superClass)) {
- sb.append(' ');
- sb.append(SARLKeywords.EXTENDS);
- sb.append(' ');
- String superClassname = stripPackage(superClass);
- if (eventName.equals(superClassname)) {
- sb.append(superClass);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, superClass);
- }
- }
-
- sb.append(" {"); //$NON-NLS-1$
- sb.append(lineSeparator);
-
- sb.append(indentation);
- sb.append(lineSeparator);
-
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
- return sb.toString();
- }
-
- /** Create the SARL code that corresponds to a skill with the given properties.
- *
- * @param packageName - the name of the package where the skill is created.
- * @param skillName - name of the event type.
- * @param superClass - the name of the super type.
- * @param capacityTypes - the implemented capacities.
- * @param imports - the list of the types to put into the import section for supporting
- * the generated code. If this parameter is null
, the
- * list is not filled.
- * @param indentation - identation string.
- * @param lineSeparator - line separator.
- * @param generateActions - indicates if the actions should be generated.
- * @return the SARL code for the skill.
- */
- public static String createSkillContent(
- String packageName,
- String skillName, String superClass,
- Collection capacityTypes,
- Set imports,
- String indentation, String lineSeparator,
- boolean generateActions) {
- StringBuilder sb = new StringBuilder();
- sb.append(SARLKeywords.SKILL);
- sb.append(' ');
- sb.append(skillName);
-
- if (!Strings.isNullOrEmpty(superClass) && !Skill.class.getName().equals(superClass)) {
- sb.append(' ');
- sb.append(SARLKeywords.EXTENDS);
- sb.append(' ');
- String superClassname = stripPackage(superClass);
- if (skillName.equals(superClassname)) {
- sb.append(superClass);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, superClass);
- }
- }
-
- if (!capacityTypes.isEmpty()) {
- sb.append(' ');
- sb.append(SARLKeywords.IMPLEMENTS);
- sb.append(' ');
- boolean addComa = false;
- for (String capacityType : capacityTypes) {
- if (addComa) {
- sb.append(", "); //$NON-NLS-1$
- }
- String superClassname = stripPackage(capacityType);
- if (skillName.equals(superClassname)) {
- sb.append(capacityType);
- } else {
- sb.append(superClassname);
- addImport(packageName, imports, capacityType);
- }
- addComa = true;
- }
- }
-
- sb.append(" {"); //$NON-NLS-1$
- sb.append(lineSeparator);
-
- sb.append(indentation);
- sb.append(lineSeparator);
-
- sb.append("}"); //$NON-NLS-1$
- sb.append(lineSeparator);
- return sb.toString();
- }
-
- private static String stripPackage(Object object) {
- return object.toString().replaceAll("^(\\w+\\.)*", ""); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private static boolean isInCurrentPackage(String currentPackage, String element) {
- Pattern pattern = Pattern.compile("^(?:\\w+\\.)+(\\w+)$"); //$NON-NLS-1$
- Matcher matcher = pattern.matcher(element);
- String packageName;
- if (matcher.matches()) {
- String name = matcher.group(1);
- packageName = element.substring(0, element.length() - name.length() - 1);
- } else {
- packageName = ""; //$NON-NLS-1$
- }
- if (!packageName.equals(currentPackage)) {
- return false;
- }
- return true;
- }
-
- private static void addImport(String currentPackage, Set imports, String importElement) {
- if (imports != null && !isInCurrentPackage(currentPackage, importElement)) {
- imports.add(importElement);
- }
- }
-
-}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/messages.properties b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/messages.properties
new file mode 100644
index 0000000000..de54cae61f
--- /dev/null
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/messages.properties
@@ -0,0 +1,3 @@
+AbstractNewSarlElementWizardPage_0=Constructors from superclass
+AbstractNewSarlElementWizardPage_1=Inherited abstract methods
+AbstractNewSarlElementWizardPage_2=Which method stubs would you like to create?
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newagent/NewSarlAgentWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newagent/NewSarlAgentWizardPage.java
index eda62b3c95..23403e6b95 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newagent/NewSarlAgentWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newagent/NewSarlAgentWizardPage.java
@@ -20,20 +20,29 @@
*/
package io.sarl.eclipse.wizards.elements.newagent;
+import static io.sarl.eclipse.util.Jdt2Ecore.populateInheritanceContext;
import io.sarl.eclipse.SARLConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
+import io.sarl.eclipse.util.Jdt2Ecore;
import io.sarl.eclipse.wizards.elements.AbstractNewSarlElementWizardPage;
-import io.sarl.eclipse.wizards.elements.SarlTypeCreatorUtil;
import io.sarl.lang.core.Agent;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
+import io.sarl.lang.signature.ActionKey;
-import java.util.Set;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.Maps;
+
/**
* Wizard page for creating a new SARL agent.
*
@@ -54,10 +63,10 @@ public NewSarlAgentWizardPage() {
}
@Override
- public void createControl(Composite parent) {
- Composite composite = createCommonControls(parent);
- createSuperClassControls(composite, COLUMNS);
- setControl(composite);
+ public void createPageControls(Composite parent) {
+ createSuperClassControls(parent, COLUMNS);
+ createSeparator(parent, COLUMNS);
+ createMethodStubControls(parent, COLUMNS, false, true);
}
@Override
@@ -72,18 +81,39 @@ protected void doStatusUpdate() {
}
@Override
- protected void getTypeContent(IPackageFragment packageFragment,
- StringBuilder typeContent, Set imports,
- String indentation, String lineSeparator) {
- String content = SarlTypeCreatorUtil.createAgentContent(
- packageFragment.getElementName(),
- getTypeName(),
+ protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
+ GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
+ io.sarl.lang.sarl.Agent agent = this.sarlGenerator.createAgent(code, getTypeName(), getSuperClass());
+ this.sarlGenerator.attachComment(code, agent, typeComment);
+
+ Map operationsToImplement;
+
+ if (isCreateInherited()) {
+ operationsToImplement = Maps.newTreeMap((Comparator) null);
+ } else {
+ operationsToImplement = null;
+ }
+
+ populateInheritanceContext(
+ getJavaProject(),
+ // Discarding final operation.
+ null,
+ // Discarding overridable operation.
+ null,
+ // Discarding inherited fields,
+ null,
+ operationsToImplement,
+ // Discarding super constructors,
+ null,
+ code.getCodeGenerator().getActionSignatureProvider(),
getSuperClass(),
- imports,
- indentation, lineSeparator,
- // Generate the Initialize event handler
- true);
- typeContent.append(content);
+ Collections.emptyList());
+
+ if (operationsToImplement != null) {
+ Jdt2Ecore.createActions(code, operationsToImplement.values(), agent);
+ }
+
+ code.finalizeScript();
}
@Override
@@ -98,7 +128,7 @@ protected String getInvalidSubtypeErrorMessage() {
@Override
protected IType getRootSuperType() throws JavaModelException {
- return findType(getJavaProject(), Agent.class.getName());
+ return Jdt2Ecore.findType(getJavaProject(), Agent.class.getName());
}
}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newbehavior/NewSarlBehaviorWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newbehavior/NewSarlBehaviorWizardPage.java
index b1e1acebb6..e141ba645b 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newbehavior/NewSarlBehaviorWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newbehavior/NewSarlBehaviorWizardPage.java
@@ -20,20 +20,31 @@
*/
package io.sarl.eclipse.wizards.elements.newbehavior;
+import static io.sarl.eclipse.util.Jdt2Ecore.populateInheritanceContext;
import io.sarl.eclipse.SARLConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
+import io.sarl.eclipse.util.Jdt2Ecore;
import io.sarl.eclipse.wizards.elements.AbstractNewSarlElementWizardPage;
-import io.sarl.eclipse.wizards.elements.SarlTypeCreatorUtil;
import io.sarl.lang.core.Behavior;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
+import io.sarl.lang.signature.ActionKey;
+import io.sarl.lang.signature.SignatureKey;
-import java.util.Set;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+
/**
* Wizard page for creating a new SARL behavior.
*
@@ -54,10 +65,10 @@ public NewSarlBehaviorWizardPage() {
}
@Override
- public void createControl(Composite parent) {
- Composite composite = createCommonControls(parent);
- createSuperClassControls(composite, COLUMNS);
- setControl(composite);
+ public void createPageControls(Composite parent) {
+ createSuperClassControls(parent, COLUMNS);
+ createSeparator(parent, COLUMNS);
+ createMethodStubControls(parent, COLUMNS, true, true);
}
@Override
@@ -72,16 +83,50 @@ protected void doStatusUpdate() {
}
@Override
- protected void getTypeContent(IPackageFragment packageFragment,
- StringBuilder typeContent, Set imports,
- String indentation, String lineSeparator) {
- String content = SarlTypeCreatorUtil.createBehaviorContent(
- packageFragment.getElementName(),
- getTypeName(),
+ protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
+ GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
+ io.sarl.lang.sarl.Behavior behavior = this.sarlGenerator.createBehavior(code, getTypeName(), getSuperClass());
+ this.sarlGenerator.attachComment(code, behavior, typeComment);
+
+ Map operationsToImplement;
+ Map constructors;
+
+ String superClass = getSuperClass();
+ if (Strings.isNullOrEmpty(superClass) || !isCreateConstructors()) {
+ constructors = null;
+ } else {
+ constructors = Maps.newTreeMap((Comparator) null);
+ }
+
+ if (isCreateInherited()) {
+ operationsToImplement = Maps.newTreeMap((Comparator) null);
+ } else {
+ operationsToImplement = null;
+ }
+
+ populateInheritanceContext(
+ getJavaProject(),
+ // Discarding final operation.
+ null,
+ // Discarding overridable operation.
+ null,
+ // Discarding inherited fields,
+ null,
+ operationsToImplement,
+ constructors,
+ code.getCodeGenerator().getActionSignatureProvider(),
getSuperClass(),
- imports,
- indentation, lineSeparator);
- typeContent.append(content);
+ Collections.emptyList());
+
+ if (constructors != null) {
+ Jdt2Ecore.createStandardConstructors(code, constructors.values(), behavior);
+ }
+
+ if (operationsToImplement != null) {
+ Jdt2Ecore.createActions(code, operationsToImplement.values(), behavior);
+ }
+
+ code.finalizeScript();
}
@Override
@@ -96,7 +141,7 @@ protected String getInvalidSubtypeErrorMessage() {
@Override
protected IType getRootSuperType() throws JavaModelException {
- return findType(getJavaProject(), Behavior.class.getName());
+ return Jdt2Ecore.findType(getJavaProject(), Behavior.class.getName());
}
}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newcapacity/NewSarlCapacityWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newcapacity/NewSarlCapacityWizardPage.java
index edae95e3ae..3b41dc5964 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newcapacity/NewSarlCapacityWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newcapacity/NewSarlCapacityWizardPage.java
@@ -22,14 +22,14 @@
import io.sarl.eclipse.SARLConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
+import io.sarl.eclipse.util.Jdt2Ecore;
import io.sarl.eclipse.wizards.elements.AbstractNewSarlElementWizardPage;
-import io.sarl.eclipse.wizards.elements.SarlTypeCreatorUtil;
import io.sarl.lang.core.Capacity;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
-import java.util.Set;
-
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.widgets.Composite;
@@ -54,10 +54,8 @@ public NewSarlCapacityWizardPage() {
}
@Override
- public void createControl(Composite parent) {
- Composite composite = createCommonControls(parent);
- createSuperClassControls(composite, COLUMNS);
- setControl(composite);
+ public void createPageControls(Composite parent) {
+ createSuperClassControls(parent, COLUMNS);
}
@Override
@@ -72,16 +70,11 @@ protected void doStatusUpdate() {
}
@Override
- protected void getTypeContent(IPackageFragment packageFragment,
- StringBuilder typeContent, Set imports,
- String indentation, String lineSeparator) {
- String content = SarlTypeCreatorUtil.createCapacityContent(
- packageFragment.getElementName(),
- getTypeName(),
- getSuperClass(),
- imports,
- indentation, lineSeparator);
- typeContent.append(content);
+ protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
+ GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
+ io.sarl.lang.sarl.Capacity capacity = this.sarlGenerator.createCapacity(code, getTypeName(), getSuperClass());
+ this.sarlGenerator.attachComment(code, capacity, typeComment);
+ code.finalizeScript();
}
@Override
@@ -96,7 +89,7 @@ protected String getInvalidSubtypeErrorMessage() {
@Override
protected IType getRootSuperType() throws JavaModelException {
- return findType(getJavaProject(), Capacity.class.getName());
+ return Jdt2Ecore.findType(getJavaProject(), Capacity.class.getName());
}
}
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newevent/NewSarlEventWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newevent/NewSarlEventWizardPage.java
index 0fb7e30e8f..d2bed4c671 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newevent/NewSarlEventWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newevent/NewSarlEventWizardPage.java
@@ -20,20 +20,31 @@
*/
package io.sarl.eclipse.wizards.elements.newevent;
+import static io.sarl.eclipse.util.Jdt2Ecore.findType;
+import static io.sarl.eclipse.util.Jdt2Ecore.populateInheritanceContext;
import io.sarl.eclipse.SARLConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
+import io.sarl.eclipse.util.Jdt2Ecore;
import io.sarl.eclipse.wizards.elements.AbstractNewSarlElementWizardPage;
-import io.sarl.eclipse.wizards.elements.SarlTypeCreatorUtil;
import io.sarl.lang.core.Event;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
+import io.sarl.lang.signature.SignatureKey;
-import java.util.Set;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+
/**
* Wizard page for creating a new SARL event.
*
@@ -54,10 +65,10 @@ public NewSarlEventWizardPage() {
}
@Override
- public void createControl(Composite parent) {
- Composite composite = createCommonControls(parent);
- createSuperClassControls(composite, COLUMNS);
- setControl(composite);
+ public void createPageControls(Composite parent) {
+ createSuperClassControls(parent, COLUMNS);
+ createSeparator(parent, COLUMNS);
+ createMethodStubControls(parent, COLUMNS, true, false);
}
@Override
@@ -72,16 +83,40 @@ protected void doStatusUpdate() {
}
@Override
- protected void getTypeContent(IPackageFragment packageFragment,
- StringBuilder typeContent, Set imports,
- String indentation, String lineSeparator) {
- String content = SarlTypeCreatorUtil.createEventContent(
- packageFragment.getElementName(),
- getTypeName(),
+ protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
+ GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
+ io.sarl.lang.sarl.Event event = this.sarlGenerator.createEvent(code, getTypeName(), getSuperClass());
+ this.sarlGenerator.attachComment(code, event, typeComment);
+
+ Map constructors;
+
+ String superClass = getSuperClass();
+ if (Strings.isNullOrEmpty(superClass) || !isCreateConstructors()) {
+ constructors = null;
+ } else {
+ constructors = Maps.newTreeMap((Comparator) null);
+ }
+
+ populateInheritanceContext(
+ getJavaProject(),
+ // Discarding final operation.
+ null,
+ // Discarding overridable operation.
+ null,
+ // Discarding inherited fields,
+ null,
+ // Discarding the operations to implement.
+ null,
+ constructors,
+ code.getCodeGenerator().getActionSignatureProvider(),
getSuperClass(),
- imports,
- indentation, lineSeparator);
- typeContent.append(content);
+ Collections.emptyList());
+
+ if (constructors != null) {
+ Jdt2Ecore.createStandardConstructors(code, constructors.values(), event);
+ }
+
+ code.finalizeScript();
}
@Override
diff --git a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newskill/NewSarlSkillWizardPage.java b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newskill/NewSarlSkillWizardPage.java
index e0938c68ac..c420097555 100644
--- a/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newskill/NewSarlSkillWizardPage.java
+++ b/plugins/io.sarl.eclipse/src/io/sarl/eclipse/wizards/elements/newskill/NewSarlSkillWizardPage.java
@@ -20,21 +20,32 @@
*/
package io.sarl.eclipse.wizards.elements.newskill;
+import static io.sarl.eclipse.util.Jdt2Ecore.findType;
+import static io.sarl.eclipse.util.Jdt2Ecore.populateInheritanceContext;
import io.sarl.eclipse.SARLConfig;
import io.sarl.eclipse.SARLEclipsePlugin;
+import io.sarl.eclipse.util.Jdt2Ecore;
import io.sarl.eclipse.wizards.elements.AbstractNewSarlElementWizardPage;
-import io.sarl.eclipse.wizards.elements.SarlTypeCreatorUtil;
import io.sarl.lang.core.Capacity;
import io.sarl.lang.core.Skill;
+import io.sarl.lang.genmodel.SARLCodeGenerator.GeneratedCode;
+import io.sarl.lang.signature.ActionKey;
+import io.sarl.lang.signature.SignatureKey;
-import java.util.Set;
+import java.util.Comparator;
+import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.base.Strings;
+import com.google.common.collect.Maps;
+
/**
* Wizard page for creating a new SARL skill.
*
@@ -55,11 +66,11 @@ public NewSarlSkillWizardPage() {
}
@Override
- public void createControl(Composite parent) {
- Composite composite = createCommonControls(parent);
- createSuperClassControls(composite, COLUMNS);
- createSuperInterfacesControls(composite, COLUMNS);
- setControl(composite);
+ public void createPageControls(Composite parent) {
+ createSuperClassControls(parent, COLUMNS);
+ createSuperInterfacesControls(parent, COLUMNS);
+ createSeparator(parent, COLUMNS);
+ createMethodStubControls(parent, COLUMNS, true, true);
}
@Override
@@ -75,19 +86,51 @@ protected void doStatusUpdate() {
}
@Override
- protected void getTypeContent(IPackageFragment packageFragment,
- StringBuilder typeContent, Set imports,
- String indentation, String lineSeparator) {
- String content = SarlTypeCreatorUtil.createSkillContent(
- packageFragment.getElementName(),
- getTypeName(),
+ protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
+ GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
+ io.sarl.lang.sarl.Skill skill = this.sarlGenerator.createSkill(code, getTypeName(),
+ getSuperClass(), getSuperInterfaces());
+ this.sarlGenerator.attachComment(code, skill, typeComment);
+
+ Map operationsToImplement;
+ Map constructors;
+
+ String superClass = getSuperClass();
+ if (Strings.isNullOrEmpty(superClass) || !isCreateConstructors()) {
+ constructors = null;
+ } else {
+ constructors = Maps.newTreeMap((Comparator) null);
+ }
+
+ if (isCreateInherited()) {
+ operationsToImplement = Maps.newTreeMap((Comparator) null);
+ } else {
+ operationsToImplement = null;
+ }
+
+ populateInheritanceContext(
+ getJavaProject(),
+ // Discarding final operation
+ null,
+ // Discarding overridable operation
+ null,
+ // Discarding inherited fields,
+ null,
+ operationsToImplement,
+ constructors,
+ code.getCodeGenerator().getActionSignatureProvider(),
getSuperClass(),
- getSuperInterfaces(),
- imports,
- indentation, lineSeparator,
- // Generate the actions
- true);
- typeContent.append(content);
+ getSuperInterfaces());
+
+ if (constructors != null) {
+ Jdt2Ecore.createStandardConstructors(code, constructors.values(), skill);
+ }
+
+ if (operationsToImplement != null) {
+ Jdt2Ecore.createActions(code, operationsToImplement.values(), skill);
+ }
+
+ code.finalizeScript();
}
@Override