org.eclipse.uml2.uml.Interface Java Examples

The following examples show how to use org.eclipse.uml2.uml.Interface. 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: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testClassDependency() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "interface SomeInterface\n";
    source += "end;\n";
    source += "class SomeClass\n";
    source += "dependency SomeInterface;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    final Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    final Interface someInterface = (Interface) getRepository().findNamedElement("someModel::SomeInterface",
            IRepository.PACKAGE.getInterface(), null);
    assertNotNull(someClass);
    assertNotNull(someInterface);
    assertTrue(someClass.getClientDependencies().get(0).getSuppliers().contains(someInterface));
}
 
Example #2
Source File: ClassDiagramElementsManager.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the types of elements that are to be added
 * @return Returns the types of elements that are to be added
 */
private List<java.lang.Class<? extends Element>> generateElementsToBeAdded() {
	List<java.lang.Class<? extends Element>> nodes = new LinkedList<>(Arrays.asList(
			Class.class,
			Component.class,
			DataType.class,
			Enumeration.class,
			InformationItem.class,
			InstanceSpecification.class,
			Interface.class,
			Model.class,
			Package.class,
			PrimitiveType.class
	));
	
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_CONSTRAINT_PREF))
		nodes.add(Constraint.class);
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_COMMENT_PREF))
		nodes.add(Comment.class);
	if(PreferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_SIGNAL_PREF))
		nodes.add(Signal.class);
	
	return nodes;
}
 
Example #3
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testInterfaceSpecializes() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "interface SuperInterface\n";
    source += "end;\n";
    source += "interface SubInterface specializes SuperInterface\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    final Interface superInterface = (Interface) getRepository().findNamedElement("someModel::SuperInterface",
            IRepository.PACKAGE.getInterface(), null);
    final Interface subInterface = (Interface) getRepository().findNamedElement("someModel::SubInterface",
            IRepository.PACKAGE.getInterface(), null);
    assertNotNull(superInterface);
    assertNotNull(subInterface);
    assertNotNull(subInterface.getGeneralization(superInterface));
}
 
Example #4
Source File: CppExporterUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
public static String getUsedInterfaceName(Interface inf) {
	EList<Element> modelRoot = inf.getModel().allOwnedElements();
	List<Usage> usages = new ArrayList<>();
	CppExporterUtils.getTypedElements(usages, UMLPackage.Literals.USAGE, modelRoot);

	Optional<Usage> infOptionalUsage = usages.stream().filter(u -> u.getClients().contains(inf)).findFirst();
	if (infOptionalUsage.isPresent()) {
		Usage infUsage = infOptionalUsage.get();
		if (infUsage.getSuppliers().isEmpty()) {
			return GenerationNames.InterfaceNames.EmptyInfName;
		}
		return PrivateFunctionalTemplates.mapUMLTypeToCppClass(infUsage.getSuppliers().get(0).getName());
	} else {
		return GenerationNames.InterfaceNames.EmptyInfName;
	}
}
 
Example #5
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testClassImplements() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "interface SomeInterface\n";
    source += "end;\n";
    source += "class SomeClass implements SomeInterface\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    final Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    final Interface someInterface = (Interface) getRepository().findNamedElement("someModel::SomeInterface",
            IRepository.PACKAGE.getInterface(), null);
    assertNotNull(someClass);
    assertNotNull(someInterface);
    assertTrue(someClass.getImplementedInterfaces().contains(someInterface));
}
 
Example #6
Source File: InterfaceRealizationRenderer.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean basicRenderObject(InterfaceRealization element, IndentedPrintWriter pw, IRenderingSession context) {
    final BehavioredClassifier implementor = element.getImplementingClassifier();
    final Interface contract = element.getContract();
    if (!shouldRender(context, implementor, contract))
        return true;
    context.render(contract, contract.eResource() != element.eResource());
    context.render(implementor, implementor.eResource() != element.eResource());
    pw.print("edge ");
    pw.println("[");
    pw.enterLevel();
    DOTRenderingUtils.addAttribute(pw, "arrowtail", "empty");
    DOTRenderingUtils.addAttribute(pw, "arrowhead", "none");
    DOTRenderingUtils.addAttribute(pw, "taillabel", "");
    DOTRenderingUtils.addAttribute(pw, "headlabel", "");
    DOTRenderingUtils.addAttribute(pw, "style", "dashed");
    pw.exitLevel();
    pw.println("]");
    pw.println(contract.getName() + ":port" + " -- " + implementor.getName() + ":port");
    return true;
}
 
