use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class MutableJvmInterfaceDeclarationImpl method setExtendedInterfaces.
@Override
public void setExtendedInterfaces(final Iterable<? extends TypeReference> superinterfaces) {
this.checkMutable();
ConditionUtils.checkIterable(superinterfaces, "superinterfaces");
this.getDelegate().getSuperTypes().clear();
for (final TypeReference typeRef : superinterfaces) {
{
boolean _isInferred = typeRef.isInferred();
if (_isInferred) {
throw new IllegalArgumentException("Cannot use inferred type as extended interface.");
}
EList<JvmTypeReference> _superTypes = this.getDelegate().getSuperTypes();
JvmTypeReference _jvmTypeReference = this.getCompilationUnit().toJvmTypeReference(typeRef);
_superTypes.add(_jvmTypeReference);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class MutableJvmInterfaceDeclarationImpl method addTypeParameter.
@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
this.checkMutable();
ConditionUtils.checkJavaIdentifier(name, "name");
ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
param.setName(name);
this.getDelegate().getTypeParameters().add(param);
for (final TypeReference upper : upperBounds) {
{
final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
jvmUpperBound.setTypeReference(typeRef);
param.getConstraints().add(jvmUpperBound);
}
}
TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class AnnotationValidation method isValidAnnotationValueType.
public boolean isValidAnnotationValueType(final JvmTypeReference reference) {
JvmTypeReference _switchResult = null;
boolean _matched = false;
if (reference instanceof JvmGenericArrayTypeReference) {
_matched = true;
_switchResult = ((JvmGenericArrayTypeReference) reference).getComponentType();
}
if (!_matched) {
_switchResult = reference;
}
final JvmTypeReference toCheck = _switchResult;
if ((toCheck == null)) {
return true;
}
JvmType _type = toCheck.getType();
if ((_type instanceof JvmPrimitiveType)) {
return true;
}
JvmType _type_1 = toCheck.getType();
if ((_type_1 instanceof JvmEnumerationType)) {
return true;
}
JvmType _type_2 = toCheck.getType();
if ((_type_2 instanceof JvmAnnotationType)) {
return true;
}
if ((Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.String") || Objects.equal(toCheck.getType().getQualifiedName(), "java.lang.Class"))) {
return true;
}
return false;
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transformCreateExtension.
protected void transformCreateExtension(XtendFunction source, CreateExtensionInfo createExtensionInfo, JvmGenericType container, JvmOperation operation, /* @Nullable */
JvmTypeReference returnType) {
JvmField cacheVar = jvmTypesBuilder.toField(source, CREATE_CHACHE_VARIABLE_PREFIX + source.getName(), jvmTypesBuilder.inferredType());
if (cacheVar != null) {
cacheVar.setFinal(true);
jvmTypesBuilder.setInitializer(cacheVar, compileStrategies.forCacheVariable(source));
container.getMembers().add(cacheVar);
JvmOperation initializer = typesFactory.createJvmOperation();
container.getMembers().add(initializer);
initializer.setSimpleName(CREATE_INITIALIZER_PREFIX + source.getName());
initializer.setVisibility(JvmVisibility.PRIVATE);
initializer.setReturnType(typeReferences.getTypeForName(Void.TYPE, source));
for (JvmTypeReference exception : source.getExceptions()) {
initializer.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
}
jvmTypesBuilder.setBody(operation, compileStrategies.forCacheMethod(createExtensionInfo, cacheVar, initializer));
// the first parameter is the created object
JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
jvmParam.setName(createExtensionInfo.getName());
// TODO consider type parameters
jvmParam.setParameterType(jvmTypesBuilder.inferredType());
initializer.getParameters().add(jvmParam);
associator.associate(createExtensionInfo, jvmParam);
// add all others
for (XtendParameter parameter : source.getParameters()) {
jvmParam = typesFactory.createJvmFormalParameter();
jvmParam.setName(parameter.getName());
jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
initializer.getParameters().add(jvmParam);
associator.associate(parameter, jvmParam);
}
associator.associate(source, initializer);
setBody(operation, createExtensionInfo.getCreateExpression());
setBody(initializer, source.getExpression());
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (!Strings.isEmpty(field.getName())) {
JvmOperation operation = typesFactory.createJvmOperation();
associator.associatePrimary(member, operation);
operation.setSimpleName(field.getName());
JvmTypeReference returnType = null;
XExpression initialValue = field.getInitialValue();
if (field.getType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
} else if (initialValue != null) {
returnType = jvmTypesBuilder.inferredType(initialValue);
}
operation.setReturnType(returnType);
if (initialValue != null) {
JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
if (jvmAnnotationValue != null) {
operation.setDefaultValue(jvmAnnotationValue);
jvmAnnotationValue.setOperation(operation);
}
jvmTypesBuilder.setBody(operation, initialValue);
}
operation.setVisibility(JvmVisibility.PUBLIC);
translateAnnotationsTo(member.getAnnotations(), operation);
jvmTypesBuilder.copyDocumentationTo(member, operation);
inferredJvmType.getMembers().add(operation);
}
}
}
}
Aggregations