-
Notifications
You must be signed in to change notification settings - Fork 34
/
UnionType.java
82 lines (71 loc) · 2.29 KB
/
UnionType.java
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
package com.redhat.ceylon.compiler.typechecker.model;
import java.util.List;
import java.util.Map;
public class UnionType extends TypeDeclaration {
public UnionType(Unit unit) {
this.unit = unit;
}
@Override
public String getName() {
String name = "";
for (ProducedType pt: getCaseTypes()) {
if (pt==null) {
name+="<unknown>";
}
else {
name+=pt.getProducedTypeName(false);
}
name+="|";
}
return name.substring(0,name.length()-1);
}
@Override
public String getQualifiedNameString() {
String name = "";
for (ProducedType pt: getCaseTypes()) {
if (pt==null) {
name+="<unknown>";
}
else {
name+=pt.getProducedTypeQualifiedName();
}
name+="|";
}
return name.substring(0,name.length()-1);
}
@Override
public String toString() {
return "UnionType[" + getName() + "]";
}
@Override @Deprecated
public List<String> getQualifiedName() {
throw new UnsupportedOperationException();
}
@Override
public ProducedType getType() {
if (getCaseTypes().size()==0) {
return unit.getBottomDeclaration().getType();
}
else if (getCaseTypes().size()==1) {
return getCaseTypes().get(0).getType();
}
else {
return super.getType();
}
}
@Override
public Map<DeclarationKey, DeclarationWithProximity> getMatchingMemberDeclarations(String startingWith, int proximity) {
//TODO: this can result in the wrong parameter types, and the
// same bug also affects intersection types
Map<DeclarationKey, DeclarationWithProximity> result = super.getMatchingMemberDeclarations(startingWith, proximity);
result.putAll(getCaseTypes().get(0).getDeclaration().getMatchingMemberDeclarations(startingWith, proximity));
for (ProducedType ct: getCaseTypes()) {
result.keySet().retainAll(ct.getDeclaration().getMatchingMemberDeclarations(startingWith, proximity).keySet());
}
return result;
}
@Override
public DeclarationKind getDeclarationKind() {
return null;
}
}