/** Copy and clean the given documentation by removing any unnecessary <code>@param</code>. * * @param sourceOperation the source for the documentation. * @param targetOperation the target for the documentation. * @return <code>true</code> if a documentation was added. */ protected boolean copyAndCleanDocumentationTo(JvmExecutable sourceOperation, JvmExecutable targetOperation) { assert sourceOperation != null; assert targetOperation != null; String comment = SARLJvmModelInferrer.this.typeBuilder.getDocumentation(sourceOperation); if (Strings.isNullOrEmpty(comment)) { return false; } comment = cleanDocumentation(comment, Iterables.transform(sourceOperation.getParameters(), it -> it.getSimpleName()), Iterables.transform(targetOperation.getParameters(), it -> it.getSimpleName())); SARLJvmModelInferrer.this.typeBuilder.setDocumentation(targetOperation, comment); return true; }
/** Copy and clean the given documentation by removing any unecessary <code>@param</code>. * * @param sourceOperation the source for the documentation. * @param targetOperation the target for the documentation. * @return <code>true</code> if a documentation was added. */ protected boolean copyAndCleanDocumentationTo(XtendExecutable sourceOperation, JvmExecutable targetOperation) { assert sourceOperation != null; assert targetOperation != null; String comment = SARLJvmModelInferrer.this.typeBuilder.getDocumentation(sourceOperation); if (Strings.isNullOrEmpty(comment)) { return false; } comment = cleanDocumentation(comment, Iterables.transform(sourceOperation.getParameters(), it -> it.getName()), Iterables.transform(targetOperation.getParameters(), it -> it.getSimpleName())); SARLJvmModelInferrer.this.typeBuilder.setDocumentation(targetOperation, comment); return true; }
@Override public void applyToModel(IResolvedTypes resolvedTypes) { if (!closure.isExplicitSyntax()) { List<JvmFormalParameter> parametersToAdd = getParameters(); InternalEList<JvmFormalParameter> targetList = (InternalEList<JvmFormalParameter>) closure.getImplicitFormalParameters(); if (!targetList.isEmpty()) { // things are already available, do nothing return; } for(int i = 0; i < parametersToAdd.size(); i++) { JvmFormalParameter parameter = parametersToAdd.get(i); LightweightTypeReference parameterType = resolvedTypes.getActualType(parameter); if (parameterType == null) { throw new IllegalStateException("Cannot find type for parameter " + parameter.getSimpleName()); } JvmTypeReference typeReference = parameterType.toTypeReference(); parameter.setParameterType(typeReference); targetList.addUnique(parameter); } } ((XClosureImplCustom) closure).setLinked(true); }
/** Generate the given object. * * @param forLoop the for-loop. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XForLoopExpression forLoop, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("for "); //$NON-NLS-1$ final String varName = it.declareUniqueNameVariable(forLoop.getDeclaredParam(), forLoop.getDeclaredParam().getSimpleName()); it.append(varName); it.append(" in "); //$NON-NLS-1$ generate(forLoop.getForExpression(), it, context); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); final XExpression last = generate(forLoop.getEachExpression(), it, context); it.decreaseIndentation(); return last; }
newParam.setName(parameter.getSimpleName()); newCons.getParameters().add(newParam); it.append(", "); //$NON-NLS-1$ it.append(parameter.getSimpleName());
final JvmFormalParameter newParam = this.typesFactory.createJvmFormalParameter(); newOp.getParameters().add(newParam); newParam.setName(parameter.getSimpleName()); newParam.setParameterType(cloneWithTypeParametersAndProxies(parameter.getParameterType(), newOp));
public void generateParameter(final JvmFormalParameter it, final ITreeAppendable appendable, final boolean vararg, final GeneratorConfig config) { final ITreeAppendable tracedAppendable = appendable.trace(it); this.generateAnnotations(it.getAnnotations(), tracedAppendable, false, config); tracedAppendable.append("final "); if (vararg) { JvmTypeReference _parameterType = it.getParameterType(); boolean _not = (!(_parameterType instanceof JvmGenericArrayTypeReference)); if (_not) { tracedAppendable.append("/* Internal Error: Parameter was vararg but not an array type. */"); } else { JvmTypeReference _parameterType_1 = it.getParameterType(); this._errorSafeExtensions.serializeSafely(((JvmGenericArrayTypeReference) _parameterType_1).getComponentType(), "Object", tracedAppendable); } tracedAppendable.append("..."); } else { this._errorSafeExtensions.serializeSafely(it.getParameterType(), "Object", tracedAppendable); } tracedAppendable.append(" "); final String name = tracedAppendable.declareVariable(it, this.makeJavaIdentifier(it.getSimpleName())); this._treeAppendableUtil.traceSignificant(tracedAppendable, it).append(name); }
/** Generate the given object. * * @param tryStatement the try-catch-finally statement. * @param it the target for the generated content. * @param context the context. * @return the statement. */ protected XExpression _generate(XTryCatchFinallyExpression tryStatement, IAppendable it, IExtraLanguageGeneratorContext context) { it.append("try:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(tryStatement.getExpression(), context.getExpectedExpressionType(), it, context); it.decreaseIndentation().newLine(); for (final XCatchClause clause : tryStatement.getCatchClauses()) { it.append("except "); //$NON-NLS-1$ it.append(clause.getDeclaredParam().getParameterType().getType()); it.append(", "); //$NON-NLS-1$ it.append(it.declareUniqueNameVariable(clause.getDeclaredParam(), clause.getDeclaredParam().getSimpleName())); it.append(":"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(clause.getExpression(), context.getExpectedExpressionType(), it, context); it.decreaseIndentation().newLine(); } if (tryStatement.getFinallyExpression() != null) { it.append("finally:"); //$NON-NLS-1$ it.increaseIndentation().newLine(); generate(tryStatement.getFinallyExpression(), it, context); it.decreaseIndentation(); } return tryStatement; }
if (switchStatement.getDeclaredParam() != null) { varName = it.declareUniqueNameVariable(switchStatement.getDeclaredParam(), switchStatement.getDeclaredParam().getSimpleName()); } else { varName = it.declareSyntheticVariable(switchStatement, "___expression"); //$NON-NLS-1$