org.eclipse.uml2.uml.UMLPackage Java Examples

The following examples show how to use org.eclipse.uml2.uml.UMLPackage. 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: ActivityExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private String createActivityPartCode(ActivityNode startNode_, ActivityNode stopNode_,
		List<ActivityNode> finishedControlNodes_) {
	StringBuilder source = new StringBuilder("");
	LinkedList<ActivityNode> nodeList = new LinkedList<ActivityNode>(Arrays.asList(startNode_));

	List<ActivityNode> finishedControlNodes = finishedControlNodes_;
	while (!nodeList.isEmpty() && (stopNode_ == null || nodeList.getFirst() != stopNode_)) {
		ActivityNode currentNode = nodeList.removeFirst();
		if (currentNode != null)// TODO have to see the model, to find what
								// caused it, and change the code here
		{
			if (currentNode.eClass().equals(UMLPackage.Literals.INPUT_PIN)) {
				currentNode = (ActivityNode) currentNode.getOwner();
			}
			// current node compile
			source.append(createActivityNodeCode(currentNode));

			for (ActivityNode node : getNextNodes(currentNode)) {
				if (!finishedControlNodes.contains(node) && !nodeList.contains(node)) {
					nodeList.add(node);
				}
			}
		}
	}
	return source.toString();
}
 
Example #2
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testReadOnlyModifier() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClass\n";
    source += "readonly attribute att1 : Integer;\n";
    source += "attribute att2 : Integer;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    final Property attr1 = (Property) getRepository().findNamedElement("someModel::SomeClass::att1",
            UMLPackage.Literals.PROPERTY, null);
    final Property attr2 = (Property) getRepository().findNamedElement("someModel::SomeClass::att2",
            UMLPackage.Literals.PROPERTY, null);
    assertTrue(attr1.isReadOnly());
    assertFalse(attr2.isReadOnly());
}
 
Example #3
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void caseACatchSection(ACatchSection node) {
    StructuredActivityNode protectedBlock = builder.getCurrentBlock();
    createBlock(IRepository.PACKAGE.getStructuredActivityNode(), false, (handlerBlock) -> {
        // declare exception variable
        node.getVarDecl().apply(this);
        node.getHandlerBlock().apply(this);
        Variable exceptionVar = handlerBlock.getVariables().get(0);
        ExceptionHandler exceptionHandler = protectedBlock.createHandler();
        exceptionHandler.getExceptionTypes().add((Classifier) exceptionVar.getType());
        InputPin exceptionInputPin = (InputPin) handlerBlock.createNode(exceptionVar.getName(),
                UMLPackage.Literals.INPUT_PIN);
        exceptionInputPin.setType(exceptionVar.getType());
        exceptionHandler.setExceptionInput(exceptionInputPin);
        exceptionHandler.setHandlerBody(handlerBlock);
    });
}
 
Example #4
Source File: WildcardTypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testInstanceOperationWildcardTypeInClosureReplaced() throws CoreException {
    String model = "";
    model += "model tests;\n";
    model += "import base;\n";
    model += "class MyClass1\n";
    model += "  operation <T1, T2> op1(par1 : {(a : T1) : T2}) : T1;\n";
    model += "  operation op2();\n";
    model += "  begin\n";
    model += "      var local;\n";
    model += "      local := self.op1((a : Boolean) : Integer { 1 });\n";
    model += "  end;\n";
    model += "end;\n";
    model += "end.";
    parseAndCheck(model);

    Operation op2 = getOperation("tests::MyClass1::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::Boolean");
    assertSame(integerType, localVar.getType());
}
 
