protected IScope createLocalVarScopeForJvmConstructor( JvmConstructor context, IScope parentScope) { EList<JvmFormalParameter> parameters = context.getParameters(); List<LocalVarDescription> descriptions = newArrayList(); for (JvmFormalParameter p : parameters) { if (p.getName() != null) descriptions.add(new LocalVarDescription(QualifiedName.create(p.getName()), p)); } return new JvmFeatureScope(parentScope, "constructor " + context.getSimpleName(), descriptions); }
public IScope createConstructorCallSerializationScope(EObject context) { if (!(context instanceof XConstructorCall)) { return IScope.NULLSCOPE; } XConstructorCall constructorCall = (XConstructorCall) context; JvmConstructor constructor = constructorCall.getConstructor(); if (constructor.eIsProxy()) { return IScope.NULLSCOPE; } return doCreateConstructorCallSerializationScope(constructorCall); }
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; }
@Override protected JvmConstructor getConstructorFromType( EObject context, Class<?> type, String constructor) { JvmConstructor result = super.getConstructorFromType(context, type, constructor); if (result != null) { IJavaElement found = elementFinder.findElementFor(result); assertEquals(IJavaElement.METHOD, found.getElementType()); assertEquals(result.getSimpleName(), found.getElementName()); IMethod foundMethod = (IMethod) found; assertEquals(result.getParameters().size(), foundMethod.getNumberOfParameters()); } return result; }
protected void addDefaultConstructor(XtendClass source, JvmGenericType target) { boolean declaredConstructor = false; for (XtendMember member : source.getMembers()) { if (member instanceof XtendConstructor) { declaredConstructor = true; break; } } if (!declaredConstructor) { JvmConstructor constructor = typesFactory.createJvmConstructor(); target.getMembers().add(constructor); associator.associatePrimary(source, constructor); constructor.setSimpleName(source.getName()); constructor.setVisibility(JvmVisibility.PUBLIC); } }
protected String _case( JvmConstructor input, XConstructorCall context, EReference ref, JvmFeatureDescription jvmFeatureDescription) { List<XExpression> arguments = context.getArguments(); if (!isValidNumberOfArguments(input, arguments)) return INVALID_NUMBER_OF_ARGUMENTS; // expected constructor type argument count is the sum of the declaring type's type parameters // and the constructors type parameters int expectedTypeArguments = input.getTypeParameters().size() + ((JvmTypeParameterDeclarator) input.getDeclaringType()).getTypeParameters().size(); if ((!context.getTypeArguments().isEmpty()) // raw type or inferred arguments && expectedTypeArguments != context.getTypeArguments().size()) return INVALID_NUMBER_OF_TYPE_ARGUMENTS; // TODO check type parameter bounds against type arguments if (!areArgumentTypesValid(input, arguments)) return INVALID_ARGUMENT_TYPES; return null; }
protected IScope getThisOrSuperScope(XAbstractFeatureCall call, JvmConstructor constructor) { QualifiedName name = THIS; JvmIdentifiableElement logicalContainer = logicalContainerProvider.getNearestLogicalContainer(call); if (logicalContainer instanceof JvmConstructor) { JvmDeclaredType thisType = ((JvmConstructor) logicalContainer).getDeclaringType(); if (thisType != constructor.getDeclaringType()) { name = SUPER; } } return new SingletonScope(EObjectDescription.create(name, constructor), IScope.NULLSCOPE); }
protected void transform(XtendConstructor source, JvmGenericType container) { JvmConstructor constructor = typesFactory.createJvmConstructor(); container.getMembers().add(constructor); associator.associatePrimary(source, constructor); JvmVisibility visibility = source.getVisibility(); constructor.setSimpleName(container.getSimpleName()); constructor.setVisibility(visibility); for (XtendParameter parameter : source.getParameters()) { JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter(); jvmParam.setName(parameter.getName()); jvmParam.setParameterType(cloneWithProxies(parameter.getParameterType())); constructor.getParameters().add(jvmParam); associator.associate(parameter, jvmParam); } copyAndFixTypeParameters(source.getTypeParameters(), constructor); for (JvmTypeReference exception : source.getExceptions()) { constructor.getExceptions().add(cloneWithProxies(exception)); } jvmTypesBuilder.translateAnnotationsTo( source.getAnnotationInfo().getAnnotations(), constructor); associator.associateLogicalContainer(source.getExpression(), constructor); jvmTypesBuilder.setDocumentation(constructor, jvmTypesBuilder.getDocumentation(source)); }