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 Project: xtext-extras   Author: eclipse   File: ReflectionTypeFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #2
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #3
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #4
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #5
Source Project: xtext-xtend   Author: eclipse   File: MemberFromSuperImplementor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #6
Source Project: xtext-extras   Author: eclipse   File: XSwitchExpressionImpl.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #7
Source Project: xtext-xtend   Author: eclipse   File: InferredJvmModelTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #8
Source Project: xtext-eclipse   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #9
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #10
Source Project: xtext-extras   Author: eclipse   File: JvmDeclaredTypeSignatureHashProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #11
Source Project: xtext-xtend   Author: eclipse   File: MemberFromSuperImplementor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #12
Source Project: xtext-eclipse   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #13
Source Project: xtext-extras   Author: eclipse   File: AbstractClosureTypeHelper.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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 #14
Source Project: sarl   Author: sarl   File: SARLFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@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 #15
Source Project: xtext-eclipse   Author: eclipse   File: OperationImpl.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * <!-- 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 #16
Source Project: xtext-xtend   Author: eclipse   File: DispatchRenameSupportTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #17
Source Project: xtext-eclipse   Author: eclipse   File: JdtBasedTypeFactory.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #18
Source Project: xtext-extras   Author: eclipse   File: SerializerScopeProvider.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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 #19
Source Project: xtext-extras   Author: eclipse   File: JvmDeclaredTypeSignatureHashProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected SignatureHashBuilder appendSignature(JvmConstructor operation) {
	appendVisibility(operation.getVisibility()).appendTypeParameters(operation).append("(");
	for (JvmFormalParameter p : operation.getParameters()) {
		appendType(p.getParameterType()).append(" ");
	}
	append(") ");
	for (JvmTypeReference ex : operation.getExceptions()) {
		appendType(ex).append(" ");
	}
	return this;
}
 
Example #20
Source Project: xtext-xtend   Author: eclipse   File: CompilationUnitImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public NamedElement toNamedElement(final JvmIdentifiableElement delegate) {
  final Function1<JvmIdentifiableElement, Declaration> _function = (JvmIdentifiableElement it) -> {
    Declaration _switchResult = null;
    boolean _matched = false;
    if (delegate instanceof JvmMember) {
      _matched=true;
      _switchResult = this.toMemberDeclaration(((JvmMember)delegate));
    }
    if (!_matched) {
      if (delegate instanceof JvmTypeParameter) {
        _matched=true;
        _switchResult = this.toTypeParameterDeclaration(((JvmTypeParameter)delegate));
      }
    }
    if (!_matched) {
      if (delegate instanceof JvmFormalParameter) {
        _matched=true;
        _switchResult = this.toParameterDeclaration(((JvmFormalParameter)delegate));
      }
    }
    if (!_matched) {
      throw new UnsupportedOperationException((("Couldn\'t translate \'" + delegate) + "\'"));
    }
    return _switchResult;
  };
  return this.<JvmIdentifiableElement, Declaration>getOrCreate(delegate, _function);
}
 
Example #21
Source Project: sarl   Author: sarl   File: JvmFormalParameterProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getFormalParameterDefaultValueString(int position) {
	final JvmFormalParameter parameter = this.parameters.get(position);
	final IActionPrototypeProvider provider = this.prototypeProvider.get();
	if (provider != null) {
		return provider.extractDefaultValueString(parameter);
	}
	return null;
}
 
Example #22
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_twoListWildcardsNoResult_02() {
	JvmOperation twoListWildcardsNoResult = getMethodFromParameterizedMethods(
			"twoListWildcardsNoResult(java.util.List,java.util.List)");
	JvmFormalParameter firstParam = twoListWildcardsNoResult.getParameters().get(0);
	JvmTypeReference paramType = firstParam.getParameterType();
	assertNotNull(paramType);
	assertEquals("java.util.List<? extends java.lang.Object>", paramType.getIdentifier());
	assertTrue(paramType instanceof JvmParameterizedTypeReference);
	JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) paramType;
	JvmType rawType = parameterized.getType();
	assertFalse(rawType.eIsProxy());
	assertEquals("java.util.List", rawType.getIdentifier());
}
 
