org.eclipse.uml2.uml.Type Java Examples

The following examples show how to use org.eclipse.uml2.uml.Type. 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: FieldImpl.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case ExtensionsPackage.FIELD__DIRECTION:
			setDirection(DIRECTION_EDEFAULT);
			return;
		case ExtensionsPackage.FIELD__DEFAULT_VALUE:
			setDefaultValue((Expression)null);
			return;
		case ExtensionsPackage.FIELD__TYPE:
			setType((Type)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #2
Source File: FieldImpl.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case ExtensionsPackage.FIELD__DIRECTION:
			setDirection((Direction)newValue);
			return;
		case ExtensionsPackage.FIELD__DEFAULT_VALUE:
			setDefaultValue((Expression)newValue);
			return;
		case ExtensionsPackage.FIELD__TYPE:
			setType((Type)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #3
Source File: WildcardTypeTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testOperationWildcardTypeInResult() throws CoreException {
    String model = "";
    model += "model tests;\n";
    model += "import base;\n";
    model += "class MyClass1\n";
    model += "  operation <T> op1() : T;\n";
    model += "end;\n";
    model += "end.";
    parseAndCheck(model);

    Operation op1 = getOperation("tests::MyClass1::op1");
    Type wildcardType = op1.getReturnResult().getType();
    assertTrue(MDDExtensionUtils.isWildcardTypeContext(op1));
    assertTrue(MDDExtensionUtils.isWildcardType(wildcardType));

    assertSame(op1, MDDExtensionUtils.getWildcardTypeContext(wildcardType));
    assertTrue(MDDExtensionUtils.getWildcardTypes(op1).contains(wildcardType));
}
 
Example #4
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 #5
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 #6
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void caseADestroySpecificStatement(ADestroySpecificStatement node) {
    final DestroyObjectAction action = (DestroyObjectAction) builder.createAction(IRepository.PACKAGE
            .getDestroyObjectAction());
    final InputPin object;
    try {
        object = action.createTarget(null, null);
        builder.registerInput(object);
        super.caseADestroySpecificStatement(node);
        final Type expressionType = ActivityUtils.getSource(object).getType();
        object.setType(expressionType);
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node, getBoundElement());
}
 
Example #7
Source File: FeatureUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isMatch(IRepository repository, Operation operation, List<TypedElement> arguments,
        ParameterSubstitutionMap substitutions) {
    if (arguments == null)
        return true;
    List<Parameter> operationParameters = getInputParameters(operation.getOwnedParameters());
    if (arguments.size() != operationParameters.size())
        return false;
    Map<Type, Type> wildcardSubstitutions = new HashMap<Type, Type>();
    for (Iterator<?> argIter = arguments.iterator(), parIter = operationParameters.iterator(); argIter.hasNext();) {
        Parameter parameter = (Parameter) parIter.next();
        TypedElement argument = (TypedElement) argIter.next();
        if (MDDExtensionUtils.isWildcardType(parameter.getType())) {
            Type existingWildcardSub = wildcardSubstitutions.put(parameter.getType(), argument.getType());
            if (existingWildcardSub != null && existingWildcardSub != argument.getType())
                return false;
        } else if (!TypeUtils.isCompatible(repository, argument, parameter, substitutions))
            return false;
    }
    return true;
}
 
Example #8
Source File: AbstractTypeResolver.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private Type basicResolveType(final Node node, final String qualifiedIdentifier, Type type) {
    if (type == null) {
        problemBuilder.addProblem(new UnknownType(qualifiedIdentifier), node);
        return null;
    }
    if (type instanceof Classifier) {
        final Classifier asClassifier = ((Classifier) type);
        if (asClassifier.isTemplate()) {
            if (this.parameterIdentifiers == null) {
                problemBuilder.addProblem(new UnboundTemplate(qualifiedIdentifier), node);
                return null;
            }
            type = createBinding(node, asClassifier);
        } else if (this.parameterIdentifiers != null) {
            problemBuilder.addProblem(new NotATemplate(qualifiedIdentifier), node);
            return null;
        }
    }
    return type;
}
 
Example #9
Source File: TypeUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * For a typed element that has a classifier as its type, determines the
 * actual target classifier.
 * 
 * The actual target classifier will be a collection type if the given typed
 * element is multivalued, otherwise it will be the original type itself.
 */
public static Type getTargetType(IBasicRepository repository, TypedElement typed, boolean resolveCollectionTypes) {
    Type type = typed.getType();
    if (!resolveCollectionTypes)
        return type;
    if (!(typed instanceof MultiplicityElement))
        return type;
    MultiplicityElement multiple = (MultiplicityElement) typed;
    if (!multiple.isMultivalued())
        return type;
    final boolean ordered = multiple.isOrdered();
    final boolean unique = multiple.isUnique();
    String collectionTypeName = "mdd_collections::"
            + (ordered ? (unique ? "OrderedSet" : "Sequence") : (unique ? "Set" : "Bag"));
    Classifier collectionType = (Classifier) repository.findNamedElement(collectionTypeName,
            IRepository.PACKAGE.getClass_(), null);
    Assert.isNotNull(collectionType, "Could not find collection type: " + collectionTypeName);
    return TemplateUtils.createBinding(typed.getNearestPackage(), collectionType, Collections.singletonList(type));
}
 
Example #10
Source File: TypeUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Copies the type from the source element to the target element. It also
 * does a few other things:
 * <ol>
 * <li>if the source type is a template formal parameter, replaces it with
 * the actual parameter</li>
 * <li>if the source element has multiplicity > 1, sets the target type to
 * be the corresponding collection type</li>
 * </ol>
 * 
 * @param source
 * @param target
 * @param boundElement
 */
public static void copyType(TypedElement source, TypedElement target, TemplateableElement boundElement) {
    Type sourceType = source.getType();
    if (sourceType == null) {
        target.setType(null);
        return;
    }
    // if source is a template parameter, resolve it if possible
    Assert.isTrue(!sourceType.isTemplateParameter() || boundElement != null);
    Type resolvedType = TemplateUtils.resolveTemplateParameters(boundElement, (Classifier) sourceType);
    target.setType(resolvedType);
    Assert.isLegal(source instanceof MultiplicityElement == target instanceof MultiplicityElement);
    if (!(source instanceof MultiplicityElement))
        return;
    copyMultiplicity((MultiplicityElement) source, (MultiplicityElement) target);
}
 
Example #11
Source File: IFMLSlotImpl.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void eUnset(int featureID) {
	switch (featureID) {
		case ExtensionsPackage.IFML_SLOT__DIRECTION:
			setDirection(DIRECTION_EDEFAULT);
			return;
		case ExtensionsPackage.IFML_SLOT__DEFAULT_VALUE:
			setDefaultValue((Expression)null);
			return;
		case ExtensionsPackage.IFML_SLOT__TYPE:
			setType((Type)null);
			return;
	}
	super.eUnset(featureID);
}
 
Example #12
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 #13
Source File: IFMLSlotImpl.java    From ifml-editor with MIT License 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
	switch (featureID) {
		case ExtensionsPackage.IFML_SLOT__DIRECTION:
			setDirection((Direction)newValue);
			return;
		case ExtensionsPackage.IFML_SLOT__DEFAULT_VALUE:
			setDefaultValue((Expression)newValue);
			return;
		case ExtensionsPackage.IFML_SLOT__TYPE:
			setType((Type)newValue);
			return;
	}
	super.eSet(featureID, newValue);
}
 
Example #14
Source File: BehaviorGenerator.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void caseARaiseSpecificStatement(ARaiseSpecificStatement node) {
    final RaiseExceptionAction action = (RaiseExceptionAction) builder.createAction(IRepository.PACKAGE
            .getRaiseExceptionAction());
    final InputPin exception;
    try {
        exception = action.createException(null, null);
        builder.registerInput(exception);
        super.caseARaiseSpecificStatement(node);
        final Type exceptionType = ActivityUtils.getSource(exception).getType();
        exception.setType(exceptionType);
        if (ActivityUtils.findHandler(action, (Classifier) exceptionType, true) == null)
            if (!builder.getCurrentActivity().getSpecification().getRaisedExceptions().contains(exceptionType))
                problemBuilder.addWarning("Exception '" + exceptionType.getQualifiedName()
                        + "' is not declared by operation", node.getRootExpression());
        fillDebugInfo(action, node);
    } finally {
        builder.closeAction();
    }
    checkIncomings(action, node.getRaise(), getBoundElement());
    // a raise exception action is a final action
    ActivityUtils.makeFinal(builder.getCurrentBlock(), action);
}
 
Example #15
Source File: FunctionTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testBasicFunction() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "function someFunction(par1 : Integer,par2 : Integer) : Boolean;\n";
    source += "end.";
    parseAndCheck(source);
    final FunctionBehavior function = (FunctionBehavior) getRepository().findNamedElement(
            "someModel::someFunction", IRepository.PACKAGE.getFunctionBehavior(), null);
    final Type booleanType = (Type) getRepository().findNamedElement("base::Boolean",
            IRepository.PACKAGE.getType(), null);
    final Type integerType = (Type) getRepository().findNamedElement("base::Integer",
            IRepository.PACKAGE.getType(), null);
    assertNotNull(function);
    assertNotNull(function.getOwnedParameter("par1", integerType));
    assertNotNull(function.getOwnedParameter("par2", integerType));
    assertNotNull(function.getOwnedParameter(null, booleanType));
}
 
