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

The following examples show how to use org.eclipse.uml2.uml.Classifier#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: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private Property parseSimpleTraversal(Classifier sourceType, ASimpleAssociationTraversal node) {
    final String openEndName = TextUMLCore.getSourceMiner().getIdentifier(node.getIdentifier());
    Property openEnd = sourceType.getAttribute(openEndName, null);
    Association association;
    if (openEnd == null) {
        EList<Association> associations = sourceType.getAssociations();
        for (Association current : associations)
            if ((openEnd = current.getMemberEnd(openEndName, null)) != null)
                break;
        if (openEnd == null) {
            problemBuilder.addProblem(new UnknownRole(sourceType.getQualifiedName() + NamedElement.SEPARATOR
                    + openEndName), node.getIdentifier());
            throw new AbortedStatementCompilationException();
        }
    }
    association = openEnd.getAssociation();
    if (association == null) {
        problemBuilder.addError(openEndName + " is not an association member end", node.getIdentifier());
        throw new AbortedStatementCompilationException();
    }
    return openEnd;
}
 
Example 2
Source File: FeatureUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static Property findProperty(Classifier classifier, String attributeIdentifier, boolean ignoreCase,
        boolean recurse, EClass propertyClass) {
    Property found = classifier.getAttribute(attributeIdentifier, null, ignoreCase, propertyClass);
    if (found != null || !recurse)
        return found;
    final EList<TemplateBinding> templateBindings = classifier.getTemplateBindings();
    if (!templateBindings.isEmpty()) {
        for (TemplateBinding templateBinding : templateBindings) {
            TemplateSignature signature = templateBinding.getSignature();
            found = findProperty((Classifier) signature.getTemplate(), attributeIdentifier, ignoreCase, true,
                    propertyClass);
            if (found != null)
                return found;
        }
    }
    for (Generalization generalization : classifier.getGeneralizations())
        if ((found = findProperty(generalization.getGeneral(), attributeIdentifier, ignoreCase, true, propertyClass)) != null)
            return found;
    return null;
}
 
Example 3
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testBindingOfTemplateWithOperation() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Zoo\n";
    model += "end;\n";
    model += "class Bar<T>\n";
    model += "  operation op1(a : T);\n";
    model += "end;\n";
    model += "class Foo\n";
    model += "  attribute boz : Bar<Zoo>;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    Classifier zooClass = (Classifier) getRepository().findNamedElement("test::Zoo",
            IRepository.PACKAGE.getClassifier(), null);
    assertNotNull(zooClass);
    Classifier fooClass = (Classifier) getRepository().findNamedElement("test::Foo",
            IRepository.PACKAGE.getClassifier(), null);
    assertNotNull(fooClass);
    Property bozProperty = fooClass.getAttribute("boz", null);
    Classifier bozType = (Classifier) bozProperty.getType();
    assertNotNull(bozType);
    Operation boundOp1 = StructuralFeatureUtils.findOperation(getRepository(), bozType, "op1", null);
    assertNotNull(boundOp1);
    assertEquals("T", boundOp1.getOwnedParameter("a", null).getType().getName());
}
 
Example 4
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testTemplateBindingAsAttributeType() 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 += "  attribute attr1 : Bar<Zoo>;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    Classifier fooType = (Classifier) getRepository().findNamedElement("test::Foo",
            IRepository.PACKAGE.getClassifier(), null);
    Property fooAttr1 = fooType.getAttribute("attr1", null);
    assertNotNull(fooAttr1);
    checkTemplateBinding((Classifier) fooAttr1.getType(), "test::Bar", "test::Zoo");
}
 
Example 5
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testTemplateDeclarationWithAttribute() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Bar<T>\n";
    model += "attribute attr1 : T;\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);
    Property attribute = barClass.getAttribute("attr1", null);
    assertNotNull(attribute);
    assertSame(parameterType, attribute.getType());
}
 
Example 6
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void testAttributes(String classifierKeyword, EClass metaClass) throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "$classifier SomeClassifier\n";
    source += "attribute attrib1 : Integer;\n";
    source += "public attribute attrib2 : Integer;\n";
    source += "private attribute attrib3 : Integer;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source.replace("$classifier", classifierKeyword));

    Type integerType = (Type) getRepository()
            .findNamedElement("base::Integer", IRepository.PACKAGE.getType(), null);
    assertNotNull(integerType);

    Classifier classifier = (Classifier) getRepository().findNamedElement("someModel::SomeClassifier", metaClass,
            null);
    assertNotNull(classifier);
    Property property = classifier.getAttribute("attrib1", integerType);
    assertNotNull(property);
}
 