Example #5
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 #6
Source File: StructureBehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void buildReceptionBehavior(AReceptionDecl node) {
	final String signalName = TextUMLCore.getSourceMiner().getQualifiedIdentifier(node.getSimpleParamDecl());
	final Classifier currentClassifier = (Classifier) namespaceTracker.currentNamespace(null);
	Signal currentSignal = (Signal) getRepository().findNamedElement(signalName, UMLPackage.Literals.SIGNAL,
			currentClassifier);

	Reception currentReception = ReceptionUtils.findBySignal(currentClassifier, currentSignal);
	if (currentReception == null) {
		problemBuilder.addError("Reception not found for signal " + signalName, node.getReception());
		// could not find the reception, don't go further
		return;
	}
	namespaceTracker.enterNamespace(currentReception);
	try {
		node.getOptionalBehavioralFeatureBody().apply(this);
	} finally {
		namespaceTracker.leaveNamespace();
	}
}
 
Example #7
Source File: StateMachineTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testStateAttribute() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "  class SimpleClass\n";
    source += "    attribute status : Status;\n";
    source += "    statemachine Status\n";
    source += "      initial state First end;\n";
    source += "    end;\n";
    source += "  end;\n";
    source += "end.";
    parseAndCheck(source);
    StateMachine statusSM = (StateMachine) getRepository().findNamedElement("simple::SimpleClass::Status",
            UMLPackage.Literals.STATE_MACHINE, null);
    Property statusProperty = (Property) getRepository().findNamedElement("simple::SimpleClass::status",
            UMLPackage.Literals.PROPERTY, null);
    assertNotNull(statusProperty);
    assertEquals(statusSM, statusProperty.getType());
}
 
Example #8
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom1To1ShortForm() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "class Class1\n";
    source += "  attribute attr1 : Integer[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 #9
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 #10
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 #11
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 #12
Source File: StructuredElementExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private String createAttributes(VisibilityKind modifyer) {
	StringBuilder source = new StringBuilder("");
	for (Property attribute : structuredElement.getOwnedAttributes()) {
		if(attribute.getType().eClass().equals(UMLPackage.Literals.INTERFACE)) {
			continue;
		}
		if (attribute.getVisibility().equals(modifyer)) {
			String type = UKNOWN_TYPE;
			if (attribute.getType() != null) {
				type = attribute.getType().getName();
			}

			if (isSimpleAttribute(attribute)) {
				source.append(ObjectDeclDefTemplates.propertyDecl(type, attribute.getName(), attribute.getDefault(), 
						VariableType.getUMLMultpliedElementType(attribute.getLower(), attribute.getUpper())));
			} else {
				dependencyExporter.addDependency(type);
			}
		}
	}
	return source.toString();
}
 
Example #13
Source File: ClassExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String createUnitCppCode() {
	StringBuilder source = new StringBuilder("");
	List<StateMachine> smList = new ArrayList<StateMachine>();
	CppExporterUtils.getTypedElements(smList, UMLPackage.Literals.STATE_MACHINE,
			structuredElement.allOwnedElements());
	if (CppExporterUtils.isStateMachineOwner(structuredElement)) {
		source.append(stateMachineExporter.createStateMachineRelatedCppSourceCodes());

	}

	source.append(super.createOperationDefinitions());
	source.append(constructorExporter.exportConstructorsDefinitions(name,
			CppExporterUtils.isStateMachineOwner(structuredElement)));
	source.append(CppExporterUtils.isStateMachineOwner(structuredElement)
			? ConstructorTemplates.destructorDef(name, true) : ConstructorTemplates.destructorDef(name, false));
	source.append(FunctionTemplates.functionDef(name, GenerationNames.InitializerFixFunctionNames.InitPorts,
			portExporter.createInitPortsCode()));
	source.append(portExporter.createPortTypeInfoDefinitions());

	return source.toString();
}
 
Example #14
Source File: StateMachineTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testNaming() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "  class SimpleClass\n";
    source += "    attribute status : Status;\n";
    source += "    statemachine Status\n";
    source += "      initial state First end;\n";
    source += "      state Second end;\n";
    source += "      state Third end;\n";
    source += "      terminate state Last end;\n";
    source += "    end;\n";
    source += "  end;\n";
    source += "end.";
    parseAndCheck(source);
    StateMachine statusSM = (StateMachine) getRepository().findNamedElement("simple::SimpleClass::Status",
            UMLPackage.Literals.STATE_MACHINE, null);
    List<State> vertices = StateMachineUtils.getStates(statusSM);
    assertEquals("First", vertices.get(0).getName());
    assertEquals("Second", vertices.get(1).getName());
    assertEquals("Third", vertices.get(2).getName());
    assertEquals("Last", vertices.get(3).getName());
}
 