Example #16
Source File: MDDUtil.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String getTypeName(Type type) {
    if (type == null)
        return "<any>";
    if (type.getName() != null)
        return type.getName();
    if (type instanceof Behavior)
        return computeSignatureName(type);
    if (MDDExtensionUtils.isSignature(type))
        return computeSignatureName(type);
    return "Unknown " + type.eClass().getName();
}
 
Example #17
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 #18
Source File: MDDUtil.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String computeSignatureName(List<Parameter> signature) {
    StringBuffer name = new StringBuffer("{(");
    final List<Parameter> inputParameters = FeatureUtils.getInputParameters(signature);
    for (Parameter parameter : inputParameters) {
        if (parameter.getName() != null) {
            name.append(parameter.getName());
            name.append(" ");
        }
        name.append(": ");
        final Type parameterType = parameter.getType();
        final String parameterTypeName = parameterType == null ? "any" : parameterType.getQualifiedName();
        name.append(parameterTypeName);
        addMultiplicity(name, parameter);
        name.append(", ");
    }
    if (!inputParameters.isEmpty())
        name.delete(name.length() - ", ".length(), name.length());
    name.append(")");
    List<Parameter> returnParameter = FeatureUtils.filterParameters(signature,
            ParameterDirectionKind.RETURN_LITERAL);
    if (!returnParameter.isEmpty()) {
        name.append(" : ");
        final Type returnType = returnParameter.get(0).getType();
        final String returnTypeName = returnType == null ? "any" : returnType.getQualifiedName();
        name.append(returnTypeName);
    }
    name.append('}');
    return name.toString();
}
 
