org.eclipse.uml2.uml.Stereotype Java Examples

The following examples show how to use org.eclipse.uml2.uml.Stereotype. 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: IRepositoryFindTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testStereotypeApplicationMatching() {
    Stereotype stereotype1 = getRepository()
            .findNamedElement("someProfile::stereotype1", Literals.STEREOTYPE, null);
    Stereotype stereotype2 = getRepository()
            .findNamedElement("someProfile::stereotype2", Literals.STEREOTYPE, null);
    assertNotNull(stereotype1);
    assertNotNull(stereotype2);

    assertIncluded("someModel::Class1", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype1') <> null"));
    assertNotIncluded("someModel::Class1", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype2') <> null"));

    assertIncluded("someModel::Class2", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype2') <> null"));
    assertNotIncluded("someModel::Class2", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype1') <> null"));

    assertIncluded("someModel::Class3", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype2') <> null"));
    assertNotIncluded("someModel::Class3", Literals.CLASS,
            createMatcher("self.getAppliedStereotype('someProfile::stereotype1') <> null"));
}
 
Example #2
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 #3
Source File: ClassifierBuilder.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void extendMetaclasses() {
    for (NameReference toResolve : extensions) {
        final Boolean required = (Boolean) toResolve.getProperty(Literals.EXTENSION__IS_REQUIRED.getName());
        new ReferenceSetter<Class>(toResolve, getParentProduct(), getContext()) {
            @Override
            protected void link(Class metaclass) {
                if (!metaclass.isMetaclass())
                    getContext().getProblemTracker().add(new NotAMetaclass(metaclass.getQualifiedName()));
                else {
                    Stereotype stereotype = (Stereotype) getProduct();
                    if (!stereotype.getProfile().getReferencedMetamodels().contains(metaclass.getModel()))
                        stereotype.getProfile().createMetamodelReference(metaclass.getNearestPackage());
                    stereotype.createExtension(metaclass, required != null && required);
                }
            }
        };
    }
}
 
Example #4
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 #5
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 #6
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testClassStereotypeApplication() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype my_stereotype extends UML::Class end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "[my_stereotype] class SomeClass end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClassifier(), null);
    assertNotNull(class_);
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertTrue(class_.isStereotypeApplied(stereotype));
}
 
Example #7
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
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 #8
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testStereotypeSpecialization() throws CoreException {
    String source = "";
    source += "profile someProfile;\n";
    source += "import UML;\n";
    source += "stereotype super_stereotype extends Class end;\n";
    source += "stereotype sub_stereotype specializes super_stereotype end;\n";
    source += "end.\n";
    parseAndCheck(source);
    final Stereotype superClass = (Stereotype) getRepository().findNamedElement("someProfile::super_stereotype",
            IRepository.PACKAGE.getClass_(), null);
    final Stereotype subClass = (Stereotype) getRepository().findNamedElement("someProfile::sub_stereotype",
            IRepository.PACKAGE.getClass_(), null);
    assertNotNull(superClass);
    assertNotNull(subClass);
    assertTrue(subClass.getSuperClasses().contains(superClass));
}
 
Example #9
Source File: Uml2Service.java    From uml2solidity with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the value cast as an List.
 * 
 * @param clazz
 * @param stereotypeName
 * @param propertyName
 * @return
 */
public static List<?> getStereotypeListValue(Element clazz, String stereotypeName, String propertyName) {
	Stereotype stereotype = getStereotype(clazz, stereotypeName);
	if (stereotype != null) {
		try {
			Object value = clazz.getValue(stereotype, propertyName);
			if (value instanceof List) {
				List<?> new_name = (List<?>) value;
				return new_name;
			}
		} catch (IllegalArgumentException e) {
		}

	}
	return new ArrayList<Object>();
}
 
Example #10
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testStereotypeApplication() {
    // builds a package with a class, applying a stereotype
    PackageBuilder packageBuilder = new UML2BuilderFactory().newBuilder(UML2ProductKind.PACKAGE);
    packageBuilder.name("myPackage");
    packageBuilder.applyProfile("myProfile");
    ClassifierBuilder classBuilder = packageBuilder.newClassifier(UML2ProductKind.CLASS);
    classBuilder.name("MyClass").applyStereotype("Stereotype1");

    // builds a profile with a stereotype
    PackageBuilder profileBuilder = new UML2BuilderFactory().newBuilder(UML2ProductKind.PROFILE);
    profileBuilder.name("myProfile");
    ClassifierBuilder stereotypeBuilder = profileBuilder.newClassifier(UML2ProductKind.STEREOTYPE);
    stereotypeBuilder.name("Stereotype1");
    stereotypeBuilder.extend("uml::Class", false);

    // builds the model from the given package builders
    new UML2ModelBuildDriver().build(buildContext, packageBuilder, profileBuilder);

    assertFalse(buildContext.getProblemTracker().hasProblems(Severity.ERROR));

    Classifier targetClass = classBuilder.getProduct();
    Stereotype stereotype = (Stereotype) stereotypeBuilder.getProduct();
    assertTrue(targetClass.isStereotypeApplied(stereotype));
}
 
Example #11
Source File: TextUMLCompletionProcessor.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private Stereotype findStereotypeByName(String profileName, String name) {
    Profile profile = findProfileByName(profileName);
    if (profile == null)
        return null;
    EList<Element> elements = profile.getOwnedElements();
    for (Iterator<Element> iterator = elements.iterator(); iterator.hasNext();) {
        Element element = iterator.next();
        if (element instanceof Stereotype)
            if (((Stereotype) element).getName().equals(name))
                return (Stereotype) element;
    }
    return null;
}
 
Example #12
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The meta reference facility is not currently in use.
 */
@Deprecated
public static ValueSpecification buildMetaReference(Package parent, Element referred, Type type) {
	LiteralNull nullLiteral = MDDUtil.createLiteralNull(parent);
	Stereotype referenceStereotype = StereotypeUtils.findStereotype(META_REFERENCE_STEREOTYPE);
	nullLiteral.applyStereotype(referenceStereotype);
	nullLiteral.setValue(referenceStereotype, "target", referred);
	nullLiteral.setType(type);
	return nullLiteral;
}
 
Example #13
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Object getBasicValue(ValueSpecification specification) {
	Assert.isLegal(isBasicValue(specification));
	String stringValue = ((LiteralString) specification).getValue();
	Stereotype basicValueStereotype = specification.getAppliedStereotype(BASIC_VALUE_STEREOTYPE);
	Classifier basicType = (Classifier) specification.getValue(basicValueStereotype, "basicType");
	return BasicTypeUtils.buildBasicValue(basicType, stringValue);
}
 
Example #14
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Constraint createConstraint(NamedElement element, String constraintName,
		Stereotype invariantStereotype, boolean isStatic) {
	Namespace namespace = element instanceof Namespace ? ((Namespace) element) : element.getNamespace();
	Constraint invariant = namespace.createOwnedRule(constraintName);
	invariant.applyStereotype(invariantStereotype);
	setConstraintAsStatic(invariant, isStatic);
	invariant.getConstrainedElements().add(element);
	return invariant;
}
 
Example #15
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static void setConstraintAsStatic(Constraint constraint, boolean isStatic) {
	EList<Stereotype> appliedStereotypes = constraint.getAppliedStereotypes();
	Stereotype stereotype = appliedStereotypes.stream().filter(it -> { 
		EList<Class> allExtendedMetaclasses = it.getAllExtendedMetaclasses();
		return allExtendedMetaclasses.stream().anyMatch(mc -> {
			boolean isConstraint = UMLPackage.Literals.CONSTRAINT.getName().equals(mc.getName());
			return isConstraint;
		});
	}).findAny().orElseThrow(() -> new IllegalArgumentException());
	constraint.setValue(stereotype, CONTEXTUALIZED_CONSTRAINT_IS_STATIC_PROPERTY, isStatic);
}
 
Example #16
Source File: Uml2Service.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the stereotype.
 * 
 * @param clazz
 * @param stereotypeName
 * @return
 */
public static Stereotype getStereotype(Element clazz, String stereotypeName) {
	if(clazz==null) return null;
	List<Stereotype> stereotypes = clazz.getAppliedStereotypes();
	for (Stereotype stereotype : stereotypes) {
		if (stereotype.getName().equals(stereotypeName)) {
			return stereotype;
		}
	}
	return null;
}
 
Example #17
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Constraint createAccessConstraint(NamedElement constrainedElement, String name,
		Collection<Class> roles, Collection<AccessCapability> allowed) {
	Stereotype accessStereotype = StereotypeUtils.findStereotype(ACCESS_STEREOTYPE);
	Enumeration accessCapabilityEnum = MDDCore.getInProgressRepository()
			.findNamedElement(ACCESS_CAPABILITY_ENUMERATION, Literals.ENUMERATION, null);
	boolean isStatic = allowed.stream().filter(it -> !it.isInstance()).findAny().isPresent();
	Constraint constraint = createConstraint(constrainedElement, name, accessStereotype, isStatic);
	constraint.setValue(accessStereotype, ACCESS_ALLOWED, toEnumerationLiterals(accessCapabilityEnum, allowed));
	constraint.setValue(accessStereotype, ACCESS_ROLES, new LinkedList<>(roles));
	return constraint;
}
 
Example #18
Source File: StereotypeUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean hasStereotype(Element element, String stereotypeQName) {
    for (Stereotype s : element.getAppliedStereotypes())
        if (stereotypeQName.equals(s.getName()) || stereotypeQName.equals(s.getQualifiedName()))
            return true;
    if (element instanceof Classifier)
        for (Classifier general : ((Classifier) element).getGenerals())
            if (hasStereotype(general, stereotypeQName))
                return true;
    return false;
}
 
Example #19
Source File: StereotypeUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Stereotype getStereotype(Element element, String stereotypeQName) {
    for (Stereotype s : element.getAppliedStereotypes())
        if (stereotypeQName.equals(s.getName()) || stereotypeQName.equals(s.getQualifiedName()))
            return s;
    if (element instanceof Classifier)
        for (Classifier general : ((Classifier) element).getGenerals()) {
            Stereotype found = getStereotype(general, stereotypeQName);
            if (found != null)
                return found;
        }
    return null;
}
 
Example #20
Source File: ElementBuilder.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void applyStereotypes() {
    for (NameReference stereotypeName : this.stereotypesApplied)
        new ReferenceSetter<Stereotype>(stereotypeName, getParentProduct(), getContext(),
                Step.STEREOTYPE_APPLICATIONS) {
            @Override
            protected void link(Stereotype stereotype) {
                if (!getProduct().isStereotypeApplicable(stereotype))
                    getContext().getProblemTracker().add(new UnclassifiedProblem("Stereotype not applicable"));
                else
                    getProduct().applyStereotype(stereotype);
            }
        };
}
 
Example #21
Source File: TextUMLCompletionProcessor.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private List<String> findTaggedAttributesForStereotype(Stereotype stereotype) {
    List<String> result = new ArrayList<String>();
    for (Iterator<Property> iterator = stereotype.getAllAttributes().iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        result.add(property.getName());
    }
    return result;
}
 
Example #22
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testStereotypeApplicationPersistence() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype my_stereotype extends UML::Class end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "[my_stereotype] class SomeClass end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);

    getRepository().save(null);
    getRepository().dispose();
    // RepositoryService.DEFAULT.synchronizeCurrent();

    IRepository newRepo = MDDCore.createRepository(getRepository().getBaseURI());
    Class class_ = (Class) newRepo.findNamedElement("someModel::SomeClass", IRepository.PACKAGE.getClassifier(),
            null);
    assertNotNull(class_);
    Stereotype stereotype = (Stereotype) newRepo.findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertTrue(class_.isStereotypeApplied(stereotype));
    newRepo.dispose();
}
 
Example #23
Source File: TextUMLCompletionProcessor.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private List<Stereotype> findStereotypesForExtendedClass(List<Stereotype> stereos, EClass targetMetaclass) {
    List<Stereotype> result = new ArrayList<Stereotype>();
    for (Iterator<Stereotype> iterator = stereos.iterator(); iterator.hasNext();) {
        Stereotype stereotype = iterator.next();
        for (Iterator<Class> clazzIter = stereotype.getAllExtendedMetaclasses().iterator(); clazzIter.hasNext();) {
            Class clazz = clazzIter.next();
            // FIXME this does not handle inheritance (a stereotype for a
            // base metaclass should apply to any sub metaclasses)
            if (clazz.getName().equals(targetMetaclass.getName()))
                result.add(stereotype);
        }
    }
    return result;
}
 
Example #24
Source File: TextUMLCompletionProcessor.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private List<Stereotype> getStereotypes() {
    List<Stereotype> result = new ArrayList<Stereotype>();
    Package[] packages = getRepository().getTopLevelPackages(null);
    Profile[] validProfiles = getValidProfiles(packages);
    for (int i = 0; i < validProfiles.length; i++) {
        EList<Element> elements = validProfiles[i].getOwnedElements();
        for (Iterator<Element> iterator = elements.iterator(); iterator.hasNext();) {
            Element element = iterator.next();
            if (element instanceof Stereotype)
                result.add((Stereotype) element);
        }
    }
    return result;
}
 
Example #25
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testParameterStereotypeApplication() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype my_stereotype1 extends UML::Parameter end;\n";
    profileSource += "stereotype my_stereotype2 extends UML::Parameter end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "import base;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "class SomeClass\n";
    modelSource += "  operation someOperation([my_stereotype1] out someParam : Integer) [my_stereotype2] : Boolean;\n";
    modelSource += "end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);
    Operation operation = (Operation) getRepository().findNamedElement("someModel::SomeClass::someOperation",
            IRepository.PACKAGE.getOperation(), null);
    Parameter param = operation.getOwnedParameter("someParam", null);
    assertEquals(ParameterDirectionKind.OUT_LITERAL, param.getDirection());
    Stereotype stereotype1 = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype1",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype1);
    assertTrue(param.isStereotypeApplied(stereotype1));

    Parameter returnParameter = operation.getReturnResult();
    Stereotype stereotype2 = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype2",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype2);
    assertTrue(returnParameter.isStereotypeApplied(stereotype2));

}
 
Example #26
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testStereotypeWithPropertiesSettingValues() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "import UML;\n";
    profileSource += "enumeration Values VALUE1; VALUE2; VALUE3; end;\n";
    profileSource += "stereotype my_stereotype extends Class\n";
    profileSource += "property prop1 : PrimitiveTypes::String;\n";
    profileSource += "property prop2 : PrimitiveTypes::Boolean;\n";
    profileSource += "property prop3 : PrimitiveTypes::Integer;\n";
    profileSource += "property prop4 : Values;\n";
    profileSource += "end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "[my_stereotype(prop1=\"value1\",prop2=true,prop3=45,prop4=VALUE2)]\n";
    modelSource += "class SomeClass end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);

    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    assertEquals("value1", someClass.getValue(stereotype, "prop1"));
    assertEquals(true, someClass.getValue(stereotype, "prop2"));
    assertEquals(45, someClass.getValue(stereotype, "prop3"));

    Enumeration valuesEnum = (Enumeration) getRepository().findNamedElement("someProfile::Values",
            IRepository.PACKAGE.getEnumeration(), null);
    final EnumerationLiteral expectedLiteral = valuesEnum.getOwnedLiteral("VALUE2");
    assertNotNull(expectedLiteral);
    assertEquals(expectedLiteral, someClass.getValue(stereotype, "prop4"));
}
 
Example #27
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));
}
 
