org.eclipse.uml2.uml.Class Java Examples

The following examples show how to use org.eclipse.uml2.uml.Class. 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: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static Class createWildcardType(Namespace context, String name) {
	Class wildcardType = ClassifierUtils.createClassifier(context, null, Literals.CLASS);
	if (context.getNearestPackage() != context) {
		ElementImport elementImport = context.createElementImport(wildcardType);
		elementImport.setAlias(name);
	}
	Stereotype constraintStereotype = StereotypeUtils.findStereotype(WILDCARD_TYPE_STEREOTYPE);
	wildcardType.applyStereotype(constraintStereotype);
	wildcardType.setValue(constraintStereotype, WILDCARD_TYPE_CONTEXT, context);

	Stereotype contextStereotype = StereotypeUtils.findStereotype(WILDCARD_TYPE_CONTEXT_STEREOTYPE);
	List<Type> newTypes;
	if (!context.isStereotypeApplied(contextStereotype)) {
		context.applyStereotype(contextStereotype);
		newTypes = new ArrayList<Type>();
	} else
		newTypes = new ArrayList<Type>(
				(List<Type>) context.getValue(contextStereotype, WILDCARD_TYPE_CONTEXT_TYPES));
	newTypes.add(wildcardType);
	context.setValue(contextStereotype, WILDCARD_TYPE_CONTEXT_TYPES, newTypes);
	return wildcardType;
}
 
Example #2
Source File: TestActionCode.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testUnlink() throws Exception {
	Model model = model("hu.elte.txtuml.export.uml2.tests.models.link_and_unlink");
	Class clsA = cls(model, "A");
	Property otherEnd = property(clsA, "OtherEnd", "B");
	Class clsB = cls(model, "B");
	Property thisEnd = property(clsB, "ThisEnd", "A");

	SequenceNode body = loadActionCode(model, "A", "testUnlink");
	SequenceNode linkStmt = node(body, 0, "unlink inst1 from inst2;", SequenceNode.class);
	node(linkStmt, 0, "inst1", ReadVariableAction.class);
	node(linkStmt, 1, "inst2", ReadVariableAction.class);
	DestroyLinkAction linkNode = node(linkStmt, 2, "unlink inst1 from inst2", DestroyLinkAction.class);
	assertEquals(thisEnd, linkNode.getEndData().get(0).getEnd());
	assertNotNull(linkNode.getEndData().get(0).getValue());
	assertEquals(otherEnd, linkNode.getEndData().get(1).getEnd());
	assertNotNull(linkNode.getEndData().get(1).getValue());
}
 
Example #3
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testAttributeStereotypeApplication() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype my_stereotype extends UML::Property end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "import base;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "class SomeClass\n";
    modelSource += "  [my_stereotype] attribute someAttribute : Integer;\n";
    modelSource += "end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClassifier(), null);
    Property attribute = class_.getAttribute("someAttribute", null);
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertTrue(attribute.isStereotypeApplied(stereotype));
}
 
Example #4
Source File: TestActionCode.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testLink() throws Exception {
	Model model = model("hu.elte.txtuml.export.uml2.tests.models.link_and_unlink");
	Class clsA = cls(model, "A");
	Property otherEnd = property(clsA, "OtherEnd", "B");
	Class clsB = cls(model, "B");
	Property thisEnd = property(clsB, "ThisEnd", "A");

	SequenceNode body = loadActionCode(model, "A", "testLink");
	SequenceNode linkStmt = node(body, 0, "link inst1 to inst2;", SequenceNode.class);
	node(linkStmt, 0, "inst1", ReadVariableAction.class);
	node(linkStmt, 1, "inst2", ReadVariableAction.class);
	CreateLinkAction linkNode = node(linkStmt, 2, "link inst1 to inst2", CreateLinkAction.class);
	assertEquals(thisEnd, linkNode.getEndData().get(0).getEnd());
	assertNotNull(linkNode.getEndData().get(0).getValue());
	assertEquals(otherEnd, linkNode.getEndData().get(1).getEnd());
	assertNotNull(linkNode.getEndData().get(1).getValue());
}
 
