protected void recomputeAndCheckIdentifiers(Resource resource) { Iterator<JvmMember> iter = Iterators.filter(EcoreUtil.getAllContents(resource, false), JvmMember.class); while (iter.hasNext()) { JvmMember member = iter.next(); String identifier = member.getIdentifier(); member.internalSetIdentifier(null); String computed = member.getIdentifier(); assertNotNull(String.valueOf(member), computed); assertEquals(identifier, computed); checkDeprecatedBitSet(member); } Iterator<JvmFormalParameter> params = Iterators.filter(EcoreUtil.getAllContents(resource, false), JvmFormalParameter.class); while (params.hasNext()) { JvmFormalParameter parameter = params.next(); assertNotNull(parameter.eContainer().toString(), parameter.getName()); } }
public LightweightTypeReference getSwitchVariableType(final XSwitchExpression it) { @Extension final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(it); final JvmFormalParameter declaredParam = it.getDeclaredParam(); if ((declaredParam == null)) { return resolvedTypes.getActualType(it.getSwitch()); } final LightweightTypeReference paramType = resolvedTypes.getActualType(declaredParam); LightweightTypeReference _elvis = null; if (paramType != null) { _elvis = paramType; } else { LightweightTypeReference _actualType = resolvedTypes.getActualType(it.getSwitch()); _elvis = _actualType; } return _elvis; }
@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()); }
@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); }
@Override public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) { if (obj instanceof JvmTypeParameter) return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName(); if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter) return fallback.getFragment(obj); if (obj instanceof JvmIdentifiableElement) { if (obj instanceof JvmArrayType) { if (obj.eContainer() instanceof JvmGenericArrayTypeReference) return fallback.getFragment(obj); if (obj.eContainer() instanceof JvmIdentifiableElement) { return getFragment(obj.eContainer(), fallback) + "[]"; } } return ((JvmIdentifiableElement) obj).getIdentifier(); } return fallback.getFragment(obj); }
@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); }
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(); }
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 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); }
protected void appendParameters(JvmExecutable executable, StringBuilder result, boolean extension) { List<JvmFormalParameter> parameters = executable.getParameters(); int start = extension ? 1 : 0; int end = parameters.size(); if (start != end) { result.append('('); for(int i = start; i < end; i++) { if (i != start) { result.append(','); } JvmFormalParameter parameter = parameters.get(i); LightweightTypeReference parameterType = getParameterType(parameter); if (parameterType != null) result.append(parameterType.getIdentifier()); else result.append("[null]"); } result.append(')'); } }
protected JvmTypeReference getDeclaredType(JvmIdentifiableElement identifiable) { if (identifiable instanceof JvmOperation) { return ((JvmOperation) identifiable).getReturnType(); } if (identifiable instanceof JvmField) { return ((JvmField) identifiable).getType(); } if (identifiable instanceof JvmConstructor) { return shared.resolver.getServices().getTypeReferences().createTypeRef(((JvmConstructor) identifiable).getDeclaringType()); } if (identifiable instanceof JvmFormalParameter) { JvmTypeReference parameterType = ((JvmFormalParameter) identifiable).getParameterType(); return parameterType; } return null; }
@Test public void testSimple() { try { final XExpression expression = this.expression("return s.toUpperCase", false); final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmOperation> _function_1 = (JvmOperation it_1) -> { EList<JvmFormalParameter> _parameters = it_1.getParameters(); JvmFormalParameter _parameter = this.builder.toParameter(expression, "s", this.references.getTypeForName(String.class, expression)); this.builder.<JvmFormalParameter>operator_add(_parameters, _parameter); this.builder.setBody(it_1, expression); }; JvmOperation _method = this.builder.toMethod(expression, "doStuff", this.references.getTypeForName(String.class, expression), _function_1); this.builder.<JvmOperation>operator_add(_members, _method); }; final JvmGenericType clazz = this.builder.toClass(expression, "my.test.Foo", _function); final Class<?> compiledClass = this.compile(expression.eResource(), clazz); final Object instance = compiledClass.newInstance(); Assert.assertEquals("FOO", compiledClass.getMethod("doStuff", String.class).invoke(instance, "foo")); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case TypesPackage.JVM_EXECUTABLE__TYPE_PARAMETERS: getTypeParameters().clear(); getTypeParameters().addAll((Collection<? extends JvmTypeParameter>)newValue); return; case TypesPackage.JVM_EXECUTABLE__PARAMETERS: getParameters().clear(); getParameters().addAll((Collection<? extends JvmFormalParameter>)newValue); return; case TypesPackage.JVM_EXECUTABLE__EXCEPTIONS: getExceptions().clear(); getExceptions().addAll((Collection<? extends JvmTypeReference>)newValue); return; case TypesPackage.JVM_EXECUTABLE__VAR_ARGS: setVarArgs((Boolean)newValue); return; } super.eSet(featureID, newValue); }
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()); }
protected JvmFormalParameter internalGetParameter(int idx) { int unshiftedParameterSize = parameters.size(); int unshiftedArgumentSize = arguments.size(); if (idx >= unshiftedParameterSize || idx >= unshiftedArgumentSize) { // number of args matches number of parameters if (unshiftedParameterSize == unshiftedArgumentSize) { return shiftedParameters.get(idx - unshiftedParameterSize); } // superfluous args available if (unshiftedParameterSize < unshiftedArgumentSize) { int shiftedIdx = idx - unshiftedParameterSize; if (shiftedIdx >= shiftedArguments.size()) return parameters.get(idx - shiftedArguments.size()); return shiftedParameters.get(shiftedIdx); } // too few args available return shiftedParameters.get(idx - unshiftedArgumentSize); } return parameters.get(idx); }
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; }
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 String getSwitchLocalVariableName(XSwitchExpression expr, ITreeAppendable b) { JvmFormalParameter declaredParam = expr.getDeclaredParam(); if (declaredParam != null) { if (b.hasName(declaredParam)) { return b.getName(declaredParam); } return null; } XExpression switchExpression = expr.getSwitch(); if (b.hasName(switchExpression)) { return b.getName(switchExpression); } if (switchExpression instanceof XFeatureCall) { XFeatureCall featureCall = (XFeatureCall) switchExpression; JvmIdentifiableElement feature = featureCall.getFeature(); if (b.hasName(feature)) { return b.getName(feature); } } return null; }
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()); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setDeclaredParam(JvmFormalParameter newDeclaredParam) { if (newDeclaredParam != declaredParam) { NotificationChain msgs = null; if (declaredParam != null) msgs = ((InternalEObject)declaredParam).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XFOR_LOOP_EXPRESSION__DECLARED_PARAM, null, msgs); if (newDeclaredParam != null) msgs = ((InternalEObject)newDeclaredParam).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XFOR_LOOP_EXPRESSION__DECLARED_PARAM, null, msgs); msgs = basicSetDeclaredParam(newDeclaredParam, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XFOR_LOOP_EXPRESSION__DECLARED_PARAM, newDeclaredParam, newDeclaredParam)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setDeclaredParam(JvmFormalParameter newDeclaredParam) { if (newDeclaredParam != declaredParam) { NotificationChain msgs = null; if (declaredParam != null) msgs = ((InternalEObject)declaredParam).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XCATCH_CLAUSE__DECLARED_PARAM, null, msgs); if (newDeclaredParam != null) msgs = ((InternalEObject)newDeclaredParam).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - XbasePackage.XCATCH_CLAUSE__DECLARED_PARAM, null, msgs); msgs = basicSetDeclaredParam(newDeclaredParam, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, XbasePackage.XCATCH_CLAUSE__DECLARED_PARAM, newDeclaredParam, newDeclaredParam)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XbasePackage.XFOR_LOOP_EXPRESSION__FOR_EXPRESSION: setForExpression((XExpression)null); return; case XbasePackage.XFOR_LOOP_EXPRESSION__EACH_EXPRESSION: setEachExpression((XExpression)null); return; case XbasePackage.XFOR_LOOP_EXPRESSION__DECLARED_PARAM: setDeclaredParam((JvmFormalParameter)null); return; } super.eUnset(featureID); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XbasePackage.XCLOSURE__DECLARED_FORMAL_PARAMETERS: getDeclaredFormalParameters().clear(); getDeclaredFormalParameters().addAll((Collection<? extends JvmFormalParameter>)newValue); return; case XbasePackage.XCLOSURE__EXPRESSION: setExpression((XExpression)newValue); return; case XbasePackage.XCLOSURE__EXPLICIT_SYNTAX: setExplicitSyntax((Boolean)newValue); return; case XbasePackage.XCLOSURE__IMPLICIT_FORMAL_PARAMETERS: getImplicitFormalParameters().clear(); getImplicitFormalParameters().addAll((Collection<? extends JvmFormalParameter>)newValue); return; } super.eSet(featureID, newValue); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ 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)); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XbasePackage.XSWITCH_EXPRESSION__SWITCH: setSwitch((XExpression)null); return; case XbasePackage.XSWITCH_EXPRESSION__CASES: getCases().clear(); return; case XbasePackage.XSWITCH_EXPRESSION__DEFAULT: setDefault((XExpression)null); return; case XbasePackage.XSWITCH_EXPRESSION__DECLARED_PARAM: setDeclaredParam((JvmFormalParameter)null); return; } super.eUnset(featureID); }
@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()); }
@Test public void testClosure_6() throws Exception { XClosure closure = (XClosure) expression("([(String) => String mapper|mapper('something')])"); assertTrue(((XBlockExpression)closure.getExpression()).getExpressions().get(0) instanceof XFeatureCall); JvmFormalParameter formalParameter = closure.getFormalParameters().get(0); assertEquals("mapper", formalParameter.getName()); assertTrue(formalParameter.getParameterType() instanceof XFunctionTypeRef); }
@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()); }
protected void doTestInnerType_WrappedIterator_03(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() == 4; } }); assertNotNull(constructor); JvmFormalParameter firstParameter = constructor.getParameters().get(0); assertEquals(0, firstParameter.getAnnotations().size()); assertEquals("int", firstParameter.getParameterType().getIdentifier()); JvmFormalParameter secondParameter = constructor.getParameters().get(1); assertEquals(1, secondParameter.getAnnotations().size()); assertEquals("java.lang.String", secondParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotationWithDefaults.class.getName(), secondParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); JvmFormalParameter thirdParameter = constructor.getParameters().get(2); assertEquals(0, thirdParameter.getAnnotations().size()); assertEquals("int", thirdParameter.getParameterType().getIdentifier()); JvmFormalParameter forthParameter = constructor.getParameters().get(3); assertEquals(1, forthParameter.getAnnotations().size()); assertEquals("java.lang.String", forthParameter.getParameterType().getIdentifier()); assertEquals(TestAnnotation.NestedAnnotation.class.getName(), forthParameter.getAnnotations().get(0).getAnnotation().getQualifiedName()); }
@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()); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case XbasePackage.XCATCH_CLAUSE__EXPRESSION: setExpression((XExpression)null); return; case XbasePackage.XCATCH_CLAUSE__DECLARED_PARAM: setDeclaredParam((JvmFormalParameter)null); return; } super.eUnset(featureID); }
@Test public void testTypeParamEndsWithDollar_03() { String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar"; JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function3").iterator().next(); JvmFormalParameter parameter = function.getParameters().get(0); JvmType parameterType = parameter.getParameterType().getType(); assertEquals(function.getTypeParameters().get(0), parameterType); }
/** * Contexts: * FullJvmFormalParameter returns JvmFormalParameter * * Constraint: * (parameterType=JvmTypeReference name=ValidID) */ protected void sequence_FullJvmFormalParameter(ISerializationContext context, JvmFormalParameter semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, TypesPackage.Literals.JVM_FORMAL_PARAMETER__PARAMETER_TYPE)); if (transientValues.isValueTransient(semanticObject, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, TypesPackage.Literals.JVM_FORMAL_PARAMETER__NAME)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getFullJvmFormalParameterAccess().getParameterTypeJvmTypeReferenceParserRuleCall_0_0(), semanticObject.getParameterType()); feeder.accept(grammarAccess.getFullJvmFormalParameterAccess().getNameValidIDParserRuleCall_1_0(), semanticObject.getName()); feeder.finish(); }
@Check public void checkClosureParameterTypes(XClosure closure) { if (closure.getFormalParameters().isEmpty()) return; LightweightTypeReference closureType = getActualType(closure); if (closureType != null && closureType.isUnknown()) return; boolean checkedClosure = false; for (JvmFormalParameter p : closure.getFormalParameters()) { if (p.getParameterType() == null) { if (!checkedClosure) { LightweightTypeReference type = getExpectedType(closure); if (type == null) { error("There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.", closure, null, INSIGNIFICANT_INDEX, TOO_LITTLE_TYPE_INFORMATION); return; } else { JvmOperation operation = getServices().getFunctionTypes().findImplementingOperation(type); if (operation == null) { error("There is no context to infer the closure's argument types from. Consider typing the arguments or use the closures in a more specific context.", closure, null, INSIGNIFICANT_INDEX, TOO_LITTLE_TYPE_INFORMATION); return; } } checkedClosure = true; } LightweightTypeReference parameterType = getActualType(closure, p); if (parameterType == null) { error("There is no context to infer the closure's argument types from. Consider typing the arguments or use the closures in a more specific context.", closure, null, INSIGNIFICANT_INDEX, TOO_LITTLE_TYPE_INFORMATION); return; } } } }
private boolean isTypeParameterOfClosureImpl(JvmTypeReference ref) { JvmFormalParameter parameter = EcoreUtil2.getContainerOfType(ref, JvmFormalParameter.class); if (parameter != null) { return parameter.eContainer() instanceof XClosure; } return false; }
protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) { if (!(expression instanceof XAbstractFeatureCall)) { error("The left-hand side of an assignment must be a variable", expression, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE); return; } XAbstractFeatureCall assignment = (XAbstractFeatureCall) expression; JvmIdentifiableElement assignmentFeature = assignment.getFeature(); if (assignmentFeature instanceof XVariableDeclaration) { XVariableDeclaration variableDeclaration = (XVariableDeclaration) assignmentFeature; if (variableDeclaration.isWriteable()) { return; } error("Assignment to final variable", expression, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL); } else if (assignmentFeature instanceof JvmFormalParameter) { error("Assignment to final parameter", expression, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL); } else if (assignmentFeature instanceof JvmField) { JvmField field = (JvmField) assignmentFeature; if (!field.isFinal()) { return; } if (simpleAssignment) { JvmIdentifiableElement container = logicalContainerProvider.getNearestLogicalContainer(assignment); // don't issue an error if it's an assignment of a local final field within a constructor. if (container != null && container instanceof JvmConstructor) { JvmConstructor constructor = (JvmConstructor) container; if (field.getDeclaringType() == constructor.getDeclaringType()) return; } } error("Assignment to final field", expression, feature, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_FINAL); } else if (!simpleAssignment) { error("The left-hand side of an assignment must be a variable", expression, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ASSIGNMENT_TO_NO_VARIABLE); } }
@Override public AnnotationVisitor visitParameterAnnotation( final int parameter, final String desc, final boolean visible) { if (parameter < offset) return null; JvmFormalParameter formalParameter = result.getParameters().get(parameter - offset); return new JvmAnnotationReferenceBuilder((InternalEList<JvmAnnotationReference>) formalParameter.getAnnotations(), desc, proxies); }
@Override public List<JvmFormalParameter> getParameters() { XClosure closure = getClosure(); if (closure.isExplicitSyntax()) { return closure.getDeclaredFormalParameters(); } if (implicitParameters != null) return implicitParameters; return closure.getImplicitFormalParameters(); }