Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9861e6300ac65fb3d85252834aa2d614cfd74f01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
package org.eclipse.xtend.typesystem.uml2.profile;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.xtend.expression.TypeSystem;
import org.eclipse.xtend.typesystem.Feature;
import org.eclipse.xtend.typesystem.Type;

/**
 * This type is used to support assignment of multiple stereotypes to a
 * model element. Methods from the superclass are overridden to evaluate
 * them for each wrapped stereotype.
 * @author karsten.thoms@itemis.eu
 * @since 4.2
 */
public final class MultipleStereotypeType extends StereotypeType {
	List<StereotypeType> stereotypes;
	
	public MultipleStereotypeType(TypeSystem typeSystem, List<StereotypeType> stereotypes) {
		super(typeSystem, computeName(stereotypes), null);
		this.stereotypes = stereotypes;
	}

	/** Needed to be called within constructor */
	private static String computeName (List<StereotypeType> stereotypes) {
		String result = stereotypes.get(0).getName();
		for (int i=1; i<stereotypes.size(); i++) {
			result += ","+stereotypes.get(i).getName(); 
		}
		return result;
	}

	@Override
	public Feature[] getContributedFeatures() {
		List<Feature> features = new ArrayList<Feature>();
		for (StereotypeType st : stereotypes) {
			features.addAll(Arrays.asList(st.getContributedFeatures()));
		}
		return features.toArray(new Feature[stereotypes.size()]);
	}

	@Override
	public Set<Type> getSuperTypes() {
		Set<Type> superTypes = new HashSet<Type>();
		for (StereotypeType st : stereotypes) {
			superTypes.addAll(st.getSuperTypes());
		}
		return superTypes;
	}

	@Override
	public boolean isInstance(Object o) {
		for (StereotypeType st : stereotypes) {
			if (st.isInstance(o)) {
				return true;
			}
		}
		return false;
	}

	@Override
	protected boolean isCompatible(Type t) {
		for (StereotypeType st : stereotypes) {
			if (st.equals(t)) {
				return true;
			}
		}
		return false;
	}

	
}

Back to the top