Example #5
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom0ToUnlimited() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "class Class1\n";
    source += "  attribute attr1 : Integer[0,*];\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class1 = getRepository().findNamedElement("simple::Class1", UMLPackage.Literals.CLASS, null);
    assertNotNull(class1);
    Property attr1 = class1.getAttribute("attr1", null);
    assertNotNull(attr1);
    assertEquals(0, attr1.getLower());
    assertEquals(LiteralUnlimitedNatural.UNLIMITED, attr1.getUpper());

    ValueSpecification lowerValue = attr1.getLowerValue();
    assertNotNull(lowerValue);
    assertTrue(lowerValue instanceof LiteralInteger);
    assertEquals(0, lowerValue.integerValue());

    ValueSpecification upperValue = attr1.getUpperValue();
    assertNotNull(upperValue);
    assertTrue(upperValue instanceof LiteralUnlimitedNatural);
    assertEquals(LiteralUnlimitedNatural.UNLIMITED, ((LiteralUnlimitedNatural) upperValue).unlimitedValue());
}
 
Example #6
Source File: WildcardTypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testOperationWildcardTypeReplacedInResult() throws CoreException {
    String model = "";
    model += "model tests;\n";
    model += "import base;\n";
    model += "class MyClass1\n";
    model += "  static operation <T> op1(par1 : T) : T;\n";
    model += "end;\n";
    model += "class MyClass2\n";
    model += "  operation op2();\n";
    model += "  begin\n";
    model += "      var local;\n";
    model += "      local := MyClass1#op1(1);\n";
    model += "  end;\n";
    model += "end;\n";
    model += "end.";
    parseAndCheck(model);

    Operation op2 = getOperation("tests::MyClass2::op2");
    StructuredActivityNode firstChild = (StructuredActivityNode) ActivityUtils.getRootAction(op2).getContainedNode(
            null, false, UMLPackage.Literals.STRUCTURED_ACTIVITY_NODE);
    Variable localVar = ActivityUtils.findVariable(firstChild, "local");
    Class integerType = getClass("mdd_types::Integer");
    assertSame(integerType, localVar.getType());
}
 
Example #7
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstraintsPerRole_BankAccount() throws CoreException {
	parseAndCheck(source);
	Class bankAccount = getClass("banking::BankAccount");
	Class branchManager = getClass("banking::BranchManager");
	Class accountManager = getClass("banking::AccountManager");
	Class teller = getClass("banking::Teller");
	
	Map<Classifier, Map<AccessCapability, Constraint>> computed = AccessControlUtils.computeConstraintsPerRoleClass(Arrays.asList(branchManager, teller, accountManager), Arrays.asList(AccessCapability.values()), Arrays.asList(bankAccount));
	assertEquals(3, computed.size());
	assertSameClasses(Arrays.asList(branchManager, accountManager, teller), computed.keySet());
	
	Map<AccessCapability, Constraint> branchManagerConstraints = computed.get(branchManager);
	Map<AccessCapability, Constraint> accountManagerConstraints = computed.get(accountManager);
	Map<AccessCapability, Constraint> tellerConstraints = computed.get(teller);
	
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Call, AccessCapability.Delete, AccessCapability.Create, AccessCapability.Call)),
			branchManagerConstraints.keySet());
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Call, AccessCapability.Delete, AccessCapability.Create, AccessCapability.Call)),
			accountManagerConstraints.keySet());
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Read, AccessCapability.List)),
			tellerConstraints.keySet());
}
 
Example #8
Source File: ReceptionTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testReception() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "  signal SimpleSignal end;\n";
    source += "  class SimpleClass\n";
    source += "    reception simpleReception(s:SimpleSignal);\n";
    source += "    begin end;\n";
    source += "  end;\n";
    source += "end.";
    parseAndCheck(source);
    Class simpleClass = getClass("simple::SimpleClass");
    Signal simpleSignal = get("simple::SimpleSignal", UMLPackage.Literals.SIGNAL);
    Reception reception = simpleClass.getOwnedReception("simpleReception", null, null);
    assertEquals(1, reception.getOwnedParameters().size());
    assertSame(simpleSignal, reception.getOwnedParameters().get(0).getType());
    assertSame(simpleSignal, reception.getSignal());
    assertEquals(1, reception.getMethods().size());
}
 
