/** Generate the given object. * * @param action the action. * @param it the target for the generated content. * @param context the context. */ protected void _generate(SarlAction action, PyAppendable it, IExtraLanguageGeneratorContext context) { final String feature = getFeatureNameConverter(context).convertDeclarationName(action.getName(), action); generateExecutable(feature, action, !action.isStatic(), action.isAbstract(), action.getReturnType(), getTypeBuilder().getDocumentation(action), it, context); }
/** Replies the resource. */ @Pure public Resource eResource() { return getSarlAction().eResource(); }
/** Add a throwable exception. * @param type the fully qualified name of the exception. */ public void addException(String type) { this.sarlAction.getExceptions().add(newTypeRef(this.container, type)); }
/** Initialize the Ecore element. * @param container the container of the SarlAction. * @param name the name of the SarlAction. */ public void eInit(XtendTypeDeclaration container, String name, String modifier, IJvmTypeProvider context) { setTypeResolutionContext(context); if (this.sarlAction == null) { this.container = container; this.sarlAction = SarlFactory.eINSTANCE.createSarlAction(); this.sarlAction.setAnnotationInfo(XtendFactory.eINSTANCE.createXtendMember()); this.sarlAction.setName(name); if (Strings.equal(modifier, "def") || Strings.equal(modifier, "override")) { this.sarlAction.getModifiers().add(modifier); } else { throw new IllegalStateException("Invalid modifier"); } container.getMembers().add(this.sarlAction); } }
for (final XAnnotation annotation : signature.getAnnotations()) { addAnnotationToSignature(textRepresentation, grammarAccess, serializer, importManager, annotation); for (final String modifier : signature.getModifiers()) { textRepresentation.append(modifier); textRepresentation.append(' '); if (!signature.getTypeParameters().isEmpty()) { boolean addComa = false; textRepresentation.append(grammarAccess.getLessThanSignKeyword()); for (final JvmTypeParameter typeParameter : signature.getTypeParameters()) { if (addComa) { textRepresentation.append(grammarAccess.getCommaKeyword()); textRepresentation.append(signature.getName()); if (!signature.getParameters().isEmpty()) { textRepresentation.append(grammarAccess.getLeftParenthesisKeyword()); final int idx = signature.getParameters().size() - 1; for (int i = 0; i < idx; ++i) { addParamToSignature(textRepresentation, signature.getParameters().get(i), grammarAccess, importManager, serializer); textRepresentation.append(grammarAccess.getCommaKeyword()); textRepresentation.append(' '); addParamToSignature(textRepresentation, signature.getParameters().get(idx), grammarAccess, importManager, serializer); textRepresentation.append(grammarAccess.getRightParenthesisKeyword());
&& sourceElement instanceof SarlAction) { final SarlAction function = (SarlAction) sourceElement; if (function.getReturnType() == null && !inherited.getResolvedReturnType().isPrimitiveVoid()) { warning(MessageFormat.format(Messages.SARLValidator_46, resolved.getResolvedReturnType().getHumanReadableName()), if (!overrideProblems && !function.isOverride() && !function.isStatic() && !isIgnored(MISSING_OVERRIDE, sourceElement)) { warning(MessageFormat.format(Messages.SARLValidator_47, XTEND_FUNCTION__NAME, MISSING_OVERRIDE); if (!overrideProblems && function.isOverride() && function.isStatic()) { for (final IResolvedOperation inherited: allInherited) { error(MessageFormat.format(Messages.SARLValidator_48, getDeclaratorName(inherited)), function, XTEND_FUNCTION__NAME, function.getModifiers().indexOf(Messages.SARLValidator_49), OBSOLETE_OVERRIDE);
/** Add a fired exception. * @param type the fully qualified name of the event. */ public void addFiredEvent(String type) { this.sarlAction.getFiredEvents().add(newTypeRef(this.container, type)); }
/** Check if the given action has a valid name. * * @param action the action to test. * @see SARLFeatureNameValidator */ @Check(CheckType.FAST) public void checkActionName(SarlAction action) { final JvmOperation inferredType = this.associations.getDirectlyInferredOperation(action); final QualifiedName name = QualifiedName.create(inferredType.getQualifiedName('.').split("\\.")); //$NON-NLS-1$ if (this.featureNames.isDisallowedName(name)) { final String validName = Utils.fixHiddenMember(action.getName()); error(MessageFormat.format( Messages.SARLValidator_39, action.getName()), action, XTEND_FUNCTION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_MEMBER_NAME, validName); } else if (!isIgnored(DISCOURAGED_FUNCTION_NAME) && this.featureNames.isDiscouragedName(name)) { warning(MessageFormat.format( Messages.SARLValidator_39, action.getName()), action, XTEND_FUNCTION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, DISCOURAGED_FUNCTION_NAME); } }
@Override public int compare(SarlAction left, SarlAction right) { if (left == right) { return 0; } if (left == null) { return Integer.MIN_VALUE; } if (right == null) { return Integer.MAX_VALUE; } return this.comparator.compare(left.getParameters(), right.getParameters()); }
/** Add a modifier. * @param modifier the modifier to add. */ public void addModifier(String modifier) { if (!Strings.isEmpty(modifier)) { getSarlAction().getModifiers().add(modifier); } }
/** Add an annotation. * @param type the qualified name of the annotation */ public void addAnnotation(String type) { if (!Strings.isEmpty(type)) { XAnnotation annotation = XAnnotationsFactory.eINSTANCE.createXAnnotation(); annotation.setAnnotationType(newTypeRef(getSarlAction(), type).getType()); getSarlAction().getAnnotations().add(annotation); } }
/** Change the documentation of the element. * * <p>The documentation will be displayed just before the element. * * @param doc the documentation. */ public void setDocumentation(String doc) { if (Strings.isEmpty(doc)) { getSarlAction().eAdapters().removeIf(new Predicate<Adapter>() { public boolean test(Adapter adapter) { return adapter.isAdapterForType(DocumentationAdapter.class); } }); } else { DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter( getSarlAction(), DocumentationAdapter.class); if (adapter == null) { adapter = new DocumentationAdapter(); getSarlAction().eAdapters().add(adapter); } adapter.setDocumentation(doc); } }
@Override public boolean isEarlyExitOperation(SarlAction operation) { if (operation != null) { final Iterator<JvmTypeReference> eventIterator = operation.getFiredEvents().iterator(); while (eventIterator.hasNext()) { if (isEarlyExitEvent(eventIterator.next())) { return true; } } } return false; }
/** Emit a warning when the "fires" keyword is used. * * @param action the action to check. */ @Check public void checkFiresKeywordUse(SarlAction action) { if (!action.getFiredEvents().isEmpty()) { warning(MessageFormat.format( Messages.SARLValidator_1, this.grammarAccess.getFiresKeyword()), action, SarlPackage.eINSTANCE.getSarlAction_FiredEvents()); } }
/** Replies the resource. */ @Pure public Resource eResource() { return getSarlAction().eResource(); }
/** Check the types of the parameters of the "fires" statement. * * @param action the signature that contains the "fires" statement. */ @Check(CheckType.FAST) public void checkActionFires(SarlAction action) { for (final JvmTypeReference event : action.getFiredEvents()) { final LightweightTypeReference ref = toLightweightTypeReference(event); if (ref != null && !this.inheritanceHelper.isSarlEvent(ref)) { error(MessageFormat.format( Messages.SARLValidator_57, event.getQualifiedName(), Messages.SARLValidator_62, this.grammarAccess.getFiresKeyword()), event, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_FIRING_EVENT_TYPE, event.getSimpleName()); } } }
if (source instanceof SarlAction) { final SarlAction action = (SarlAction) source; firedEvents = action.getFiredEvents(); isEarlyExit = this.earlyExitComputer.isEarlyExitOperation(action); if (isEarlyExit) {
final EList<JvmTypeReference> events = ((SarlAction) function).getFiredEvents(); if (!events.isEmpty()) { document.surround(regionFor.keyword(this.keywords.getFiresKeyword()), ONE_SPACE);