@Override public JvmTypeReference apply(JvmFormalParameter from) { return from.getParameterType(); } }));
protected String parametersToString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs, boolean includeName) { StringBuilder result = new StringBuilder(); boolean needsSeparator = false; Iterator<? extends JvmFormalParameter> iterator = elements.iterator(); while (iterator.hasNext()) { JvmFormalParameter parameter = iterator.next(); if (needsSeparator) result.append(", "); needsSeparator = true; JvmTypeReference typeRef = parameter.getParameterType(); if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) { typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType(); result.append(referenceToString(typeRef, "[null]")); result.append("..."); } else { result.append(referenceToString(typeRef, "[null]")); } if (includeName) { result.append(" " + parameter.getName()); } } return result.toString(); }
protected JvmFormalParameter createFormalParameter(Type parameterType, String paramName, JvmMember container, GenericDeclaration member, Annotation[] annotations) { JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter(); result.setName(paramName); if (isLocal(parameterType, member)) { result.setParameterType(createLocalTypeReference(parameterType, (JvmTypeParameterDeclarator) container, member)); } else { result.setParameterType(createTypeReference(parameterType)); } if (annotations.length != 0) { InternalEList<JvmAnnotationReference> annotationsReferences = (InternalEList<JvmAnnotationReference>)result.getAnnotations(); for (Annotation annotation : annotations) { annotationsReferences.addUnique(createAnnotationReference(annotation)); } } return result; }
protected JvmFormalParameter createFormalParameter(BinaryTypeSignature parameterType, String paramName, JvmMember container, Map<String, JvmTypeParameter> typeParameters) { JvmFormalParameter result = TypesFactory.eINSTANCE.createJvmFormalParameter(); result.setName(paramName); result.setParameterType(proxies.createTypeReference(parameterType, typeParameters)); return result; }
protected void highlightFormalParameter(JvmFormalParameter parameterDecl, IHighlightedPositionAcceptor acceptor) { if (!SPECIAL_FEATURE_NAMES.contains(parameterDecl.getName())) { // highlighting of special identifiers is done separately, so it's omitted here if (parameterDecl.eContainingFeature() == XbasePackage.Literals.XCLOSURE__DECLARED_FORMAL_PARAMETERS) { highlightFeature(acceptor, parameterDecl, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, PARAMETER_VARIABLE); } else { // covers parameters of for and template expr FOR loops, as well as switch statements highlightFeature(acceptor, parameterDecl, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, LOCAL_VARIABLE_DECLARATION); highlightFeature(acceptor, parameterDecl, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME, LOCAL_FINAL_VARIABLE_DECLARATION); } } }
newParam.setName(parameter.getSimpleName()); newCons.getParameters().add(newParam); final JvmTypeReference originalParamTypeReference = parameter.getParameterType(); final JvmTypeReference paramType = cloneWithTypeParametersAndProxies(originalParamTypeReference, newCons); assert originalParamTypeReference != paramType; newParam.setParameterType(paramType); for (final JvmAnnotationReference annotationReference : parameter.getAnnotations()) { if (this.annotationUtils.findAnnotation(newParam, annotationReference.getAnnotation().getQualifiedName()) == null) { final JvmAnnotationReference annotation = EcoreUtil.copy(annotationReference); if (annotation != null) { newParam.getAnnotations().add(annotation); this.associator.removeAllAssociation(annotation); it.append(", "); //$NON-NLS-1$ it.append(parameter.getSimpleName());
protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner) { XClosure closure = getClosure(); if (closure.isExplicitSyntax() || !closure.getImplicitFormalParameters().isEmpty()) { List<JvmFormalParameter> closureParameters = closure.getFormalParameters(); int paramCount = closureParameters.size(); for(int i = 0; i < paramCount; i++) { JvmFormalParameter closureParameter = closureParameters.get(i); if (closureParameter.getParameterType() != null) { final LightweightTypeReference closureParameterType = typeAssigner.toLightweightTypeReference(closureParameter.getParameterType()); typeAssigner.assignType(closureParameter, closureParameterType); } else { UnknownTypeReference unknownType = typeAssigner.getReferenceOwner().newUnknownTypeReference(); typeAssigner.assignType(closureParameter, unknownType); } } ITypeComputationState result = typeAssigner.getForkedState(); return result; } else { JvmFormalParameter implicitParameter = TypesFactory.eINSTANCE.createJvmFormalParameter(); implicitParameter.setName(IFeatureNames.IT.getFirstSegment()); implicitParameters = Collections.singletonList(implicitParameter); typeAssigner.assignType(implicitParameter, typeAssigner.getReferenceOwner().newUnknownTypeReference()); ITypeComputationState result = typeAssigner.getForkedState(); return result; } } }
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); }
@Override public String getFormalParameterName(int position) { return this.parameters.get(position).getName(); }
JvmFormalParameter parameter = typesFactory.createJvmFormalParameter(); result.getParameters().add(parameter); parameter.setParameterType(jvmTypesBuilder.inferredType()); JvmFormalParameter parameter2 = first.getParameters().get(i); parameter.setName(parameter2.getName());
for (int i = 0; i < parameters.size(); i++) { JvmFormalParameter parameter = parameters.get(i); JvmTypeReference parameterType = parameter.getParameterType(); if (InferredTypeIndicator.isInferred(parameterType)) { XComputedTypeReference casted = (XComputedTypeReference) parameterType; XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference(); computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this)); parameter.setParameterType(computedParameterType); if (function.getCreateExtensionInfo() != null) { JvmFormalParameter firstParameter = operation.getParameters().get(0); JvmTypeReference parameterType = firstParameter.getParameterType(); if (InferredTypeIndicator.isInferred(parameterType)) { XComputedTypeReference casted = (XComputedTypeReference) parameterType;
/** 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; }
@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); }
@Override public AnnotationVisitor visitParameterAnnotation(final int parameter, final String desc, final boolean visible) { JvmFormalParameter formalParameter = result.getParameters().get(parameter); return new JvmAnnotationReferenceBuilder( (InternalEList<JvmAnnotationReference>) formalParameter.getAnnotations(), desc, proxies); }
@Override public void setSimpleName(final String name) { this.checkMutable(); ConditionUtils.checkJavaIdentifier(name, "name"); JvmFormalParameter _delegate = this.getDelegate(); _delegate.setName(name); } }
/** 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; }
final JvmFormalParameter newParam = this.typesFactory.createJvmFormalParameter(); newOp.getParameters().add(newParam); newParam.setName(parameter.getSimpleName()); newParam.setParameterType(cloneWithTypeParametersAndProxies(parameter.getParameterType(), newOp));
/** * Creates and returns a formal parameter for the given name and type, which is associated to the given source * element. * * @return a Java parameter given name, <code>null</code> if sourceElement or name are <code>null</code>. */ /* @Nullable */ public JvmFormalParameter toParameter(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name, /* @Nullable */ JvmTypeReference typeRef) { if(sourceElement == null || name == null) return null; JvmFormalParameter result = typesFactory.createJvmFormalParameter(); result.setName(name); result.setParameterType(cloneWithProxies(typeRef)); return associate(sourceElement, result); }
JvmFormalParameter closureParameter = closureParameters.get(i); final LightweightTypeReference operationParameterType = operationParameterTypes.get(i); if (explicit && closureParameter.getParameterType() != null) { final LightweightTypeReference closureParameterType = typeAssigner.toLightweightTypeReference(closureParameter.getParameterType()); new DeferredTypeParameterHintCollector(getExpectation().getReferenceOwner()) { @Override JvmTypeReference parameterType = closureParameter.getParameterType(); if (parameterType != null) { LightweightTypeReference lightweight = typeAssigner.toLightweightTypeReference(parameterType); implicitParameter.setName(IFeatureNames.IT.getFirstSegment()); implicitParameters = Collections.singletonList(implicitParameter); LightweightTypeReference operationParameterType = operationParameterTypes.get(0);
private boolean containsParam(final EList<JvmFormalParameter> params, final String param) { final Function1<JvmFormalParameter, String> _function = (JvmFormalParameter it) -> { return it.getName(); }; return ListExtensions.<JvmFormalParameter, String>map(params, _function).contains(param); }