org.eclipse.uml2.uml.Classifier Java Examples

The following examples show how to use org.eclipse.uml2.uml.Classifier. 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: 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 #2
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 #3
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 #4
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 #5
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Helper method that creates generalizations.
 */
private void createGeneralization(String baseTypeName, final Classifier classifier, EClass superMetaClass,
        final Node contextNode) {
    if (superMetaClass == null)
        superMetaClass = classifier.eClass();
    getRefTracker().add(
            new DeferredReference<Classifier>(baseTypeName, superMetaClass, namespaceTracker.currentPackage()) {
                @Override
                protected void onBind(Classifier valueClass) {
                    if (valueClass == classifier)
                        // avoid creating a specialization on itself
                        return;
                    if (valueClass == null)
                        problemBuilder.addProblem(new UnresolvedSymbol(getSymbolName()), contextNode);
                    else
                        classifier.createGeneralization(valueClass);
                }
            }, Step.GENERAL_RESOLUTION);
}
 
Example #6
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void checkTemplateBinding(Classifier boundClassifier, final String templateClassName,
        final String templateBindingParameterTypeName) {
    assertNotNull(boundClassifier);
    Classifier templateClass = (Classifier) getRepository().findNamedElement(templateClassName,
            IRepository.PACKAGE.getClassifier(), null);
    Classifier templateParameterClassifier = (Classifier) getRepository().findNamedElement(
            templateBindingParameterTypeName, IRepository.PACKAGE.getClassifier(), null);
    final TemplateBinding templateBinding = boundClassifier.getTemplateBinding(templateClass
            .getOwnedTemplateSignature());
    assertNotNull(templateBinding);
    List<TemplateParameterSubstitution> substitutions = templateBinding.getParameterSubstitutions();
    assertEquals(1, substitutions.size());
    final TemplateParameter templateParameter = templateClass.getOwnedTemplateSignature().getOwnedParameters()
            .get(0);
    assertSame(templateParameter, substitutions.get(0).getFormal());
    assertSame(templateParameterClassifier, UML2Compatibility.getActualParameter(substitutions.get(0)));
    assertSame(boundClassifier, boundClassifier);
}
 
Example #7
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstraintsPerRole_BankAccount_open() throws CoreException {
  	parseAndCheck(source);
  	Class bankAccount = getClass("banking::BankAccount");
  	Operation openAction = getOperation("banking::BankAccount::open");
  	
  	Class branchManager = getClass("banking::BranchManager");
  	Class accountManager = getClass("banking::AccountManager");
  	Class teller = getClass("banking::Teller");
  	
  	Map<Classifier, Map<AccessCapability, Constraint>> computed = AccessControlUtils.computeConstraintsPerRoleClass(Arrays.asList(branchManager, teller, accountManager), Arrays.asList(AccessCapability.Call), Arrays.asList(bankAccount, openAction));
assertEquals(3, computed.size());
  	assertSameClasses(Arrays.asList(branchManager, accountManager, teller), computed.keySet());
  	
  	assertEquals(Collections.emptySet(), computed.get(branchManager).keySet());
  	assertEquals(Collections.emptySet(), computed.get(teller).keySet());
  	assertEquals(Collections.singleton(AccessCapability.Call), computed.get(accountManager).keySet());
  }
 
Example #8
Source File: TemplateTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testTemplateDeclarationWithOperation() throws CoreException {
    String model = "";
    model += "model test;\n";
    model += "class Bar<T>\n";
    model += "operation op1(a : 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);
    Operation operation = barClass.getOperation("op1", null, null);
    assertNotNull(operation);
    assertNotNull(operation.getOwnedParameter("a", parameterType));
}
 
Example #9
Source File: TemplateUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a template binding for the given template and parameters.
 * 
 * @param template
 * @param actualParam
 * @return the created bound element
 */
