Java Code Examples for org.eclipse.uml2.uml.Class#getAttribute()

The following examples show how to use org.eclipse.uml2.uml.Class#getAttribute() . 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: 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 2
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 3
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom0ToUnlimitedShortForm() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "import base;\n";
    source += "class Class1\n";
    source += "  attribute attr1 : Integer[*];\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 4
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 5
Source File: MultiplicityTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testFrom1ToUnlimited() 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(LiteralUnlimitedNatural.UNLIMITED, 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(LiteralUnlimitedNatural.UNLIMITED, ((LiteralUnlimitedNatural) upperValue).unlimitedValue());
}
 
Example 6
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 7
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 8
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testDerivedReference() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "class Class1\n";
    source += "  reference myClass2a : Class2[*];\n";
    source += "  reference myClass2b : Class2[*];\n";
    source += "  derived attribute allMyClass2 : Class2[*] := { self.myClass2a.union(self.myClass2b) };\n";
    source += "end;\n";
    source += "class Class2\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class1 = getRepository().findNamedElement("simple::Class1", IRepository.PACKAGE.getClass_(), null);
    Class class2 = getRepository().findNamedElement("simple::Class2", IRepository.PACKAGE.getClass_(), null);
    assertNotNull(class1);
    assertNotNull(class2);
    Property derived = class1.getAttribute("allMyClass2", class2);
    assertTrue(derived.isDerived());
    assertTrue(derived.isMultivalued());
    assertNull(derived.getAssociation());
}
 
Example 9
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 10
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstants() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClass\n";
    source += "static readonly attribute CONST1 : Integer := 10;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Type integerType = (Type) getRepository()
            .findNamedElement("base::Integer", IRepository.PACKAGE.getType(), null);
    assertNotNull(integerType);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    assertNotNull(class_);
    Property property = class_.getAttribute("CONST1", integerType);
    assertNotNull(property);
    assertTrue(property.isReadOnly());
    ValueSpecification defaultValue = property.getDefaultValue();
    assertNotNull(defaultValue);
    assertTrue(MDDExtensionUtils.isBasicValue(defaultValue));
    assertEquals(10L, MDDExtensionUtils.getBasicValue(defaultValue));
}
 
Example 11
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testAssociationRoleStereotypeApplication() 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 += "  attribute someAttribute : Integer;\n";
    modelSource += "end;\n";
    modelSource += "class AnotherClass\n";
    modelSource += "  attribute anotherAttribute : Integer;\n";
    modelSource += "end;\n";
    modelSource += "association SomeAssoc\n";
    modelSource += "  [my_stereotype] role anotherAttribute : AnotherClass;\n";
    modelSource += "  [my_stereotype] navigable role SomeClass.someAttribute;\n";
    modelSource += "end;\n";
    modelSource += "end.\n";
    IProblem[] problems = parse(profileSource, modelSource);
    assertTrue(problems.length == 1);
    assertTrue(problems[0].getSeverity() == IProblem.Severity.WARNING);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClassifier(), null);
    Property attribute = class_.getAttribute("someAttribute", null);
    Association assoc = (Association) getRepository().findNamedElement("someModel::SomeAssoc",
            IRepository.PACKAGE.getAssociation(), null);
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertNotNull(assoc);
    Property anotherEnd = assoc.getOwnedEnd("anotherAttribute", null);
    assertNotNull(anotherEnd);
    assertTrue(anotherEnd.isStereotypeApplied(stereotype));
    assertFalse(attribute.isStereotypeApplied(stereotype));
}