org.eclipse.uml2.uml.Behavior Java Examples

The following examples show how to use org.eclipse.uml2.uml.Behavior. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TxtUMLElementsRegistry.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the roots elements of all reports 
 * @return
 */
public List<Triple<DiagramType, String, Element>> getDiagramRootsWithDiagramNames(){
	List<Triple<DiagramType, String, Element>> roots = new ArrayList<>();
	for(Pair<String, DiagramExportationReport> pair : this.descriptor.getReportsWithDiagramNames()){
		DiagramExportationReport report = pair.getSecond();
		String name = report.getReferencedElementName();
		DiagramType type = report.getType();
		if(type.equals(DiagramType.Class)){
			findElement(report.getModelName()).ifPresent(
					e -> roots.add(new Triple<>(type, pair.getFirst(), e))
				);
		}else if(type.equals(DiagramType.StateMachine)){
			Optional<Element> classOfStatemachine =  findElement(name);
			if(classOfStatemachine.isPresent()){
				Behavior behavior =  ((org.eclipse.uml2.uml.BehavioredClassifier) classOfStatemachine.get()).getClassifierBehavior();
				roots.add(new Triple<>(type, pair.getFirst(), behavior));
			}
		} else if(type.equals(DiagramType.Composite)) {
			Optional<Element> classOfComposite = findElement(name);
			if(classOfComposite.isPresent()){
				roots.add(new Triple<>(type, pair.getFirst(), classOfComposite.get()));
			}
		}
	}
	return roots;
}
 
Example #2
Source File: TransitionExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
String createTransitionFunctionsDef() {
	StringBuilder source = new StringBuilder("");
	for (Transition transition : transitions) {
		ActivityExportResult activityResult = new ActivityExportResult();
		Behavior b = transition.getEffect();
		String setState = createSetState(transition);
		activityResult = activityExporter.createFunctionBody((Activity) b);

		
		source.append(StateMachineTemplates.transitionActionDef(owner.getUnitName(), transition.getName(),
				transition.getName(), activityResult.getActivitySource() + setState,
				hasChoiceTarget(transition) || activityResult.sourceHasSignalReference()));
	}
	source.append("\n");
	return source.toString();
}
 
Example #3
Source File: LeakTest.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void _testLeak3() throws Exception {
    Properties creationSettings = new Properties();
    creationSettings.setProperty(IRepository.ENABLE_EXTENSIONS, Boolean.TRUE.toString());
    creationSettings.setProperty(IRepository.ENABLE_LIBRARIES, Boolean.TRUE.toString());
    IRepository repo = MDDCore.createRepository(URI
            .createURI("file:///C:/Users/rafael/AppData/Local/Temp/kirra/perf2"));
    org.eclipse.uml2.uml.Class employeeClass = repo.findNamedElement("expenses::Employee", Literals.CLASS, null);
    Operation activeEmployeesOperation = employeeClass.getOperation("activeEmployees", null, null, true);
    assertEquals(1, activeEmployeesOperation.getMethods().size());
    Behavior method = activeEmployeesOperation.getMethods().get(0);
    Behavior closure = method.getOwnedBehaviors().get(0);
    assertEquals(1, closure.getStereotypeApplications().size());
    assertTrue(StereotypeUtils.hasStereotype(closure, "mdd_extensions::Closure"));
    repo.dispose();
    showMemory("after test");
}
 
Example #4
Source File: StateMachineUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static Map<Operation, List<Vertex>> findStateSpecificOperations(BehavioredClassifier classifier) {
    Map<Operation, List<Vertex>> result = new LinkedHashMap<Operation, List<Vertex>>();
    EList<Behavior> behaviors = classifier.getOwnedBehaviors();
    for (Behavior behavior : behaviors)
        if (behavior instanceof StateMachine)
            for (Vertex state : getStates((StateMachine) behavior))
                for (Transition transition : state.getOutgoings())
                    for (Trigger trigger : transition.getTriggers())
                        if (trigger.getEvent() instanceof CallEvent) {
                            Operation triggerOperation = ((CallEvent) trigger.getEvent()).getOperation();
                            List<Vertex> supportedStates = result.get(triggerOperation);
                            if (supportedStates == null)
                                result.put(triggerOperation, supportedStates = new LinkedList<Vertex>());
                            supportedStates.add(state);
                        }
    return result;
}
 