@SuppressWarnings("unchecked")
public static <TE extends TemplateableElement & NamedElement, PE extends ParameterableElement> TE createBinding(
        Namespace namespace, TE template, List<PE> actualParams) {
    TemplateSignature signature = template.getOwnedTemplateSignature();
    List<TemplateParameter> formalParameters = signature.getParameters();
    Assert.isTrue(formalParameters.size() == actualParams.size());
    TE result;
    if (template instanceof Classifier) {
        result = (TE) namespace.getNearestPackage().createOwnedType(null, template.eClass());
        result.setName(generateTemplateInstanceName(template, actualParams));
    } else if (template instanceof Operation)
        result = (TE) FeatureUtils.createOperation((Classifier) namespace, template.getName());
    else
        throw new IllegalArgumentException(template.eClass().getName());
    TemplateBinding binding = result.createTemplateBinding(signature);
    for (int i = 0; i < formalParameters.size(); i++) {
        TemplateParameterSubstitution substitution = binding.createParameterSubstitution();
        substitution.setFormal(signature.getOwnedParameters().get(i));
        UML2Compatibility.setActualParameter(substitution, actualParams.get(i));
    }
    return result;
}
 
Example #10
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 #11
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstraintsPerRole_harmlessAction() throws CoreException {
  	parseAndCheck(source);
  	Class bankAccount = getClass("banking::BankAccount");
  	Operation harmlessAction = getOperation("banking::BankAccount::harmlessAction");
  	
  	Class branchManager = getClass("banking::BranchManager");
  	Class accountManager = getClass("banking::AccountManager");
  	Class teller = getClass("banking::Teller");
  	
  	Map<Classifier, Map<AccessCapability, Constraint>> computed = AccessControlUtils.computeConstraintsPerRoleClass(Arrays.asList(branchManager, teller, accountManager), Arrays.asList(AccessCapability.Call), Arrays.asList(bankAccount, harmlessAction));
assertEquals(4, computed.size());
  	assertSameClasses(Arrays.asList(branchManager, accountManager, teller, null), computed.keySet());
  	
  	assertEquals(Collections.singleton(AccessCapability.Call), computed.get(null).keySet());
  	assertEquals(Collections.singleton(AccessCapability.Call), computed.get(branchManager).keySet());
  	assertEquals(Collections.singleton(AccessCapability.Call), computed.get(accountManager).keySet());
  	assertEquals(Collections.singleton(AccessCapability.Call), computed.get(teller).keySet());
  }
 
Example #12
Source File: AddStructuralFeatureValueActionBuilder.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void enhanceAction() {
    getProduct().createObject(null, null);
    buildSource(getProduct().getObject(), targetBuilder);

    Classifier targetClassifier = (Classifier) ActivityUtils.getSource(getProduct().getObject()).getType();
    getProduct().getObject().setType(targetClassifier);

    Property attribute = StructuralFeatureUtils.findAttribute(targetClassifier, featureName, false, true);
    if (attribute == null)
        abortStatement(new UnresolvedSymbol(featureName, Literals.STRUCTURAL_FEATURE));
    if (attribute.isDerived())
        abortStatement(new CannotModifyADerivedAttribute());
    getProduct().setStructuralFeature(attribute);

    getProduct().createValue(null, null);
    TypeUtils.copyType(attribute, getProduct().getValue(), targetClassifier);
    buildSource(getProduct().getValue(), valueBuilder);
}
 
Example #13
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstraintsPerRole_AccountApplication() throws CoreException {
	parseAndCheck(source);
	Class accountApplication = getClass("banking::AccountApplication");
	Class branchManager = getClass("banking::BranchManager");
	Class accountManager = getClass("banking::AccountManager");
	Class employee = getClass("banking::Employee");
	Class teller = getClass("banking::Teller");
	
	Map<Classifier, Map<AccessCapability, Constraint>> computed = AccessControlUtils.computeConstraintsPerRoleClass(Arrays.asList(employee, branchManager, teller, accountManager), Arrays.asList(AccessCapability.values()), Arrays.asList(accountApplication));
	
	assertSameClasses(Arrays.asList(branchManager, accountManager, teller, null), computed.keySet());
	
	Map<AccessCapability, Constraint> branchManagerConstraints = computed.get(branchManager);
	Map<AccessCapability, Constraint> accountManagerConstraints = computed.get(accountManager);
	Map<AccessCapability, Constraint> tellerConstraints = computed.get(teller);
	Map<AccessCapability, Constraint> anonymousConstraints = computed.get(null);
	
	Set<AccessCapability> allCapabilities = new LinkedHashSet<>(Arrays.asList(AccessCapability.values()));
	
	assertEquals(allCapabilities, branchManagerConstraints.keySet());
	assertEquals(allCapabilities, accountManagerConstraints.keySet());
	assertEquals(allCapabilities, tellerConstraints.keySet());
	assertEquals(Collections.singleton(AccessCapability.Create), anonymousConstraints.keySet());
}
 