Example #15
Source File: ActivityNodeResolver.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public String getTargetFromInputPin(InputPin node, Boolean recursive) {
	String source = "UNKNOWN_TYPE_FROM_VALUEPIN";
	if (node.eClass().equals(UMLPackage.Literals.INPUT_PIN)) {

		if (node.getIncomings().size() > 0) {
			source = getTargetFromActivityNode(node.getIncomings().get(0).getSource(), false);
		}

	} else if (node.eClass().equals(UMLPackage.Literals.VALUE_PIN)) {

		ValueSpecification valueSpec = ((ValuePin) node).getValue();
		if (valueSpec != null) {
			source = getValueFromValueSpecification(valueSpec);
		} else if (node.getIncomings().size() > 0) {
			source = getTargetFromActivityNode(node.getIncomings().get(0).getSource(), false);
		}

	}
	return source;
}
 
Example #16
Source File: ResourceSetFactory.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates and initializes a resource set.
 * 
 * @return The created and initialized resource set.
 */
public ResourceSet createAndInitResourceSet() {
	ResourceSet resourceSet = new ResourceSetImpl();

	URI uml2ResourcesPluginURI = URI.createURI(ExporterConfiguration.UML2_RESOURCES_PLUGIN_PATH);
	resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
			UMLResource.Factory.INSTANCE);

	Map<URI, URI> uriMap = resourceSet.getURIConverter().getURIMap();

	uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
			uml2ResourcesPluginURI.appendSegment("libraries").appendSegment(""));

	uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
			uml2ResourcesPluginURI.appendSegment("metamodels").appendSegment(""));

	uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
			uml2ResourcesPluginURI.appendSegment("profiles").appendSegment(""));

	uriMap.put(URI.createURI("pathmap://TXTUML_STDLIB/"),
			URI.createURI("platform:/plugin/hu.elte.txtuml.stdlib/src/hu/elte/txtuml/stdlib/"));

	UMLResourcesUtil.init(resourceSet);
	return resourceSet;
}
 
Example #17
Source File: ComponentTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConnector_UnnamedPort() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "interface SimpleInterface\n";
    source += "end;\n";
    source += "class SimpleClass implements SimpleInterface\n";
    source += "end;\n";
    source += "class SimpleClass2\n";
    source += "    required port c : SimpleInterface;\n";
    source += "end;\n";
    source += "component SimpleComponent\n";
    source += "    composition a : SimpleClass;\n";
    source += "    composition b : SimpleClass2;\n";
    source += "    provided port  : SimpleInterface connector a, b.c;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);

    Component component = get("simple::SimpleComponent", UMLPackage.Literals.COMPONENT);
    assertEquals(1, component.getOwnedPorts().size());
    Port port = component.getOwnedPorts().get(0);
    assertNull(port.getName());
    Property attributeA = get("simple::SimpleComponent::a", UMLPackage.Literals.PROPERTY);
    Property attributeC = get("simple::SimpleClass2::c", UMLPackage.Literals.PROPERTY);
    validatePort(port, attributeA, attributeC);
}
 