Example #5
Source File: ConstraintUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean hasParameterConstraints(Parameter parameter) {
       List<Constraint> operationConstraints = parameter.getOperation().getPreconditions();
	for (Constraint constraint : operationConstraints) {
           Behavior constraintBehavior = ActivityUtils.resolveBehaviorReference(constraint.getSpecification());
           List<Parameter> constraintInputParameters = FeatureUtils.getInputParameters(constraintBehavior.getOwnedParameters());
           if (constraintInputParameters.size() == 1) {
           	// we can't handle constraints on multiple parameters
           	Optional<Parameter> matchingParameter = constraintInputParameters.stream().filter(it -> 
           		constraintBehavior.getOwnedParameter(parameter.getName(), parameter.getType()) != null
   			).findAny();
           	if (matchingParameter.isPresent())
           		return true;
           }
	}
       return false;
}
 
Example #6
Source File: ConstraintUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns all constraints that apply to the given operation parameter.
 * 
 * @param parameter
 * @return
 */
public static List<Constraint> getParameterConstraints(Parameter parameter) {
       List<Constraint> operationConstraints = parameter.getOperation().getPreconditions();
       List<Constraint> result = new LinkedList<>();
	for (Constraint constraint : operationConstraints) {
           Behavior constraintBehavior = ActivityUtils.resolveBehaviorReference(constraint.getSpecification());
           List<Parameter> constraintInputParameters = FeatureUtils.getInputParameters(constraintBehavior.getOwnedParameters());
           if (constraintInputParameters.size() == 1) {
           	// we can't handle constraints on multiple parameters
           	Optional<Parameter> matchingParameter = constraintInputParameters.stream().filter(it -> 
           		constraintBehavior.getOwnedParameter(parameter.getName(), parameter.getType()) != null
   			).findAny();
           	if (matchingParameter.isPresent()) {
           		result.add(constraint);
           	}
           }
	}
       return result;
}
 
Example #7
Source File: CppExporterUtils.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
public static Activity getOperationActivity(Operation operation) {
	Activity activity = null;
	for (Behavior behavior : operation.getMethods()) {

		if (behavior.eClass().equals(UMLPackage.Literals.ACTIVITY)) {
			activity = (Activity) behavior;
			break;
		}
	}

	return activity;
}
 
Example #8
Source File: MDDUtil.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String computeSignatureName(Type type) {
    if (type instanceof Behavior)
        return computeSignatureName(((Behavior) type).getOwnedParameters());
    if (MDDExtensionUtils.isSignature(type))
        return computeSignatureName(MDDExtensionUtils.getSignatureParameters(type));
    return null;
}
 
Example #9
Source File: MDDUtil.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String getTypeName(Type type) {
    if (type == null)
        return "<any>";
    if (type.getName() != null)
        return type.getName();
    if (type instanceof Behavior)
        return computeSignatureName(type);
    if (MDDExtensionUtils.isSignature(type))
        return computeSignatureName(type);
    return "Unknown " + type.eClass().getName();
}
 
Example #10
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static BehavioredClassifier getBehaviorContext(Behavior behavior) {
    BehavioredClassifier standardContext = behavior.getContext();
    if (standardContext instanceof Behavior) {
        BehavioredClassifier contextsContext = getContext((Behavior) standardContext);
        if (contextsContext != null)
            return contextsContext;
    }
    if (standardContext == null && (behavior.getOwner() instanceof BehavioredClassifier))
        // bug in UML2? During a tycho build, a behavior owned by a
        // behaviored classifier would be null sometimes
        return (BehavioredClassifier) behavior.getOwner();
    return standardContext;
}
 
Example #11
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Activity getActivity(Operation operation) {
    List<Behavior> methods = operation.getMethods();
    if (methods.isEmpty())
        return null;
    Behavior method = methods.get(0);
    if (!(method instanceof Activity))
        return null;
    return (Activity) method;
}
 
Example #12
Source File: AbstractGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
protected SignatureProcessor newSignatureProcessor(Namespace target) {
    if (target instanceof Behavior)
        return new BehaviorSignatureProcessor(sourceContext, (Behavior) target);
    if (target instanceof BehavioralFeature)
        return new BehavioralFeatureSignatureProcessor(sourceContext, (BehavioralFeature) target);
    throw new IllegalArgumentException("" + target);
}
 