Example #19
Source File: DeferredCollectionFiller.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAAnySingleTypeIdentifier(AAnySingleTypeIdentifier node) {
    final Type anyType = (Type) getContext().getRepository().findNamedElement(TypeUtils.ANY_TYPE,
            IRepository.PACKAGE.getType(), null);
    if (anyType == null) {
        problemBuilder.addProblem(new UnresolvedSymbol(TypeUtils.ANY_TYPE), node);
        throw new AbortedStatementCompilationException();
    }
    addElement(anyType);
}
 
Example #20
Source File: ActivityUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static ValueSpecification buildBehaviorReference(Package parent, Activity activity, Type type) {
    OpaqueExpression expression = (OpaqueExpression) parent.createPackagedElement(null,
            UMLPackage.Literals.OPAQUE_EXPRESSION);
    expression.setBehavior(activity);
    expression.setType(type == null ? activity : type);
    return expression;
}
 
Example #21
Source File: DataTypeUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static String computeTupleTypeName(List<String> slotNames, List<Type> slotTypes) {
    List<String> components = new ArrayList<String>();
    for (int i = 0; i < slotNames.size(); i++) {
        String componentName = StringUtils.trimToEmpty(slotNames.get(i)) + " : "
                + slotTypes.get(i).getQualifiedName();
        components.add(componentName);
    }
    return ANONYMOUS_PREFIX + "[" + StringUtils.join(components, ", ") + "]";
}
 
