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>
*
* Copyright (c) 2002-2007 itemis AG 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:
* itemis AG - Initial API and implementation
*
* </copyright>
*
*/
package org.eclipse.xpand3.analyzation.typesystem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.xpand3.analyzation.TypeSystem;
import org.eclipse.xpand3.staticTypesystem.AbstractTypeReference;
import org.eclipse.xpand3.staticTypesystem.FunctionType;
import org.eclipse.xpand3.staticTypesystem.Type;
/**
* @author Sven Efftinge
*
*/
public class CompositeTypeSystemImpl extends AbstractTypeSystemImpl implements TypeSystem {
private List<? extends TypeSystem> delegates = null;
public CompositeTypeSystemImpl(List<? extends TypeSystem> delegates) {
this.delegates = delegates;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.xand3.analyzation.TypeSystem#functionForName(java.lang.String,
* java.util.List,
* org.eclipse.xpand3.staticTypesystem.AbstractTypeReference[])
*/
public FunctionType functionForName(String name,
List<AbstractTypeReference> parameterTypes,
AbstractTypeReference... typeArguments) {
List<FunctionType> possibilities = new ArrayList<FunctionType>();
for (TypeSystem ts : delegates) {
FunctionType functionType = ts.functionForName(name, parameterTypes, typeArguments);
if (functionType!=null)
possibilities.add(functionType);
}
if (possibilities.isEmpty())
return null;
//TODO sort by specialization
return possibilities.get(0);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.xand3.analyzation.TypeSystem#functionForNameAndParameterTypes(java.lang.String,
* org.eclipse.xpand3.staticTypesystem.AbstractTypeReference[])
*/
public FunctionType functionForNameAndParameterTypes(String name,
AbstractTypeReference... parameterTypes) {
return functionForName(name, Arrays.asList(parameterTypes));
}
/*
* (non-Javadoc)
*
* @see org.eclipse.xand3.analyzation.TypeSystem#typeForName(java.lang.String,
* org.eclipse.xpand3.staticTypesystem.AbstractTypeReference[])
*/
public Type typeForName(String name, AbstractTypeReference... typeArguments) {
for (TypeSystem ts : delegates) {
Type type = ts.typeForName(name, typeArguments);
if (type!=null)
return type;
}
return null;
}
}
|