@Check public void checkComponentTypeIsInterfaceOrAbstract(Component component) { if (component.getModule() != null) return; JvmType actualType = component.getActualType(); if (actualType == null || actualType.eIsProxy()) return; JvmDeclaredType declaredType = (JvmDeclaredType) actualType; if (declaredType.isAbstract() || (declaredType instanceof JvmGenericType && ((JvmGenericType) declaredType).isInterface())) { error( "'" + declaredType.getQualifiedName('.') + "' is not instantiable.", component, Mwe2Package.Literals.REFERRABLE__TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ABSTRACT_OR_INTERFACE); } }
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmDeclaredType declaringType = getConstructor().getDeclaringType(); if (declaringType.isAbstract()) { String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.ABSTRACT_CLASS_INSTANTIATION, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return super.validate(result); }
@Check public void checkInstantiable(Component component) { if (component.getModule() != null) return; JvmType actualType = component.getActualType(); if (actualType == null || actualType.eIsProxy()) return; JvmDeclaredType declaredType = (JvmDeclaredType) actualType; if (!declaredType.isAbstract() && !(declaredType instanceof JvmGenericType && ((JvmGenericType) declaredType).isInterface())) { for(JvmMember member: declaredType.getMembers()) { if (member instanceof JvmConstructor) { if (((JvmConstructor) member).getParameters().isEmpty() && member.getVisibility().equals(JvmVisibility.PUBLIC)) return; } } error( "'" + declaredType.getQualifiedName('.') + "' does not have a public default constructor.", component, Mwe2Package.Literals.REFERRABLE__TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, MISSING_DEFAULT_CONSTRUCTOR); } }
public SignatureHashBuilder appendSignature(JvmDeclaredType type) { if (type.getVisibility() != JvmVisibility.PRIVATE) { appendAnnotationReferences(type); appendVisibility(type.getVisibility()).append(" "); if (type.isAbstract()) append("abstract "); if (type.isStatic()) append("static "); if (type.isFinal()) append("final "); append("class ").append(type.getIdentifier()); if (type instanceof JvmTypeParameterDeclarator) appendTypeParameters((JvmTypeParameterDeclarator) type); append("\n").appendSuperTypeSignatures(type).appendMemberSignatures(type, false); } return this; }