Example #22
Source File: DataTypeUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static DataType findOrCreateDataType(Package currentPackage, List<String> slotNames, List<Type> slotTypes) {
    // we set a name so we can easily find a similarly shaped/named data
    // type later
    String tupleTypeName = computeTupleTypeName(slotNames, slotTypes);
    DataType dataType = (DataType) currentPackage.getOwnedType(tupleTypeName, false, UMLPackage.Literals.DATA_TYPE,
            false);
    if (dataType == null) {
        dataType = (DataType) currentPackage.createOwnedType(null, UMLPackage.Literals.DATA_TYPE);
        for (int i = 0; i < slotNames.size(); i++)
            dataType.createOwnedAttribute(slotNames.get(i), slotTypes.get(i));
        dataType.setName(tupleTypeName);
        dataType.setVisibility(VisibilityKind.PRIVATE_LITERAL);
    }
    return dataType;
}
 
Example #23
Source File: TypeSetter.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAFunctionTypeIdentifier(AFunctionTypeIdentifier node) {
    processMultiplicity(node.getOptionalMultiplicity());
    final Type signature = MDDExtensionUtils.createSignature(getCurrentNamespace().getNearestPackage());
    node.getFunctionSignature().apply(
            new SignatureProcessor(getSourceContext(), getCurrentNamespace(), true, true) {
                @Override
                protected Parameter createParameter(String name) {
                    return MDDExtensionUtils.createSignatureParameter(signature, name, null);
                }
            });
    setType(signature);
    signature.setName(MDDUtil.computeSignatureName(signature));
}
 
Example #24
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 #25
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAReceptionDecl(final AReceptionDecl node) {
    final String receptionName = TextUMLCore.getSourceMiner().getIdentifier(node.getReceptionName());
    final Classifier parent = (Classifier) this.namespaceTracker.currentNamespace(null);
    final Reception reception = ReceptionUtils.createReception(parent, receptionName);
    if (reception == null) {
        problemBuilder.addError("Unexpected context for a reception", node.getReception());
        throw new AbortedCompilationException();
    }
    fillDebugInfo(reception, node);
    applyCurrentComment(reception);
    namespaceTracker.enterNamespace(reception);
    try {
        getRefTracker().add(new IDeferredReference() {
            public void resolve(IBasicRepository repository) {
                node.apply(new BehavioralFeatureSignatureProcessor(sourceContext, reception, false, true));
                Type signal = reception.getOwnedParameters().get(0).getType();
                if (!(signal instanceof Signal)) {
                    problemBuilder.addError("Reception parameter must be a signal", node.getReception());
                    throw new AbortedCompilationException();
                }
                if (ReceptionUtils.findBySignal(parent, (Signal) signal) != null) {
                    problemBuilder.addError("Another reception for this signal already defined",
                            node.getReception());
                    throw new AbortedCompilationException();
                }
                reception.setSignal((Signal) signal);
            }
        }, Step.GENERAL_RESOLUTION);

    } finally {
        namespaceTracker.leaveNamespace();
    }

}
 
Example #26
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static ValueSpecification buildEmptySet(Package parent, Type type) {
	LiteralNull emptySetLiteral = MDDUtil.createLiteralNull(parent);
	Stereotype referenceStereotype = StereotypeUtils.findStereotype(EMPTY_SET_STEREOTYPE);
	emptySetLiteral.applyStereotype(referenceStereotype);
	emptySetLiteral.setType(type);
	return emptySetLiteral;
}
 