Example 7
Source File: UMLExportTestBase.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
protected Property property(Classifier cls, String name, String typeName) {
	Property attribute = cls.getAttribute(name, null);
	assertNotNull(attribute);
	assertEquals(typeName, attribute.getType().getName());
	assertEquals(1, attribute.getLower());
	assertEquals(1, attribute.getUpper());
	assertEquals(true, attribute.isNavigable());
	return attribute;
}
 
Example 8
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testDerivedAttribute() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClassifier\n";
    source += "attribute attrib1 : Integer;\n";
    source += "derived attribute attrib2 : Integer := { self.attrib1 * 2 };\n";
    source += "derived attribute attrib3 : Boolean := { self.attrib1 > 0 };\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);

    Type integerType = (Type) getRepository()
            .findNamedElement("base::Integer", IRepository.PACKAGE.getType(), null);
    assertNotNull(integerType);

    Classifier classifier = (Classifier) getRepository().findNamedElement("someModel::SomeClassifier",
            Literals.CLASS, null);

    Property attr1 = classifier.getAttribute("attrib1", null);
    assertFalse(attr1.isDerived());

    Property attr2 = classifier.getAttribute("attrib2", null);
    assertTrue(attr2.isDerived());

    Property attr3 = classifier.getAttribute("attrib3", null);
    assertTrue(attr3.isDerived());

    assertNotNull(attr2.getDefaultValue());
    assertTrue(ActivityUtils.isBehaviorReference(attr2.getDefaultValue()));

    assertNotNull(attr3.getDefaultValue());
    assertTrue(ActivityUtils.isBehaviorReference(attr3.getDefaultValue()));
}
 
Example 9
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public void testAttributeInitialization() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "enumeration MyEnum literal VALUE1; literal VALUE2; literal VALUE3; end;\n";
    source += "class SomeClassifier\n";
    source += "attribute attrib1 : Integer := 10;\n";
    source += "attribute attrib2 : Boolean := true;\n";
    source += "attribute attrib3 : String := \"foo\";\n";
    source += "attribute attrib4 : MyEnum := VALUE2;\n";
    source += "attribute attrib5 : Date := { Date#today() };\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);

    Type integerType = (Type) getRepository()
            .findNamedElement("base::Integer", IRepository.PACKAGE.getType(), null);
    assertNotNull(integerType);

    Classifier classifier = (Classifier) getRepository().findNamedElement("someModel::SomeClassifier",
            Literals.CLASS, null);

    Property attr1 = classifier.getAttribute("attrib1", null);
    ValueSpecification attr1DefaultValue = attr1.getDefaultValue();
    assertNotNull(attr1DefaultValue);
    assertTrue(MDDExtensionUtils.isBasicValue(attr1DefaultValue));
    assertEquals(10L, MDDExtensionUtils.getBasicValue(attr1DefaultValue));

    Property attr2 = classifier.getAttribute("attrib2", null);
    ValueSpecification attr2DefaultValue = attr2.getDefaultValue();
    assertNotNull(attr2DefaultValue);
    assertTrue(MDDExtensionUtils.isBasicValue(attr2DefaultValue));
    assertEquals(true, MDDExtensionUtils.getBasicValue(attr2DefaultValue));

    Property attr3 = classifier.getAttribute("attrib3", null);
    ValueSpecification attr3DefaultValue = attr3.getDefaultValue();
    assertNotNull(attr3DefaultValue);
    assertTrue(attr3DefaultValue instanceof LiteralString);
    assertEquals("foo", MDDExtensionUtils.getBasicValue(attr3DefaultValue));

    Property attr4 = classifier.getAttribute("attrib4", null);
    ValueSpecification attr4DefaultValue = attr4.getDefaultValue();
    assertNotNull(attr4DefaultValue);
    assertTrue(attr4DefaultValue instanceof InstanceValue);
    assertTrue(((InstanceValue) attr4DefaultValue).getInstance() instanceof EnumerationLiteral);
    assertEquals("VALUE2", ((EnumerationLiteral) ((InstanceValue) attr4DefaultValue).getInstance()).getName());

    Property attr5 = classifier.getAttribute("attrib5", null);
    ValueSpecification attr5DefaultValue = attr5.getDefaultValue();
    assertNotNull(attr5DefaultValue);
    assertTrue(ActivityUtils.isBehaviorReference(attr5DefaultValue));
}