net.sf.nakeduml.javageneration.oclexpressions.ConstrainedImplementor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metamodel Show documentation
Show all versions of metamodel Show documentation
A uml code generator and execution engine
The newest version!
package net.sf.nakeduml.javageneration.oclexpressions;
import net.sf.nakeduml.feature.visit.VisitAfter;
import net.sf.nakeduml.feature.visit.VisitBefore;
import net.sf.nakeduml.javageneration.AbstractJavaProducingVisitor;
import net.sf.nakeduml.javageneration.JavaTransformationPhase;
import net.sf.nakeduml.javageneration.util.OJUtil;
import net.sf.nakeduml.javametamodel.OJClass;
import net.sf.nakeduml.javametamodel.OJClassifier;
import net.sf.nakeduml.javametamodel.OJPathName;
import net.sf.nakeduml.metamodel.core.INakedClassifier;
import net.sf.nakeduml.metamodel.core.INakedConstraint;
import net.sf.nakeduml.metamodel.core.INakedTypedElement;
import net.sf.nakeduml.metamodel.models.INakedModel;
import net.sf.nakeduml.util.Constrained;
import net.sf.nakeduml.util.IInvariantError;
import nl.klasse.octopus.codegen.umlToJava.modelgenerators.visitors.UtilityCreator;
/**
* This class implements the Constrained interface on classes that have invariants.
*/
public class ConstrainedImplementor extends AbstractJavaProducingVisitor{
private static final OJPathName CONSTRAINED = new OJPathName(Constrained.class.getName());
@VisitBefore()
public void visitModel(INakedModel p){
if(JavaTransformationPhase.IS_RUNTIME_AVAILABLE){
super.javaModel.findClass(new OJPathName(UtilityCreator.getUtilPathName() + ".InvariantError")).addToImplementedInterfaces(
new OJPathName(IInvariantError.class.getName()));
}
}
@VisitAfter(matchSubclasses = true)
public void visitClass(INakedClassifier c){
OJPathName path = OJUtil.classifierPathname(c);
OJClassifier ojClassifier = this.javaModel.findIntfOrCls(path);
if(ojClassifier instanceof OJClass && c instanceof INakedClassifier){
INakedClassifier nc = c;
if(hasInvariants(nc)){
OJClass ojClass = (OJClass) ojClassifier;
ojClass.addToImplementedInterfaces(CONSTRAINED);
}
}
}
private boolean hasInvariants(INakedClassifier nc){
for(INakedConstraint c:nc.getOwnedRules()){
if(!(c.getConstrainedElement() instanceof INakedTypedElement)){
return true;
}
}
return false;
}
}