Example #7
Source File: InterfaceRenderer.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public boolean renderObject(Interface interface_, IndentedPrintWriter writer, IRenderingSession context) {
    RenderingUtils.renderAll(context, ElementUtils.getComments(interface_));
    TextUMLRenderingUtils.renderStereotypeApplications(writer, interface_);
    writer.print("interface " + name(interface_));
    List<Generalization> generalizations = interface_.getGeneralizations();
    StringBuilder specializationList = new StringBuilder();
    for (Generalization generalization : generalizations)
        specializationList.append(TextUMLRenderingUtils.getQualifiedNameIfNeeded(generalization.getGeneral(),
                interface_.getNamespace()) + ", ");
    if (specializationList.length() > 0) {
        specializationList.delete(specializationList.length() - 2, specializationList.length());
        writer.print(" specializes ");
        writer.print(specializationList);
    }
    writer.println();
    writer.enterLevel();
    RenderingUtils.renderAll(context, interface_.getOwnedAttributes());
    RenderingUtils.renderAll(context, interface_.getOwnedOperations());
    RenderingUtils.renderAll(context, interface_.getClientDependencies());
    writer.exitLevel();
    writer.println("end;");
    writer.println();
    return true;
}
 
Example #8
Source File: ClassifierUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public static List<Classifier> findAllSpecifics(IRepository repository, final Classifier general) {
	boolean isInterface = general instanceof Interface;
    List<Classifier> specifics = repository.findInAnyPackage(new EObjectCondition() {
        @Override
        public boolean isSatisfied(EObject object) {
            if (object instanceof Classifier) {
            	if (object == general) 
            		return false;
                Classifier classifier = (Classifier) object;
                if (classifier.conformsTo(general))
                	return true;
                if (isInterface && object instanceof BehavioredClassifier)
                	return doesImplement((BehavioredClassifier) object, (Interface) general);
            }
            return false;
        }
    });
    return specifics;
}
 
Example #9
Source File: ConnectorUtils.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private static Property findProvidingPart(Set<ConnectorEnd> visited, List<Interface> required,
        ConnectorEnd connectorEnd) {
    if (!visited.add(connectorEnd))
        // already visited
        return null;
    if (connectorEnd.getRole() instanceof Port) {
        Port asPort = (Port) connectorEnd.getRole();
        if (!asPort.getProvideds().containsAll(required) && !asPort.getRequireds().containsAll(required))
            // wrong path
            return null;
        Property found = findProvidingPart(visited, required, asPort);
        if (found != null)
            return found;
        return findProvidingPart(visited, required, getAllEnds(connectorEnd));
    } else {
        Property asProperty = (Property) connectorEnd.getRole();
        return asProperty;
    }
}
 
Example #10
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Type createSignature(Namespace namespace) {
	namespace = NamedElementUtils.findNearestNamespace(namespace, UMLPackage.Literals.PACKAGE,
			UMLPackage.Literals.CLASS);
	Interface signature = ClassifierUtils.createClassifier(namespace, null, Literals.INTERFACE);
	signature.createOwnedOperation("signatureOperation", null, null);
	Stereotype signatureStereotype = StereotypeUtils.findStereotype(SIGNATURE_STEREOTYPE);
	signature.applyStereotype(signatureStereotype);
	signature.setValue(signatureStereotype, SIGNATURE_CONTEXT, namespace);
	return signature;
}
 
Example #11
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testBasicInterface() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "interface SomeInterface\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    final Interface interface_ = (Interface) getRepository().findNamedElement("someModel::SomeInterface",
            IRepository.PACKAGE.getInterface(), null);
    assertNotNull(interface_);
}
 