Example #9
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom1To1() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "class Class1\n";
    source += "  attribute attr1 : Integer[1,1];\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class1 = getRepository().findNamedElement("simple::Class1", UMLPackage.Literals.CLASS, null);
    assertNotNull(class1);
    Property attr1 = class1.getAttribute("attr1", null);
    assertNotNull(attr1);
    assertEquals(1, attr1.getLower());
    assertEquals(1, attr1.getUpper());

    ValueSpecification lowerValue = attr1.getLowerValue();
    assertNotNull(lowerValue);
    assertTrue(lowerValue instanceof LiteralInteger);
    assertEquals(1, lowerValue.integerValue());

    ValueSpecification upperValue = attr1.getUpperValue();
    assertNotNull(upperValue);
    assertTrue(upperValue instanceof LiteralUnlimitedNatural);
    assertEquals(1, ((LiteralUnlimitedNatural) upperValue).unlimitedValue());
}
 
Example #10
Source File: ClassExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public ClassExporter(Class structuredElement, String name, String sourceDestination) {
	super(structuredElement, name, sourceDestination);
	super.init();
	baseClasses = new LinkedList<String>();
	interfacesToImplement = new LinkedList<String>();
	constructorExporter = new ConstructorExporter(structuredElement.getOwnedOperations(), super.activityExporter);
	additionalSourcesNames = new ArrayList<String>();

	portExporter = new PortExporter(structuredElement.getOwnedPorts(), structuredElement.getName(), this);

	Optional<StateMachine> classOptionalSM = CppExporterUtils.getStateMachine(structuredElement);
	if (classOptionalSM.isPresent()) {
		stateMachineExporter = new StateMachineExporter(classOptionalSM.get(), this, this, poolId);
	}

}
 
Example #11
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testDependencyStereotypeApplication() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype my_dep_stereotype extends UML::Dependency end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "import base;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "class SomeClass\n";
    modelSource += "  [my_dep_stereotype] dependency Integer;\n";
    modelSource += "end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClassifier(), null);
    Dependency dependency = class_.getClientDependency(null);
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_dep_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertTrue(dependency.isStereotypeApplied(stereotype));
}
 
Example #12
Source File: TestStructure.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGeneralization() throws Exception {
	Model model = model("hu.elte.txtuml.export.uml2.tests.models.generalization");
	Class abstractBase = cls(model, "AbstractBaseClass");
	Operation baseMethod = operation(abstractBase, "baseMethod");
	assertTrue(baseMethod.isAbstract());

	Class concreteBase = cls(model, "ConcreteBaseClass");
	checkSubclass(concreteBase, abstractBase);
	Operation baseMethodInConcBase = operation(concreteBase, "baseMethod");
	overrides(baseMethodInConcBase, baseMethod);
	assertFalse(baseMethodInConcBase.isAbstract());
	property(concreteBase, "baseField", "Integer");

	Class concreteSub = cls(model, "ConcreteSubclass");
	checkSubclass(concreteSub, concreteBase);

	Operation baseMethodInConcSub = operation(concreteSub, "baseMethod");
	Operation newMethod = operation(concreteSub, "newMethod");
	Activity activity = (Activity) newMethod.getMethods().get(0);
	SequenceNode actBody = (SequenceNode) activity.getNode("#body");
	SequenceNode callStmt = (SequenceNode) actBody.getNode("this.baseMethod();");
	CallOperationAction callExpr = (CallOperationAction) callStmt.getNode("this.baseMethod()");
	assertEquals(baseMethodInConcSub, callExpr.getOperation());
}
 
