use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class DispatchHelper method compare.
protected int compare(JvmOperation o1, JvmOperation o2) {
int params = o1.getParameters().size();
for (int i = 0; i < params; i++) {
final JvmTypeReference p1 = o1.getParameters().get(i).getParameterType();
final JvmTypeReference p2 = o2.getParameters().get(i).getParameterType();
int distance1 = p1 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p1);
int distance2 = p2 == null ? Integer.MAX_VALUE : getMaxDistanceToObject(p2);
if (distance1 != distance2) {
return distance2 - distance1;
}
}
String identifier1 = o1.getIdentifier();
String parameterTypes1 = identifier1.substring(identifier1.indexOf('('));
String identifier2 = o2.getIdentifier();
String parameterTypes2 = identifier2.substring(identifier2.indexOf('('));
return parameterTypes1.compareTo(parameterTypes2);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method computeFieldName.
/* @Nullable */
protected String computeFieldName(XtendField field) {
if (field.getName() != null)
return field.getName();
JvmTypeReference type = field.getType();
String name = null;
if (type != null) {
while (type instanceof JvmGenericArrayTypeReference) {
type = ((JvmGenericArrayTypeReference) type).getComponentType();
}
if (type instanceof JvmParameterizedTypeReference) {
List<INode> nodes = NodeModelUtils.findNodesForFeature(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
if (!nodes.isEmpty()) {
String typeName = nodes.get(0).getText().trim();
int lastDot = typeName.lastIndexOf('.');
if (lastDot != -1) {
typeName = typeName.substring(lastDot + 1);
}
name = "_" + Strings.toFirstLower(typeName);
}
}
}
return name;
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transform.
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()) {
translateParameter(constructor, parameter);
}
copyAndFixTypeParameters(source.getTypeParameters(), constructor);
for (JvmTypeReference exception : source.getExceptions()) {
constructor.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
}
translateAnnotationsTo(source.getAnnotations(), constructor);
setBody(constructor, source.getExpression());
jvmTypesBuilder.copyDocumentationTo(source, constructor);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method transform.
protected void transform(XtendFunction source, JvmGenericType container, boolean allowDispatch) {
JvmOperation operation = typesFactory.createJvmOperation();
operation.setAbstract(source.isAbstract());
operation.setNative(source.isNative());
operation.setSynchronized(source.isSynchonized());
operation.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!source.isAbstract())
operation.setFinal(source.isFinal());
container.getMembers().add(operation);
associator.associatePrimary(source, operation);
String sourceName = source.getName();
JvmVisibility visibility = source.getVisibility();
if (allowDispatch && source.isDispatch()) {
if (source.getDeclaredVisibility() == null)
visibility = JvmVisibility.PROTECTED;
sourceName = "_" + sourceName;
}
operation.setSimpleName(sourceName);
operation.setVisibility(visibility);
operation.setStatic(source.isStatic());
if (!operation.isAbstract() && !operation.isStatic() && container.isInterface())
operation.setDefault(true);
for (XtendParameter parameter : source.getParameters()) {
translateParameter(operation, parameter);
}
XExpression expression = source.getExpression();
CreateExtensionInfo createExtensionInfo = source.getCreateExtensionInfo();
JvmTypeReference returnType = null;
if (source.getReturnType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(source.getReturnType());
} else if (createExtensionInfo != null) {
returnType = jvmTypesBuilder.inferredType(createExtensionInfo.getCreateExpression());
} else if (expression != null) {
returnType = jvmTypesBuilder.inferredType(expression);
} else {
returnType = jvmTypesBuilder.inferredType();
}
operation.setReturnType(returnType);
copyAndFixTypeParameters(source.getTypeParameters(), operation);
for (JvmTypeReference exception : source.getExceptions()) {
operation.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
}
translateAnnotationsTo(source.getAnnotations(), operation);
if (source.isOverride() && generatorConfig.getJavaSourceVersion().isAtLeast(JAVA6) && !containsAnnotation(operation, Override.class) && typeReferences.findDeclaredType(Override.class, source) != null) {
operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(Override.class));
}
if (createExtensionInfo != null) {
transformCreateExtension(source, createExtensionInfo, container, operation, returnType);
} else {
setBody(operation, expression);
}
jvmTypesBuilder.copyDocumentationTo(source, operation);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendClassImpl method basicSetExtends.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetExtends(JvmTypeReference newExtends, NotificationChain msgs) {
JvmTypeReference oldExtends = extends_;
extends_ = newExtends;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtendPackage.XTEND_CLASS__EXTENDS, oldExtends, newExtends);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
Aggregations