Example #12
Source File: ComponentTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testPorts() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "interface Interface1\n";
    source += "end;\n";
    source += "interface Interface2\n";
    source += "end;\n";
    source += "class SomeClass\n";
    source += "    required port p1 : Interface1;\n";
    source += "    static required port sp1 : Interface1;\n";
    source += "    provided port p2 : Interface2;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class someClass = getClass("someModel::SomeClass");
    Interface someInterface1 = get("someModel::Interface1", IRepository.PACKAGE.getInterface());
    Interface someInterface2 = get("someModel::Interface2", IRepository.PACKAGE.getInterface());

    Port p1 = someClass.getOwnedPort("p1", null);
    assertNotNull(p1);
    assertNotNull(p1.getType());
    assertTrue(p1.getType() instanceof BehavioredClassifier);
    BehavioredClassifier p1Type = (BehavioredClassifier) p1.getType();
    assertEquals(Collections.singletonList(someInterface1), p1Type.getImplementedInterfaces());
    assertEquals(0, p1Type.getUsedInterfaces().size());

    Port p2 = someClass.getOwnedPort("p2", null);
    assertNotNull(p2.getType());
    assertNotNull(p2);
    assertTrue(p2.getType() instanceof BehavioredClassifier);
    BehavioredClassifier p2Type = (BehavioredClassifier) p2.getType();
    assertEquals(Collections.singletonList(someInterface2), p2Type.getImplementedInterfaces());
    assertEquals(0, p2Type.getUsedInterfaces().size());

    assertEquals(0, p1.getProvideds().size());
    assertEquals(Collections.singletonList(someInterface1), p1.getRequireds());

    assertEquals(0, p2.getRequireds().size());
    assertEquals(Collections.singletonList(someInterface2), p2.getProvideds());
}
 
Example #13
Source File: ClassifierBuilder.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void realizeInterfaces() {
    for (NameReference toResolve : contracts)
        new ReferenceSetter<Interface>(toResolve, getParentProduct(), getContext()) {
            @Override
            protected void link(Interface contract) {
                ((BehavioredClassifier) getProduct()).createInterfaceRealization(null, contract);
            }
        };
}
 
Example #14
Source File: OperationBuilder.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Operation createProduct() {
    if (getParentProduct() != null) {
        if (getParentProduct() instanceof org.eclipse.uml2.uml.Class)
            return ((Class) getParentProduct()).createOwnedOperation(null, null, null);
        if (getParentProduct() instanceof DataType)
            return ((DataType) getParentProduct()).createOwnedOperation(null, null, null);
        if (getParentProduct() instanceof Interface)
            return ((Interface) getParentProduct()).createOwnedOperation(null, null, null);
    }
    return (Operation) EcoreUtil.create(getEClass());
}
 
Example #15
Source File: FeatureUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static List<? extends BehavioralFeature> getBehavioralFeatures(Classifier classifier) {
    if (!(classifier instanceof Interface) && !(classifier instanceof Class))
        return classifier.getOperations();
    List<BehavioralFeature> combined = new ArrayList<>(classifier.getOperations());
    EList<Reception> receptions = (classifier instanceof Interface) ? ((Interface) classifier).getOwnedReceptions()
            : ((Class) classifier).getOwnedReceptions();
    combined.addAll(receptions);
    return combined;
}
 
Example #16
Source File: Uml2Service.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Should web3 file being generated.
 * 
 * @param an
 *            element
 * @return
 */
public static String solidity2javaType(Type type) {
	IPreferenceStore store = getStore(type);		
	String typeName="";
	if(hasStereotype(type, "Contract")||hasStereotype(type, "Library")|| type instanceof Interface)
		typeName = store.getString(PreferenceConstants.GENERATION_JAVA_2_SOLIDITY_TYPE_PREFIX+"address");
	else
		typeName = store.getString(PreferenceConstants.GENERATION_JAVA_2_SOLIDITY_TYPE_PREFIX+type.getName());
	if(typeName==null)
		return "String";
	
	return typeName;
}
 
