/** * Convert an OCCI action to an Ecore operation. * * @param action * the OCCI action to convert. * @return the resulting Ecore operation. */ protected EOperation convertAction(Action action) { // Create the Ecore operation. EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation(); // Set the name of the Ecore operation. eOperation.setName(ConverterUtils.formatName(action.getTerm())); // Convert all attributes of the OCCI action. for (Attribute attribute : action.getAttributes()) { // Each OCCI attribute of the OCCI action is converted to an Ecore // parameter of the Ecore operation. EParameter convertParameter = convertParameter(attribute); if (convertParameter != null) { // Add the Ecore parameter to the Ecore operation. eOperation.getEParameters().add(convertParameter); } } attachInfo(eOperation, action.getTitle()); return eOperation; }
/** * Convert an OCCI action's attribute to an Ecore operation parameter. * * @param attribute * the OCCI attribute to convert. * @return the resulting Ecore operation parameter. */ protected EParameter convertParameter(Attribute attribute) { // Create an Ecore parameter. EParameter eParam = EcoreFactory.eINSTANCE.createEParameter(); // Set the name of the Ecore parameter. eParam.setName(Occi2Ecore.convertOcciAttributeName2EcoreAttributeName(attribute.getName())); // Set the type of the Ecore parameter. eParam.setEType(getMappedType(attribute.getType())); // If the OCCI attribute is required then the Ecore parameter is also // required. if (attribute.isRequired()) { eParam.setLowerBound(1); } attachInfo(eParam, attribute.getDescription()); return eParam; }
@Override public String visitVariableExp(VariableExp<EClassifier, EParameter> v) { ++counter; oclTranslation.append("% Lookup for variable " + v.getName() + "\n"); String predName = "nVariable" + counter + constraintName; oclTranslation.append(predName); oclTranslation.append("(_, Vars, Result):-"); oclTranslation.append("\n\t"); oclTranslation.append("ocl_variable(Vars,"); int index = varStack.search(v.getName()); if (index < 0) { logger.writeErrorMessage(this.getClass().toString(), "Internal error: Variable " + v.getName() + " not found"); } oclTranslation.append(index); oclTranslation.append(",Result).\n"); return predName; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public boolean isOverrideOf(EOperation someOperation) { if (someOperation.getEContainingClass().isSuperTypeOf(getEContainingClass()) && someOperation.getName().equals(getName())) { EList<EParameter> parameters = getEParameters(); EList<EParameter> otherParameters = someOperation.getEParameters(); if (parameters.size() == otherParameters.size()) { for (Iterator<EParameter> i = parameters.iterator(), j = otherParameters.iterator(); i.hasNext(); ) { EParameter parameter = i.next(); EParameter otherParameter = j.next(); if (!parameter.getEType().getInstanceTypeName().equals(otherParameter.getEType().getInstanceTypeName())) { return false; } } return true; } } return false; }
/** * Text for EOperation. * * @param eOperation * the EOperation * @return the name and types of all EParameters */ protected String text(final EOperation eOperation) { return eOperation.getName() + "(" + Joiner.on(", ").join(Iterables.transform(eOperation.getEParameters(), new Function<EParameter, String>() { public String apply(final EParameter input) { return getText(input.getEType()); } })) + ") : " + (eOperation.getEType() == null ? "Void" : getText(eOperation.getEType())); }
private void extendWith(EClass c, EOperation op) { if ( op.getEType() == null ) { // Operations without return type cannot be invoked in ATL return; } ContextHelper helper = ATLFactory.eINSTANCE.createContextHelper(); helper.getCommentsBefore().add(EOPERATION_TAG); OclFeatureDefinition fd = OCLFactory.eINSTANCE.createOclFeatureDefinition(); OclContextDefinition ctx = OCLFactory.eINSTANCE.createOclContextDefinition(); Operation oclOp = OCLFactory.eINSTANCE.createOperation(); ctx.setContext_(createType(c, false)); fd.setContext_(ctx); fd.setFeature(oclOp); oclOp.setName(op.getName()); oclOp.setReturnType(createType(op.getEType(), op.isMany())); oclOp.setBody( OCLFactory.eINSTANCE.createJavaBody() ); for(EParameter p : op.getEParameters()) { Parameter pnew = OCLFactory.eINSTANCE.createParameter(); pnew.setVarName(p.getName()); pnew.setType(createType(p.getEType(), p.isMany())); oclOp.getParameters().add(pnew); } helper.setDefinition(fd); if ( unit instanceof Module ) { ((Module) unit).getElements().add(helper); } else if ( unit instanceof Library ) { ((Library) unit).getHelpers().add(helper); } else { // Ignore } }
@Override public EList<EParameter> getEParameters() { List<Parameter> paramList = origOperation.getOwnedParameters(); EList<EParameter> result = new BasicEList<EParameter>(); if (! paramList.isEmpty()){ for (Parameter param : paramList) if (param.getDirection() != ParameterDirectionKind.RETURN_LITERAL) result.add(((EResourceUMLAdapter)owningResource).getParamIfNotExists(new EParameterUMLAdapter(param,owningResource))); } return result; }
public EParameter getParamIfNotExists(EParameter param){ Assert.isNotNull(param); for (EParameter par : loadedParameters) if (par.equals(param)) return par; loadedParameters.add(param); return param; }
@Override public String visitExpressionInOCL(ExpressionInOCL<EClassifier, EParameter> expression) { constraintName = ((Constraint)expression.eContainer()).getName(); oclTranslation = new StringBuilder(); oclTranslation.append("% OCL constraint " + expression.getBodyExpression().toString() + "\n" ); varStack = new Stack<String>(); firstPredicate = ""; counter = 0; return super.visitExpressionInOCL(expression); }
@Override public String visitIteratorExp(IteratorExp<EClassifier, EParameter> callExp) { List<String> variableResults; EList<Variable<EClassifier, EParameter>> variables = callExp.getIterator(); if (variables.isEmpty()) { variableResults = Collections.emptyList(); } else { variableResults = new java.util.ArrayList<String>(variables.size()); } Iterator<Variable<EClassifier, EParameter>> it = variables.iterator(); return processIterators(callExp, it, variableResults); }
@Override protected String handleIteratorExp(IteratorExp<EClassifier, EParameter> callExp, String sourceResult, List<String> variableResults, String bodyResult) { String itName = callExp.getName(); //String type = itName.equalsIgnoreCase("forAll") ? "Boolean" : getType(callExp); ++counter; String predName = "n" + itName + counter + constraintName; oclTranslation.append(predName); oclTranslation.append("(Instances, Vars, Result):-"); oclTranslation.append("\n\t"); oclTranslation.append(sourceResult); oclTranslation.append("(Instances, Vars, Value1),"); oclTranslation.append("\n\t"); oclTranslation.append("ocl_"); if (itName.equals("collect") || itName.equals("select") || itName.equals("reject") || itName.equals("collectNested") || itName.equals("sortedBy")) { //FIXME: this is a dirty bug fix oclTranslation.append("bag"); oclTranslation.append("_"); } else oclTranslation.append("col_"); oclTranslation.append(itName); oclTranslation.append("(Instances, Vars, Value1, "); oclTranslation.append(bodyResult); oclTranslation.append(", Result).\n"); return predName; }
@Override protected String handleExpressionInOCL(ExpressionInOCL<EClassifier, EParameter> callExp, String contextResult, String resultResult, List<String> parameterResults, String bodyResult) { String predName = constraintName.substring(0,1).toLowerCase().concat(constraintName.substring(1, constraintName.length())); setConstraintFirstPredicate(bodyResult); oclTranslation.append(predName); oclTranslation.append("(Instances):-"); oclTranslation.append("\n\t"); oclTranslation.append(bodyResult); oclTranslation.append("(Instances, [], Result),"); oclTranslation.append("\n\t"); oclTranslation.append("Result #=1.\n"); return oclTranslation.toString(); }
public Variable<EClassifier, EParameter> visitVariableExp(VariableExp<EClassifier, EParameter> v) { Variable<EClassifier, EParameter> referredVar = v.getReferredVariable(); if ("self".equals(referredVar.getName())) { result = referredVar; } return result; }
/** * Add quantification for self variable if required. * @param helper * @param contextCls The context of this expression (i.e., the type of "self") * @param oclExpression The OCL expression to be extended * @throws ParserException */ @SuppressWarnings("rawtypes") private void insertQuantificationForSelf(OCLHelper<EClassifier, EOperation, EStructuralFeature, Constraint> helper, EClass contextCls, ExpressionInOCL oclExpression) throws ParserException { /* TODO: This method inserts the quantification for "self" only if this variable * occurs. This is working and practical. * However, the precise semantics of OCL would require that self is always quantified. * In the long term, a switch for EMFtoCSP should be added. */ OCLExpression bodyExp = oclExpression.getBodyExpression(); LookupSelfVariableVisitor lookupVisitor = new LookupSelfVariableVisitor(); bodyExp.accept(lookupVisitor); Variable<EClassifier, EParameter> selfDecl = lookupVisitor.getResult(); if (selfDecl != null) { System.err.println("Adding required self variable quantification"); EcorePackage oclPackage = (EcorePackage) oclExpression.eClass().getEPackage(); EcoreFactory oclFactory = (EcoreFactory) oclPackage.getEFactoryInstance(); IteratorExp forAllExp = oclFactory.createIteratorExp(); forAllExp.setName("forAll"); forAllExp.setType((EClassifier) bodyExp.getType()); selfDecl.setName("self"); selfDecl.setType(contextCls); forAllExp.getIterator().add(selfDecl); forAllExp.setBody(bodyExp); helper.setContext(contextCls); OCLExpression<EClassifier> allInstancesExp = helper.createQuery(contextCls.getName() + ".allInstances()"); forAllExp.setSource(allInstancesExp); oclExpression.setBodyExpression(forAllExp); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<EParameter> getEParameters() { if (eParameters == null) { eParameters = new EObjectContainmentWithInverseEList<EParameter>(EParameter.class, this, EcorePackage.EOPERATION__EPARAMETERS, EcorePackage.EPARAMETER__EOPERATION); } return eParameters; }
private EParameter internalAddEParameter(EOperation owner, EClassifier type, String name) { EParameter p = ecoreFactory.createEParameter(); p.setEType(type); p.setName(name); owner.getEParameters().add(p); return p; }
protected EParameter addEParameter(EOperation owner, EClassifier type, String name, int lowerBound, int upperBound, boolean isUnique, boolean isOrdered) { EParameter p = internalAddEParameter(owner, type, name); p.setLowerBound(lowerBound); p.setUpperBound(upperBound); p.setUnique(isUnique); p.setOrdered(isOrdered); return p; }
@Deprecated protected void addEParameter(EOperation owner, EGenericType type, String name, int lowerBound, int upperBound) { EParameter p = ecoreFactory.createEParameter(); p.setEGenericType(type); p.setName(name); owner.getEParameters().add(p); p.setLowerBound(lowerBound); p.setUpperBound(upperBound); }
protected void addEParameter(EOperation owner, EGenericType type, String name, int lowerBound, int upperBound, boolean isUnique, boolean isOrdered) { EParameter p = ecoreFactory.createEParameter(); p.setEGenericType(type); p.setName(name); owner.getEParameters().add(p); p.setLowerBound(lowerBound); p.setUpperBound(upperBound); p.setUnique(isUnique); p.setOrdered(isOrdered); }
private String getBody(final EOperation op) { final StringBuffer buff = new StringBuffer(); if (op.getEType() != null) { buff.append("return "); } buff.append(getExtensionClassName(op)).append("."); buff.append(op.getName()); buff.append("("); final List<EParameter> params = op.getEParameters(); for (final Iterator<EParameter> iter = params.iterator(); iter.hasNext();) { final EParameter element = iter.next(); buff.append(element.getName()); } return buff.append("this);").toString(); }
public static org.eclipse.emf.ecore.EParameter findEParameterById(java.util.List<org.eclipse.emf.ecore.EParameter> list, String id){ for (EParameter obji : list) { if (getEParameterId(obji).equals(id)) return obji; } return null; }
/** * @generated */ private static void initCustomEnv( Environment<?, EClassifier, ?, ?, ?, EParameter, ?, ?, ?, ?, ?, ?> ecoreEnv, Map<String, EClassifier> environment) { // Use EObject as implicit root class for any object, to allow eContainer() and other EObject operations from OCL expressions ParsingOptions .setOption(ecoreEnv, ParsingOptions.implicitRootClass(ecoreEnv), EcorePackage.eINSTANCE.getEObject()); for (String varName : environment.keySet()) { EClassifier varType = environment.get(varName); ecoreEnv.addElement(varName, createVar(ecoreEnv, varName, varType), false); } }
/** * @generated */ private static void initCustomEnv(Environment<?, EClassifier, ?, ?, ?, EParameter, ?, ?, ?, ?, ?, ?> ecoreEnv, Map<String, EClassifier> environment) { // Use EObject as implicit root class for any object, to allow eContainer() and other EObject operations from OCL expressions ParsingOptions.setOption(ecoreEnv, ParsingOptions.implicitRootClass(ecoreEnv), EcorePackage.eINSTANCE.getEObject()); for (String varName : environment.keySet()) { EClassifier varType = environment.get(varName); ecoreEnv.addElement(varName, createVar(ecoreEnv, varName, varType), false); } }
public void createViewFilterLinks() { for (Filter viewpointFilter : viewpointFilters) { // Part 1: Execute the ocl query. if (!viewpointFilter.isFilterOnlyEstructuralFeatures()) { String oclQuery = viewpointFilter.getOclQuery(); OCL<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, org.eclipse.ocl.ecore.Constraint, EClass, EObject> ocl; ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE); // create an OCL helper object helper = ocl.createOCLHelper(); try { // En el caso que el query sea un allInstances toca crear un extentMap // para su evaluacion. (Lo que pasa es que en el caso que estoy usando // no hay condiciones que se apliquen sobre el allInstances) // TODO El extentMap se necesita solo si el ocl es un allInstances. ocl.setExtentMap(createExtentMapHelper(viewpointFilter)); OCLExpression<EClassifier> parsedQuery = helper.createQuery(oclQuery); Query<EClassifier, EClass, EObject> theQueryCreatedByOcl = ocl.createQuery(parsedQuery); Object objectsToFilter = theQueryCreatedByOcl.evaluate(); if (objectsToFilter instanceof Collection) { Collection<EObject> objs = (Collection<EObject>) objectsToFilter; createFilterLinks(objs, viewpointFilter); } else if (objectsToFilter instanceof EObject) { createFilterLink((EObject) objectsToFilter, viewpointFilter); } // Part 2: Generate the link. } catch (ParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
private VariableDeclaration transform( Variable<EClassifier, EParameter> variable) { System.err.println("Not done yet"); return null; }
public void bind(Variable<EClassifier, EParameter> v1, VariableDeclaration tgt) { vars.put(v1, tgt); }
public VariableDeclaration get(Variable<EClassifier, EParameter> v1) { if ( ! vars.containsKey(v1)) throw new IllegalStateException("No var: " + v1); return vars.get(v1); }
@Override public abstract EList<EParameter> getEParameters();
public EResourceUMLAdapter(UMLResource newResource) { super(newResource); loadedClasses = new BasicEList<EClassifier>(); loadedParameters = new BasicEList<EParameter>(); }
public static OclToEcl getInstance(ILogger logger) { Environment<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, EClass, EObject> auxEnv = EcoreEnvironmentFactory.INSTANCE.createEnvironment(); return new OclToEcl(auxEnv, logger); }
public static OclToEcl getInstance( Environment<?, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, ?, ?> env, ILogger logger) { return new OclToEcl(env, logger); }
protected OclToEcl(Environment<?, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, ?, ?> env, ILogger logger) { this.env = env; uml = (env == null) ? null : env.getUMLReflection(); this.logger = logger; }
@Override protected String handleVariable(Variable<EClassifier, EParameter> variable, String initResult) { return ""; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case EcorePackage.EOPERATION__EANNOTATIONS: getEAnnotations().clear(); getEAnnotations().addAll((Collection<? extends EAnnotation>)newValue); return; case EcorePackage.EOPERATION__NAME: setName((String)newValue); return; case EcorePackage.EOPERATION__ORDERED: setOrdered((Boolean)newValue); return; case EcorePackage.EOPERATION__UNIQUE: setUnique((Boolean)newValue); return; case EcorePackage.EOPERATION__LOWER_BOUND: setLowerBound((Integer)newValue); return; case EcorePackage.EOPERATION__UPPER_BOUND: setUpperBound((Integer)newValue); return; case EcorePackage.EOPERATION__ETYPE: setEType((EClassifier)newValue); return; case EcorePackage.EOPERATION__EGENERIC_TYPE: setEGenericType((EGenericType)newValue); return; case EcorePackage.EOPERATION__ETYPE_PARAMETERS: getETypeParameters().clear(); getETypeParameters().addAll((Collection<? extends ETypeParameter>)newValue); return; case EcorePackage.EOPERATION__EPARAMETERS: getEParameters().clear(); getEParameters().addAll((Collection<? extends EParameter>)newValue); return; case EcorePackage.EOPERATION__EEXCEPTIONS: getEExceptions().clear(); getEExceptions().addAll((Collection<? extends EClassifier>)newValue); return; case EcorePackage.EOPERATION__EGENERIC_EXCEPTIONS: getEGenericExceptions().clear(); getEGenericExceptions().addAll((Collection<? extends EGenericType>)newValue); return; } eDynamicSet(featureID, newValue); }