Example #14
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void handleSameBinaryOperator(Node left, Node right) {
    TestIdentityAction action = (TestIdentityAction) builder.createAction(IRepository.PACKAGE
            .getTestIdentityAction());
    try {
        builder.registerInput(action.createFirst(null, null));
        builder.registerInput(action.createSecond(null, null));
        left.apply(this);
        right.apply(this);
        TypeUtils.copyType(ActivityUtils.getSource(action.getFirst()), action.getFirst());
        TypeUtils.copyType(ActivityUtils.getSource(action.getSecond()), action.getSecond());
        Classifier expressionType = BasicTypeUtils.findBuiltInType("Boolean");
        builder.registerOutput(action.createResult(null, expressionType));
        fillDebugInfo(action, left.parent());
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, left.parent(), getBoundElement());
}
 
Example #15
Source File: AccessControlTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testConstraintsPerRole_BankAccount() throws CoreException {
	parseAndCheck(source);
	Class bankAccount = getClass("banking::BankAccount");
	Class branchManager = getClass("banking::BranchManager");
	Class accountManager = getClass("banking::AccountManager");
	Class teller = getClass("banking::Teller");
	
	Map<Classifier, Map<AccessCapability, Constraint>> computed = AccessControlUtils.computeConstraintsPerRoleClass(Arrays.asList(branchManager, teller, accountManager), Arrays.asList(AccessCapability.values()), Arrays.asList(bankAccount));
	assertEquals(3, computed.size());
	assertSameClasses(Arrays.asList(branchManager, accountManager, teller), computed.keySet());
	
	Map<AccessCapability, Constraint> branchManagerConstraints = computed.get(branchManager);
	Map<AccessCapability, Constraint> accountManagerConstraints = computed.get(accountManager);
	Map<AccessCapability, Constraint> tellerConstraints = computed.get(teller);
	
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Call, AccessCapability.Delete, AccessCapability.Create, AccessCapability.Call)),
			branchManagerConstraints.keySet());
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Call, AccessCapability.Delete, AccessCapability.Create, AccessCapability.Call)),
			accountManagerConstraints.keySet());
	assertEquals(new LinkedHashSet<>(Arrays.asList(AccessCapability.Read, AccessCapability.List)),
			tellerConstraints.keySet());
}
 
Example #16
Source File: ClassifierBuilderTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testStereotype() {
    PackageBuilder packageBuilder = new UML2BuilderFactory().newBuilder(UML2ProductKind.PACKAGE);
    ClassifierBuilder stereotypeBuilder = packageBuilder.newClassifier(UML2ProductKind.STEREOTYPE);
    stereotypeBuilder.name("myStereotype");
    new UML2ModelBuildDriver().build(buildContext, stereotypeBuilder);
    assertNotNull(stereotypeBuilder.getProduct());
    Classifier product = stereotypeBuilder.getProduct();
    assertEquals("myStereotype", product.getName());
    assertNull(product.getNearestPackage());
}
 
Example #17
Source File: TemplateUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static void createSubclassTemplateBinding(Classifier base, Classifier sub, List<Type> subParams) {
    TemplateSignature signature = base.getOwnedTemplateSignature();
    List<TemplateParameter> formalParameters = signature.getParameters();
    Assert.isTrue(formalParameters.size() == subParams.size());
    TemplateBinding binding = sub.createTemplateBinding(signature);
    for (int i = 0; i < formalParameters.size(); i++) {
        TemplateParameterSubstitution substitution = binding.createParameterSubstitution();
        substitution.setFormal(signature.getOwnedParameters().get(i));
        UML2Compatibility.setActualParameter(substitution, subParams.get(i));
    }
}
 