Example #18
Source File: ActivityNodeResolver.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private String getTypeFromSpecialAcivityNode(ActivityNode node) {
	String targetTypeName;
	// because the output pins not count as parent i have to if-else again
	// ...
	if (node.eClass().equals(UMLPackage.Literals.READ_SELF_ACTION)) {
		targetTypeName = getParentClass(node.getActivity()).getName();
	}
	if (node.eClass().equals(UMLPackage.Literals.ADD_STRUCTURAL_FEATURE_VALUE_ACTION)) {
		targetTypeName = getTypeFromInputPin(((AddStructuralFeatureValueAction) node).getObject());
	} else if (node.eClass().equals(UMLPackage.Literals.READ_STRUCTURAL_FEATURE_ACTION)) {
		targetTypeName = getTypeFromInputPin(((ReadStructuralFeatureAction) node).getObject());
	} else if (node.eClass().equals(UMLPackage.Literals.ACTIVITY_PARAMETER_NODE)) {
		targetTypeName = ((ActivityParameterNode) node).getType().getName();
	} else {
		targetTypeName = "UNKNOWN_TARGET_TYPER_NAME";
		// TODO unknown for me, need the model
	}

	return targetTypeName;
}
 
Example #19
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void caseABroadcastSpecificStatement(ABroadcastSpecificStatement node) {
    SendSignalAction action = (SendSignalAction) builder.createAction(IRepository.PACKAGE.getSendSignalAction());
    try {
        super.caseABroadcastSpecificStatement(node);
        final String signalIdentifier = TextUMLCore.getSourceMiner().getIdentifier(node.getSignal());
        Signal signal = this.context.getRepository().findNamedElement(signalIdentifier, UMLPackage.Literals.SIGNAL,
                namespaceTracker.currentNamespace(null));
        if (signal == null) {
            problemBuilder.addError("Unknown signal '" + signalIdentifier + "'", node.getSignal());
            throw new AbortedStatementCompilationException();
        }
        action.setSignal(signal);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node.getSignal(), getBoundElement());
}
 
Example #20
Source File: ActivityNodeResolver.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private String getValueFromValueSpecification(ValueSpecification valueSpec) {
	String source = "";
	if (valueSpec.eClass().equals(UMLPackage.Literals.LITERAL_INTEGER)) {
		source = ((Integer) ((LiteralInteger) valueSpec).getValue()).toString();
	} else if(valueSpec.eClass().equals(UMLPackage.Literals.LITERAL_REAL)) {
		source = ((Double)  ((LiteralReal) valueSpec).getValue()).toString();
	}
	else if (valueSpec.eClass().equals(UMLPackage.Literals.LITERAL_BOOLEAN)) {
		source = ((Boolean) ((LiteralBoolean) valueSpec).isValue()).toString();
	} else if (valueSpec.eClass().equals(UMLPackage.Literals.LITERAL_STRING)) {
		source =  ((LiteralString) valueSpec).getValue();			
		source = GenerationNames.BasicTypeNames.StringTypeName + "(" + "\"" + CppExporterUtils.escapeQuates(source) + "\"" + ")";
	
	} else if(valueSpec.eClass().equals(UMLPackage.Literals.LITERAL_NULL)) {
		source = ActivityTemplates.NullPtrLiteral;
	}
	else {
		source = "UNHANDLED_VALUEPIN_VALUETYPE";
		
	}
	return source;
}
 
Example #21
Source File: ReturnNodeExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public void searchReturnNode(List<ActivityEdge> edges) {
	if (!containsReturnNode) {

		for (ActivityEdge aEdge : edges) {
			if (aEdge.eClass().equals(UMLPackage.Literals.OBJECT_FLOW)) {
				ObjectFlow objectFlow = (ObjectFlow) aEdge;
				if (objectFlow.getTarget().eClass().equals(UMLPackage.Literals.ACTIVITY_PARAMETER_NODE)) {
					ActivityParameterNode parameterNode = (ActivityParameterNode) objectFlow.getTarget();
					if (parameterNode.getParameter().getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
						returnNode = objectFlow.getSource();
						containsReturnNode = true;
					}
				}
			}
		}
	}
}
 