Example #13
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testRaisedExceptions() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeException1 end;\n";
    source += "class SomeException2 end;\n";
    source += "class SomeClass\n";
    source += "operation op1(par1 : Boolean) : Integer raises SomeException1, SomeException2;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    Operation operation = someClass.getOperation("op1", null, null);
    assertNotNull(operation);
    assertNotNull(operation.getRaisedException("SomeException1"));
    assertNotNull(operation.getRaisedException("SomeException2"));
}
 
Example #14
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testOperationWithBody() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClass\n";
    source += "operation op1(par1 : Boolean);\n";
    source += "begin\n";
    source += "end;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    assertNotNull(class_);
    Operation operation = class_.getOperation("op1", null, null);
    assertNotNull(operation);
    assertEquals(1, operation.getMethods().size());
}
 
Example #15
Source File: TestStructure.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSend() throws Exception {
	Model model = model("hu.elte.txtuml.export.uml2.tests.models.send");
	Class clsA = cls(model, "A");
	Property otherEnd = property(clsA, "B_end", "B");
	Class clsB = cls(model, "B");
	Property thisEnd = property(clsB, "A_end", "A");

	SequenceNode body = loadActionCode(model, "A", "test");
	SequenceNode sendStmt = node(body, 0, "send create Sig to select(a -> B_end);", SequenceNode.class);
	node(sendStmt, 0, "create Sig", SequenceNode.class);
	node(sendStmt, 1, "a", ReadVariableAction.class);
	ReadLinkAction readLink = node(sendStmt, 2, "a -> B_end", ReadLinkAction.class);
	node(sendStmt, 3, "select(a -> B_end)", CallOperationAction.class);
	node(sendStmt, 4, "send create Sig to select(a -> B_end)", SendObjectAction.class);
	assertEquals(thisEnd, readLink.getEndData().get(0).getEnd());
	assertNotNull(readLink.getEndData().get(0).getValue());
	assertEquals(otherEnd, readLink.getEndData().get(1).getEnd());
	assertEquals(null, readLink.getEndData().get(1).getValue());
}
 
Example #16
Source File: TestStructure.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSignal() throws Exception {
	Model model = model("hu.elte.txtuml.export.uml2.tests.models.signal");
	Signal sig = signal(model, "Sig");
	SignalEvent sigEvent = signalEvent(model, "Sig");
	assertEquals(sig, sigEvent.getSignal());
	Class sigFactory = cls(model, "#Sig_factory");
	Operation sigCtor = operation(sigFactory, "Sig");
	assertEquals(4, sigCtor.getOwnedParameters().size());

	SequenceNode body = loadActionCode(model, "A", "test");
	SequenceNode createNode = node(body, 0, "create Sig", SequenceNode.class);
	CreateObjectAction initiateNode = node(createNode, 0, "instantiate Sig", CreateObjectAction.class);
	assertEquals(sig, initiateNode.getClassifier());
	node(createNode, 1, "#temp=instantiate Sig", AddVariableValueAction.class);
	node(createNode, 2, "1", ValueSpecificationAction.class);
	node(createNode, 3, "true", ValueSpecificationAction.class);
	node(createNode, 4, "\"test\"", ValueSpecificationAction.class);
	node(createNode, 5, "#temp", ReadVariableAction.class);
	CallOperationAction ctorCall = node(createNode, 6, "Sig(Sig p0, Integer p1, Boolean p2, String p3)",
			CallOperationAction.class);
	assertEquals(sigCtor, ctorCall.getOperation());
	node(createNode, 7, "#temp", ReadVariableAction.class);
}
 
Example #17
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testBasicTemplateDeclaration() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Bar<T>\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    Classifier barClass = (Classifier) getRepository().findNamedElement("test::Bar",
            IRepository.PACKAGE.getClassifier(), null);
    assertNotNull(barClass);
    assertTrue(barClass.isTemplate());
    TemplateSignature signature = barClass.getOwnedTemplateSignature();
    assertNotNull(signature);
    List<TemplateParameter> parameters = signature.getOwnedParameters();
    assertNotNull(parameters);
    assertEquals(1, parameters.size());
    assertTrue(parameters.get(0).getParameteredElement() instanceof Class);
    assertEquals("T", ((Class) parameters.get(0).getParameteredElement()).getName());
}
 
