org.eclipse.xtext.common.types.JvmFormalParameter Java Examples
The following examples show how to use
org.eclipse.xtext.common.types.JvmFormalParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override protected void _format(XForLoopExpression expr, IFormattableDocument document) { final ISemanticRegionsFinder regionFor = this.textRegionExtensions.regionFor(expr); document.append(regionFor.keyword(this.keywords.getForKeyword()), ONE_SPACE); final JvmFormalParameter declaredParam = expr.getDeclaredParam(); document.prepend(declaredParam, NO_SPACE); document.append(declaredParam, ONE_SPACE); document.format(declaredParam); final XExpression forExpression = expr.getForExpression(); document.prepend(forExpression, ONE_SPACE); document.append(forExpression, NO_SPACE); document.format(forExpression); final XExpression eachExpression = expr.getEachExpression(); if (eachExpression != null) { formatBody(eachExpression, true, document); } else { document.prepend(regionFor.keyword(this.keywords.getSemicolonKeyword()), NO_SPACE); } }
Example #2
Source File: XSwitchExpressionImpl.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void setDeclaredParam(JvmFormalParameter newDeclaredParam) { if (newDeclaredParam != declaredParam) { NotificationChain msgs = null; if (declaredParam != null) msgs = ((InternalEObject)declaredParam).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XSWITCH_EXPRESSION__DECLARED_PARAM, null, msgs); if (newDeclaredParam != null) msgs = ((InternalEObject)newDeclaredParam).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XSWITCH_EXPRESSION__DECLARED_PARAM, null, msgs); msgs = basicSetDeclaredParam(newDeclaredParam, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XSWITCH_EXPRESSION__DECLARED_PARAM, newDeclaredParam, newDeclaredParam)); }
Example #3
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListParamsNoResult_03() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsNoResult, typeVar.getDeclarator()); }
Example #4
Source File: InferredJvmModelTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testDispatchFunction_09() throws Exception { XtendFile xtendFile = file( "import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor\n" + "import org.eclipse.xtend.core.xtend.XtendClass\n" + "import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer\n" + "class Z extends AbstractModelInferrer {\n" + " def dispatch infer(XtendClass x, IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) {}\n" + "}\n"); Iterable<JvmOperation> operations = getInferredType(xtendFile).getDeclaredOperations(); JvmOperation dispatcher = find(operations, new Predicate<JvmOperation>() { @Override public boolean apply(JvmOperation input) { return equal("infer", input.getSimpleName()); } }); JvmFormalParameter firstParameter = dispatcher.getParameters().get(0); assertEquals("EObject", firstParameter.getParameterType().getSimpleName()); String returnType = dispatcher.getReturnType().getIdentifier(); assertEquals("void", returnType); }
Example #5
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testNestedEnum_04() throws Exception { String typeName = TestEnum.Nested.class.getName(); JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); boolean constructorFound = false; for (JvmMember member : members) { if (member instanceof JvmConstructor) { assertFalse(constructorFound); constructorFound = true; List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters(); assertEquals(0, parameters.size()); // synthetic parameters are not returned } } assertTrue(constructorFound); }
Example #6
Source File: JvmDeclaredTypeSignatureHashProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected SignatureHashBuilder appendSignature(JvmOperation operation) { appendVisibility(operation.getVisibility()).append(" "); if (operation.isAbstract()) append("abstract "); if (operation.isStatic()) append("static "); if (operation.isFinal()) append("final "); appendType(operation.getReturnType()).appendTypeParameters(operation).append(" ") .append(operation.getSimpleName()).append("("); for (JvmFormalParameter p : operation.getParameters()) { appendType(p.getParameterType()); append(" "); } append(") "); for (JvmTypeReference ex : operation.getExceptions()) { appendType(ex).append(" "); } return this; }
Example #7
Source File: MemberFromSuperImplementor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void initializeExecutableBuilder(final AbstractExecutableBuilder builder, final JvmDeclaredType overrider, final IResolvedExecutable overridden) { final JvmExecutable executable = overridden.getDeclaration(); builder.setContext(overrider); builder.setVisibility(overridden.getDeclaration().getVisibility()); final Procedure2<LightweightTypeReference, Integer> _function = (LightweightTypeReference it, Integer index) -> { final JvmFormalParameter declaredParameter = executable.getParameters().get((index).intValue()); final AbstractParameterBuilder parameterBuilder = builder.newParameterBuilder(); parameterBuilder.setName(declaredParameter.getSimpleName()); parameterBuilder.setType(it); JvmAnnotationReference _findAnnotation = this.annotationLookup.findAnnotation(declaredParameter, Extension.class); boolean _tripleNotEquals = (_findAnnotation != null); parameterBuilder.setExtensionFlag(_tripleNotEquals); }; IterableExtensions.<LightweightTypeReference>forEach(overridden.getResolvedParameterTypes(), _function); builder.setVarArgsFlag(executable.isVarArgs()); builder.setExceptions(overridden.getResolvedExceptions()); }
Example #8
Source File: MemberFromSuperImplementor.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void appendConstructorFromSuper(final XtendClass overrider, final IResolvedConstructor superConstructor, final ISourceAppender appendable) { final JvmGenericType inferredType = this.associations.getInferredType(overrider); final AbstractConstructorBuilder constructorBuilder = this.codeBuilderFactory.createConstructorBuilder(inferredType); this.initializeExecutableBuilder(constructorBuilder, inferredType, superConstructor); final Procedure1<ISourceAppender> _function = (ISourceAppender it) -> { boolean _isEmpty = superConstructor.getResolvedParameterTypes().isEmpty(); boolean _not = (!_isEmpty); if (_not) { StringConcatenation _builder = new StringConcatenation(); _builder.append("super("); final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it_1) -> { return it_1.getSimpleName(); }; String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(superConstructor.getDeclaration().getParameters(), _function_1), ", "); _builder.append(_join); _builder.append(")"); it.append(_builder); } }; constructorBuilder.setBodyGenerator(_function); boolean _isValid = constructorBuilder.isValid(); if (_isValid) { constructorBuilder.build(appendable); } }
Example #9
Source File: DispatchRenameSupportTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public String signature(final JvmOperation it) { StringConcatenation _builder = new StringConcatenation(); String _qualifiedName = it.getQualifiedName(); _builder.append(_qualifiedName); _builder.append("("); { EList<JvmFormalParameter> _parameters = it.getParameters(); boolean _hasElements = false; for(final JvmFormalParameter p : _parameters) { if (!_hasElements) { _hasElements = true; } else { _builder.appendImmediate(",", ""); } String _simpleName = p.getParameterType().getType().getSimpleName(); _builder.append(_simpleName); } } _builder.append(")"); return _builder.toString(); }
Example #10
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void doTestInnerType_WrappedIterator_02(JvmGenericType wrappedIterator) { assertEquals(3, Iterables.size(wrappedIterator.getDeclaredConstructors())); JvmConstructor constructor = (JvmConstructor) Iterables.find(wrappedIterator.getMembers(), new Predicate<JvmMember>() { @Override public boolean apply(JvmMember input) { return (input instanceof JvmConstructor) && input.getSimpleName().equals("WrappedIterator") && ((JvmConstructor) input).getParameters().size() == 3; } }); assertNotNull(constructor); JvmFormalParameter firstParameter = constructor.getParameters().get(0); assertEquals(1, firstParameter.getAnnotations().size()); assertEquals("java.lang.String", firstParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotationWithDefaults.class.getName(), firstParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); JvmFormalParameter secondParameter = constructor.getParameters().get(1); assertEquals(0, secondParameter.getAnnotations().size()); assertEquals("int", secondParameter.getParameterType().getIdentifier()); JvmFormalParameter thirdParameter = constructor.getParameters().get(2); assertEquals(1, thirdParameter.getAnnotations().size()); assertEquals("java.util.Iterator<V>", thirdParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotation.NestedAnnotation.class.getName(), thirdParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); }
Example #11
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes, String[] parameterNames, JvmExecutable result) { InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters(); for (int i = 0; i < parameterTypes.length; i++) { IAnnotationBinding[] parameterAnnotations; try { parameterAnnotations = method.getParameterAnnotations(i); } catch(AbortCompilation aborted) { parameterAnnotations = null; } ITypeBinding parameterType = parameterTypes[i]; String parameterName = parameterNames == null ? null /* lazy */ : i < parameterNames.length ? parameterNames[i] : "arg" + i; JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations); parameters.addUnique(formalParameter); } }
Example #12
Source File: SerializerScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public IScope createFeatureCallSerializationScope(EObject context) { if (!(context instanceof XAbstractFeatureCall)) { return IScope.NULLSCOPE; } XAbstractFeatureCall call = (XAbstractFeatureCall) context; JvmIdentifiableElement feature = call.getFeature(); // this and super - logical container aware FeatureScopes if (feature instanceof JvmType) { return getTypeScope(call, (JvmType) feature); } if (feature instanceof JvmConstructor) { return getThisOrSuperScope(call, (JvmConstructor) feature); } if (feature instanceof JvmExecutable) { return getExecutableScope(call, feature); } if (feature instanceof JvmFormalParameter || feature instanceof JvmField || feature instanceof XVariableDeclaration || feature instanceof XSwitchExpression) { return new SingletonScope(EObjectDescription.create(feature.getSimpleName(), feature), IScope.NULLSCOPE); } return IScope.NULLSCOPE; }
Example #13
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testEnum_04() throws Exception { String typeName = TestEnum.class.getName(); JvmEnumerationType type = (JvmEnumerationType) getTypeProvider().findTypeByName(typeName); List<JvmMember> members = type.getMembers(); boolean constructorFound = false; for (JvmMember member : members) { if (member instanceof JvmConstructor) { assertFalse(constructorFound); constructorFound = true; List<JvmFormalParameter> parameters = ((JvmConstructor) member).getParameters(); assertEquals(1, parameters.size()); // synthetic parameters are not returned } } assertTrue(constructorFound); }
Example #14
Source File: AbstractClosureTypeHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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); }
Example #15
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListWildcardsNoResult_03() { JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods( "twoListWildcardsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); assertTrue(typeParameter instanceof JvmWildcardTypeReference); JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) typeParameter; assertEquals(1, wildcard.getConstraints().size()); assertTrue(wildcard.getConstraints().get(0) instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) wildcard.getConstraints().get(0); assertNotNull(upperBound.getTypeReference()); JvmType upperBoundType = upperBound.getTypeReference().getType(); assertFalse(upperBoundType.eIsProxy()); assertEquals("java.lang.Object", upperBoundType.getIdentifier()); }
Example #16
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_twoListParamsNoResult_03() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; assertEquals(1, parameterized.getArguments().size()); JvmTypeReference typeParameter = parameterized.getArguments().get(0); JvmType referencedType = typeParameter.getType(); assertFalse(referencedType.eIsProxy()); assertTrue(referencedType instanceof JvmTypeParameter); JvmTypeParameter typeVar = (JvmTypeParameter) referencedType; assertEquals("T", typeVar.getName()); assertSame(twoListParamsNoResult, typeVar.getDeclarator()); }
Example #17
Source File: OperationImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case DomainmodelPackage.OPERATION__PARAMS: getParams().clear(); getParams().addAll((Collection<? extends JvmFormalParameter>)newValue); return; case DomainmodelPackage.OPERATION__BODY: setBody((XExpression)newValue); return; } super.eSet(featureID, newValue); }
Example #18
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected <T extends Member & GenericDeclaration> void enhanceExecutable(JvmExecutable result, T member, String simpleName, Type[] parameterTypes, Annotation[][] annotations, int offset) { StringBuilder fqName = new StringBuilder(48); fqName.append(member.getDeclaringClass().getName()); fqName.append('.'); fqName.append(simpleName); fqName.append('('); InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters(); for (int typeIdx = offset, annotationIdx = annotations.length - parameterTypes.length + offset; typeIdx < parameterTypes.length; typeIdx++, annotationIdx++) { if (typeIdx != offset) fqName.append(','); Type parameterType = parameterTypes[typeIdx]; uriHelper.computeTypeName(parameterType, fqName); parameters.addUnique( createFormalParameter(parameterType, "arg" + (typeIdx - offset), result, member, annotations[annotationIdx])); } fqName.append(')'); result.internalSetIdentifier(fqName.toString()); result.setSimpleName(simpleName); setVisibility(result, member.getModifiers()); }
Example #19
Source File: JvmModelBasedLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testLinkToParameter_1() throws Exception { XFeatureCall expr = (XFeatureCall) expression("x", false); Resource resource = expr.eResource(); resource.eSetDeliver(false); resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> { cls.getMembers().add(jvmTypesBuilder.toField(expr, "x", stringType(expr))); cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "doStuff", stringType(expr), (JvmOperation o) -> { o.getParameters().add(jvmTypesBuilder.toParameter(expr, "x", stringType(expr))); jvmTypesBuilder.setBody(o, expr); })); })); validationTestHelper.assertNoErrors(expr); Assert.assertTrue(expr.getFeature() instanceof JvmFormalParameter); }
Example #20
Source File: ExtensionScopeHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isMatchingFirstParameter(JvmOperation feature) { List<JvmFormalParameter> parameters = feature.getParameters(); JvmFormalParameter firstParameter = parameters.get(0); JvmTypeReference type = firstParameter.getParameterType(); if (type == null) return false; JvmType rawParameterType = type.getType(); if (rawParameterType == null || rawParameterType.eIsProxy()) return false; if (!(rawParameterType instanceof JvmTypeParameter)) { if (rawArgumentType.isResolved()) { // short circuit - limit extension scope entries to real candidates LightweightTypeReference parameterTypeReference = rawArgumentType.getOwner().toPlainTypeReference(rawParameterType); if (parameterTypeReference.isResolved() && !parameterTypeReference.isAssignableFrom(rawArgumentType)) { if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && rawArgumentType.isSubtypeOf(Iterable.class)) { return true; } return false; } if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && !rawArgumentType.isSubtypeOf(Iterable.class)) { return false; } } else if (isArrayTypeMismatch(rawArgumentType, rawParameterType)) { return false; } } return true; }
Example #21
Source File: XSwitchExpressions.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public LightweightTypeReference getSwitchVariableType(XSwitchExpression it) { IResolvedTypes resolvedTypes = batchTypeResolver.resolveTypes(it); JvmFormalParameter declaredParam = it.getDeclaredParam(); if (declaredParam == null) { return resolvedTypes.getActualType(it.getSwitch()); } LightweightTypeReference paramType = resolvedTypes.getActualType(declaredParam); if (paramType != null) { return paramType; } else { return resolvedTypes.getActualType(it.getSwitch()); } }
Example #22
Source File: OverrideHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected JvmOperation findOverriddenOperation(JvmOperation operation, LightweightTypeReference declaringType, TypeParameterSubstitutor<?> substitutor, ITypeReferenceOwner owner, IVisibilityHelper visibilityHelper) { int parameterSize = operation.getParameters().size(); List<LightweightTypeReference> superTypes = declaringType.getSuperTypes(); for(LightweightTypeReference superType: superTypes) { if (superType.getType() instanceof JvmDeclaredType) { JvmDeclaredType declaredSuperType = (JvmDeclaredType) superType.getType(); if (declaredSuperType != null) { Iterable<JvmFeature> equallyNamedFeatures = declaredSuperType.findAllFeaturesByName(operation.getSimpleName()); for(JvmFeature feature: equallyNamedFeatures) { if (feature instanceof JvmOperation) { JvmOperation candidate = (JvmOperation) feature; if (parameterSize == candidate.getParameters().size()) { if (visibilityHelper.isVisible(feature)) { boolean matchesSignature = true; for(int i = 0; i < parameterSize && matchesSignature; i++) { JvmFormalParameter parameter = operation.getParameters().get(i); JvmFormalParameter candidateParameter = candidate.getParameters().get(i); matchesSignature = isMatchesSignature(parameter, candidateParameter, substitutor, owner); } if (matchesSignature) { return candidate; } } } } } } } } return null; }
Example #23
Source File: XbaseDispatchingEObjectTextHover.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, int offset) { Pair<EObject, IRegion> original = super.getXtextElementAt(resource, offset); if (original != null) { EObject object = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset); if (object instanceof XAbstractFeatureCall){ JvmIdentifiableElement feature = ((XAbstractFeatureCall) object).getFeature(); if(feature instanceof JvmExecutable || feature instanceof JvmField || feature instanceof JvmConstructor || feature instanceof XVariableDeclaration || feature instanceof JvmFormalParameter) return Tuples.create(object, original.getSecond()); } else if (object instanceof XConstructorCall){ return Tuples.create(object, original.getSecond()); } } EObjectInComment eObjectReferencedInComment = javaDocTypeReferenceProvider.computeEObjectReferencedInComment(resource, offset); if(eObjectReferencedInComment != null) { EObject eObject = eObjectReferencedInComment.getEObject(); ITextRegion region = eObjectReferencedInComment.getRegion(); return Tuples.create(eObject, new Region(region.getOffset(), region.getLength())); } return original; }
Example #24
Source File: XtendReentrantTypeResolver.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected JvmConstructor inferAnonymousClassConstructor(AnonymousClass anonymousClass, JvmGenericType inferredLocalClass, JvmConstructor superConstructor, boolean visible) { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); inferredLocalClass.getMembers().add(constructor); associator.associatePrimary(anonymousClass.getConstructorCall(), constructor); if (visible) { constructor.setVisibility(JvmVisibility.DEFAULT); } else constructor.setVisibility(JvmVisibility.PRIVATE); constructor.setSimpleName(inferredLocalClass.getSimpleName()); constructor.setVarArgs(superConstructor.isVarArgs()); final List<JvmFormalParameter> parameters = superConstructor.getParameters(); for(JvmFormalParameter parameter: parameters) { parameter.getName(); // trigger name computation constructor.getParameters().add(typesBuilder.cloneWithProxies(parameter)); } for (JvmTypeReference exception : superConstructor.getExceptions()) constructor.getExceptions().add(typesBuilder.cloneWithProxies(exception)); if (!parameters.isEmpty()) { typesBuilder.setBody(constructor, new Procedures.Procedure1<ITreeAppendable>() { @Override public void apply(ITreeAppendable a) { a.append("super("); for(int i = 0; i < parameters.size(); i++) { if (i != 0) { a.append(", "); } a.append(parameters.get(i).getSimpleName()); } a.append(");"); } }); } return constructor; }
Example #25
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void test_twoListParamsNoResult_02() { JvmOperation twoListParamsNoResult = getMethodFromParameterizedMethods( "twoListParamsNoResult(java.util.List,java.util.List)"); JvmFormalParameter firstParam = twoListParamsNoResult.getParameters().get(0); JvmTypeReference paramType = firstParam.getParameterType(); assertNotNull(paramType); assertFalse(paramType.getType().eIsProxy()); assertEquals("java.util.List<T>", paramType.getIdentifier()); assertTrue(paramType instanceof JvmParameterizedTypeReference); JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType; JvmType rawType = parameterized.getType(); assertFalse(rawType.eIsProxy()); assertEquals("java.util.List", rawType.getIdentifier()); }
Example #26
Source File: AbstractPendingLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getFeatureParameterTypesAsString(JvmExecutable executable) { ITypeReferenceOwner referenceOwner = getState().getReferenceOwner(); List<JvmFormalParameter> parameters = executable.getParameters(); StringBuilder b = new StringBuilder(); b.append("("); for(int i=0; i<parameters.size(); ++i) { JvmTypeReference parameterType = parameters.get(i).getParameterType(); LightweightTypeReference typeReference = referenceOwner.toLightweightTypeReference(parameterType); b.append(typeReference.getHumanReadableName()); if(i < parameters.size()-1) b.append(", "); } b.append(")"); return b.toString(); }
Example #27
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testTypeParamEndsWithDollar_01() { String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar"; JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function1").iterator().next(); JvmFormalParameter parameter = function.getParameters().get(0); JvmType parameterType = parameter.getParameterType().getType(); assertEquals(function.getTypeParameters().get(0), parameterType); }
Example #28
Source File: SARLUIStrings.java From sarl with Apache License 2.0 | 5 votes |
/** Format the parameters. * * @param elements the list of the formal parameters. * @param isVarArgs indicates if the function has var args. * @param includeName indicates if the names are included in the replied valued. * @param keywords the keyword provider. * @param annotationFinder the finder of attached annotations. * @param utils the utility. * @return the string representation of the parameters. */ public static String getParameterString(Iterable<? extends JvmFormalParameter> elements, boolean isVarArgs, boolean includeName, SARLGrammarKeywordAccess keywords, AnnotationLookup annotationFinder, UIStrings utils) { final StringBuilder result = new StringBuilder(); boolean needsSeparator = false; final Iterator<? extends JvmFormalParameter> iterator = elements.iterator(); while (iterator.hasNext()) { final JvmFormalParameter parameter = iterator.next(); if (needsSeparator) { result.append(keywords.getCommaKeyword()).append(" "); //$NON-NLS-1$ } needsSeparator = true; final boolean isDefaultValued = annotationFinder.findAnnotation(parameter, DefaultValue.class) != null; if (isDefaultValued) { result.append(keywords.getLeftSquareBracketKeyword()); } if (includeName) { result.append(parameter.getName()).append(" "); //$NON-NLS-1$ result.append(keywords.getColonKeyword()).append(" "); //$NON-NLS-1$ } JvmTypeReference typeRef = parameter.getParameterType(); if (isVarArgs && !iterator.hasNext() && typeRef instanceof JvmGenericArrayTypeReference) { typeRef = ((JvmGenericArrayTypeReference) typeRef).getComponentType(); result.append(utils.referenceToString(typeRef, NULL_TYPE)); result.append(keywords.getWildcardAsteriskKeyword()); } else { result.append(utils.referenceToString(typeRef, NULL_TYPE)); } if (isDefaultValued) { result.append(keywords.getRightSquareBracketKeyword()); } } return result.toString(); }
Example #29
Source File: LogicalContainerAwareReentrantTypeResolver.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void recordAnnotationExpressions(JvmExecutable executable) { List<JvmFormalParameter> parameters = executable.getParameters(); for(JvmFormalParameter parameter: parameters) { recordAnnotationExpressions(parameter); } recordAnnotationExpressions((JvmAnnotationTarget) executable); }
Example #30
Source File: ExpressionArgumentFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void reorder(boolean varArgs, List<XExpression> copiedArgumentList, List<JvmFormalParameter> copiedParameterList, List<XExpression> shiftedArgumentList, List<JvmFormalParameter> shiftedParameterList) { int max = Math.min(copiedArgumentList.size(), copiedParameterList.size()); if (varArgs && copiedArgumentList.size() >= copiedParameterList.size()) max = max - 1; for(int i = 0; i < max; i++) { XExpression expression = copiedArgumentList.get(i); if (expression instanceof XClosure) { shiftedArgumentList.add(expression); shiftedParameterList.add(copiedParameterList.get(i)); } } copiedArgumentList.removeAll(shiftedArgumentList); copiedParameterList.removeAll(shiftedParameterList); }