Skip to content

Commit 29efdb1

Browse files
committed
MetaType.getPreferredTypeSystem(Type)
1 parent a9c9939 commit 29efdb1

File tree

5 files changed

+60
-9
lines changed

5 files changed

+60
-9
lines changed

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeSystemImpl.java

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,37 @@ public IValue valueOf(IRMember member) {
9696
private final Map<Type, RTypeDeclaration> declarations = new HashMap<Type, RTypeDeclaration>();
9797

9898
public IRTypeDeclaration convert(Type type) {
99+
return convert0(resolveType(type));
100+
}
101+
102+
final IRTypeDeclaration convert0(Type type) {
103+
final ITypeSystem preferred = type.getMetaType()
104+
.getPreferredTypeSystem(type);
105+
if (preferred != null && preferred != this) {
106+
if (preferred instanceof TypeSystemImpl) {
107+
return ((TypeSystemImpl) preferred).convert1(type);
108+
} else {
109+
return preferred.convert(type);
110+
}
111+
}
112+
return convert1(type);
113+
}
114+
115+
final IRTypeDeclaration convert1(Type type) {
116+
synchronized (lock) {
117+
return convertType(type, null);
118+
}
119+
}
120+
121+
/**
122+
* Clears the cached data of this type system.
123+
*/
124+
public void reset() {
99125
synchronized (lock) {
100-
return convertType(type, new HashSet<Type>());
126+
declarations.clear();
127+
parameterized.clear();
128+
contextualized.clear();
129+
values.clear();
101130
}
102131
}
103132

@@ -108,6 +137,9 @@ private RTypeDeclaration convertType(Type type, Set<Type> processedTypes) {
108137
return declaration;
109138
}
110139
}
140+
if (processedTypes == null) {
141+
processedTypes = new HashSet<Type>();
142+
}
111143
if (!processedTypes.add(type)) {
112144
return null;
113145
}
@@ -131,9 +163,12 @@ private void buildType(final RTypeDeclaration declaration, Type type,
131163
declaration.setSuperType(parameterizeType(generic, RTypes
132164
.convert(this, ((ParameterizedType) superType)
133165
.getActualTypeArguments())));
134-
} else {
166+
} else if (declaration.isParameterized()) {
135167
declaration.setSuperType(parameterizeType(generic,
136168
declaration.getActualTypeArguments()));
169+
} else {
170+
declaration.setSuperType(convertType(generic,
171+
processedTypes));
137172
}
138173
} else {
139174
declaration.setSuperType(convertType(superType.getTarget(),
@@ -304,12 +339,11 @@ public String toString() {
304339
*/
305340
public IRTypeDeclaration parameterize(Type target, List<IRType> parameters) {
306341
target = resolveType(target);
342+
if (!(target instanceof GenericType)) {
343+
return convert0(target);
344+
}
307345
synchronized (lock) {
308-
if (target instanceof GenericType) {
309-
return parameterizeType((GenericType) target, parameters);
310-
} else {
311-
return convertType(target, new HashSet<Type>());
312-
}
346+
return parameterizeType((GenericType) target, parameters);
313347
}
314348
}
315349

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/DefaultMetaType.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
*******************************************************************************/
1212
package org.eclipse.dltk.javascript.typeinfo;
1313

14+
import org.eclipse.dltk.javascript.core.Types;
15+
import org.eclipse.dltk.javascript.internal.core.TypeSystems;
1416
import org.eclipse.dltk.javascript.typeinfo.model.Type;
17+
import org.eclipse.emf.ecore.resource.Resource;
1518

1619
public abstract class DefaultMetaType implements MetaType {
1720

@@ -36,4 +39,12 @@ public String toString() {
3639
return getId();
3740
}
3841

42+
public ITypeSystem getPreferredTypeSystem(Type type) {
43+
final Resource resource = type.eResource();
44+
if (resource != null && resource == Types.OBJECT.eResource()) {
45+
return TypeSystems.GLOBAL;
46+
}
47+
return null;
48+
}
49+
3950
}

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/MetaType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ public interface MetaType {
4444
*/
4545
IRType toRType(ITypeSystem typeSystem, IRTypeDeclaration declaration);
4646

47+
/**
48+
* Returns the preferred type system for converting the specified type to
49+
* {@link IRTypeDeclaration} or <code>null</code> if no preference.
50+
*/
51+
ITypeSystem getPreferredTypeSystem(Type type);
52+
4753
}

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/model/impl/ClassTypeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public IRType toRType(ITypeSystem typeSystem) {
147147
if (t != null && t.isProxy() && typeSystem != null) {
148148
t = typeSystem.resolveType(t);
149149
}
150-
return RTypes.classType(t);
150+
return RTypes.classType(typeSystem, t);
151151
}
152152

153153
/**

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/model/impl/SimpleTypeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public IRType toRType(ITypeSystem typeSystem) {
131131
if (t.isProxy() && typeSystem != null) {
132132
t = typeSystem.resolveType(t);
133133
}
134-
return RTypes.simple(t);
134+
return RTypes.simple(typeSystem, t);
135135
}
136136

137137
@Override

0 commit comments

Comments
 (0)