use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
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) {
isStatic = true;
}
}
inferredJvmType.setStatic(isStatic);
inferredJvmType.setAbstract(source.isAbstract());
inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
if (!inferredJvmType.isAbstract()) {
inferredJvmType.setFinal(source.isFinal());
}
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
JvmTypeReference extendsClause = source.getExtends();
if (extendsClause == null || extendsClause.getType() == null) {
JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
if (typeRefToObject != null)
inferredJvmType.getSuperTypes().add(typeRefToObject);
} else {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
}
for (JvmTypeReference intf : source.getImplements()) {
inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
}
fixTypeParameters(inferredJvmType);
addDefaultConstructor(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
transform(member, inferredJvmType, true);
}
}
appendSyntheticDispatchMethods(source, inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
nameClashResolver.resolveNameClashes(inferredJvmType);
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method deriveGenericDispatchOperationSignature.
/**
* @return a {@link JvmOperation} with common denominator argument types of all given operations
*/
/* @Nullable */
protected JvmOperation deriveGenericDispatchOperationSignature(Iterable<JvmOperation> localOperations, JvmGenericType target) {
final Iterator<JvmOperation> iterator = localOperations.iterator();
if (!iterator.hasNext())
return null;
JvmOperation first = iterator.next();
JvmOperation result = typesFactory.createJvmOperation();
target.getMembers().add(result);
for (int i = 0; i < first.getParameters().size(); i++) {
JvmFormalParameter parameter = typesFactory.createJvmFormalParameter();
result.getParameters().add(parameter);
parameter.setParameterType(jvmTypesBuilder.inferredType());
JvmFormalParameter parameter2 = first.getParameters().get(i);
parameter.setName(parameter2.getName());
}
jvmTypesBuilder.setBody(result, compileStrategies.forDispatcher(result));
JvmVisibility commonVisibility = null;
boolean isFirst = true;
boolean allStatic = true;
boolean override = false;
for (JvmOperation jvmOperation : localOperations) {
Iterable<XtendFunction> xtendFunctions = Iterables.filter(associations.getSourceElements(jvmOperation), XtendFunction.class);
for (XtendFunction func : xtendFunctions) {
JvmVisibility xtendVisibility = func.getDeclaredVisibility();
if (isFirst) {
commonVisibility = xtendVisibility;
isFirst = false;
} else if (commonVisibility != xtendVisibility) {
commonVisibility = null;
}
associator.associate(func, result);
if (!func.isStatic())
allStatic = false;
if (func.isOverride())
override = true;
}
for (JvmTypeReference declaredException : jvmOperation.getExceptions()) result.getExceptions().add(jvmTypesBuilder.cloneWithProxies(declaredException));
}
if (commonVisibility == null)
result.setVisibility(JvmVisibility.PUBLIC);
else
result.setVisibility(commonVisibility);
result.setStatic(allStatic);
if (override)
setOverride(result);
return result;
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkMemberNamesAreUnique.
@Check
public void checkMemberNamesAreUnique(XtendTypeDeclaration xtendType) {
final Multimap<String, XtendField> name2field = HashMultimap.create();
final Multimap<String, XtendTypeDeclaration> name2type = HashMultimap.create();
final Multimap<JvmType, XtendField> type2extension = HashMultimap.create();
for (XtendMember member : xtendType.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (isEmpty(field.getName())) {
if (field.isExtension()) {
JvmTypeReference typeReference = field.getType();
if (typeReference != null) {
JvmType type = typeReference.getType();
if (type != null)
type2extension.put(type, field);
}
}
} else {
name2field.put(field.getName(), field);
}
} else if (member instanceof XtendTypeDeclaration) {
String name = ((XtendTypeDeclaration) member).getName();
if (name != null && name.length() > 0) {
name2type.put(name, (XtendTypeDeclaration) member);
}
}
}
for (String name : name2field.keySet()) {
Collection<XtendField> fields = name2field.get(name);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate field " + name, field, XtendPackage.Literals.XTEND_FIELD__NAME, DUPLICATE_FIELD);
}
}
for (String name : name2type.keySet()) {
Collection<XtendTypeDeclaration> types = name2type.get(name);
if (types.size() > 1) {
for (XtendTypeDeclaration type : types) error("Duplicate nested type " + name, type, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, DUPLICATE_TYPE_NAME);
}
}
for (JvmType type : type2extension.keySet()) {
Collection<XtendField> fields = type2extension.get(type);
if (fields.size() > 1) {
for (XtendField field : fields) error("Duplicate extension with same type", field, XTEND_FIELD__TYPE, DUPLICATE_FIELD);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method checkNonRawTypeInferred.
@Check
public void checkNonRawTypeInferred(XtendFunction function) {
if (function.getReturnType() == null) {
JvmOperation operation = associations.getDirectlyInferredOperation(function);
// operation could have been removed by AA, thus the resource is possibly null
if (operation != null && operation.eResource() != null) {
JvmTypeReference returnType = operation.getReturnType();
validateInferredType(returnType, function, "The inferred return type ", XTEND_FUNCTION__NAME);
}
}
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendValidator method getReadableSignature.
protected String getReadableSignature(String elementName, List<JvmTypeReference> parameterTypes) {
StringBuilder result = new StringBuilder(elementName);
result.append('(');
for (int i = 0; i < parameterTypes.size(); i++) {
if (i != 0) {
result.append(", ");
}
JvmTypeReference parameterType = parameterTypes.get(i);
if (parameterType != null)
result.append(parameterType.getSimpleName());
else
result.append("null");
}
result.append(')');
return result.toString();
}
Aggregations