Example #23
Source Project: xtext-xtend   Author: eclipse   File: XtendValidator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected String doGetReadableSignature(String simpleName, List<JvmFormalParameter> parameters) {
	return getReadableSignature(simpleName,
			Lists.transform(parameters, new Function<JvmFormalParameter, JvmTypeReference>() {
				@Override
				public JvmTypeReference apply(JvmFormalParameter from) {
					return from.getParameterType();
				}
			}));
}
 
Example #24
Source Project: xtext-eclipse   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFindTypeByName_AbstractMultimap_02() {
	String typeName = "com.google.common.collect.AbstractMultimap";
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmOperation containsValue = (JvmOperation) Iterables
			.getOnlyElement(type.findAllFeaturesByName("containsValue"));
	assertNotNull(containsValue);
	JvmFormalParameter firstParam = containsValue.getParameters().get(0);
	assertEquals(0, firstParam.getAnnotations().size());
}
 
Example #25
Source Project: xtext-xtend   Author: eclipse   File: AbstractSuperTypesTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void assertSuperTypes(final Pair<String, String> type, final String... superTypes) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def ");
    {
      boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(type.getValue());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder.append("<");
        String _value = type.getValue();
        _builder.append(_value);
        _builder.append("> ");
      }
    }
    _builder.append("void method(");
    String _key = type.getKey();
    _builder.append(_key);
    _builder.append(" type) {}");
    final String signature = _builder.toString();
    final XtendFunction function = this.function(signature.toString());
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final LightweightTypeReference subtype = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
    final Function1<LightweightTypeReference, String> _function = (LightweightTypeReference it) -> {
      return it.getSimpleName();
    };
    Assert.assertEquals(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(superTypes))), IterableExtensions.<String>toList(IterableExtensions.<LightweightTypeReference, String>map(this.collectSuperTypes(subtype), _function)));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source Project: xtext-extras   Author: eclipse   File: AbstractTypeProviderTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testTypeParamEndsWithDollar_02() {
	String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar";
	JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
	JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function2").iterator().next();
	JvmFormalParameter parameter = function.getParameters().get(0);
	JvmType parameterType = parameter.getParameterType().getType();
	assertEquals(function.getTypeParameters().get(0), parameterType);
	JvmFormalParameter secondParameter = function.getParameters().get(1);
	JvmType secondParameterType = secondParameter.getParameterType().getType();
	assertEquals(type.getTypeParameters().get(0), secondParameterType);
}
 
Example #27
Source Project: sarl   Author: sarl   File: DefaultActionPrototypeProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ActionParameterTypes createParameterTypesFromJvmModel(boolean isVarargs, List<JvmFormalParameter> parameters) {
	final ActionParameterTypes sig = new ActionParameterTypes(isVarargs, parameters.size());
	for (final JvmFormalParameter p : parameters) {
		final JvmTypeReference paramType = p.getParameterType();
		if (paramType != null) {
			sig.add(paramType.getIdentifier());
		}
	}
	return sig;
}
 
Example #28
Source Project: xtext-extras   Author: eclipse   File: JvmExecutableImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public EList<JvmFormalParameter> getParameters()
{
	if (parameters == null)
	{
		parameters = new EObjectContainmentEList<JvmFormalParameter>(JvmFormalParameter.class, this, TypesPackage.JVM_EXECUTABLE__PARAMETERS);
	}
	return parameters;
}
 
Example #29
Source Project: xtext-xtend   Author: eclipse   File: XtendReentrantTypeResolver.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public InitializerParameterTypeReferenceProvider(
		JvmFormalParameter param,
		XtendFunction createFunction,
		Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext,
		ResolvedTypes resolvedTypes,
		IFeatureScopeSession featureScopeSession,
		XtendReentrantTypeResolver typeResolver) {
	this.param = param;
	this.createFunction = createFunction;
	this.resolvedTypesByContext = resolvedTypesByContext;
	this.resolvedTypes = resolvedTypes;
	this.featureScopeSession = featureScopeSession;
	this.typeResolver = typeResolver;
}
 
Example #30
Source Project: xtext-eclipse   Author: eclipse   File: JdtBasedTypeFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void synthesizeNames(List<JvmFormalParameter> parameters) {
	int i = 0;
	for (JvmFormalParameter p : parameters) {
		if (p.getName() == null) {
			p.setName("arg"+i);
		}
		i++;
	}
}