Example #22
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testTemplateDeclarationWithLocalVar() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Bar<T>\n";
    model += "  operation op1();\n";
    model += "  begin\n";
    model += "    var x : T;\n";
    model += "  end;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    Classifier barClass = (Classifier) getRepository().findNamedElement("test::Bar",
            IRepository.PACKAGE.getClassifier(), null);
    Classifier parameterType = (Classifier) barClass.getOwnedTemplateSignature().getParameters().get(0)
            .getParameteredElement();
    assertNotNull(parameterType);
    Operation operation = barClass.getOperation("op1", null, null);
    assertNotNull(operation);
    StructuredActivityNode block = ActivityUtils.getRootAction(operation);
    StructuredActivityNode firstChild = (StructuredActivityNode) block.getContainedNode(null, false,
            UMLPackage.Literals.STRUCTURED_ACTIVITY_NODE);
    Variable xVar = ActivityUtils.findVariable(firstChild, "x");
    assertNotNull(xVar.getType());
    assertNotNull(((TemplateableElement) xVar.getType()).isTemplate());
}
 
Example #23
Source File: PackageTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testClashBetweenImportedAndLocal() throws CoreException {
    String sourcePackage = "";
    sourcePackage += "package somePackage;\n";
    sourcePackage += "class Expression\n";
    sourcePackage += "end;\n";
    sourcePackage += "class Foo\n";
    sourcePackage += "attribute attr1 : Expression;\n";
    sourcePackage += "end;\n";
    sourcePackage += "end.";
    parseAndCheck(sourcePackage);
    Class localExpressionClass = getRepository().findNamedElement("somePackage::Expression",
            UMLPackage.Literals.CLASS, null);
    assertEquals("somePackage::Expression", localExpressionClass.getQualifiedName());
    Class fooClass = getRepository().findNamedElement("somePackage::Foo", UMLPackage.Literals.CLASS, null);
    Class umlExpressionClass = getRepository().findNamedElement("UML::Expression", UMLPackage.Literals.CLASS, null);
    assertNotNull(localExpressionClass);
    assertNotNull(fooClass);
    assertNotNull(umlExpressionClass);
    Property attribute = fooClass.getAttribute("attr1", null);
    assertEquals(localExpressionClass.getQualifiedName(), attribute.getType().getQualifiedName());
}
 
Example #24
Source File: WildcardTypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testOperationWildcardTypeInClosureReplaced() throws CoreException {
    String model = "";
    model += "model tests;\n";
    model += "import base;\n";
    model += "class MyClass1\n";
    model += "  static operation <T1, T2> op1(par1 : {(a : T1) : T2}) : T1;\n";
    model += "  operation op2();\n";
    model += "  begin\n";
    model += "      var local;\n";
    model += "      local := MyClass1#op1((a : Boolean) : Integer { 1 });\n";
    model += "  end;\n";
    model += "end;\n";
    model += "end.";
    parseAndCheck(model);

    Operation op2 = getOperation("tests::MyClass1::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::Boolean");
    assertSame(integerType, localVar.getType());
}
 
Example #25
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * In the presence of multiple conflicting modifiers, the last one wins.
 */
public void testParameterModifiers() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClass\n";
    source += "operation op1(create read in out param1 : Integer);\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Operation op1 = (Operation) getRepository().findNamedElement("someModel::SomeClass::op1",
            UMLPackage.Literals.OPERATION, null);
    Parameter param1 = op1.getOwnedParameter("param1", null);
    assertNotNull(param1);
    assertEquals(ParameterDirectionKind.OUT_LITERAL, param1.getDirection());
    assertEquals(ParameterEffectKind.READ_LITERAL, param1.getEffect());
}
 
Example #26
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAStateMachineDecl(AStateMachineDecl node) {
    StateMachine newStateMachine = new StateMachineProcessor(sourceContext,
            (BehavioredClassifier) namespaceTracker.currentNamespace(UMLPackage.Literals.BEHAVIORED_CLASSIFIER))
            .processAndProduce(node);
    if (newStateMachine != null) {
    	applyCurrentComment(newStateMachine);
        boolean typesEnabled = Boolean.TRUE.toString().equals(
                context.getRepositoryProperties().get(IRepository.ENABLE_TYPES));
        if (typesEnabled)
        	createGeneralization(TypeUtils.makeTypeName("ComparableBasic"), newStateMachine, Literals.CLASS, node);
    }
}
 
