use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendValidator method checkDefaultSuperConstructor.
@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
JvmGenericType inferredType = associations.getInferredType(xtendClass);
if (inferredType == null)
return;
Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
if (inferredType.getExtendedClass() != null) {
JvmType superType = inferredType.getExtendedClass().getType();
if (superType instanceof JvmGenericType) {
Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
for (JvmConstructor superConstructor : superConstructors) {
if (superConstructor.getParameters().isEmpty())
// there is a default super constructor. nothing more to check
return;
}
if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
List<String> issueData = newArrayList();
for (JvmConstructor superConstructor : superConstructors) {
issueData.add(EcoreUtil.getURI(superConstructor).toString());
issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
}
error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
} else {
for (JvmConstructor constructor : constructors) {
XExpression expression = containerProvider.getAssociatedExpression(constructor);
if (expression instanceof XBlockExpression) {
List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
EObject source = associations.getPrimarySourceElement(constructor);
error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
}
}
}
}
}
}
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendValidator method checkDuplicateAndOverriddenFunctions.
@Check
public void checkDuplicateAndOverriddenFunctions(XtendTypeDeclaration xtendType) {
final JvmDeclaredType inferredType = associations.getInferredType(xtendType);
if (inferredType instanceof JvmGenericType) {
JavaVersion targetVersion = getGeneratorConfig(xtendType).getJavaSourceVersion();
ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(inferredType, targetVersion);
Set<EObject> flaggedOperations = Sets.newHashSet();
doCheckDuplicateExecutables((JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
doCheckOverriddenMethods(xtendType, (JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
doCheckFunctionOverrides(resolvedFeatures, flaggedOperations);
}
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendValidator method checkFinalFieldInitialization.
@Check
public void checkFinalFieldInitialization(XtendInterface xtendInterface) {
JvmGenericType inferredType = associations.getInferredType(xtendInterface);
if (inferredType == null)
return;
super.checkFinalFieldInitialization(inferredType);
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class XtendValidator method checkSuperTypes.
@Check
public void checkSuperTypes(XtendInterface xtendInterface) {
for (int i = 0; i < xtendInterface.getExtends().size(); ++i) {
JvmTypeReference extendedType = xtendInterface.getExtends().get(i);
if (!isInterface(extendedType.getType())) {
error("Extended interface must be an interface", XTEND_INTERFACE__EXTENDS, i, INTERFACE_EXPECTED);
}
checkWildcardSupertype(xtendInterface, extendedType, XTEND_INTERFACE__EXTENDS, i);
}
JvmGenericType inferredType = associations.getInferredType(xtendInterface);
if (inferredType != null && hasCycleInHierarchy(inferredType, Sets.<JvmGenericType>newHashSet())) {
error("The inheritance hierarchy of " + notNull(xtendInterface.getName()) + " contains cycles", XTEND_TYPE_DECLARATION__NAME, CYCLIC_INHERITANCE);
}
}
use of org.eclipse.xtext.common.types.JvmGenericType in project xtext-xtend by eclipse.
the class TypeReferenceProviderImpl method createTypeRef.
public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) {
if ((type == null)) {
throw new NullPointerException("type");
}
final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
reference.setType(type);
for (final JvmTypeReference typeArg : typeArgs) {
reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg));
}
if ((type instanceof JvmGenericType)) {
final EList<JvmTypeParameter> list = ((JvmGenericType) type).getTypeParameters();
if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) {
String _identifier = ((JvmGenericType) type).getIdentifier();
String _plus = ("The type " + _identifier);
String _plus_1 = (_plus + " expects ");
int _size = list.size();
String _plus_2 = (_plus_1 + Integer.valueOf(_size));
String _plus_3 = (_plus_2 + " type arguments, but was ");
int _size_1 = reference.getArguments().size();
String _plus_4 = (_plus_3 + Integer.valueOf(_size_1));
String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number.");
throw new IllegalArgumentException(_plus_5);
}
}
return reference;
}
Aggregations