Example #17
Source File: ConnectorUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private static Property findProvidingPart(Set<ConnectorEnd> visited, List<Interface> required,
        List<ConnectorEnd> ends) {
    for (ConnectorEnd end : ends) {
        Property provider = findProvidingPart(visited, required, end);
        if (provider != null)
            return provider;
    }
    return null;
}
 
Example #18
Source File: Uml2ToCppExporter.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private void createInterfaces(String outputDirectory) throws FileNotFoundException, UnsupportedEncodingException {
	List<Interface> interfaces = new ArrayList<Interface>();

	CppExporterUtils.getTypedElements(interfaces, UMLPackage.Literals.INTERFACE, modelRoot);

	for (Interface inf : interfaces) {
		if (!inf.getOwnedReceptions().isEmpty()) {
			InterfaceExporter interfaceExporter = new InterfaceExporter(inf,inf.getName(), outputDirectory);
			interfaceExporter.createUnitSource();
		}

	}
}
 
Example #19
Source File: PortExporter.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private Pair<String,String> getPortActualInterfaceTypes(Port port) {
	Interface portInf = (Interface) port.getType();
	String actualProvidedInfName = CppExporterUtils.getFirstGeneralClassName(portInf);
	String actualRequiredInfName = CppExporterUtils.getUsedInterfaceName(portInf);
			
	return new Pair<String,String>(actualProvidedInfName,actualRequiredInfName);
	
}
 
Example #20
Source File: InterfaceRenderer.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean renderObject(Interface element, IndentedPrintWriter w, IRenderingSession context) {
    if (!context.getSettings().getBoolean(SHOW_INTERFACES))
        return false;
    return super.renderObject(element, w, context);

}
 
Example #21
Source File: ReceptionUtils.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public static Reception createReception(Classifier parent, String receptionName) {
    if (parent instanceof Class)
        return ((Class) parent).createOwnedReception(receptionName, null, null);
    if (parent instanceof Interface)
        return ((Interface) parent).createOwnedReception(receptionName, null, null);
    return null;
}
 
Example #22
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public final void caseAClassImplementsItem(final AClassImplementsItem node) {
    if (!(namespaceTracker.currentNamespace(null) instanceof BehavioredClassifier)) {
        problemBuilder
                .addError(
                        "'"
                                + namespaceTracker.currentNamespace(null).getName()
                                + "' is not a behaviored classifier. Only behaviored classifiers (i.e. classes, stereotypes) can realize interfaces'",
                        node.getMinimalTypeIdentifier());
        throw new AbortedCompilationException();
    }
    final BehavioredClassifier implementingClassifier = (BehavioredClassifier) namespaceTracker
            .currentNamespace(null);
    String qualifiedIdentifier = TextUMLCore.getSourceMiner().getQualifiedIdentifier(
            node.getMinimalTypeIdentifier());
    getRefTracker().add(
            new DeferredReference<Interface>(qualifiedIdentifier, IRepository.PACKAGE.getInterface(),
                    namespaceTracker.currentPackage()) {
                @Override
                protected void onBind(Interface interface_) {
                    if (interface_ == null) {
                        problemBuilder.addError("Could not find interface: '" + getSymbolName() + "'",
                                node.getMinimalTypeIdentifier());
                        return;
                    }
                    InterfaceRealization realization = implementingClassifier.createInterfaceRealization(null,
                            interface_);
                    processAnnotations(node.getAnnotations(), realization);
                }
            }, Step.GENERAL_RESOLUTION);
}
 
Example #23
Source File: UMLExportTestBase.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
protected Interface getProvided(Port port) {
	Interface actualIface = port.getProvideds().get(0);
	Interface formalIface = (Interface) actualIface.getGenerals().get(0);
	assertNotNull(formalIface);
	return formalIface;
}
 
Example #24
Source File: InterfaceExporter.java    From txtUML with Eclipse Public License 1.0 4 votes vote down vote up
public InterfaceExporter(Interface structuredElement, String name, String dest) {
	super(structuredElement, name, dest);
}
 