Example #27
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testApplySubstitution() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "import base;\n";
    model += "class Zoo\n";
    model += "end;\n";
    model += "class Bar<T>\n";
    model += "operation op1(t : T) : T;\n";
    model += "end;\n";
    model += "class Bar2<V> specializes Bar<V>\n";
    model += "operation op2(v : V) : V;\n";
    model += "end;\n";
    model += "class Foo\n";
    model += "attribute attr1 : Bar2<Zoo>;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    IRepository repo = getRepository();
    Property attr1 = (Property) repo.findNamedElement("test::Foo::attr1", UMLPackage.Literals.PROPERTY, null);
    Operation op1 = (Operation) repo.findNamedElement("test::Bar::op1", UMLPackage.Literals.OPERATION, null);
    org.eclipse.uml2.uml.Class foo = (org.eclipse.uml2.uml.Class) repo.findNamedElement("test::Foo",
            UMLPackage.Literals.CLASS, null);
    org.eclipse.uml2.uml.Class zoo = (org.eclipse.uml2.uml.Class) repo.findNamedElement("test::Zoo",
            UMLPackage.Literals.CLASS, null);
    assertNotNull(foo);
    assertNotNull(zoo);
    assertNotNull(attr1);
    assertNotNull(op1);
    assertNotNull(op1.getType());
    assertTrue(op1.getType().isTemplateParameter());
    // tests TemplateUtils.applySubstitution
    assertSame(zoo, TemplateUtils.applySubstitution((Classifier) attr1.getType(), op1.getType()));
}
 
Example #28
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAEnumerationClassType(AEnumerationClassType node) {
    super.caseAEnumerationClassType(node);
    Classifier newEnumeration = createClassifier(UMLPackage.Literals.ENUMERATION);
    boolean typesEnabled = Boolean.TRUE.toString().equals(
            context.getRepositoryProperties().get(IRepository.ENABLE_TYPES));
    if (typesEnabled)
    	createGeneralization(TypeUtils.makeTypeName("Value"), newEnumeration, Literals.DATA_TYPE, node);
}
 
Example #29
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Type createSignature(Namespace namespace) {
	namespace = NamedElementUtils.findNearestNamespace(namespace, UMLPackage.Literals.PACKAGE,
			UMLPackage.Literals.CLASS);
	Interface signature = ClassifierUtils.createClassifier(namespace, null, Literals.INTERFACE);
	signature.createOwnedOperation("signatureOperation", null, null);
	Stereotype signatureStereotype = StereotypeUtils.findStereotype(SIGNATURE_STEREOTYPE);
	signature.applyStereotype(signatureStereotype);
	signature.setValue(signatureStereotype, SIGNATURE_CONTEXT, namespace);
	return signature;
}
 
Example #30
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testTemplateBindingAsLocalVar() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Zoo\n";
    model += "end;\n";
    model += "class Bar<T>\n";
    model += "end;\n";
    model += "class Foo\n";
    model += "  operation my_op1();\n";
    model += "  begin\n";
    model += "    var f : Bar<Zoo>;\n";
    model += "  end;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    Classifier fooType = (Classifier) getRepository().findNamedElement("test::Foo",
            IRepository.PACKAGE.getClassifier(), null);
    Operation myOp1 = fooType.getOperation("my_op1", null, null);
    assertNotNull(myOp1);
    StructuredActivityNode mainNode = ActivityUtils.getRootAction(myOp1);
    assertNotNull(mainNode);
    StructuredActivityNode firstChild = (StructuredActivityNode) mainNode.getContainedNode(null, false,
            UMLPackage.Literals.STRUCTURED_ACTIVITY_NODE);
    Variable variable = firstChild.getVariable("f", null);
    assertNotNull(variable);
    checkTemplateBinding((Classifier) variable.getType(), "test::Bar", "test::Zoo");
}