diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index a1b41c52c72..7b82fc0712d 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -14,6 +14,7 @@
+
diff --git a/idea/src/jet/lang/Library.jet b/idea/src/jet/lang/Library.jet
new file mode 100644
index 00000000000..1b2b16eee1b
--- /dev/null
+++ b/idea/src/jet/lang/Library.jet
@@ -0,0 +1,62 @@
+namespace jet.lang
+
+virtual class Comparable {
+ fun compareTo(other : T) : Int
+}
+
+class Boolean {
+}
+
+class String {
+ fun get(index : Int) : Char
+ val length : Int
+
+ fun plus(other : Any?) : String
+}
+
+class Double {
+ fun plus(other : Double) : Double
+}
+
+class Float {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+}
+
+class Long {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+ fun plus(other : Long) : Long
+}
+
+class Int {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+ fun plus(other : Long) : Long
+ fun plus(other : Int) : Int
+}
+
+class Char {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+ fun plus(other : Long) : Long
+ fun plus(other : Int) : Int
+ fun plus(other : Char) : Char
+}
+
+class Short {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+ fun plus(other : Long) : Long
+ fun plus(other : Int) : Int
+ fun plus(other : Short) : Short
+}
+
+class Byte {
+ fun plus(other : Double) : Double
+ fun plus(other : Float) : Float
+ fun plus(other : Long) : Long
+ fun plus(other : Int) : Int
+ fun plus(other : Short) : Short
+ fun plus(other : Byte) : Byte
+}
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
index 14132b1f083..2760424463f 100644
--- a/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
+++ b/idea/src/org/jetbrains/jet/lang/resolve/ClassDescriptorResolver.java
@@ -18,7 +18,7 @@ public class ClassDescriptorResolver {
@Nullable
public ClassDescriptor resolveClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement) {
- ParameterExtensibleScope parameterScope = new ParameterExtensibleScope(scope);
+ WritableScope parameterScope = new WritableScope(scope);
// This call has side-effects on the parameterScope (fills it in)
List typeParameters
@@ -32,7 +32,7 @@ public class ClassDescriptorResolver {
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
WritableScope members = resolveMembers(classElement, typeParameters, scope, parameterScope, superclasses);
- return new ClassDescriptor(
+ return new ClassDescriptorImpl(
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
!open,
classElement.getName(),
@@ -49,7 +49,7 @@ public class ClassDescriptorResolver {
final JetScope typeParameterScope,
final Collection extends Type> supertypes) {
- final WritableScope memberDeclarations = new WritableScope();
+ final WritableScope memberDeclarations = new WritableScope(typeParameterScope);
List declarations = classElement.getDeclarations();
for (JetDeclaration declaration : declarations) {
@@ -86,7 +86,7 @@ public class ClassDescriptorResolver {
@NotNull
public FunctionDescriptor resolveFunctionDescriptor(JetScope scope, JetFunction function) {
- ParameterExtensibleScope parameterScope = new ParameterExtensibleScope(scope);
+ WritableScope parameterScope = new WritableScope(scope);
// The two calls below have side-effects on parameterScope
List typeParameterDescriptors = resolveTypeParameters(parameterScope, function.getTypeParameters());
List valueParameterDescriptors = resolveValueParameters(parameterScope, function.getValueParameters());
@@ -112,7 +112,7 @@ public class ClassDescriptorResolver {
);
}
- private List resolveValueParameters(ParameterExtensibleScope parameterScope, List valueParameters) {
+ private List resolveValueParameters(WritableScope parameterScope, List valueParameters) {
List result = new ArrayList();
for (JetParameter valueParameter : valueParameters) {
JetTypeReference typeReference = valueParameter.getTypeReference();
@@ -135,7 +135,7 @@ public class ClassDescriptorResolver {
return result;
}
- private static List resolveTypeParameters(ParameterExtensibleScope extensibleScope, List typeParameters) {
+ public List resolveTypeParameters(WritableScope extensibleScope, List typeParameters) {
// TODO : When-clause
List result = new ArrayList();
for (JetTypeParameter typeParameter : typeParameters) {
@@ -144,7 +144,7 @@ public class ClassDescriptorResolver {
return result;
}
- private static TypeParameterDescriptor resolveTypeParameter(ParameterExtensibleScope extensibleScope, JetTypeParameter typeParameter) {
+ private static TypeParameterDescriptor resolveTypeParameter(WritableScope extensibleScope, JetTypeParameter typeParameter) {
JetTypeReference extendsBound = typeParameter.getExtendsBound();
TypeParameterDescriptor typeParameterDescriptor = new TypeParameterDescriptor(
AttributeResolver.INSTANCE.resolveAttributes(typeParameter.getModifierList()),
@@ -158,7 +158,7 @@ public class ClassDescriptorResolver {
return typeParameterDescriptor;
}
- private static Collection extends Type> resolveTypes(ParameterExtensibleScope extensibleScope, List delegationSpecifiers) {
+ public static Collection extends Type> resolveTypes(WritableScope extensibleScope, List delegationSpecifiers) {
if (delegationSpecifiers.isEmpty()) {
return Collections.emptyList();
}
@@ -201,49 +201,4 @@ public class ClassDescriptorResolver {
property.getName(),
type);
}
-
- private static final class ParameterExtensibleScope extends JetScopeAdapter {
-
- private final Map typeParameterDescriptors = new HashMap();
- private final Map propertyDescriptors = new HashMap();
-
- private ParameterExtensibleScope(JetScope scope) {
- super(scope);
- }
-
- public void addTypeParameterDescriptor(TypeParameterDescriptor typeParameterDescriptor) {
- String name = typeParameterDescriptor.getName();
- if (typeParameterDescriptors.containsKey(name)) {
- throw new UnsupportedOperationException(); // TODO
- }
- typeParameterDescriptors.put(name, typeParameterDescriptor);
- }
-
- @Override
- public TypeParameterDescriptor getTypeParameter(String name) {
- TypeParameterDescriptor typeParameterDescriptor = typeParameterDescriptors.get(name);
- if (typeParameterDescriptor != null) {
- return typeParameterDescriptor;
- }
- return super.getTypeParameter(name);
- }
-
- public void addPropertyDescriptor(PropertyDescriptor descriptor) {
- String name = descriptor.getName();
- if (propertyDescriptors.containsKey(name)) {
- throw new UnsupportedOperationException(); // TODO
- }
- propertyDescriptors.put(name, descriptor);
- }
-
- @Override
- public PropertyDescriptor getProperty(String name) {
- PropertyDescriptor PropertyDescriptor = propertyDescriptors.get(name);
- if (PropertyDescriptor != null) {
- return PropertyDescriptor;
- }
- return super.getProperty(name);
- }
-
- }
}
diff --git a/idea/src/org/jetbrains/jet/lang/resolve/FileContentsResolver.java b/idea/src/org/jetbrains/jet/lang/resolve/FileContentsResolver.java
new file mode 100644
index 00000000000..129f0b4c783
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/lang/resolve/FileContentsResolver.java
@@ -0,0 +1,20 @@
+package org.jetbrains.jet.lang.resolve;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.*;
+
+/**
+ * @author abreslav
+ */
+public class FileContentsResolver {
+
+ public static final FileContentsResolver INSTANCE = new FileContentsResolver();
+
+ private FileContentsResolver() {}
+
+ @NotNull
+ public JetScope resolveFileContents(@NotNull JetScope scope, @NotNull JetFile file) {
+ return new LazyScope(scope, file.getRootNamespace().getDeclarations());
+ }
+
+}
diff --git a/idea/src/org/jetbrains/jet/lang/resolve/LazyClassDescriptor.java b/idea/src/org/jetbrains/jet/lang/resolve/LazyClassDescriptor.java
new file mode 100644
index 00000000000..06cb226dbcc
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/lang/resolve/LazyClassDescriptor.java
@@ -0,0 +1,84 @@
+package org.jetbrains.jet.lang.resolve;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
+import org.jetbrains.jet.lang.types.*;
+import org.jetbrains.jet.lexer.JetTokens;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author abreslav
+ */
+public class LazyClassDescriptor implements ClassDescriptor {
+ private final JetScope outerScope;
+ private JetClass declaration;
+ private TypeConstructor typeConstructor;
+ private LazyScope unsubstitutedMemberScope;
+ private List attributes;
+ private WritableScope parameterScope;
+ private List typeParameterDescriptors;
+
+ public LazyClassDescriptor(@NotNull JetScope scope, @NotNull JetClass klass) {
+ this.declaration = klass;
+ this.outerScope = scope;
+ }
+
+ @Override
+ public List getAttributes() {
+ if (attributes == null) {
+ attributes = AttributeResolver.INSTANCE.resolveAttributes(declaration.getModifierList());
+ }
+ return attributes;
+ }
+
+ @Override
+ public String getName() {
+ return declaration.getName();
+ }
+
+ @NotNull
+ @Override
+ public TypeConstructor getTypeConstructor() {
+ if (typeConstructor == null) {
+ List typeParameters = getTypeParameters();
+ List delegationSpecifiers = declaration.getDelegationSpecifiers();
+ // TODO : assuming that the hierarchy is acyclic
+ // TODO : cannot inherit from an inner class
+ Collection extends Type> superclasses = delegationSpecifiers.isEmpty()
+ ? Collections.singleton(JetStandardClasses.getAnyType())
+ : ClassDescriptorResolver.resolveTypes(getTypeParameterScope(), delegationSpecifiers);
+ boolean open = declaration.hasModifier(JetTokens.OPEN_KEYWORD);
+
+ typeConstructor = new TypeConstructor(getAttributes(), !open, getName(), typeParameters, superclasses);
+ }
+ return typeConstructor;
+ }
+
+ public WritableScope getTypeParameterScope() {
+ getTypeParameters();
+ return parameterScope;
+ }
+
+ private List getTypeParameters() {
+ if (parameterScope == null) {
+ parameterScope = new WritableScope(outerScope);
+ typeParameterDescriptors = ClassDescriptorResolver.INSTANCE.resolveTypeParameters(parameterScope, declaration.getTypeParameters());
+ }
+ return typeParameterDescriptors;
+ }
+
+ @Override
+ public JetScope getMemberScope(List typeArguments) {
+ if (unsubstitutedMemberScope == null) {
+ unsubstitutedMemberScope = new LazyScope(getTypeParameterScope(), declaration.getDeclarations());
+ }
+ List parameters = getTypeConstructor().getParameters();
+ Map substitutionContext = TypeSubstitutor.INSTANCE.buildSubstitutionContext(parameters, typeArguments);
+ return new SubstitutingScope(unsubstitutedMemberScope, substitutionContext);
+ }
+}
diff --git a/idea/src/org/jetbrains/jet/lang/resolve/LazyScope.java b/idea/src/org/jetbrains/jet/lang/resolve/LazyScope.java
new file mode 100644
index 00000000000..58840468058
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/lang/resolve/LazyScope.java
@@ -0,0 +1,81 @@
+package org.jetbrains.jet.lang.resolve;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetDeclaration;
+import org.jetbrains.jet.lang.psi.JetVisitor;
+import org.jetbrains.jet.lang.types.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author abreslav
+ */
+public class LazyScope extends JetScopeAdapter {
+ private final List declarations;
+
+ private Map classDescriptors;
+
+ public LazyScope(JetScope scope, List declarations) {
+ super(scope);
+ this.declarations = declarations;
+ }
+
+ public Map getClassDescriptors() {
+ if (classDescriptors == null) {
+ classDescriptors = new HashMap();
+ for (JetDeclaration declaration : declarations) {
+ declaration.accept(new JetVisitor() {
+ @Override
+ public void visitClass(JetClass klass) {
+ classDescriptors.put(klass.getName(), new LazyClassDescriptor(LazyScope.this, klass));
+ }
+ });
+ }
+ }
+ return classDescriptors;
+ }
+
+ @Override
+ public ClassDescriptor getClass(String name) {
+ ClassDescriptor classDescriptor = getClassDescriptors().get(name);
+ if (classDescriptor != null) {
+ return classDescriptor;
+ }
+ return super.getClass(name);
+ }
+
+ @Override
+ public PropertyDescriptor getProperty(String name) {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public ExtensionDescriptor getExtension(String name) {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public NamespaceDescriptor getNamespace(String name) {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @Override
+ public TypeParameterDescriptor getTypeParameter(String name) {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @NotNull
+ @Override
+ public Type getThisType() {
+ throw new UnsupportedOperationException(); // TODO
+ }
+
+ @NotNull
+ @Override
+ public FunctionGroup getFunctionGroup(@NotNull String name) {
+ throw new UnsupportedOperationException(); // TODO
+ }
+}
diff --git a/idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java b/idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
index ebfbf1cbd04..addfdcdeb0c 100644
--- a/idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
+++ b/idea/src/org/jetbrains/jet/lang/resolve/WritableScope.java
@@ -9,11 +9,21 @@ import java.util.*;
/**
* @author abreslav
*/
-public class WritableScope implements JetScope {
+public class WritableScope extends JetScopeAdapter {
@Nullable
private Map propertyDescriptors;
@Nullable
private Map functionGroups;
+ @Nullable
+ private Map typeParameterDescriptors;
+
+ public WritableScope(JetScope scope) {
+ super(scope);
+ }
+
+ public WritableScope() {
+ super(JetScope.EMPTY);
+ }
@NotNull
private Map getPropertyDescriptors() {
@@ -25,7 +35,9 @@ public class WritableScope implements JetScope {
public void addPropertyDescriptor(PropertyDescriptor propertyDescriptor) {
Map propertyDescriptors = getPropertyDescriptors();
- assert !propertyDescriptors.containsKey(propertyDescriptor.getName()) : "Property redeclared";
+ if (propertyDescriptors.containsKey(propertyDescriptor.getName())) {
+ throw new UnsupportedOperationException("Property redeclared: " + propertyDescriptor.getName());
+ }
propertyDescriptors.put(propertyDescriptor.getName(), propertyDescriptor);
}
@@ -67,9 +79,35 @@ public class WritableScope implements JetScope {
return functionGroup;
}
+ @NotNull
+ private Map getTypeParameterDescriptors() {
+ if (typeParameterDescriptors == null) {
+ typeParameterDescriptors = new HashMap();
+ }
+ return typeParameterDescriptors;
+ }
+
+ public void addTypeParameterDescriptor(TypeParameterDescriptor typeParameterDescriptor) {
+ String name = typeParameterDescriptor.getName();
+ Map typeParameterDescriptors = getTypeParameterDescriptors();
+ if (typeParameterDescriptors.containsKey(name)) {
+ throw new UnsupportedOperationException("Type parameter redeclared"); // TODO
+ }
+ typeParameterDescriptors.put(name, typeParameterDescriptor);
+ }
+
+ @Override
+ public TypeParameterDescriptor getTypeParameter(String name) {
+ TypeParameterDescriptor typeParameterDescriptor = getTypeParameterDescriptors().get(name);
+ if (typeParameterDescriptor != null) {
+ return typeParameterDescriptor;
+ }
+ return super.getTypeParameter(name);
+ }
+
@Override
public ClassDescriptor getClass(String name) {
- throw new UnsupportedOperationException(); // TODO
+ return super.getClass(name); // TODO
}
@Override
@@ -82,11 +120,6 @@ public class WritableScope implements JetScope {
throw new UnsupportedOperationException(); // TODO
}
- @Override
- public TypeParameterDescriptor getTypeParameter(String name) {
- throw new UnsupportedOperationException(); // TODO
- }
-
@NotNull
@Override
public Type getThisType() {
diff --git a/idea/src/org/jetbrains/jet/lang/types/ClassDescriptor.java b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptor.java
index da0a9bc1fed..c41443b8311 100644
--- a/idea/src/org/jetbrains/jet/lang/types/ClassDescriptor.java
+++ b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptor.java
@@ -2,42 +2,15 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.JetScope;
-import org.jetbrains.jet.lang.resolve.SubstitutingScope;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
/**
* @author abreslav
*/
-public class ClassDescriptor extends MemberDescriptorImpl {
- private final TypeConstructor typeConstructor;
- private final JetScope memberDeclarations;
-
- public ClassDescriptor(
- List attributes, boolean sealed,
- String name, List typeParameters,
- Collection extends Type> superclasses, JetScope memberDeclarations) {
- super(attributes, name);
- this.typeConstructor = new TypeConstructor(attributes, sealed, name, typeParameters, superclasses);
- this.memberDeclarations = memberDeclarations;
- }
-
- public ClassDescriptor(String name, JetScope memberDeclarations) {
- this(Collections.emptyList(), true,
- name, Collections.emptyList(),
- Collections.singleton(JetStandardClasses.getAnyType()), memberDeclarations);
- }
-
+public interface ClassDescriptor extends Annotated, Named {
@NotNull
- public TypeConstructor getTypeConstructor() {
- return typeConstructor;
- }
+ TypeConstructor getTypeConstructor();
- public JetScope getMemberScope(List typeArguments) {
- Map substitutionContext = TypeSubstitutor.INSTANCE.buildSubstitutionContext(typeConstructor.getParameters(), typeArguments);
- return new SubstitutingScope(memberDeclarations, substitutionContext);
- }
-}
\ No newline at end of file
+ JetScope getMemberScope(List typeArguments);
+}
diff --git a/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java
new file mode 100644
index 00000000000..2d7e83a15d0
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/lang/types/ClassDescriptorImpl.java
@@ -0,0 +1,45 @@
+package org.jetbrains.jet.lang.types;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.resolve.JetScope;
+import org.jetbrains.jet.lang.resolve.SubstitutingScope;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author abreslav
+ */
+public class ClassDescriptorImpl extends MemberDescriptorImpl implements ClassDescriptor {
+ private final TypeConstructor typeConstructor;
+ private final JetScope memberDeclarations;
+
+ public ClassDescriptorImpl(
+ List attributes, boolean sealed,
+ String name, List typeParameters,
+ Collection extends Type> superclasses, JetScope memberDeclarations) {
+ super(attributes, name);
+ this.typeConstructor = new TypeConstructor(attributes, sealed, name, typeParameters, superclasses);
+ this.memberDeclarations = memberDeclarations;
+ }
+
+ public ClassDescriptorImpl(String name, JetScope memberDeclarations) {
+ this(Collections.emptyList(), true,
+ name, Collections.emptyList(),
+ Collections.singleton(JetStandardClasses.getAnyType()), memberDeclarations);
+ }
+
+ @Override
+ @NotNull
+ public TypeConstructor getTypeConstructor() {
+ return typeConstructor;
+ }
+
+ @Override
+ public JetScope getMemberScope(List typeArguments) {
+ Map substitutionContext = TypeSubstitutor.INSTANCE.buildSubstitutionContext(typeConstructor.getParameters(), typeArguments);
+ return new SubstitutingScope(memberDeclarations, substitutionContext);
+ }
+}
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java b/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
index 6d7fea52bcb..808ee0e18fc 100644
--- a/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
+++ b/idea/src/org/jetbrains/jet/lang/types/JetStandardClasses.java
@@ -1,10 +1,20 @@
package org.jetbrains.jet.lang.types;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectManager;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.psi.PsiFileFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.lang.JetFileType;
+import org.jetbrains.jet.lang.psi.JetFile;
+import org.jetbrains.jet.lang.resolve.FileContentsResolver;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
@@ -14,7 +24,7 @@ import java.util.*;
*/
public class JetStandardClasses {
- private static ClassDescriptor NOTHING_CLASS = new ClassDescriptor(
+ private static ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
Collections.emptyList(),
true,
"Nothing",
@@ -37,7 +47,7 @@ public class JetStandardClasses {
}, JetScope.EMPTY
);
- private static final ClassDescriptor ANY = new ClassDescriptor(
+ private static final ClassDescriptor ANY = new ClassDescriptorImpl(
Collections.emptyList(),
false,
"Any",
@@ -50,17 +60,40 @@ public class JetStandardClasses {
private static final Type ANY_TYPE = new TypeImpl(ANY.getTypeConstructor(), JetScope.EMPTY);
- private static final Type NULLABLE_ANY_TYPE = TypeUtils.makeNullable(ANY_TYPE);
- private static final ClassDescriptor BYTE = new ClassDescriptor("Byte", STUB);
- private static final ClassDescriptor CHAR = new ClassDescriptor("Char", STUB);
- private static final ClassDescriptor SHORT = new ClassDescriptor("Short", STUB);
- private static final ClassDescriptor INT = new ClassDescriptor("Int", STUB);
- private static final ClassDescriptor LONG = new ClassDescriptor("Long", STUB);
- private static final ClassDescriptor FLOAT = new ClassDescriptor("Float", STUB);
- private static final ClassDescriptor DOUBLE = new ClassDescriptor("Double", STUB);
- private static final ClassDescriptor BOOLEAN = new ClassDescriptor("Boolean", STUB);
+ private static final JetScope LIBRARY_SCOPE;
+ static {
+ // TODO : review
+ Project project = ProjectManager.getInstance().getDefaultProject();
+ InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/lang/Library.jet");
+ try {
+ //noinspection IOResourceOpenedButNotSafelyClosed
+ JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
- private static final ClassDescriptor STRING = new ClassDescriptor("String", STUB);
+ LIBRARY_SCOPE = FileContentsResolver.INSTANCE.resolveFileContents(JetScope.EMPTY, file);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private static final Type NULLABLE_ANY_TYPE = TypeUtils.makeNullable(ANY_TYPE);
+ @NotNull
+ private static final ClassDescriptor BYTE = LIBRARY_SCOPE.getClass("Byte");
+ @NotNull
+ private static final ClassDescriptor CHAR = LIBRARY_SCOPE.getClass("Char");
+ @NotNull
+ private static final ClassDescriptor SHORT = LIBRARY_SCOPE.getClass("Short");
+ @NotNull
+ private static final ClassDescriptor INT = LIBRARY_SCOPE.getClass("Int");
+ @NotNull
+ private static final ClassDescriptor LONG = LIBRARY_SCOPE.getClass("Long");
+ @NotNull
+ private static final ClassDescriptor FLOAT = LIBRARY_SCOPE.getClass("Float");
+ @NotNull
+ private static final ClassDescriptor DOUBLE = LIBRARY_SCOPE.getClass("Double");
+ @NotNull
+ private static final ClassDescriptor BOOLEAN = LIBRARY_SCOPE.getClass("Boolean");
+ @NotNull
+ private static final ClassDescriptor STRING = LIBRARY_SCOPE.getClass("String");
public static final int TUPLE_COUNT = 22;
private static final ClassDescriptor[] TUPLE = new ClassDescriptor[TUPLE_COUNT];
@@ -74,7 +107,7 @@ public class JetStandardClasses {
Variance.OUT_VARIANCE, "T" + j,
Collections.singleton(getNullableAnyType())));
}
- TUPLE[i] = new ClassDescriptor(
+ TUPLE[i] = new ClassDescriptorImpl(
Collections.emptyList(),
true,
"Tuple" + i,
@@ -100,7 +133,7 @@ public class JetStandardClasses {
Collections.emptyList(),
Variance.OUT_VARIANCE, "R",
Collections.singleton(getNullableAnyType())));
- FUNCTION[i] = new ClassDescriptor(
+ FUNCTION[i] = new ClassDescriptorImpl(
Collections.emptyList(),
false,
"Function" + i,
@@ -110,7 +143,7 @@ public class JetStandardClasses {
Collections.emptyList(),
Variance.IN_VARIANCE, "T",
Collections.singleton(getNullableAnyType())));
- RECEIVER_FUNCTION[i] = new ClassDescriptor(
+ RECEIVER_FUNCTION[i] = new ClassDescriptorImpl(
Collections.emptyList(),
false,
"ReceiverFunction" + i,