protected JvmType getType(Class<?> class1, Notifier context) { return typeReferences.findDeclaredType(class1, context); }
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param ctx * an EMF context, which is used to look up the {@link org.eclipse.xtext.common.types.JvmType} for the * given clazz. * @param typeName * the name of the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} * * @deprecated use {@link JvmTypeReferenceBuilder#typeRef(String, JvmTypeReference...)} */ @Deprecated public JvmTypeReference newTypeRef(EObject ctx, String typeName, JvmTypeReference... typeArgs) { return references.getTypeForName(typeName, ctx, typeArgs); }
public boolean accept(JvmTypeReference superType, int distance) { JvmTypeReference arraySuperType = references.createArrayType(superType); boolean result = !outerCollecting[0]; if (!outerCollecting[0] || (result = original.accept(arraySuperType, distance))) { outerCollecting[0] = true; } if (references.is(superType, Object.class)) { outerCollecting[0] = true; result = original.accept(superType, distance + 1) || result; result = original.accept(references.getTypeForName(Serializable.class, superType.getType()), distance + 1) || result; result = original.accept(references.getTypeForName(Cloneable.class, superType.getType()), distance + 1) || result; } return result; } };
public JvmTypeReference getTypeForName(String typeName, Notifier context, JvmTypeReference... params) { if (typeName == null) throw new NullPointerException("typeName"); JvmType declaredType = findDeclaredType(typeName, context); if (declaredType == null) return getUnknownTypeReference(typeName); JvmParameterizedTypeReference result = createTypeRef(declaredType, params); return result; }
public JvmType getPrimitiveTypeIfWrapper(JvmDeclaredType type) { if (typeReferences.is(type, Byte.class)) { return typeReferences.findDeclaredType(Byte.TYPE, type); } else if (typeReferences.is(type, Short.class)) { return typeReferences.findDeclaredType(Short.TYPE, type); } else if (typeReferences.is(type, Character.class)) { return typeReferences.findDeclaredType(Character.TYPE, type); } else if (typeReferences.is(type, Integer.class)) { return typeReferences.findDeclaredType(Integer.TYPE, type); } else if (typeReferences.is(type, Long.class)) { return typeReferences.findDeclaredType(Long.TYPE, type); } else if (typeReferences.is(type, Float.class)) { return typeReferences.findDeclaredType(Float.TYPE, type); } else if (typeReferences.is(type, Double.class)) { return typeReferences.findDeclaredType(Double.TYPE, type); } else if (typeReferences.is(type, Boolean.class)) { return typeReferences.findDeclaredType(Boolean.TYPE, type); } else if (typeReferences.is(type, Void.class)) { return typeReferences.findDeclaredType(Void.TYPE, type); } return null; }
public boolean isInstanceOf(JvmTypeReference reference, Class<?> clazz) { if (isNullOrProxy(reference)) return false; if (is(reference, clazz)) { return true; } Set<JvmTypeReference> types = superTypeCollector.collectSuperTypes(reference); for (JvmTypeReference jvmTypeReference : types) { if (is(jvmTypeReference, clazz)) return true; } return false; }
@SuppressWarnings({"checkstyle:booleanexpressioncomplexity", "checkstyle:cyclomaticcomplexity"}) private boolean isEqualityTestValidField(JvmTypeReference reference) { for (final Class<?> type : EQUALITY_TEST_TYPES) { if (this.typeReferences.is(reference, type)) { return true; } } return false; }
private JvmTypeReference innerFindType(Notifier context, String typeName) { final IJvmTypeProvider provider = getTypeResolutionContext(); JvmType type = null; if (provider != null) { type = provider.findTypeByName(typeName); } TypeReferences typeRefs = getTypeReferences(); if (type == null) { type = typeRefs.findDeclaredType(typeName, context); } if (type == null) { return null; } return typeRefs.createTypeRef(type); }
protected void completeJvmEnumerationType(JvmEnumerationType element) { if (element.getSuperTypes().isEmpty()) { JvmTypeReference objectType = references.getTypeForName(Enum.class, element, references.createTypeRef(element)); if (objectType != null) element.getSuperTypes().add(objectType); values.setStatic(true); values.setSimpleName("values"); values.setReturnType(references.createArrayType(references.createTypeRef(element))); typeExtensions.setSynthetic(values, true); if (primarySourceElement != null) { valueOf.setStatic(true); valueOf.setSimpleName("valueOf"); valueOf.setReturnType(references.createTypeRef(element)); JvmFormalParameter param = typesFactory.createJvmFormalParameter(); param.setName("name"); param.setParameterType(references.getTypeForName(String.class, element)); valueOf.getParameters().add(param); typeExtensions.setSynthetic(valueOf, true);
&& this.typeReferences.findDeclaredType(Override.class, source) != null) { addAnnotationSafe(operation, Override.class); final boolean hasExplicitPureAnnotation = this.annotationFinder.findAnnotation(operation, Pure.class) != null; if (context != null && context.getGeneratorConfig2().isGeneratePureAnnotation() && !hasExplicitPureAnnotation && this.typeReferences.findDeclaredType(Pure.class, source) != null) { addDynamicPureAnnotationGenerator = inheritedOperation == null; if (addDynamicPureAnnotationGenerator) { operation2.setReturnType(this.typeReferences.createDelegateTypeReference(selectedReturnType)); } else { operation2.setReturnType(cloneWithTypeParametersAndProxies(selectedReturnType, operation2)); setBody(operation2, it -> { final JvmTypeReference type = operation2.getReturnType(); if (!SARLJvmModelInferrer.this.typeReferences.is(type, void.class)) { it.append("return "); //$NON-NLS-1$ && SARLJvmModelInferrer.this.annotationFinder.findAnnotation(operation, Override.class) == null && SARLJvmModelInferrer.this.typeReferences.findDeclaredType( Override.class, source) != null) { addAnnotationSafe(
/** * @return a fresh {@link JvmMultiTypeReference} pointing to the given references or null if {@link Object} is not * on the context's class path */ public JvmMultiTypeReference createMultiTypeReference(Notifier context, JvmTypeReference... references) { if (context == null) throw new NullPointerException("context"); JvmMultiTypeReference result = factory.createJvmMultiTypeReference(); if (references != null && references.length != 0) { for (JvmTypeReference reference : references) { result.getReferences().add(createDelegateTypeReference(reference)); } } final JvmType findDeclaredType = findDeclaredType(Object.class, context); if (findDeclaredType == null) return null; result.setType(findDeclaredType); return result; }
/** * Creates a new {@link JvmTypeReference} pointing to the given class and containing the given type arguments. * * @param type * the type the reference shall point to. * @param typeArgs * type arguments * @return the newly created {@link JvmTypeReference} * * @deprecated use {@link JvmTypeReferenceBuilder#typeRef(JvmType, JvmTypeReference...)} */ @Deprecated public JvmTypeReference newTypeRef(JvmType type, JvmTypeReference... typeArgs) { return references.createTypeRef(type, typeArgs); }
protected void translateParameter(JvmExecutable executable, XtendParameter parameter) { JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter(); jvmParam.setName(parameter.getName()); if (parameter.isVarArg()) { executable.setVarArgs(true); JvmGenericArrayTypeReference arrayType = typeReferences.createArrayType(jvmTypesBuilder .cloneWithProxies(parameter.getParameterType())); jvmParam.setParameterType(arrayType); } else { jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType())); } associator.associate(parameter, jvmParam); translateAnnotationsTo(parameter.getAnnotations(), jvmParam); if (parameter.isExtension() && typeReferences.findDeclaredType(Extension.class, parameter) != null) { jvmParam.getAnnotations().add(_annotationTypesBuilder.annotationRef(Extension.class)); } executable.getParameters().add(jvmParam); }
@Override public void apply(final JvmGenericType it) { EmfParsleyDslJvmModelInferrer.this.setSuperClassTypeAndFields(it, proposalCreator, ProposalCreator.class); EList<FeatureAssociatedExpression> _proposalsSpecifications = proposalCreator.getProposalsSpecifications(); for (final FeatureAssociatedExpression specification : _proposalsSpecifications) { final Procedure2<JvmOperation, FeatureAssociatedExpression> _function = new Procedure2<JvmOperation, FeatureAssociatedExpression>() { @Override public void apply(final JvmOperation it, final FeatureAssociatedExpression spec) { EList<JvmFormalParameter> _parameters = it.getParameters(); JvmFormalParameter _parameter = EmfParsleyDslJvmModelInferrer.this._jvmTypesBuilder.toParameter(spec, "it", spec.getParameterType()); EmfParsleyDslJvmModelInferrer.this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters, _parameter); EList<JvmFormalParameter> _parameters_1 = it.getParameters(); JvmFormalParameter _parameter_1 = EmfParsleyDslJvmModelInferrer.this._jvmTypesBuilder.toParameter(spec, "feature", EmfParsleyDslJvmModelInferrer.this._typeReferenceBuilder.typeRef(EStructuralFeature.class)); EmfParsleyDslJvmModelInferrer.this._jvmTypesBuilder.<JvmFormalParameter>operator_add(_parameters_1, _parameter_1); } }; EmfParsleyDslJvmModelInferrer.this.featureAssociatedExpressionToMethod(it, specification, "proposals_", EmfParsleyDslJvmModelInferrer.this._typeReferences.createTypeRef(EmfParsleyDslJvmModelInferrer.this._typeReferenceBuilder.typeRef(List.class).getType(), EmfParsleyDslJvmModelInferrer.this._typeReferences.wildCard()), _function); } } };
final JvmTypeParameter param = typeParameterIdentifiers.get(id); if (param != null) { return typeReferences.createTypeRef(param); return typeReferences.createDelegateTypeReference(superTypeReference);
/** * @return an array type of the given type reference. Add one dimension if the given {@link JvmTypeReference} is * already an array. */ /* @Nullable */ public JvmTypeReference addArrayTypeDimension(/* @Nullable */ JvmTypeReference componentType) { return references.createArrayType(componentType); }
@Override public TypeReference newWildcardTypeReference(final TypeReference upperBound) { TypeReference _xifexpression = null; if ((upperBound == null)) { _xifexpression = this.compilationUnit.toTypeReference(this.compilationUnit.getTypeReferences().wildCard()); } else { _xifexpression = this.compilationUnit.toTypeReference(this.compilationUnit.getTypeReferences().wildCardExtends(this.compilationUnit.toJvmTypeReference(upperBound))); } return _xifexpression; }
@Override public TypeReference newWildcardTypeReferenceWithLowerBound(final TypeReference lowerBound) { TypeReference _xifexpression = null; if ((lowerBound == null)) { _xifexpression = this.compilationUnit.toTypeReference(this.compilationUnit.getTypeReferences().wildCard()); } else { _xifexpression = this.compilationUnit.toTypeReference(this.compilationUnit.getTypeReferences().wildCardSuper(this.compilationUnit.toJvmTypeReference(lowerBound))); } return _xifexpression; }
reference = delegate; JvmWildcardTypeReference wildCard = typeReferences.wildCard(); JvmUpperBound upperBound = typesFactory.createJvmUpperBound(); wildCard.getConstraints().add(upperBound);
/** Infer the return type for the given source function. * * @param source the source function. * @param target the target operation. * @param overriddenOperation reference to the overridden operation. * @return the inferred return type. * @since 0.7 */ protected JvmTypeReference inferFunctionReturnType(XtendFunction source, JvmOperation target, JvmOperation overriddenOperation) { // The return type is explicitly given if (source.getReturnType() != null) { return ensureValidType(source.eResource(), source.getReturnType()); } // An super operation was detected => reuse its return type. if (overriddenOperation != null) { final JvmTypeReference type = overriddenOperation.getReturnType(); //return cloneWithProxiesFromOtherResource(type, target); return this.typeReferences.createDelegateTypeReference(type); } // Return type is inferred from the operation's expression. final XExpression expression = source.getExpression(); JvmTypeReference returnType = null; if (expression != null && ((!(expression instanceof XBlockExpression)) || (!((XBlockExpression) expression).getExpressions().isEmpty()))) { returnType = inferFunctionReturnType(expression); } return ensureValidType(source.eResource(), returnType); }