Example #18
Source File: ClassifierUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static <T> T collectFromHierarchy(IRepository repository, final Classifier baseClass, boolean includeSubclasses, T collected, BiConsumer<Classifier, T> consumer) {
    Consumer<Classifier> collector = c -> consumer.accept(c, collected);
    if (!includeSubclasses) 
        runOnClasses(Stream.of(baseClass), collector);
    else
        runOnClasses(streamHierarchy(repository, baseClass), collector);
    return collected;
}
 
Example #19
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static ValueSpecification buildBasicValue(Package parent, Classifier type, String value) {
	LiteralString valueSpec = MDDUtil.createLiteralString(parent, value);
	Stereotype basicValueStereotype = StereotypeUtils.findStereotype(BASIC_VALUE_STEREOTYPE);
	valueSpec.applyStereotype(basicValueStereotype);
	valueSpec.setValue(value);
	valueSpec.setValue(basicValueStereotype, "basicType", type);
	valueSpec.setType(type);
	return valueSpec;
}
 
Example #20
Source File: AssociationUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the member end with the given name.
 * 
 * @param level
 * @param endName
 * @return
 */
public static Property findMemberEnd(Classifier level, String endName) {
    for (Association association : level.getAssociations())
        for (Property memberEnd : getMemberEnds(association, level))
            if (endName.equals(memberEnd.getName()))
                return memberEnd;
    for (Classifier general : level.getGenerals()) {
        Property found = findMemberEnd(general, endName);
        if (found != null)
            return found;
    }
    return null;
}
 
Example #21
Source File: AssociationUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static List<Association> allAssociations(Classifier classifier) {
    List<Association> result = new ArrayList<Association>();
    List<Classifier> allLevels = new ArrayList<Classifier>(classifier.allParents());
    allLevels.add(classifier);
    for (Classifier level : allLevels)
        result.addAll(getOwnAssociations(level));
    return result;
}
 
Example #22
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 #23
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAAttributeIdentifierExpression(AAttributeIdentifierExpression node) {
    ReadStructuralFeatureAction action = (ReadStructuralFeatureAction) builder.createAction(IRepository.PACKAGE
            .getReadStructuralFeatureAction());
    final String attributeIdentifier = TextUMLCore.getSourceMiner().getIdentifier(node.getIdentifier());
    try {
        builder.registerInput(action.createObject(null, null));
        super.caseAAttributeIdentifierExpression(node);
        builder.registerOutput(action.createResult(null, null));
        final ObjectNode targetSource = ActivityUtils.getSource(action.getObject());
        Classifier targetClassifier = (Classifier) TypeUtils.getTargetType(getRepository(), targetSource, true);
        if (targetClassifier == null) {
            problemBuilder.addError("Object type not determined for '"
                    + ((ATarget) node.getTarget()).getOperand().toString().trim() + "'", node.getIdentifier());
            throw new AbortedStatementCompilationException();
        }
        Property attribute = FeatureUtils.findAttribute(targetClassifier, attributeIdentifier, false, true);
        if (attribute == null) {
            problemBuilder.addProblem(new UnknownAttribute(targetClassifier.getName(), attributeIdentifier, false),
                    node.getIdentifier());
            throw new AbortedStatementCompilationException();
        }
        if (attribute.isStatic()) {
            problemBuilder.addError("Non-static attribute expected: '" + attributeIdentifier + "' in '"
                    + targetClassifier.getName() + "'", node.getIdentifier());
            throw new AbortedStatementCompilationException();
        }
        action.setStructuralFeature(attribute);
        action.getObject().setType(targetSource.getType());
        TypeUtils.copyType(attribute, action.getResult(), targetClassifier);
        checkIfTargetIsRequired(node.getTarget(), targetSource, () -> attribute.getName());
        if (!TypeUtils.isRequiredPin(targetSource) && !TypeUtils.isMultivalued(targetSource))
        	// it is a tentative access, result must be optional
        	action.getResult().setLower(0);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node.getIdentifier(), getBoundElement());
}
 
