Skip to content

Commit

Permalink
[ui] Generates the fires clause into the auto-generated methods.
Browse files Browse the repository at this point in the history
close #726

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 3, 2017
1 parent e58379c commit 0cd0b1d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Expand Up @@ -64,6 +64,27 @@ public class SarlMethodBuilder extends XtendMethodBuilder {
@Inject
private CommonTypeComputationServices services;

private List<LightweightTypeReference> fires;

/** Set the fired types.
*
* @param firedTypes the list of the fired types.
*/
public void setFires(List<LightweightTypeReference> firedTypes) {
this.fires = firedTypes;
}

/** Replies the fired types.
*
* @return the list of the fired types.
*/
public List<LightweightTypeReference> getFires() {
if (this.fires == null) {
return Collections.emptyList();
}
return this.fires;
}

@Override
public ISourceAppender build(ISourceAppender appendable) {
final JvmVisibility defaultVisibility = this.visiblityProvider.getDefaultJvmVisibility(getOwner(),
Expand Down Expand Up @@ -91,12 +112,34 @@ public ISourceAppender build(ISourceAppender appendable) {
}
appendTypeParameters(appendable, getTypeParameters());
appendThrowsClause(appendable);
appendFiresClause(appendable);
if (!isAbstractFlag()) {
appendBody(appendable, ""); //$NON-NLS-1$
}
return appendable;
}

/** Append the "fires" clause.
*
* @param appendable the receiver.
* @return the appendable.
*/
protected ISourceAppender appendFiresClause(ISourceAppender appendable) {
final List<LightweightTypeReference> types = getFires();
final Iterator<LightweightTypeReference> iterator = types.iterator();
if (iterator.hasNext()) {
appendable.append(" ").append(this.keywords.getFiresKeyword()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$
do {
final LightweightTypeReference type = iterator.next();
appendable.append(type);
if (iterator.hasNext()) {
appendable.append(this.keywords.getCommaKeyword()).append(" "); //$NON-NLS-1$
}
} while (iterator.hasNext());
}
return appendable;
}

@Override
protected ISourceAppender appendTypeParameters(ISourceAppender appendable, List<JvmTypeParameter> typeParameters) {
final Iterator<JvmTypeParameter> iterator = typeParameters.iterator();
Expand Down
Expand Up @@ -60,13 +60,15 @@
import org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable;
import org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters;

import io.sarl.lang.annotation.FiredEvent;
import io.sarl.lang.annotation.SyntheticMember;
import io.sarl.lang.compilation.jvmmodel.SarlJvmModelAssociations;
import io.sarl.lang.compilation.typesystem.SARLAnnotationUtil;
import io.sarl.lang.sarl.actionprototype.FormalParameterProvider;
import io.sarl.lang.sarl.actionprototype.IActionPrototypeProvider;
import io.sarl.lang.sarl.actionprototype.InferredPrototype;
import io.sarl.lang.sarl.actionprototype.QualifiedActionName;
import io.sarl.lang.ui.compilation.codebuilder.SarlMethodBuilder;
import io.sarl.lang.ui.compilation.codebuilder.SarlParameterBuilder;
import io.sarl.lang.ui.uihelpers.quickfix.SARLQuickfixProvider;
import io.sarl.lang.util.Utils;
Expand Down Expand Up @@ -156,6 +158,7 @@ public void apply(EObject element, IModificationContext context) throws Exceptio
appendable.newLine().newLine();

final XtendMethodBuilder builder = this.methodBuilder.get();
final SarlMethodBuilder sarlBuilder = (builder instanceof SarlMethodBuilder) ? (SarlMethodBuilder) builder : null;

builder.setContext(declaringType);
builder.setOwner(declaringType);
Expand Down Expand Up @@ -198,6 +201,16 @@ public void apply(EObject element, IModificationContext context) throws Exceptio

builder.setExceptions(cloneTypeReferences(operation.getExceptions(), typeParameterMap));

if (sarlBuilder != null) {
final JvmAnnotationReference firedEvents = this.annotationUtils.findAnnotation(operation, FiredEvent.class.getName());
if (firedEvents != null) {
final List<JvmTypeReference> events = this.annotationUtils.findTypeValues(firedEvents);
if (events != null) {
sarlBuilder.setFires(cloneTypeReferences(events, typeParameterMap));
}
}
}

builder.build(appendable);
}
}
Expand Down

0 comments on commit 0cd0b1d

Please sign in to comment.