Example #18
Source File: ClassAttributeLink.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a ClassAttributeLink based on the EMF-UML model-elements and
 * layout information provided
 * 
 * @param layout
 *            the layout informations of this link
 * @param assoc
 *            the EMF-UML model-element which holds informations of this
 *            diagram element
 * @param fromClass
 *            the EMF-UML model Class belonging to the from end of this
 *            association
 * @param toClass
 *            the EMF-UML model Class belonging to the to end of this
 *            association
 * @throws UnexpectedEndException
 *             Exception is thrown if an association's end could not be
 *             linked to the EMF-UML model
 */
public ClassAttributeLink(LineAssociation layout, Association assoc, Classifier fromClass, Classifier toClass)
		throws UnexpectedEndException {
	super(layout);
	name = assoc.getLabel();
	from = null;
	to = null;
	for (Property end : assoc.getMemberEnds()) {
		Class endClass = (Class) end.getType();
		// when handling reflexive links then first add the to end's, then
		// the from end's model information (to match the Papyrus exporter
		// behavior)
		if (endClass == toClass && to == null) {
			to = new AssociationEnd(end);
		} else if (endClass == fromClass && from == null) {
			from = new AssociationEnd(end);
		} else {
			throw new UnexpectedEndException(end.getName());
		}
	}
}
 
Example #19
Source File: ClassDiagramElementsManager.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the types of elements that are to be added
 * @return Returns the types of elements that are to be added
 */
private List<java.lang.Class<? extends Element>> generateElementsToBeAdded() {
	List<java.lang.Class<? extends Element>> nodes = new LinkedList<>(Arrays.asList(
			Class.class,
			Component.class,
			DataType.class,
			Enumeration.class,
			InformationItem.class,
			InstanceSpecification.class,
			Interface.class,
			Model.class,
			Package.class,
			PrimitiveType.class
	));
	
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_CONSTRAINT_PREF))
		nodes.add(Constraint.class);
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_COMMENT_PREF))
		nodes.add(Comment.class);
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_SIGNAL_PREF))
		nodes.add(Signal.class);
	
	return nodes;
}
 
Example #20
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
protected void buildReturnStatement(Node node) {
    TemplateableElement bound = (Class) MDDUtil.getNearest(builder.getCurrentActivity(),
            IRepository.PACKAGE.getClass_());
    AddVariableValueAction action = (AddVariableValueAction) builder.createAction(IRepository.PACKAGE
            .getAddVariableValueAction());
    try {
        Variable variable = builder.getReturnValueVariable();
        if (variable == null) {
            problemBuilder.addProblem(new ReturnValueNotExpected(), node);
            throw new AbortedScopeCompilationException();
        }
        final InputPin value = builder.registerInput(action.createValue(null, null));
        node.apply(this);
        action.setVariable(variable);
        TypeUtils.copyType(variable, value, bound);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node, getBoundElement());
    ActivityUtils.makeFinal(builder.getCurrentBlock(), action);
}
 
Example #21
Source File: Uml2ToCppExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private void createClassSources(String outputDirectory) throws IOException {
	for (Class cls : classes) {
		
		ClassExporter classExporter = new ClassExporter(cls, cls.getName(), outputDirectory);
		classExporter.setTesting(testing);		
		classExporter.setPoolId(threadManager.getConfiguratedPoolId(cls.getName()));

		classExporter.createUnitSource();
		if (CppExporterUtils.isStateMachineOwner(cls)) {
			classNames.addAll(classExporter.getSubmachines());
		}

		classNames.add(cls.getName());
		classNames.addAll(classExporter.getAdditionalSources());

		if (CppExporterUtils.isStateMachineOwner(cls)) {
			stateMachineOwners.add(cls.getName());
			stateMachineOwners.addAll(classExporter.getSubmachines());
		}

	}
}
 