Example #25
Source File: StereotypeTests.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public void testRealizationStereotypeApplication() throws CoreException {
    String profileSource = "";
    profileSource += "profile someProfile;\n";
    profileSource += "stereotype class_annotation extends UML::Class end;\n";
    profileSource += "stereotype realization_annotation1 extends UML::InterfaceRealization end;\n";
    profileSource += "stereotype realization_annotation2 extends UML::InterfaceRealization end;\n";
    profileSource += "stereotype realization_annotation3 extends UML::InterfaceRealization end;\n";
    profileSource += "end.\n";

    String modelSource = "";
    modelSource += "model someModel;\n";
    modelSource += "apply someProfile;\n";
    modelSource += "interface Interface1\n";
    modelSource += "end;\n";
    modelSource += "interface Interface2\n";
    modelSource += "end;\n";
    modelSource += "class SomeClass\n";
    modelSource += "  implements\n";
    modelSource += "    [realization_annotation1]Interface1,\n";
    modelSource += "    [realization_annotation2,realization_annotation3]Interface2\n";
    modelSource += "end;\n";
    modelSource += "end.\n";
    parseAndCheck(profileSource, modelSource);
    Interface interface1 = getRepository().findNamedElement("someModel::Interface1",
            IRepository.PACKAGE.getClassifier(), null);
    Interface interface2 = getRepository().findNamedElement("someModel::Interface2",
            IRepository.PACKAGE.getClassifier(), null);
    Class someClass = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClassifier(), null);
    Stereotype stereotype1 = (Stereotype) getRepository().findNamedElement("someProfile::realization_annotation1",
            IRepository.PACKAGE.getStereotype(), null);
    Stereotype stereotype2 = (Stereotype) getRepository().findNamedElement("someProfile::realization_annotation2",
            IRepository.PACKAGE.getStereotype(), null);
    Stereotype stereotype3 = (Stereotype) getRepository().findNamedElement("someProfile::realization_annotation3",
            IRepository.PACKAGE.getStereotype(), null);

    assertNotNull(stereotype1);
    assertNotNull(stereotype2);
    assertNotNull(stereotype3);
    // realization of SuperClass1
    assertTrue(someClass.getInterfaceRealization(null, interface1).isStereotypeApplied(stereotype1));
    assertFalse(someClass.getInterfaceRealization(null, interface1).isStereotypeApplied(stereotype2));
    assertFalse(someClass.getInterfaceRealization(null, interface1).isStereotypeApplied(stereotype3));
    // realization of SuperClass2
    assertFalse(someClass.getInterfaceRealization(null, interface2).isStereotypeApplied(stereotype1));
    assertTrue(someClass.getInterfaceRealization(null, interface2).isStereotypeApplied(stereotype2));
    assertTrue(someClass.getInterfaceRealization(null, interface2).isStereotypeApplied(stereotype3));
}
 
Example #26
Source File: StructureGenerator.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void caseAPortDecl(final APortDecl node) {
    if (node.getIdentifier() == null && node.getPortConnector() == null) {
        problemBuilder.addProblem(new AnonymousDisconnectedPort(), node.getPort());
        return;
    }
    final String portIdentifier = TextUMLCore.getSourceMiner().getIdentifier(node.getIdentifier());
    if (!ensureNameAvailable(portIdentifier, node, Literals.PROPERTY))
        return;
    final Class owningClass = (Class) namespaceTracker.currentNamespace(UMLPackage.Literals.CLASS);
    final Port newPort = owningClass.createOwnedPort(portIdentifier, null);
    newPort.setIsService(false);
    fillDebugInfo(newPort, node);
    applyCurrentComment(newPort);
    String interfaceName = sourceMiner.getIdentifier(node.getMinimalTypeIdentifier());
    getRefTracker().add(
            new DeferredReference<Interface>(interfaceName, UMLPackage.Literals.INTERFACE, owningClass) {
                @Override
                protected void onBind(Interface target) {
                    if (target == null) {
                        problemBuilder.addError("Could not find interface: '" + getSymbolName() + "'",
                                node.getMinimalTypeIdentifier());
                        return;
                    }
                    Class portType = (Class) owningClass.createNestedClassifier("", UMLPackage.Literals.CLASS);
                    boolean provided = node.getPortModifier() instanceof AProvidedPortModifier;
                    if (provided) {
                        portType.createInterfaceRealization(null, target);
                    } else {
                        portType.createInterfaceRealization(null, target);
                        newPort.setIsConjugated(true);
                    }
                    newPort.setType(portType);
                    if (node.getPortConnector() != null) {
                        ConnectorProcessor connectorProcessor = new ConnectorProcessor(sourceContext, owningClass);
                        connectorProcessor.addEnd(newPort);
                        connectorProcessor.process((AConnectorEndList) ((APortConnector) node.getPortConnector())
                                .getConnectorEndList());
                    }
                    if (!provided && !ProjectPropertyHelper.isLibrary(context.getRepositoryProperties()))
                        getRefTracker().add(new IDeferredReference() {

                            @Override
                            public void resolve(IBasicRepository repository) {
                                Property provider = ConnectorUtils.findProvidingPart(newPort);
                                if (provider == null)
                                    problemBuilder.addProblem(new RequiredPortHasNoMatchingProviderPort(
                                            getSymbolName()), node.getMinimalTypeIdentifier());
                            }
                        }, Step.STRUCTURE_VALIDATION);
                }
            }, Step.GENERAL_RESOLUTION);
    applyModifiers(newPort, VisibilityKind.PUBLIC_LITERAL, node);
    annotationProcessor.applyAnnotations(newPort, node.getIdentifier());
}
 
