Java Code Examples for org.eclipse.uml2.uml.Class#getOperation()
The following examples show how to use
org.eclipse.uml2.uml.Class#getOperation() .
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: StereotypeTests.java From textuml with Eclipse Public License 1.0 | 6 votes |
public void testOperationStereotypeApplication() throws CoreException { String profileSource = ""; profileSource += "profile someProfile;\n"; profileSource += "stereotype my_stereotype extends UML::Operation end;\n"; profileSource += "end.\n"; String modelSource = ""; modelSource += "model someModel;\n"; modelSource += "apply someProfile;\n"; modelSource += "class SomeClass\n"; modelSource += " [my_stereotype] operation someOperation();\n"; modelSource += " begin\n"; modelSource += " end;\n"; modelSource += "end;\n"; modelSource += "end.\n"; parseAndCheck(profileSource, modelSource); Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass", IRepository.PACKAGE.getClassifier(), null); Operation operation = class_.getOperation("someOperation", null, null); Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype", IRepository.PACKAGE.getStereotype(), null); assertNotNull(stereotype); assertTrue(operation.isStereotypeApplied(stereotype)); }
Example 2
Source File: ClassifierTests.java From textuml with Eclipse Public License 1.0 | 6 votes |
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 3
Source File: ClassifierTests.java From textuml with Eclipse Public License 1.0 | 6 votes |
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 4
Source File: ClassifierTests.java From textuml with Eclipse Public License 1.0 | 5 votes |
public void testOperationWithPreConditions() throws CoreException { String source = ""; source += "model someModel;\n"; source += "import base;\n"; source += "class SomeClass\n"; source += "operation op1(par1 : Boolean)\n"; source += "precondition condition1 { true }\n"; source += "precondition { true }\n"; source += "precondition condition3 (par1) { not par1 };\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()); assertEquals(3, operation.getPreconditions().size()); assertEquals("condition1", operation.getPreconditions().get(0).getName()); assertNull(operation.getPreconditions().get(1).getName()); assertEquals("condition3", operation.getPreconditions().get(2).getName()); assertNotNull(operation.getPreconditions().get(0).getSpecification()); int[] expectedParameterCount = { 1, 1, 2 }; int index = 0; for (Constraint constraint : operation.getPreconditions()) checkConstraint(constraint, expectedParameterCount[index++]); }
Example 5
Source File: ClassifierTests.java From textuml with Eclipse Public License 1.0 | 4 votes |
public void testOperations() throws CoreException { String source = ""; source += "model someModel;\n"; source += "import base;\n"; source += "class SomeClass\n"; source += "operation op1(par1 : Boolean) : Integer;\n"; source += "protected abstract operation op2();\n"; source += "package static operation op3();\n"; source += "end;\n"; source += "end."; parseAndCheck(source); Type integerType = (Type) getRepository() .findNamedElement("base::Integer", IRepository.PACKAGE.getType(), null); assertNotNull(integerType); Type booleanType = (Type) getRepository() .findNamedElement("base::Boolean", IRepository.PACKAGE.getType(), null); assertNotNull(booleanType); Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass", IRepository.PACKAGE.getClass_(), null); assertNotNull(class_); Operation op1 = class_.getOperation("op1", null, null); assertNotNull(op1); assertSame(op1.getType(), integerType); assertEquals(2, op1.getOwnedParameters().size()); Parameter par1 = op1.getOwnedParameter("par1", booleanType); assertNotNull(par1); assertSame(ParameterDirectionKind.IN_LITERAL, par1.getDirection()); Parameter result = op1.getOwnedParameter(null, integerType); assertNotNull(result); assertSame(ParameterDirectionKind.RETURN_LITERAL, result.getDirection()); assertSame(VisibilityKind.PUBLIC_LITERAL, op1.getVisibility()); Operation op2 = class_.getOperation("op2", null, null); assertNotNull(op2); assertTrue(op2.isAbstract()); assertFalse(op2.isStatic()); assertSame(VisibilityKind.PROTECTED_LITERAL, op2.getVisibility()); Operation op3 = class_.getOperation("op3", null, null); assertNotNull(op3); assertTrue(op3.isStatic()); assertFalse(op3.isAbstract()); assertSame(VisibilityKind.PACKAGE_LITERAL, op3.getVisibility()); }