Example #27
Source File: SignatureTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testFunctionAsParameter() throws CoreException {
    String model = "model tests;\n";
    model += "import base;\n";
    model += "class Test\n";
    model += "operation op1(filter: {(: Integer) : Boolean});\n";
    model += "begin\n";
    model += "end;\n";
    model += "end;\n";
    model += "end.\n";
    parseAndCheck(model);
    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);
    Operation op = (Operation) getRepository().findNamedElement("tests::Test::op1",
            IRepository.PACKAGE.getOperation(), null);
    assertNotNull(op);
    assertEquals(1, op.getOwnedParameters().size());
    Parameter opParam = op.getOwnedParameters().get(0);
    Type paramType = opParam.getType();
    assertTrue("found: " + paramType, MDDExtensionUtils.isSignature(paramType));
    assertEquals(2, MDDExtensionUtils.getSignatureParameters(paramType).size());
    Parameter signatureParam = MDDExtensionUtils.getSignatureParameters(paramType).get(0);
    assertNull(signatureParam.getName());
    assertEquals(ParameterDirectionKind.IN_LITERAL, signatureParam.getDirection());
    assertSame(integerType, signatureParam.getType());
    Parameter signatureReturn = MDDExtensionUtils.getSignatureParameters(paramType).get(1);
    assertNull(signatureReturn.getName());
    assertEquals(ParameterDirectionKind.RETURN_LITERAL, signatureReturn.getDirection());
    assertSame(booleanType, signatureReturn.getType());
}
 
Example #28
Source File: TypeSetter.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAMinimalTypeIdentifier(AMinimalTypeIdentifier node) {
    final String qualifiedIdentifier = TextUMLCore.getSourceMiner().getQualifiedIdentifier(node);
    Type type = resolveType(node, qualifiedIdentifier);
    if (type != null)
        setType(type);
}
 
Example #29
Source File: TypeSetter.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void caseAQualifiedSingleTypeIdentifier(AQualifiedSingleTypeIdentifier node) {
    // super.caseAQualifiedSingleTypeIdentifier(node);
    TemplateBindingProcessor<Classifier, Type> tbp = new TemplateBindingProcessor<Classifier, Type>();
    tbp.process(node);
    parameterIdentifiers = tbp.getParameterIdentifiers();
    node.getMinimalTypeIdentifier().apply(this);
}
 
Example #30
Source File: AbstractTypeResolver.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private Classifier createBinding(final Node node, final Classifier template) {
    TemplateSignature signature = template.getOwnedTemplateSignature();
    List<TemplateParameter> formalParameters = signature.getParameters();
    final int parameterCount = formalParameters.size();
    if (parameterCount != this.parameterIdentifiers.size()) {
        problemBuilder.addProblem(new WrongNumberOfArguments(parameterCount, this.parameterIdentifiers.size()),
                node);
        return null;
    }
    List<Type> templateParameterTypes = new ArrayList<Type>(parameterCount);
    for (int i = 0; i < parameterCount; i++) {
        final String templateParameterName = TextUMLCore.getSourceMiner().getQualifiedIdentifier(
                parameterIdentifiers.get(i));
        final Type resolvedParameterType = findType(templateParameterName);
        if (resolvedParameterType == null) {
            problemBuilder.addProblem(new UnknownType(templateParameterName), parameterIdentifiers.get(i));
            return null;
        }
        if (!signature.getParameters().get(i).getParameteredElement().isCompatibleWith(resolvedParameterType)) {
            problemBuilder.addProblem(new IncompatibleTemplateParameter(), parameterIdentifiers.get(i));
            return null;
        }
        templateParameterTypes.add(resolvedParameterType);
    }
    // now we know the actual parameters match the formal ones - let's
    // create the bound element and the template binding
    Classifier bound = TemplateUtils.createBinding(this.getCurrentNamespace().getNearestPackage(), template,
            templateParameterTypes);
    bound.setName(TemplateUtils.generateBoundElementName(template, templateParameterTypes));
    return bound;
}