Example #27
Source File: FeatureUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Finds an operation in the given classifier.
 * 
 * @param arguments
 *            the arguments to match, or null for name-based matching only
 */
public static Operation findOperation(IRepository repository, Classifier classifier, String operationName,
        List<TypedElement> arguments, ParameterSubstitutionMap substitutions, boolean ignoreCase, boolean recurse) {
    for (Operation operation : classifier.getOperations()) {
        if (isNameMatch(operation, operationName, ignoreCase)
                && (isMatch(repository, operation, arguments, substitutions)))
            return operation;
    }
    if (!recurse)
        return null;
    Operation found;
    final EList<TemplateBinding> templateBindings = classifier.getTemplateBindings();
    if (!templateBindings.isEmpty())
        for (TemplateBinding templateBinding : templateBindings) {
            TemplateSignature signature = templateBinding.getSignature();
            ParameterSubstitutionMap newSubstitutions = new ParameterSubstitutionMap(templateBinding);
            found = findOperation(repository, (Classifier) signature.getTemplate(), operationName, arguments,
                    newSubstitutions, ignoreCase, true);
            if (found != null)
                return found;
        }
    for (Generalization generalization : classifier.getGeneralizations())
        if ((found = findOperation(repository, generalization.getGeneral(), operationName, arguments,
                substitutions, ignoreCase, true)) != null)
            return found;
    // recurse to owning classifier
    for (Namespace owner = (Namespace) classifier.getOwner(); owner instanceof Classifier; owner = (Namespace) owner
            .getOwner())
        if ((found = findOperation(repository, (Classifier) owner, operationName, arguments, substitutions,
                ignoreCase, true)) != null)
            return found;
    // fallback to interfaces realized
    if (classifier instanceof BehavioredClassifier) {
        BehavioredClassifier asBehaviored = (BehavioredClassifier) classifier;
        for (Interface implemented : asBehaviored.getImplementedInterfaces())
            if ((found = findOperation(repository, implemented, operationName, arguments, substitutions,
                    ignoreCase, true)) != null)
                return found;
    }

    return null;
}
 
Example #28
Source File: ClassifierUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean doesImplement(BehavioredClassifier toTest, Interface candidateInterface) {
    return toTest.getAllImplementedInterfaces().stream().anyMatch(i -> i == candidateInterface);
}
 
Example #29
Source File: ConnectorUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
private static Property findProvidingPart(Set<ConnectorEnd> visited, List<Interface> requireds, Port port) {
    return findProvidingPart(visited, requireds, port.getEnds());
}
 
Example #30
Source File: MDDExtensionUtils.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isSignature(Element element) {
	return element instanceof Interface && StereotypeUtils.hasStereotype(element, SIGNATURE_STEREOTYPE);
}