@Override public Object caseEClass(EClass object) { Type type = getType(object); if (object.isInterface()) { } else { // class Class clazz = (Class) type; clazz.setAbstract(object.isAbstract()); } Set<Type> assocAndGen = new HashSet<>(); Set<Type> dependencies = new HashSet<>(); for (EClass eSuperType : object.getESuperTypes()) { Type superType = getType(eSuperType); assocAndGen.add(superType); if (eSuperType.isInterface()) { type.addInterface((Interface) superType); } else { type.addSuperClass((Class) superType); } } for (EStructuralFeature eFeature : object.getEStructuralFeatures()) { Attribute attr = (Attribute) doSwitch(eFeature); type.addAttribute(attr); assocAndGen.add(attr.type); } for (EOperation eOperation : object.getEOperations()) { Operation op = (Operation) doSwitch(eOperation); type.addOperation(op); dependencies.add(op.type); for (TypedElement fpar : op.formalParameters()) { dependencies.add(fpar.type); } } dependencies.removeAll(assocAndGen); for (Type dep : dependencies) { type.addDependency(dep); } return type; }
public static Collection<EClass> getConcreteEClasses(Collection<EClass> eClasses) { for (Iterator<EClass> it = eClasses.iterator(); it.hasNext(); ) { EClass nextEClass = it.next(); if (nextEClass != null && (nextEClass.isAbstract() || nextEClass.isInterface())) { it.remove(); } } return eClasses; }
private static void includeClass( EClassifier classifier, boolean includeInterfaces, boolean includeAbstracts, Set<EClass> result) { if (classifier instanceof EClass) { EClass eClass = (EClass) classifier; if (eClass.isInterface() && !includeInterfaces) return; if (eClass.isAbstract() && !includeAbstracts) return; result.add(eClass); } }
@Override public Object visit( VariableDeclarationExpression variableDeclarationExpression, TypeResolutionContext context, EolVisitorController<TypeResolutionContext, Object> controller) { // visit contents first controller.visitContents(variableDeclarationExpression, context); // if create is not null if (variableDeclarationExpression.getCreate() != null) { // get the value of the create boolean newExpression = variableDeclarationExpression.getCreate().isVal(); // if it is a new variable if (newExpression) { // get resolved type Type rawType = variableDeclarationExpression.getResolvedType(); // we are interested in the model element types if (rawType instanceof ModelElementType) { // get the type ModelElementType modelElementType = (ModelElementType) rawType; // if the model element type is a EClass in the meta model if (modelElementType.getEcoreType() instanceof EClass) { // get the EClass EClass eClass = (EClass) modelElementType.getEcoreType(); // check if the class is an interface or abstract if (eClass.isAbstract() || eClass.isInterface()) { context .getLogBook() .addError( modelElementType, "Model element type is not instantiable"); // throw error } } } } } return null; }
public static Collection<EClass> filterByFeatureSeqInitializer( Collection<EClass> eClasses, FeatureSeqInitializer featureSeqInitializer) { if (featureSeqInitializer.getCreatingInitializer() != null) { EStructuralFeature feature = featureSeqInitializer.getCreatingInitializer().getFeature(); if (feature != null && feature.getEType() instanceof EClass) { for (Iterator<EClass> it = eClasses.iterator(); it.hasNext(); ) { EClass nextEClass = it.next(); EClass typeEClass = (EClass) feature.getEType(); if (nextEClass == null || nextEClass.isAbstract() || nextEClass.isInterface() || !typeEClass.isSuperTypeOf(nextEClass)) { it.remove(); } } } } else if (featureSeqInitializer.getElementClass() != null) { return Collections.singleton(featureSeqInitializer.getElementClass()); } return eClasses; }
private void mapClasses(Connection connection, boolean unmap, EClass... eClasses) { for (EClass eClass : eClasses) { if (!(eClass.isInterface() || eClass.isAbstract())) { String mappingAnnotation = DBAnnotation.TABLE_MAPPING.getValue(eClass); // TODO Maybe we should explicitly report unknown values of the annotation if (mappingAnnotation != null && mappingAnnotation.equalsIgnoreCase(DBAnnotation.TABLE_MAPPING_NONE)) { continue; } if (!unmap) { // TODO Bugzilla 296087: Before we go ahead with creation, we should check if it's already // there IClassMapping mapping = createClassMapping(eClass); getStore().getDBAdapter().createTables(mapping.getDBTables(), connection); } else { IClassMapping mapping = removeClassMapping(eClass); getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection); } } } }
/** * Adds to the specified list of {@link IChildCreationSpecification} with the specified * information. * * <p>Also adds any sub-classes of child type. * * @param specs the list of specifications to add to * @param parent the parent object * @param ref the reference * @param childType the child type * @param index TODO */ public static void addToChildCreationSpecification( final List<IChildCreationSpecification> specs, EObject parent, EReference ref, final EClass childType, int index) { /* * Allow the user to prevent the addition */ final IBindingDataType dt = IBindingDataType.Factory.create(parent, ref); if (!childType.isAbstract() && !childType.isInterface() && dt.getArgument(Constants.ARG_NEW_ALLOWED, null, Boolean.class, Boolean.TRUE)) { specs.add(new ChildCreationSpecification(parent, ref, childType, index)); } final Collection<EClass> subClasses = EcoreExtendedUtils.getSubClasses(childType); if (subClasses == null) return; for (final EClass c : subClasses) { addToChildCreationSpecification(specs, parent, ref, c, index); } }
public boolean isConcrete(org.eclipse.emf.ecore.EClass eClass) { return !eClass.isAbstract() && !eClass.isInterface(); }
/** * Returns whether <code>eClass</code> can be instantiated or not. An EClass can be instantiated, * if it is neither an interface nor abstract. * * @param eClass the EClass in question * @return whether <code>eClass</code> can be instantiated or not. */ public static boolean canHaveInstance(EClass eClass) { return !eClass.isInterface() && !eClass.isAbstract(); }