protected void completeJvmGenericType(JvmGenericType element) { // if no super type add Object ensureSuperTypeObject(element); addAnnotations(element); if (!element.isInterface()) { // if no constructors have been added, add a default constructor if (isEmpty(element.getDeclaredConstructors())) { JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor(); constructor.setSimpleName(element.getSimpleName()); constructor.setVisibility(JvmVisibility.PUBLIC); typeExtensions.setSynthetic(constructor, true); EObject primarySourceElement = associations.getPrimarySourceElement(element); if (primarySourceElement != null) { associator.associate(primarySourceElement, constructor); } element.getMembers().add(constructor); } } }
@Override public void apply(final JvmGenericType it) { String _packageName = model.getPackageName(); it.setPackageName(_packageName); it.setFinal(true); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = PatternGroupClassInferrer.this.builder.typeRef(BaseGeneratedPatternGroup.class); PatternGroupClassInferrer.this._eMFJvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef); } };
protected void createUserData(EObject eObject, ImmutableMap.Builder<String, String> userData) { if (eObject instanceof JvmDeclaredType) { userData.put(SIGNATURE_HASH_KEY, hashProvider.getHash((JvmDeclaredType) eObject)); if (eObject.eContainer() != null) { userData.put(IS_NESTED_TYPE, Boolean.TRUE.toString()); } } if (eObject instanceof JvmGenericType) { JvmGenericType genericType = (JvmGenericType) eObject; if (genericType.isInterface()) userData.put(IS_INTERFACE, Boolean.TRUE.toString()); if (!genericType.getTypeParameters().isEmpty()) { String result = "<"; for (Iterator<JvmTypeParameter> iterator = genericType.getTypeParameters().iterator(); iterator.hasNext();) { JvmTypeParameter type = iterator.next(); result += type.getSimpleName(); if (iterator.hasNext()) { result += ","; } } result +=">"; userData.put(TYPE_PARAMETERS, result); } } } }
protected String getStyle(JvmGenericType type) { if (type.isInterface()) { return INTERFACE; } else if (type.isAbstract()) { return ABSTRACT_CLASS; } else { return CLASS; } }
protected boolean hasTypeParameters(JvmGenericType type) { if (!type.getTypeParameters().isEmpty()) { return true; } if (type.eContainer() instanceof JvmGenericType && !type.isStatic()) { return hasTypeParameters((JvmGenericType) type.eContainer()); } return false; }
/** Create a JvmType for a Python type. * * @param pythonName the python type name. * @return the type. */ @SuppressWarnings("static-method") protected JvmType newType(String pythonName) { final JvmGenericType type = TypesFactory.eINSTANCE.createJvmGenericType(); final int index = pythonName.indexOf("."); //$NON-NLS-1$ if (index <= 0) { type.setSimpleName(pythonName); } else { type.setPackageName(pythonName.substring(0, index - 1)); type.setSimpleName(pythonName.substring(index + 1)); } return type; }
innerType.setInterface(false); innerType.setAbstract(false); innerType.setVisibility(JvmVisibility.PUBLIC); innerType.setStatic(true); innerType.setStrictFloatingPoint(false); innerType.setFinal(false); final String innerTypeName = Capacity.ContextAwareCapacityWrapper.class.getSimpleName(); innerType.setSimpleName(innerTypeName); inferredJvmType.getMembers().add(innerType); constraint.setTypeReference(this._typeReferenceBuilder.typeRef(inferredJvmType)); typeParameter.getConstraints().add(constraint); innerType.getTypeParameters().add(typeParameter); final Iterator<JvmTypeReference> extendedTypeIterator = inferredJvmType.getExtendedInterfaces().iterator(); if (extendedTypeIterator.hasNext()) { final JvmTypeReference extendedType = extendedTypeIterator.next(); extendedType.getQualifiedName() + "$" + innerTypeName, //$NON-NLS-1$ this._typeReferenceBuilder.typeRef(typeParameter)); innerType.getSuperTypes().add(superType); innerType.getSuperTypes().add(this._typeReferenceBuilder.typeRef(inferredJvmType)); innerType.getMembers().add(constructor); final JvmFormalParameter parameter1 = this.typesFactory.createJvmFormalParameter(); parameter1.setName("capacity"); //$NON-NLS-1$
inferredJvmType.setInterface(true); inferredJvmType.setAbstract(true); setVisibility(inferredJvmType, source); inferredJvmType.setStatic(false); inferredJvmType.setStrictFloatingPoint(false); inferredJvmType.setFinal(false);
@Override public void apply(final JvmGenericType it) { it.setVisibility(JvmVisibility.PRIVATE); it.setStatic(true); it.setFinal(true); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = PatternMatchClassInferrer.this.builder.typeRef(matchClass); PatternMatchClassInferrer.this._eMFJvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef); EList<JvmMember> _members = it.getMembers(); final Procedure1<JvmConstructor> _function = new Procedure1<JvmConstructor>() { @Override JvmConstructor _constructor = PatternMatchClassInferrer.this._eMFJvmTypesBuilder.toConstructor(pattern, _function); PatternMatchClassInferrer.this._eMFJvmTypesBuilder.<JvmConstructor>operator_add(_members, _constructor); EList<JvmMember> _members_1 = it.getMembers(); JvmTypeReference _typeRef_1 = PatternMatchClassInferrer.this.builder.typeRef(boolean.class); final Procedure1<JvmOperation> _function_1 = new Procedure1<JvmOperation>() {
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) { inferredJvmType.setVisibility(source.getVisibility()); boolean isStatic = source.isStatic() && !isTopLevel(source); if (!isStatic) { JvmDeclaredType declaringType = inferredJvmType.getDeclaringType(); if (declaringType instanceof JvmGenericType) { if (((JvmGenericType) declaringType).isInterface()) isStatic = true; } else if (declaringType instanceof JvmAnnotationType) { inferredJvmType.setStatic(isStatic); inferredJvmType.setAbstract(source.isAbstract()); inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint()); if (!inferredJvmType.isAbstract()) { inferredJvmType.setFinal(source.isFinal()); JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source); if (typeRefToObject != null) inferredJvmType.getSuperTypes().add(typeRefToObject); } else { inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause)); inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
result.setInterface(clazz.isInterface()); result.setStrictFloatingPoint(Modifier.isStrict(clazz.getModifiers())); setTypeModifiers(clazz, result); setVisibility(clazz, result); result.internalSetIdentifier(clazz.getName()); result.setSimpleName(clazz.getSimpleName()); if (clazz.getDeclaringClass() == null && clazz.getPackage() != null) result.setPackageName(clazz.getPackage().getName()); TypeVariable<?>[] typeParameters = clazz.getTypeParameters(); if (typeParameters.length != 0) { InternalEList<JvmTypeParameter> jvmTypeParameters = (InternalEList<JvmTypeParameter>)result.getTypeParameters(); for (TypeVariable<?> variable : typeParameters) { jvmTypeParameters.addUnique(createTypeParameter(variable, result));
JvmFeature container) { final JvmGenericType inferredType = typesFactory.createJvmGenericType(); inferredType.setSimpleName(localClassName); inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass)); inferredType.setFinal(true); inferredType.setVisibility(JvmVisibility.DEFAULT); inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass)); container.getLocalClasses().add(inferredType); associator.associatePrimary(anonymousClass, inferredType);
/** Replies if the given JVM element is a SARL skill. * * @param type the JVM type to test. * @return {@code true} if the given type is a SARL skill, or not. * @since 0.6 */ public boolean isSarlSkill(JvmGenericType type) { return !type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_SKILL; }
protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) { inferredJvmType.setVisibility(source.getVisibility()); inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source)); inferredJvmType.setAbstract(true); inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint()); translateAnnotationsTo(source.getAnnotations(), inferredJvmType); for (JvmTypeReference intf : source.getExtends()) { inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf)); } fixTypeParameters(inferredJvmType); for (XtendMember member : source.getMembers()) { if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) { transform(member, inferredJvmType, false); } } jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType); nameClashResolver.resolveNameClashes(inferredJvmType); }
@Override public void setImplementedInterfaces(final Iterable<? extends TypeReference> superInterfaces) { this.checkMutable(); ConditionUtils.checkIterable(superInterfaces, "superIntefaces"); ConditionUtils.checkInferredTypeReferences("implemented interface", ((TypeReference[])Conversions.unwrapArray(superInterfaces, TypeReference.class))); final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> { return Boolean.valueOf(((it.getType() instanceof JvmGenericType) && ((JvmGenericType) it.getType()).isInterface())); }; final Iterable<JvmTypeReference> oldInterfaces = IterableExtensions.<JvmTypeReference>filter(this.getDelegate().getSuperTypes(), _function); CollectionExtensions.<JvmTypeReference>removeAll(this.getDelegate().getSuperTypes(), oldInterfaces); final Function1<TypeReference, JvmTypeReference> _function_1 = (TypeReference it) -> { return this.getCompilationUnit().toJvmTypeReference(it); }; Iterables.<JvmTypeReference>addAll(this.getDelegate().getSuperTypes(), IterableExtensions.map(superInterfaces, _function_1)); }
@Override public void apply(final JvmGenericType it) { EmfParsleyDslJvmModelInferrer.this.setSuperClassTypeAndFields(it, viewerContentProvider, TableViewerContentProvider.class); EList<JvmMember> _members = it.getMembers(); JvmConstructor _constructorWithInjectedAdapterFactory = EmfParsleyDslJvmModelInferrer.this.toConstructorWithInjectedAdapterFactory(viewerContentProvider); EmfParsleyDslJvmModelInferrer.this._jvmTypesBuilder.<JvmConstructor>operator_add(_members, _constructorWithInjectedAdapterFactory); EmfParsleyDslJvmModelInferrer.this.inferContentProviderElements(it, viewerContentProvider.getElements()); } };
/** * Infers the {@link Consumer} implementation class from a {@link Pattern}. */ public JvmDeclaredType inferProcessorClass(final Pattern pattern, final boolean isPrelinkingPhase, final String processorPackageName, final JvmType matchClass, final JvmTypeReferenceBuilder builder, final JvmAnnotationReferenceBuilder annBuilder, final EMFPatternLanguageGeneratorConfig config) { this.builder = builder; this.annBuilder = annBuilder; final Procedure1<JvmGenericType> _function = (JvmGenericType it) -> { EMFPatternLanguageGeneratorConfig.MatcherGenerationStrategy _matcherGenerationStrategy = config.getMatcherGenerationStrategy(); boolean _equals = Objects.equal(_matcherGenerationStrategy, EMFPatternLanguageGeneratorConfig.MatcherGenerationStrategy.NESTED_CLASS); it.setStatic(_equals); it.setPackageName(processorPackageName); this._eMFJvmTypesBuilder.setDocumentation(it, this._javadocInferrer.javadocProcessorClass(pattern).toString()); it.setAbstract(true); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = this.builder.typeRef(Consumer.class, this.builder.typeRef(matchClass)); this._eMFJvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef); this._eMFJvmTypesBuilder.setFileHeader(it, this._eMFPatternLanguageJvmModelInferrerUtil.getFileComment(pattern)); }; final JvmGenericType processorClass = this._eMFJvmTypesBuilder.toClass(pattern, this._eMFPatternLanguageJvmModelInferrerUtil.processorClassName(pattern, config.getMatcherGenerationStrategy()), _function); return processorClass; }
public JvmTypeReference getArgument(JvmTypeReference left, int index) { if (left.getType() instanceof JvmGenericType) { List<JvmTypeParameter> typeParameters = ((JvmGenericType) left.getType()).getTypeParameters(); if (typeParameters.size() <= index) { throw new IllegalArgumentException("The type " + left.getType().getIdentifier() + " cannot be parameterized with more than " + typeParameters.size() + " type arguments."); } if (left instanceof JvmParameterizedTypeReference) { List<JvmTypeReference> arguments = ((JvmParameterizedTypeReference) left).getArguments(); if (arguments.size() == typeParameters.size()) { return arguments.get(index); } } final JvmTypeParameter jvmTypeParameter = typeParameters.get(index); return createTypeRef(jvmTypeParameter); } throw new IllegalArgumentException(left.getType().getIdentifier() + " is not generic."); }
@Override public void apply(final JvmGenericType it) { it.setPackageName(processorPackageName); CharSequence _javadocProcessorClass = PatternMatchProcessorClassInferrer.this._javadocInferrer.javadocProcessorClass(pattern); String _string = _javadocProcessorClass.toString(); PatternMatchProcessorClassInferrer.this._eMFJvmTypesBuilder.setDocumentation(it, _string); it.setAbstract(true); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = PatternMatchProcessorClassInferrer.this.builder.typeRef(matchClass); JvmTypeReference _typeRef_1 = PatternMatchProcessorClassInferrer.this.builder.typeRef(IMatchProcessor.class, _typeRef); PatternMatchProcessorClassInferrer.this._eMFJvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef_1); } };
EList<JvmMember> _members_4 = it.getMembers(); final Procedure1<JvmField> _function_7 = (JvmField it_1) -> { it_1.setFinal(true); EList<JvmMember> _members_4 = it.getMembers(); final Procedure1<JvmField> _function_7 = (JvmField it_1) -> { it_1.setFinal(true); JvmField _field_3 = this._eMFJvmTypesBuilder.toField(pattern, "embeddedParameters", this.builder.typeRef(List.class, this.builder.typeRef(PParameter.class)), _function_7); this._eMFJvmTypesBuilder.<JvmField>operator_add(_members_4, _field_3); it.setVisibility(JvmVisibility.PRIVATE); EList<JvmTypeReference> _superTypes = it.getSuperTypes(); JvmTypeReference _typeRef = this.builder.typeRef(BaseGeneratedEMFPQuery.class); this._eMFJvmTypesBuilder.<JvmTypeReference>operator_add(_superTypes, _typeRef); EList<JvmMember> _members_5 = it.getMembers(); final Procedure1<JvmConstructor> _function_8 = (JvmConstructor it_1) -> { StringConcatenationClient _client = new StringConcatenationClient() { JvmConstructor _constructor = this._eMFJvmTypesBuilder.toConstructor(call, _function_8); this._eMFJvmTypesBuilder.<JvmConstructor>operator_add(_members_5, _constructor); EList<JvmMember> _members_6 = it.getMembers(); final Procedure1<JvmOperation> _function_9 = (JvmOperation it_1) -> { EList<JvmAnnotationReference> _annotations = it_1.getAnnotations(); JvmOperation _method = this._eMFJvmTypesBuilder.toMethod(call, "getFullyQualifiedName", this.builder.typeRef(String.class), _function_9); this._eMFJvmTypesBuilder.<JvmOperation>operator_add(_members_6, _method); EList<JvmMember> _members_7 = it.getMembers(); final Procedure1<JvmOperation> _function_10 = (JvmOperation it_1) -> { EList<JvmAnnotationReference> _annotations = it_1.getAnnotations();