Example #22
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom0To1() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "class Class1\n";
    source += "  attribute attr1 : Integer[0,1];\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class1 = getRepository().findNamedElement("simple::Class1", UMLPackage.Literals.CLASS, null);
    assertNotNull(class1);
    Property attr1 = class1.getAttribute("attr1", null);
    assertNotNull(attr1);
    assertEquals(0, attr1.getLower());
    assertEquals(1, attr1.getUpper());

    ValueSpecification lowerValue = attr1.getLowerValue();
    assertNotNull(lowerValue);
    assertTrue(lowerValue instanceof LiteralInteger);
    assertEquals(0, lowerValue.integerValue());

    ValueSpecification upperValue = attr1.getUpperValue();
    assertNotNull(upperValue);
    assertTrue(upperValue instanceof LiteralUnlimitedNatural);
    assertEquals(1, ((LiteralUnlimitedNatural) upperValue).unlimitedValue());
}
 
Example #23
Source File: CppExporterUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private static Class getSignalFactoryClass(Signal signal, List<Element> elements) {
	for (Element element : elements) {
		if (element.eClass().equals(UMLPackage.Literals.CLASS)) {
			Class cls = (Class) element;
			for (Operation operation : cls.getOperations()) {
				if (isConstructor(operation)) {
					for (Parameter param : operation.getOwnedParameters()) {
						if (param.getType().getName().equals(signal.getName()))
							return cls;
					}
				}

			}
		}
	}

	return null;
}
 
Example #24
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 #25
Source File: ExtensionRenderer.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean basicRenderObject(Extension element, IndentedPrintWriter pw, IRenderingSession context) {
    final Stereotype stereotype = element.getStereotype();
    final Class metaclass = element.getMetaclass();

    if (!shouldRender(context, stereotype, metaclass))
        return true;

    context.render(stereotype, stereotype.eResource() != element.eResource());
    context.render(metaclass, metaclass.eResource() != element.eResource());

    pw.print("edge ");
    // if (element.getName() != null)
    // pw.print("\"" + element.getName() + "\" ");
    pw.println("[");
    pw.enterLevel();
    pw.println("arrowtail = \"none\"");
    pw.println("arrowhead = \"normal\"");
    pw.println("taillabel = \"\"");
    pw.println("headlabel = \"\"");
    DOTRenderingUtils.addAttribute(pw, "constraint", "true");
    pw.println("style = \"none\"");
    pw.exitLevel();
    pw.println("]");
    pw.println(stereotype.getName() + ":port -- " + metaclass.getName() + ":port");
    return true;
}
 
Example #26
Source File: CallActionsDetector.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private Class getClassFromUMLModel(String name) {

		for (Class cls : classList) {
			if (cls.getName().equals(name)) {
				return cls;
			}
		}
		return null;
	}
 
Example #27
Source File: ClassRenderer.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public boolean renderObject(Class clazz, IndentedPrintWriter writer, IRenderingSession context) {
    RenderingUtils.renderAll(context, ElementUtils.getComments(clazz));
    TextUMLRenderingUtils.renderStereotypeApplications(writer, clazz);
    if (clazz.isAbstract())
        writer.print("abstract ");
    writer.print("class " + name(clazz));
    List<Generalization> generalizations = clazz.getGeneralizations();
    StringBuilder specializationList = new StringBuilder();
    for (Generalization generalization : generalizations)
        specializationList.append(TextUMLRenderingUtils.getQualifiedNameIfNeeded(generalization.getGeneral(),
                clazz.getNamespace())
                + ", ");
    if (specializationList.length() > 0) {
        specializationList.delete(specializationList.length() - 2, specializationList.length());
        writer.print(" specializes ");
        writer.print(specializationList);
    }
    List<InterfaceRealization> realizations = clazz.getInterfaceRealizations();
    StringBuilder realizationList = new StringBuilder();
    for (InterfaceRealization realization : realizations)
        realizationList.append(TextUMLRenderingUtils.getQualifiedNameIfNeeded(realization.getContract(),
                clazz.getNamespace())
                + ", ");
    if (realizationList.length() > 0) {
        realizationList.delete(realizationList.length() - 2, realizationList.length());
        writer.print(" implements ");
        writer.print(realizationList);
    }
    writer.println();
    writer.enterLevel();
    RenderingUtils.renderAll(context, clazz.getOwnedAttributes());
    RenderingUtils.renderAll(context, clazz.getOwnedOperations());
    RenderingUtils.renderAll(context, clazz.getClientDependencies());
    writer.exitLevel();
    writer.println("end;");
    writer.println();
    return true;
}
 