Example #28
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testBasicStereotype() throws CoreException {
    String source = "";
    source += "profile someProfile;\n";
    source += "import UML;\n";
    source += "stereotype my_stereotype extends Class end;\n";
    source += "end.\n";
    parseAndCheck(source);
    Profile thisProfile = (Profile) getRepository().findPackage("someProfile", IRepository.PACKAGE.getProfile());
    assertTrue(thisProfile.isDefined());
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    assertTrue(thisProfile.getOwnedStereotypes().contains(stereotype));
}
 
Example #29
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testExtensions() throws CoreException {
    String source = "";
    source += "profile testExtensions;\n";
    source += "import UML;\n";
    source += "stereotype my_stereotype extends Class, Operation required end;\n";
    source += "end.\n";
    parseAndCheck(source);
    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("testExtensions::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    Class classMetaclass = getRepository().findNamedElement("UML::Class", Literals.CLASS, null);
    Class operationMetaclass = getRepository().findNamedElement("UML::Operation", Literals.CLASS, null);

    EList<Class> extendedMetaclasses = stereotype.getExtendedMetaclasses();
    assertEquals(2, extendedMetaclasses.size());
    assertEquals(classMetaclass, extendedMetaclasses.get(0));
    assertEquals(operationMetaclass, extendedMetaclasses.get(1));

    Extension operationExtension = operationMetaclass.getExtension("Operation_my_stereotype");
    assertNotNull(operationExtension);
    assertEquals(stereotype, operationExtension.getStereotype());
    assertTrue(operationExtension.isRequired());

    Extension classExtension = classMetaclass.getExtension("Class_my_stereotype");
    assertNotNull(classExtension);
    assertEquals(stereotype, classExtension.getStereotype());
    assertFalse(classExtension.isRequired());
}
 
Example #30
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testClassStereotypeWithProperties() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "import UML;\n";
    profileSource += "stereotype my_stereotype extends Class\n";
    profileSource += "property prop1 : PrimitiveTypes::Integer;\n";
    profileSource += "property prop2 : PrimitiveTypes::Boolean;\n";
    profileSource += "end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "[my_stereotype] class SomeClass end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);

    Stereotype stereotype = (Stereotype) getRepository().findNamedElement("someProfile::my_stereotype",
            IRepository.PACKAGE.getStereotype(), null);
    assertNotNull(stereotype);
    Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    assertNotNull(someClass);
    assertTrue(someClass.isStereotypeApplied(stereotype));
    assertNotNull(stereotype.getAttribute("prop1", null));
    assertNotNull(stereotype.getAttribute("prop2", null));
    assertNull(stereotype.getAttribute("prop3", null));
}