Example #24
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseANewIdentifierExpression(final ANewIdentifierExpression node) {
    ensureNotQuery(node);
    final CreateObjectAction action = (CreateObjectAction) builder.createAction(IRepository.PACKAGE
            .getCreateObjectAction());
    try {
        super.caseANewIdentifierExpression(node);
        final OutputPin output = builder.registerOutput(action.createResult(null, null));
        String qualifiedIdentifier = TextUMLCore.getSourceMiner().getQualifiedIdentifier(
                node.getMinimalTypeIdentifier());
        Classifier classifier = (Classifier) getRepository().findNamedElement(qualifiedIdentifier,
                IRepository.PACKAGE.getClassifier(), namespaceTracker.currentPackage());
        if (classifier == null) {
            problemBuilder.addError("Unknown classifier '" + qualifiedIdentifier + "'",
                    node.getMinimalTypeIdentifier());
            throw new AbortedStatementCompilationException();
        }
        if (classifier.isAbstract()) {
            problemBuilder.addProblem(new NotAConcreteClassifier(qualifiedIdentifier),
                    node.getMinimalTypeIdentifier());
            throw new AbortedStatementCompilationException();
        }
        output.setType(classifier);
        action.setClassifier(classifier);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node.getNew(), getBoundElement());
}
 
Example #25
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 #26
Source File: CallOperationActionBuilder.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void enhanceAction() {

    Operation operation = findNamedElement(operationName, Literals.OPERATION);
    getProduct().setOperation(operation);

    List<Parameter> signatureParameters = StructuralFeatureUtils.filterParameters(operation.getOwnedParameters(),
            ParameterDirectionKind.IN_LITERAL, ParameterDirectionKind.INOUT_LITERAL,
            ParameterDirectionKind.OUT_LITERAL);
    int parameterCount = signatureParameters.size();
    int argumentCount = argumentBuilders.size();
    if (parameterCount != argumentCount)
        abortStatement(new WrongNumberOfArguments(parameterCount, argumentCount));
    // TODO only if not static
    getProduct().createTarget(null, null);
    buildSource(getProduct().getTarget(), targetBuilder);
    Classifier targetClassifier = (Classifier) ActivityUtils.getSource(getProduct().getTarget()).getType();
    getProduct().getTarget().setType(targetClassifier);
    // matches parameters and arguments
    for (int i = 0; i < parameterCount; i++) {
        Parameter current = signatureParameters.get(i);
        InputPin argument = getProduct().createArgument(null, null);
        argument.setName(current.getName());
        TypeUtils.copyType(current, argument, targetClassifier);
        buildSource(argument, argumentBuilders.get(i));
    }
    // optional result
    if (operation.getReturnResult() != null) {
        final OutputPin result = getProduct().createResult(null, null);
        TypeUtils.copyType(operation.getReturnResult(), result, getBoundElement());
    }
}
 
Example #27
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testSourceInfo() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClassifier\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Classifier classifier = (Classifier) getRepository().findNamedElement("someModel::SomeClassifier",
            Literals.CLASS, null);
    EAnnotation unitInfo = classifier.getEAnnotation(MDDUtil.UNIT);
    assertNotNull(unitInfo);
    assertNotNull(unitInfo.getDetails());
    assertEquals("foo0." + fixtureHelper.getExtension(), unitInfo.getDetails().get("name"));
}
 
Example #28
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void handleIsClassifiedOperator(Node left, Node right) {
     ReadIsClassifiedObjectAction action = (ReadIsClassifiedObjectAction) builder.createAction(IRepository.PACKAGE
             .getReadIsClassifiedObjectAction());
     Node parent = left.parent();
     try {
     	if (!(right instanceof AMinimalTypeIdentifier)) {
             problemBuilder.addError("A qualified identifier is expected",
                     right);
             throw new AbortedStatementCompilationException();
     	}
         String qualifiedIdentifier = TextUMLCore.getSourceMiner().getQualifiedIdentifier(right);
         Classifier classifier = (Classifier) getRepository().findNamedElement(qualifiedIdentifier,
                 IRepository.PACKAGE.getClassifier(), namespaceTracker.currentPackage());
         
         ensure(classifier != null, true, right, () -> new UnknownType(qualifiedIdentifier));

         builder.registerInput(action.createObject(null, null));
         left.apply(this);
         Classifier expressionType = BasicTypeUtils.findBuiltInType("Boolean");
         builder.registerOutput(action.createResult(null, expressionType));
         action.setClassifier(classifier);
fillDebugInfo(action, parent);
     } finally {
         builder.closeAction();
     }
     checkIncomings(action, parent, getBoundElement());
 }
 