Example #13
Source File: ClassRenderer.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean renderObject(Class element, IndentedPrintWriter w, IRenderingSession session) {
    boolean renderedClass = session.getSettings().getBoolean(SHOW_CLASSES)
            && super.renderObject(element, w, session);
    List<Behavior> stateMachines = element.getOwnedBehaviors().stream().filter(it -> it instanceof StateMachine)
            .collect(Collectors.toList());
    return renderedClass | RenderingUtils.renderAll(session, stateMachines);
}
 
Example #14
Source File: UMLBehaviorImpl.java    From ifml-editor with MIT License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case CorePackage.UML_BEHAVIOR__BEHAVIOR:
			setBehavior((Behavior)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #15
Source File: UMLBehaviorImpl.java    From ifml-editor with MIT License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case CorePackage.UML_BEHAVIOR__BEHAVIOR:
			setBehavior((Behavior)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #16
Source File: ActivityExporter.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
public ActivityExportResult createFunctionBody(Behavior behavior) {
	if(behavior != null && behavior.eClass().equals(UMLPackage.Literals.ACTIVITY)) {
		return createFunctionBody((Activity) behavior);
	} else {
		return ActivityExportResult.emptyResult();
	}
}
 
Example #17
Source File: UMLBehaviorImpl.java    From ifml-editor with MIT License 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setBehavior(Behavior newBehavior) {
	Behavior oldBehavior = behavior;
	behavior = newBehavior;
	if (eNotificationRequired())
		eNotify(new ENotificationImpl(this, Notification.SET, CorePackage.UML_BEHAVIOR__BEHAVIOR, oldBehavior, behavior));
}
 
Example #18
Source File: TransitionRenderer.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private String getEffectLabel(Behavior effect) {
    if (effect == null)
        return "";
    StructuredActivityNode rootAction = ActivityUtils.getRootAction((Activity) effect);
    List<Action> statements = ActivityUtils.findStatements(rootAction);
    ActivityGenerator activityGenerator = new ActivityGenerator();
    List<String> textumlStatements = statements.stream()
            .map(statement -> activityGenerator.generateAction(statement).toString()).collect(Collectors.toList());
    return " / " + StringUtils.join(textumlStatements, "; ");
}
 
Example #19
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static Behavior resolveBehaviorReference(Action action) {
    Assert.isLegal(action instanceof ValueSpecificationAction, "Not a behavior reference action: "
            + action.eClass().getName());
    return (Activity) resolveBehaviorReference(((ValueSpecificationAction) action).getValue());
}
 
Example #20
Source File: EntryExitFunctionExporter.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
private void createFuncTypeMap(FuncTypeEnum funcType) {
	List<EntryExitFunctionDescription> functionList = new LinkedList<EntryExitFunctionDescription>();
	for (State item : stateList) {
		String source = "";
		String name = "";
		Behavior behavior = null;
		String unknownName = null;
		switch (funcType) {
		case Entry: {
			behavior = item.getEntry();
			unknownName = unknownEntryName;
			break;
		}
		case Exit: {
			behavior = item.getExit();
			unknownName = unknownExitName;
			break;
		}
		}
		ActivityExportResult activityResult = new ActivityExportResult();
		activityResult = activityExporter.createFunctionBody(behavior);

		if (item.isComposite()) {
			String compositeRelatedCode = "";
			switch (funcType) {
			case Entry:
				compositeRelatedCode = ActivityTemplates.simpleIf(HierarchicalStateMachineNames.CurrentMachineName,
						ActivityTemplates.operationCallOnPointerVariable(HierarchicalStateMachineNames.CurrentMachineName,
								StateMachineMethodNames.InitializeFunctionName,
								Arrays.asList(EventTemplates.EventFParamName)));
				source = activityResult.getActivitySource() + compositeRelatedCode;

				break;
			case Exit:
				compositeRelatedCode = ActivityTemplates.simpleIf(HierarchicalStateMachineNames.CurrentMachineName,
						ActivityTemplates.operationCallOnPointerVariable(HierarchicalStateMachineNames.CurrentMachineName,
								StateMachineMethodNames.FinalizeFunctionName,
								Arrays.asList(EventTemplates.EventFParamName)));
				source = compositeRelatedCode + activityResult.getActivitySource();
				break;
			default:
				break;
			}

		} else {
			source = activityResult.getActivitySource();
		}
		if (source != "") {
			name = item.getName() + "_" + unknownName;
			functionList.add(new EntryExitFunctionDescription(item.getName(), name, source,
					item.isComposite() || activityResult.sourceHasSignalReference()));

		}
	}

	if (funcType == FuncTypeEnum.Entry) {
		entryList = functionList;
	} else if (funcType == FuncTypeEnum.Exit) {
		exitList = functionList;
	}

}
 
Example #21
Source File: FeatureUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isParametrizedConstraint(Constraint constraint) {
    Behavior toExecute = ActivityUtils.resolveBehaviorReference(constraint.getSpecification());
    return toExecute.getOwnedParameters().size() > 1;
}
 
Example #22
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static Constraint getBehaviorConstraint(Behavior toCheck) {
	return (Constraint) StereotypeUtils.getValue(toCheck, CONSTRAINT_BEHAVIOR_STEREOTYPE, CONSTRAINT_BEHAVIOR_CONSTRAINT_PROPERTY);
}
 
Example #23
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isConstraintBehavior(Behavior toCheck) {
	return StereotypeUtils.hasStereotype(toCheck, CONSTRAINT_BEHAVIOR_STEREOTYPE);
}
 
Example #24
Source File: CallActionsDetector.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
private boolean threreIsSyncrhonCall(String currentClass, String concurrentClass) {
	Class from = getClassFromUMLModel(currentClass);
	Class to = getClassFromUMLModel(concurrentClass);

	if (!isInAssoc(from, to)) {
		Logger.sys.info(from.getName() + " and " + to.getName() + " is not in assoc");
		return false;
	} else {
		Logger.sys.info(from.getName() + " and " + to.getName() + " is in assoc");
		// Detect syncrhon call
		for (Behavior b : from.getOwnedBehaviors()) {

			if (b.eClass().equals(UMLPackage.Literals.STATE_MACHINE)) {

				StateMachine fromSM = (StateMachine) b;
				Region fromR = fromSM.getRegion(from.getName());
				for (Vertex vertex : fromR.getSubvertices()) {
					if (vertex.eClass().equals(UMLPackage.Literals.STATE)) {
						State state = (State) vertex;
						Behavior entry = state.getEntry();
						Behavior exit = state.getExit();
						if (entry != null) {
							containsCallOperationForClass(entry, to);
						}
						if (exit != null) {
							containsCallOperationForClass(exit, to);
						}
					}
				}

				for (Transition trans : fromR.getTransitions()) {

					Behavior fromEffect = trans.getEffect();
					if (fromEffect != null) {
						if (containsCallOperationForClass(fromEffect, to)) {
							return true;
						}
					}
				}

			} else if (b.eClass().equals(UMLPackage.Literals.ACTIVITY)) {
				if (containsCallOperationForClass(b, to)) {
					return true;
				}

			}
		}

		return false;
	}

}
 
Example #25
Source File: CallActionsDetector.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
boolean containsCallOperationForClass(Behavior behavior, Class cls) {

		for (Element elem : behavior.allOwnedElements()) {

			if (elem.eClass().getName().equals("CallOperationAction")) {

				CallOperationAction action = (CallOperationAction) elem;

				if (action.getTarget().getType().equals(cls)) {
					return true;

				}
			}
		}

		return false;
	}
 
Example #26
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
@Deprecated
public static BehavioredClassifier getContext(Behavior behavior) {
    return getBehaviorContext(behavior);
}
 
Example #27
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static Behavior resolveBehaviorReference(ValueSpecification spec) {
    Assert.isLegal(isBehaviorReference(spec), "Not a behavior reference: " + spec);
    return ((OpaqueExpression) spec).getBehavior();
}
 
Example #28
Source File: TypeUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns whether two types are compatible. Optionally, takes template
 * parameter substitutions into account.
 * 
 * @param repository
 * @param source
 * @param destination
 * @param substitutions
 *            a list of template parameter substitutions, or
 *            <code>null</code>
 * @return
 */
public static boolean isCompatible(IBasicRepository repository, Type source, Type destination,
        ParameterSubstitutionMap substitutions) {
    if (destination == null
            || destination == repository.findNamedElement(ANY_TYPE, IRepository.PACKAGE.getClass_(), null)
            || source == repository.findNamedElement(NULL_TYPE, IRepository.PACKAGE.getClass_(), null))
        return true;
    if (source == null)
        return false;
    if (source == destination)
        return true;
    // do not check if wildcard
    if (MDDExtensionUtils.isWildcardType(destination))
        return true;
    Boolean templateCompatible = null;
    // if destination is actually a template parameter, test compatibility
    // with the resolved parameter
    if (substitutions != null && destination.isTemplateParameter()) {
        Type actualDestination = (Type) substitutions.resolveTemplateParameter(destination);
        return actualDestination == null ? false : isCompatible(repository, source, actualDestination,
                substitutions);
    }
    if ((source instanceof TemplateableElement) && !(destination instanceof TemplateableElement)) {
        if (((TemplateableElement) source).isTemplate())
            return false;
    } else if (!(source instanceof TemplateableElement) && (destination instanceof TemplateableElement)) {
        if (((TemplateableElement) destination).isTemplate())
            return false;
    } else if (source instanceof TemplateableElement && destination instanceof TemplateableElement) {
        final TemplateableElement templateableSource = (TemplateableElement) source;
        final TemplateableElement templateableDestination = (TemplateableElement) destination;
        if (templateableSource.isTemplate() != templateableDestination.isTemplate())
            // one of them is a template, the other is not, cannot be
            // compatible
            return false;
        if (templateableSource.isTemplate())
            // if both are templates, general conformance checking should be
            // enough
            return source.conformsTo(destination);
        // if both are bound elements, use template-aware conformance
        // checking
        if (!templateableSource.getTemplateBindings().isEmpty()
                || !templateableDestination.getTemplateBindings().isEmpty())
            templateCompatible = TemplateUtils.isCompatible(templateableSource, templateableDestination);
    }
    // behavior comparison takes parameters into account
    if (source instanceof Behavior || MDDExtensionUtils.isSignature(source)) {
        if (!MDDExtensionUtils.isSignature(destination))
            return false;
        final List<Parameter> destinationParams;
        final List<Parameter> sourceParams;
        if (source instanceof Behavior)
            sourceParams = ((Behavior) source).getOwnedParameters();
        else
            // source is not an inlined closure
            // (note this is currently not supported, see issue #50)
            sourceParams = MDDExtensionUtils.getSignatureParameters(source);
        destinationParams = MDDExtensionUtils.getSignatureParameters(destination);
        return isCompatible(repository, sourceParams.toArray(new Parameter[sourceParams.size()]),
                destinationParams.toArray(new Parameter[destinationParams.size()]), substitutions);
    }
    // for data types, we perform shape-based compatibility check
    if (destination instanceof DataType && source instanceof Classifier) {
        List<Property> destinationAttributes = ((Classifier) destination).getAllAttributes();
        List<Property> sourceAttributes = ((Classifier) source).getAllAttributes();
        if (destinationAttributes.size() != sourceAttributes.size())
            return false;
        for (int i = 0; i < sourceAttributes.size(); i++) {
            // if any defines a property name, names must match
            String destinationName = StringUtils.trimToNull(destinationAttributes.get(i).getName());
            String sourceName = StringUtils.trimToNull(sourceAttributes.get(i).getName());
            if (destinationName != null && sourceName != null && !destinationName.equals(sourceName))
                return false;
            if (!isCompatible(repository, sourceAttributes.get(i), destinationAttributes.get(i), substitutions))
                return false;
        }
        return true;
    }
    if (Boolean.TRUE.equals(templateCompatible))
        // if they are deemed template compatible, go with that -
        // conformance doesn't understand templates
        return true;
    // general type conformance
    return source.conformsTo(destination);
}
 
Example #29
Source File: BehaviorSignatureProcessor.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
private Behavior getBehavior() {
    return (Behavior) parent;
}
 
Example #30
Source File: BehaviorSignatureProcessor.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public BehaviorSignatureProcessor(SourceCompilationContext<Node> sourceContext, Behavior parent) {
    super(sourceContext, parent, false);
}