Example #28
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testAggregationShorthand() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "class A\n";
    source += "end;\n";
    source += "class C\n";
    source += "end;\n";
    source += "class B\n";
    source += "  aggregation a : A;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class classA = (Class) getRepository().findNamedElement("simple::A", IRepository.PACKAGE.getClass_(), null);
    Class classB = (Class) getRepository().findNamedElement("simple::B", IRepository.PACKAGE.getClass_(), null);

    Property propertyA = classB.getOwnedAttribute("a", null);
    assertNotNull(propertyA);

    Association association = propertyA.getAssociation();
    assertNotNull(association);

    assertTrue(association.getMemberEnds().contains(propertyA));
    assertFalse(association.getOwnedEnds().contains(propertyA));
    assertEquals(AggregationKind.SHARED_LITERAL, propertyA.getAggregation());
    assertSame(classA, propertyA.getType());

    Property otherEnd = propertyA.getOtherEnd();
    assertTrue(association.getMemberEnds().contains(otherEnd));
    assertTrue(association.getOwnedEnds().contains(otherEnd));
    assertEquals(AggregationKind.NONE_LITERAL, otherEnd.getAggregation());
    assertSame(classB, otherEnd.getType());
}
 
Example #29
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testSimpleAssociation() throws CoreException {
      String source = "";
      source += "model simple;\n";
      source += "association AccountClient\n";
      source += "  role account : Account[*];\n";
      source += "  readonly !navigable role client : Client[1];\n";
      source += "end;\n";
      source += "end.";
      parseAndCheck(getSimpleModelSource(), source);
      Class accountClass = (Class) getRepository().findNamedElement("simple::Account",
              IRepository.PACKAGE.getClass_(), null);
      Class clientClass = (Class) getRepository().findNamedElement("simple::Client", IRepository.PACKAGE.getClass_(),
              null);
      final Association association = (Association) getRepository().findNamedElement("simple::AccountClient",
              IRepository.PACKAGE.getAssociation(), null);
      assertNotNull(association);
      Property accountEnd = association.getOwnedEnd("account", accountClass);
      assertNotNull(accountEnd);
      assertTrue(accountEnd.isNavigable());
      assertTrue(!accountEnd.isReadOnly());
      assertEquals(AggregationKind.NONE_LITERAL, accountEnd.getAggregation());
      Property clientEnd = association.getOwnedEnd("client", clientClass);
      assertNotNull(clientEnd);
      assertTrue(!clientEnd.isNavigable());
      assertTrue(clientEnd.isReadOnly());
      assertEquals(AggregationKind.NONE_LITERAL, clientEnd.getAggregation());
      assertEquals(0, accountEnd.lowerBound());
assertEquals(LiteralUnlimitedNatural.UNLIMITED, accountEnd.upperBound());
      assertEquals(1, clientEnd.lowerBound());
      assertEquals(1, clientEnd.upperBound());
  }
 
Example #30
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testObjectPermission_Anonymous() throws CoreException {
	parseAndCheck(source);
	Class accountApplication = getClass("banking::AccountApplication");
	Constraint constraint = AccessControlUtils.findAccessConstraint(accountApplication, AccessCapability.Create, null);
	assertNotNull(constraint);
	assertEquals(Arrays.asList(AccessCapability.Create), MDDExtensionUtils.getAllowedCapabilities(constraint));
	assertEquals(Collections.emptyList(), MDDExtensionUtils.getAccessRoles(constraint));
}