Example #29
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAClassAttributeIdentifierExpression(AClassAttributeIdentifierExpression node) {
    String typeIdentifier = TextUMLCore.getSourceMiner().getQualifiedIdentifier(node.getMinimalTypeIdentifier());
    Classifier targetClassifier = (Classifier) getRepository().findNamedElement(typeIdentifier,
            IRepository.PACKAGE.getClassifier(), namespaceTracker.currentNamespace(null));
    if (targetClassifier == null) {
        problemBuilder.addError("Class reference expected: '" + typeIdentifier + "'",
                node.getMinimalTypeIdentifier());
        throw new AbortedStatementCompilationException();
    }
    String attributeIdentifier = TextUMLCore.getSourceMiner().getIdentifier(node.getIdentifier());
    Property attribute = FeatureUtils.findAttribute(targetClassifier, attributeIdentifier, false, true);
    if (attribute != null) {
        buildReadStaticStructuralFeature(targetClassifier, attribute, node);
        return;
    }
    if (targetClassifier instanceof Enumeration) {
        EnumerationLiteral enumerationValue = ((Enumeration) targetClassifier).getOwnedLiteral(attributeIdentifier);
        if (enumerationValue != null) {
            InstanceValue valueSpec = (InstanceValue) namespaceTracker.currentPackage().createPackagedElement(null,
                    IRepository.PACKAGE.getInstanceValue());
            valueSpec.setInstance(enumerationValue);
            valueSpec.setType(targetClassifier);
            buildValueSpecificationAction(valueSpec, node);
            return;
        }
    }
    if (targetClassifier instanceof StateMachine) {
        Vertex state = StateMachineUtils.getState((StateMachine) targetClassifier, attributeIdentifier);
        if (state != null) {
            ValueSpecification stateReference = MDDExtensionUtils.buildVertexLiteral(
                    namespaceTracker.currentPackage(), state);
            buildValueSpecificationAction(stateReference, node);
            return;
        }
    }
    problemBuilder.addProblem(new UnknownAttribute(targetClassifier.getName(), attributeIdentifier, true),
            node.getIdentifier());
    throw new AbortedStatementCompilationException();
}
 
Example #30
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void buildReadStaticStructuralFeature(Classifier targetClassifier, Property attribute,
        AClassAttributeIdentifierExpression node) {
    ReadStructuralFeatureAction action = (ReadStructuralFeatureAction) builder.createAction(IRepository.PACKAGE
            .getReadStructuralFeatureAction());
    try {
        // // according to UML 2.1 ยง11.1, "(...) The semantics for static
        // features is undefined. (...)"
        // // our intepretation is that they are allowed and the input is a
        // null value spec
        // builder.registerInput(action.createObject(null, null));
        // LiteralNull literalNull = (LiteralNull)
        // currentPackage().createPackagedElement(null,
        // IRepository.PACKAGE.getLiteralNull());
        // buildValueSpecificationAction(literalNull, node);
        builder.registerOutput(action.createResult(null, targetClassifier));
        if (!attribute.isStatic()) {
            problemBuilder.addError("Static attribute expected: '" + attribute.getName() + "' in '"
                    + targetClassifier.getName() + "'", node.getIdentifier());
            throw new AbortedStatementCompilationException();
        }
        action.setStructuralFeature(attribute);
        // action.getObject().setType(targetClassifier);
        TypeUtils.copyType(attribute, action.getResult(), targetClassifier);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node.getIdentifier(), getBoundElement());
}