Descriptors have containing declarations

This commit is contained in:
Andrey Breslav
2011-03-14 18:32:54 +03:00
parent 5e054c2f0a
commit 2bde517127
36 changed files with 394 additions and 143 deletions
@@ -62,11 +62,11 @@ public class JetPsiChecker implements Annotator {
});
}
catch (ProcessCanceledException e) {
// Canceled. We are fine
throw e;
}
catch (Throwable e) {
// TODO
holder.createErrorAnnotation(new TextRange(0, 1), e.getClass().getCanonicalName() + ": " + e.getMessage());
holder.createErrorAnnotation(element, e.getClass().getCanonicalName() + ": " + e.getMessage());
e.printStackTrace();
}
}
@@ -98,6 +98,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
}
},
// COLON_AS(COLON, AS_KEYWORD) {
//
// },
MULTIPLICATIVE(MUL, DIV, PERC) {
@Override
public void parseHigherPrecedence(JetExpressionParsing parser) {
@@ -25,9 +25,12 @@ public class AnalyzingUtils {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, semanticServices, bindingTraceContext);
WritableScope scope = new WritableScope(semanticServices.getStandardLibrary().getLibraryScope());
scope.importScope(new JavaPackageScope("", javaSemanticServices));
scope.importScope(new JavaPackageScope("java.lang", javaSemanticServices));
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
WritableScope scope = new WritableScope(libraryScope, libraryScope.getContainingDeclaration());
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
scope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
new TopDownAnalyzer(semanticServices, bindingTraceContext).process(scope, namespace);
return bindingTraceContext;
@@ -22,4 +22,5 @@ public interface BindingContext {
Type resolveTypeReference(JetTypeReference typeReference);
PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression);
PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor);
}
@@ -101,4 +101,8 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
return descriptorToDeclarations.get(declarationDescriptor.getOriginal());
}
@Override
public PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor) {
return descriptorToDeclarations.get(descriptor);
}
}
@@ -26,11 +26,15 @@ public class ClassDescriptorResolver {
@Nullable
public ClassDescriptor resolveClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement) {
WritableScope parameterScope = new WritableScope(scope);
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
scope.getContainingDeclaration(),
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
classElement.getName());
WritableScope parameterScope = new WritableScope(scope, classDescriptor);
// This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters
= resolveTypeParameters(parameterScope, classElement.getTypeParameters());
= resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
@@ -38,25 +42,24 @@ public class ClassDescriptorResolver {
? Collections.singleton(JetStandardClasses.getAnyType())
: resolveTypes(parameterScope, delegationSpecifiers);
boolean open = classElement.hasModifier(JetTokens.OPEN_KEYWORD);
WritableScope members = resolveMembers(classElement, typeParameters, scope, parameterScope, superclasses);
WritableScope members = resolveMembers(classDescriptor, classElement, typeParameters, scope, parameterScope, superclasses);
return new ClassDescriptorImpl(
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
return classDescriptor.initialize(
!open,
classElement.getName(),
typeParameters,
superclasses,
members
);
}
@Nullable
public void resolveMutableClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) {
descriptor.setName(classElement.getName());
WritableScope parameterScope = descriptor.getUnsubstitutedMemberScope();
// This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters
= resolveTypeParameters(parameterScope, classElement.getTypeParameters());
= resolveTypeParameters(descriptor, parameterScope, classElement.getTypeParameters());
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic
@@ -78,13 +81,14 @@ public class ClassDescriptorResolver {
}
private WritableScope resolveMembers(
final ClassDescriptor classDescriptor,
final JetClass classElement,
List<TypeParameterDescriptor> typeParameters,
final JetScope outerScope,
final JetScope typeParameterScope,
final Collection<? extends Type> supertypes) {
final WritableScope memberDeclarations = new WritableScope(typeParameterScope);
final WritableScope memberDeclarations = new WritableScope(typeParameterScope, classDescriptor);
List<JetDeclaration> declarations = classElement.getDeclarations();
for (JetDeclaration declaration : declarations) {
@@ -92,7 +96,7 @@ public class ClassDescriptorResolver {
@Override
public void visitProperty(JetProperty property) {
if (property.getPropertyTypeRef() != null) {
memberDeclarations.addPropertyDescriptor(resolvePropertyDescriptor(typeParameterScope, property));
memberDeclarations.addPropertyDescriptor(resolvePropertyDescriptor(classDescriptor, typeParameterScope, property));
} else {
// TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException();
@@ -102,7 +106,7 @@ public class ClassDescriptorResolver {
@Override
public void visitFunction(JetFunction function) {
if (function.getReturnTypeRef() != null) {
memberDeclarations.addFunctionDescriptor(resolveFunctionDescriptor(typeParameterScope, function));
memberDeclarations.addFunctionDescriptor(resolveFunctionDescriptor(classDescriptor, typeParameterScope, function));
} else {
// TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException();
@@ -120,11 +124,17 @@ public class ClassDescriptorResolver {
}
@NotNull
public FunctionDescriptor resolveFunctionDescriptor(JetScope scope, JetFunction function) {
WritableScope parameterScope = new WritableScope(scope);
public FunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, JetScope scope, JetFunction function) {
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
containingDescriptor,
AttributeResolver.INSTANCE.resolveAttributes(function.getModifierList()),
function.getName()
);
WritableScope parameterScope = new WritableScope(scope, functionDescriptor);
// The two calls below have side-effects on parameterScope
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(parameterScope, function.getTypeParameters());
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(parameterScope, function.getValueParameters());
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, parameterScope, function.getTypeParameters());
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, parameterScope, function.getValueParameters());
Type returnType;
JetTypeReference returnTypeRef = function.getReturnTypeRef();
@@ -138,20 +148,16 @@ public class ClassDescriptorResolver {
returnType = semanticServices.getTypeInferrer().safeGetType(parameterScope, bodyExpression, function.hasBlockBody());
}
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
null,
AttributeResolver.INSTANCE.resolveAttributes(function.getModifierList()),
function.getName(),
functionDescriptor.initialize(
typeParameterDescriptors,
valueParameterDescriptors,
returnType
);
returnType);
trace.recordDeclarationResolution(function, functionDescriptor);
return functionDescriptor;
}
private List<ValueParameterDescriptor> resolveValueParameters(WritableScope parameterScope, List<JetParameter> valueParameters) {
private List<ValueParameterDescriptor> resolveValueParameters(FunctionDescriptorImpl functionDescriptor, WritableScope parameterScope, List<JetParameter> valueParameters) {
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
JetParameter valueParameter = valueParameters.get(i);
@@ -165,6 +171,7 @@ public class ClassDescriptorResolver {
type = typeResolver.resolveType(parameterScope, typeReference);
}
ValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
functionDescriptor,
i,
AttributeResolver.INSTANCE.resolveAttributes(valueParameter.getModifierList()),
valueParameter.getName(),
@@ -181,18 +188,19 @@ public class ClassDescriptorResolver {
return result;
}
public List<TypeParameterDescriptor> resolveTypeParameters(WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
// TODO : When-clause
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
for (JetTypeParameter typeParameter : typeParameters) {
result.add(resolveTypeParameter(extensibleScope, typeParameter));
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter));
}
return result;
}
private TypeParameterDescriptor resolveTypeParameter(WritableScope extensibleScope, JetTypeParameter typeParameter) {
private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter) {
JetTypeReference extendsBound = typeParameter.getExtendsBound();
TypeParameterDescriptor typeParameterDescriptor = new TypeParameterDescriptor(
containingDescriptor,
AttributeResolver.INSTANCE.resolveAttributes(typeParameter.getModifierList()),
typeParameter.getVariance(),
typeParameter.getName(),
@@ -222,14 +230,15 @@ public class ClassDescriptorResolver {
}
@NotNull
public PropertyDescriptor resolvePropertyDescriptor(@NotNull JetScope scope, @NotNull JetParameter parameter) {
public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter) {
return new PropertyDescriptorImpl(
containingDeclaration,
AttributeResolver.INSTANCE.resolveAttributes(parameter.getModifierList()),
parameter.getName(),
typeResolver.resolveType(scope, parameter.getTypeReference()));
}
public PropertyDescriptor resolvePropertyDescriptor(@NotNull JetScope scope, JetProperty property) {
public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, JetProperty property) {
// TODO : receiver?
JetTypeReference propertyTypeRef = property.getPropertyTypeRef();
@@ -244,6 +253,7 @@ public class ClassDescriptorResolver {
}
return new PropertyDescriptorImpl(
containingDeclaration,
AttributeResolver.INSTANCE.resolveAttributes(property.getModifierList()),
property.getName(),
type);
@@ -8,7 +8,13 @@ import org.jetbrains.jet.lang.types.*;
* @author abreslav
*/
public interface JetScope {
JetScope EMPTY = new JetScopeImpl() {};
JetScope EMPTY = new JetScopeImpl() {
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
throw new UnsupportedOperationException(); // TODO
}
};
@Nullable
ClassDescriptor getClass(@NotNull String name);
@@ -30,4 +36,7 @@ public interface JetScope {
@NotNull
FunctionGroup getFunctionGroup(@NotNull String name);
@NotNull
DeclarationDescriptor getContainingDeclaration();
}
@@ -50,4 +50,9 @@ public class JetScopeAdapter implements JetScope {
return scope.getExtension(name);
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return scope.getContainingDeclaration();
}
}
@@ -28,6 +28,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
throw new UnsupportedOperationException(); // TODO
}
@NotNull
@Override
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
JetScope memberScope = original.getMemberScope(typeArguments);
@@ -47,11 +48,18 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
return original.getName();
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return original.getOriginal();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return original.getContainingDeclaration();
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitClassDescriptor(this, data);
@@ -14,7 +14,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
private TypeConstructor typeConstructor;
public MutableClassDescriptor(@NotNull JetScope outerScope) {
this.unsubstitutedMemberScope = new WritableScope(outerScope);
this.unsubstitutedMemberScope = new WritableScope(outerScope, this);
}
@NotNull
@@ -27,6 +27,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
this.typeConstructor = typeConstructor;
}
@NotNull
@Override
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
List<TypeParameterDescriptor> typeParameters = getTypeConstructor().getParameters();
@@ -1,5 +1,7 @@
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.types.Attribute;
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
import org.jetbrains.jet.lang.types.DeclarationDescriptorVisitor;
@@ -11,6 +13,7 @@ import java.util.List;
*/
public abstract class MutableDeclarationDescriptor implements DeclarationDescriptor {
private String name;
private DeclarationDescriptor containingDeclaration;
@Override
public List<Attribute> getAttributes() {
@@ -26,11 +29,22 @@ public abstract class MutableDeclarationDescriptor implements DeclarationDescrip
this.name = name;
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return this;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
public void setContainingDeclaration(@Nullable DeclarationDescriptor containingDeclaration) {
this.containingDeclaration = containingDeclaration;
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
accept(visitor, null);
@@ -47,4 +47,10 @@ public class ScopeWithReceiver extends JetScopeImpl {
public Type getThisType() {
return receiverTypeScope.getThisType();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return outerScope.getContainingDeclaration();
}
}
@@ -43,7 +43,7 @@ public class SubstitutingScope implements JetScope {
@Override
public NamespaceDescriptor getNamespace(@NotNull String name) {
throw new UnsupportedOperationException(); // TODO
return workerScope.getNamespace(name); // TODO
}
@Override
@@ -66,4 +66,10 @@ public class SubstitutingScope implements JetScope {
}
return new LazySubstitutingFunctionGroup(substitutionContext, functionGroup);
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return workerScope.getContainingDeclaration();
}
}
@@ -32,7 +32,7 @@ public class TopDownAnalyzer {
}
public void process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) {
final WritableScope toplevelScope = new WritableScope(outerScope);
final WritableScope toplevelScope = new WritableScope(outerScope, outerScope.getContainingDeclaration()); // TODO ?!
trace.setToplevelScope(toplevelScope); // TODO : this is a hack
collectTypeDeclarators(toplevelScope, declarations);
resolveTypeDeclarations();
@@ -57,7 +57,19 @@ public class TopDownAnalyzer {
public void visitNamespace(JetNamespace namespace) {
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
WritableScope namespaceScope = new WritableScope(declaringScope);
String name = namespace.getName();
NamespaceDescriptor namespaceDescriptor = declaringScope.getNamespace(name);
if (namespaceDescriptor == null) {
namespaceDescriptor = new NamespaceDescriptor(
declaringScope.getContainingDeclaration(),
Collections.<Attribute>emptyList(), // TODO
name
);
declaringScope.addNamespace(namespaceDescriptor);
trace.recordDeclarationResolution(namespace, namespaceDescriptor);
}
WritableScope namespaceScope = new WritableScope(declaringScope, namespaceDescriptor);
namespaceScopes.put(namespace, namespaceScope);
for (JetImportDirective importDirective : importDirectives) {
@@ -165,7 +177,7 @@ public class TopDownAnalyzer {
private void processFunction(@NotNull WritableScope declaringScope, JetFunction function) {
declaringScopes.put(function, declaringScope);
FunctionDescriptor descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope, function);
FunctionDescriptor descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope.getContainingDeclaration(), declaringScope, function);
declaringScope.addFunctionDescriptor(descriptor);
functions.put(function, descriptor);
trace.recordDeclarationResolution(function, descriptor);
@@ -173,7 +185,7 @@ public class TopDownAnalyzer {
private void processProperty(WritableScope declaringScope, JetProperty property) {
declaringScopes.put(property, declaringScope);
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope, property);
PropertyDescriptor descriptor = classDescriptorResolver.resolvePropertyDescriptor(declaringScope.getContainingDeclaration(), declaringScope, property);
declaringScope.addPropertyDescriptor(descriptor);
trace.recordDeclarationResolution(property, descriptor);
}
@@ -192,7 +204,7 @@ public class TopDownAnalyzer {
WritableScope declaringScope = declaringScopes.get(function);
assert declaringScope != null;
WritableScope parameterScope = new WritableScope(declaringScope);
WritableScope parameterScope = new WritableScope(declaringScope, descriptor);
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
parameterScope.addTypeParameterDescriptor(typeParameter);
}
@@ -22,12 +22,24 @@ public class WritableScope extends JetScopeAdapter {
@Nullable
private Map<String, ClassDescriptor> classDescriptors;
@Nullable
private Map<String, NamespaceDescriptor> namespaceDescriptors;
@Nullable
private Type thisType;
@Nullable
private List<JetScope> imports;
public WritableScope(JetScope scope) {
@NotNull
private final DeclarationDescriptor ownerDeclarationDescriptor;
public WritableScope(JetScope scope, @NotNull DeclarationDescriptor owner) {
super(scope);
this.ownerDeclarationDescriptor = owner;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return ownerDeclarationDescriptor;
}
public void importScope(JetScope imported) {
@@ -160,7 +172,6 @@ public class WritableScope extends JetScopeAdapter {
public void addClassAlias(String name, ClassDescriptor classDescriptor) {
Map<String, ClassDescriptor> classDescriptors = getClassDescriptors();
if (classDescriptors.put(name, classDescriptor) != null) {
throw new UnsupportedOperationException("Class redeclared: " + classDescriptor.getName());
}
}
@@ -190,8 +201,26 @@ public class WritableScope extends JetScopeAdapter {
return thisType;
}
@NotNull
public Map<String, NamespaceDescriptor> getNamespaceDescriptors() {
if (namespaceDescriptors == null) {
namespaceDescriptors = new HashMap<String, NamespaceDescriptor>();
}
return namespaceDescriptors;
}
public void addNamespace(NamespaceDescriptor namespaceDescriptor) {
NamespaceDescriptor oldValue = getNamespaceDescriptors().put(namespaceDescriptor.getName(), namespaceDescriptor);
if (oldValue != null) {
throw new UnsupportedOperationException("Namespace redeclared: " + namespaceDescriptor.getName());
}
}
@Override
public NamespaceDescriptor getNamespace(@NotNull String name) {
NamespaceDescriptor namespaceDescriptor = getNamespaceDescriptors().get(name);
if (namespaceDescriptor != null) return namespaceDescriptor;
NamespaceDescriptor namespace = super.getNamespace(name);
if (namespace != null) return namespace;
for (JetScope imported : getImports()) {
@@ -15,13 +15,21 @@ public class JavaClassMembersScope implements JetScope {
private final PsiClass psiClass;
private final JavaSemanticServices semanticServices;
private final boolean staticMembers;
private final DeclarationDescriptor containingDeclaration;
public JavaClassMembersScope(PsiClass psiClass, JavaSemanticServices semanticServices, boolean staticMembers) {
public JavaClassMembersScope(@NotNull DeclarationDescriptor classDescriptor, PsiClass psiClass, JavaSemanticServices semanticServices, boolean staticMembers) {
this.containingDeclaration = classDescriptor;
this.psiClass = psiClass;
this.semanticServices = semanticServices;
this.staticMembers = staticMembers;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
@Override
public ClassDescriptor getClass(@NotNull String name) {
throw new UnsupportedOperationException(); // TODO
@@ -36,6 +44,7 @@ public class JavaClassMembersScope implements JetScope {
}
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
containingDeclaration,
Collections.<Attribute>emptyList(),
field.getName(),
semanticServices.getTypeTransformer().transform(field.getType()));
@@ -55,13 +64,16 @@ public class JavaClassMembersScope implements JetScope {
if (!name.equals(method.getName())) {
continue;
}
PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiParameter[] parameters = method.getParameterList().getParameters();
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
null,
JavaDescriptorResolver.JAVA_ROOT,
Collections.<Attribute>emptyList(), // TODO
name,
name
);
functionDescriptor.initialize(
Collections.<TypeParameterDescriptor>emptyList(), // TODO
semanticServices.getDescriptorResolver().resolveParameterDescriptors(parameters),
semanticServices.getDescriptorResolver().resolveParameterDescriptors(functionDescriptor, parameters),
semanticServices.getTypeTransformer().transform(method.getReturnType())
);
semanticServices.getTrace().recordDeclarationResolution(method, functionDescriptor);
@@ -14,6 +14,13 @@ import java.util.*;
*/
public class JavaDescriptorResolver {
/*package*/ static final DeclarationDescriptor JAVA_ROOT = new DeclarationDescriptorImpl(null, Collections.<Attribute>emptyList(), "<java_root>") {
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
throw new UnsupportedOperationException(); // TODO
}
};
protected final Map<String, ClassDescriptor> classDescriptorCache = new HashMap<String, ClassDescriptor>();
protected final Map<String, NamespaceDescriptor> namespaceDescriptorCache = new HashMap<String, NamespaceDescriptor>();
protected final JavaPsiFacade javaFacade;
@@ -51,16 +58,20 @@ public class JavaDescriptorResolver {
return classDescriptor;
}
private ClassDescriptor createJavaClassDescriptor(@NotNull PsiClass psiClass) {
private ClassDescriptor createJavaClassDescriptor(@NotNull final PsiClass psiClass) {
String name = psiClass.getName();
PsiModifierList modifierList = psiClass.getModifierList();
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
JAVA_ROOT,
Collections.<Attribute>emptyList(), // TODO
name
);
classDescriptor.initialize(
// TODO
modifierList == null ? false : modifierList.hasModifierProperty(PsiModifier.FINAL),
name,
Collections.<TypeParameterDescriptor>emptyList(),
getSupertypes(psiClass),
new JavaClassMembersScope(psiClass, semanticServices, false)
new JavaClassMembersScope(classDescriptor, psiClass, semanticServices, false)
);
semanticServices.getTrace().recordDeclarationResolution(psiClass, classDescriptor);
return classDescriptor;
@@ -104,29 +115,32 @@ public class JavaDescriptorResolver {
private NamespaceDescriptor createJavaNamespaceDescriptor(PsiPackage psiPackage) {
NamespaceDescriptor namespaceDescriptor = new NamespaceDescriptor(
JAVA_ROOT,
Collections.<Attribute>emptyList(), // TODO
psiPackage.getName(),
new JavaPackageScope(psiPackage.getQualifiedName(), semanticServices)
psiPackage.getName()
);
namespaceDescriptor.initialize(new JavaPackageScope(psiPackage.getQualifiedName(), namespaceDescriptor, semanticServices));
semanticServices.getTrace().recordDeclarationResolution(psiPackage, namespaceDescriptor);
return namespaceDescriptor;
}
private NamespaceDescriptor createJavaNamespaceDescriptor(@NotNull PsiClass psiClass) {
private NamespaceDescriptor createJavaNamespaceDescriptor(@NotNull final PsiClass psiClass) {
NamespaceDescriptor namespaceDescriptor = new NamespaceDescriptor(
JAVA_ROOT,
Collections.<Attribute>emptyList(), // TODO
psiClass.getName(),
new JavaClassMembersScope(psiClass, semanticServices, true)
psiClass.getName()
);
namespaceDescriptor.initialize(new JavaClassMembersScope(namespaceDescriptor, psiClass, semanticServices, true));
semanticServices.getTrace().recordDeclarationResolution(psiClass, namespaceDescriptor);
return namespaceDescriptor;
}
public List<ValueParameterDescriptor> resolveParameterDescriptors(PsiParameter[] parameters) {
public List<ValueParameterDescriptor> resolveParameterDescriptors(DeclarationDescriptor containingDeclaration, PsiParameter[] parameters) {
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
PsiParameter parameter = parameters[i];
result.add(new ValueParameterDescriptorImpl(
containingDeclaration,
i,
Collections.<Attribute>emptyList(), // TODO
parameter.getName(),
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
import org.jetbrains.jet.lang.types.ClassDescriptor;
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
import org.jetbrains.jet.lang.types.NamespaceDescriptor;
/**
@@ -11,11 +12,13 @@ import org.jetbrains.jet.lang.types.NamespaceDescriptor;
public class JavaPackageScope extends JetScopeImpl {
private final JavaSemanticServices semanticServices;
private String packagePrefix;
private final DeclarationDescriptor containingDescriptor;
private final String packagePrefix;
public JavaPackageScope(@NotNull String packageFQN, JavaSemanticServices semanticServices) {
public JavaPackageScope(@NotNull String packageFQN, DeclarationDescriptor containingDescriptor, JavaSemanticServices semanticServices) {
this.semanticServices = semanticServices;
this.packagePrefix = packageFQN.isEmpty() ? "" : packageFQN + ".";
this.containingDescriptor = containingDescriptor;
}
@Override
@@ -28,6 +31,12 @@ public class JavaPackageScope extends JetScopeImpl {
return semanticServices.getDescriptorResolver().resolveNamespace(getQualifiedName(name));
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDescriptor;
}
private String getQualifiedName(String name) {
return packagePrefix + name;
}
@@ -12,5 +12,10 @@ public interface ClassDescriptor extends DeclarationDescriptor {
@NotNull
TypeConstructor getTypeConstructor();
@NotNull
JetScope getMemberScope(List<TypeProjection> typeArguments);
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
}
@@ -5,7 +5,6 @@ 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;
@@ -13,22 +12,30 @@ import java.util.Map;
* @author abreslav
*/
public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements ClassDescriptor {
private final TypeConstructor typeConstructor;
private final JetScope memberDeclarations;
private TypeConstructor typeConstructor;
private JetScope memberDeclarations;
public ClassDescriptorImpl(
List<Attribute> attributes, boolean sealed,
String name, List<TypeParameterDescriptor> typeParameters,
Collection<? extends Type> superclasses, JetScope memberDeclarations) {
super(attributes, name);
this.typeConstructor = new TypeConstructor(attributes, sealed, name, typeParameters, superclasses);
this.memberDeclarations = memberDeclarations;
@NotNull DeclarationDescriptor containingDeclaration,
List<Attribute> attributes,
String name) {
super(containingDeclaration, attributes, name);
}
public ClassDescriptorImpl(String name, JetScope memberDeclarations) {
this(Collections.<Attribute>emptyList(), true,
name, Collections.<TypeParameterDescriptor>emptyList(),
Collections.<Type>singleton(JetStandardClasses.getAnyType()), memberDeclarations);
// public ClassDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, String name, JetScope memberDeclarations) {
// this(containingDeclaration, Collections.<Attribute>emptyList(), name);
// this.initialize(Collections.<Attribute>emptyList(), true,
// name, Collections.<TypeParameterDescriptor>emptyList(),
// Collections.<Type>singleton(JetStandardClasses.getAnyType()), memberDeclarations);
// }
//
public final ClassDescriptorImpl initialize(boolean sealed,
List<TypeParameterDescriptor> typeParameters,
Collection<? extends Type> superclasses, JetScope memberDeclarations) {
this.typeConstructor = new TypeConstructor(getAttributes(), sealed, getName(), typeParameters, superclasses);
this.memberDeclarations = memberDeclarations;
return this;
}
@Override
@@ -38,6 +45,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
}
@Override
@NotNull
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
if (typeConstructor.getParameters().isEmpty()) {
return memberDeclarations;
@@ -1,5 +1,8 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author abreslav
*/
@@ -10,8 +13,13 @@ public interface DeclarationDescriptor extends Annotated, Named {
* or of the element itself).
* returns <code>this</code> object if the current descriptor is original itself
*/
@NotNull
DeclarationDescriptor getOriginal();
@Nullable
DeclarationDescriptor getContainingDeclaration();
<R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data);
void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor);
}
@@ -1,5 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.resolve.DescriptorUtil;
import java.util.List;
@@ -10,10 +12,12 @@ import java.util.List;
public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements Named, DeclarationDescriptor {
private final String name;
private final DeclarationDescriptor containingDeclaration;
public DeclarationDescriptorImpl(List<Attribute> attributes, String name) {
public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name) {
super(attributes);
this.name = name;
this.containingDeclaration = containingDeclaration;
}
@Override
@@ -21,11 +25,18 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
return name;
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return this;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return containingDeclaration;
}
@Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
accept(visitor, null);
@@ -48,6 +48,12 @@ public class ErrorType {
throw new UnsupportedOperationException(); // TODO
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
throw new UnsupportedOperationException(); // TODO
}
};
private ErrorType() {}
@@ -1,7 +1,6 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -18,6 +17,10 @@ public interface FunctionDescriptor extends DeclarationDescriptor {
@NotNull
Type getUnsubstitutedReturnType();
@Nullable
@NotNull
FunctionDescriptor getOriginal();
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
}
@@ -1,7 +1,6 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -9,24 +8,34 @@ import java.util.List;
* @author abreslav
*/
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor {
@NotNull
private final List<TypeParameterDescriptor> typeParameters;
@NotNull
private final List<ValueParameterDescriptor> unsubstitutedValueParameters;
@NotNull
private final Type unsubstitutedReturnType;
@Nullable
private List<TypeParameterDescriptor> typeParameters;
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
private Type unsubstitutedReturnType;
private final FunctionDescriptor original;
public FunctionDescriptorImpl(
@Nullable FunctionDescriptor original,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Attribute> attributes,
String name,
String name) {
super(containingDeclaration, attributes, name);
this.original = this;
}
public FunctionDescriptorImpl(
@NotNull FunctionDescriptor original,
@NotNull List<Attribute> attributes,
String name) {
super(original.getContainingDeclaration(), attributes, name);
this.original = original;
}
public final void initialize(
@NotNull List<TypeParameterDescriptor> typeParameters,
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
@NotNull Type unsubstitutedReturnType) {
super(attributes, name);
this.original = original == null ? this : original;
this.typeParameters = typeParameters;
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
this.unsubstitutedReturnType = unsubstitutedReturnType;
@@ -50,6 +59,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
return unsubstitutedReturnType;
}
@NotNull
@Override
public FunctionDescriptor getOriginal() {
return original;
@@ -38,7 +38,7 @@ public class FunctionDescriptorUtil {
}
@NotNull
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull List<Type> typeArguments) {
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull List<Type> typeArguments) {
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
Map<TypeConstructor, TypeProjection> context = createSubstitutionContext(functionDescriptor, typeArguments);
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getUnsubstitutedValueParameters();
@@ -46,6 +46,7 @@ public class FunctionDescriptorUtil {
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
// TODO : Lazy?
result.add(new ValueParameterDescriptorImpl(
substitutedDescriptor,
i,
unsubstitutedValueParameter.getAttributes(),
unsubstitutedValueParameter.getName(),
@@ -81,21 +82,16 @@ public class FunctionDescriptorUtil {
if (functionDescriptor.getTypeParameters().isEmpty()) {
return functionDescriptor;
}
return new FunctionDescriptorImpl(
FunctionDescriptorImpl substitutedDescriptor = new FunctionDescriptorImpl(
functionDescriptor,
// TODO : substitute
functionDescriptor.getAttributes(),
functionDescriptor.getName(),
functionDescriptor.getName());
substitutedDescriptor.initialize(
Collections.<TypeParameterDescriptor>emptyList(), // TODO : questionable
getSubstitutedValueParameters(functionDescriptor, typeArguments),
getSubstitutedValueParameters(substitutedDescriptor, functionDescriptor, typeArguments),
getSubstitutedReturnType(functionDescriptor, typeArguments)
);
}
public static FunctionDescriptor getOriginal(FunctionDescriptor descriptor) {
while (descriptor.getOriginal() != null) {
descriptor = descriptor.getOriginal();
}
return descriptor;
return substitutedDescriptor;
}
}
@@ -19,10 +19,13 @@ public class JetStandardClasses {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
private static NamespaceDescriptor STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptor(null, Collections.<Attribute>emptyList(), "jet");
private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Attribute>emptyList(),
"Nothing").initialize(
true,
"Nothing",
Collections.<TypeParameterDescriptor>emptyList(),
new AbstractCollection<Type>() {
@Override
@@ -53,9 +56,10 @@ public class JetStandardClasses {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static final ClassDescriptor ANY = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Attribute>emptyList(),
"Any").initialize(
false,
"Any",
Collections.<TypeParameterDescriptor>emptyList(),
Collections.<Type>emptySet(),
JetScope.EMPTY
@@ -76,16 +80,19 @@ public class JetStandardClasses {
static {
for (int i = 0; i < TUPLE_COUNT; i++) {
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Attribute>emptyList(),
"Tuple" + i);
for (int j = 0; j < i; j++) {
parameters.add(new TypeParameterDescriptor(
classDescriptor,
Collections.<Attribute>emptyList(),
Variance.OUT_VARIANCE, "T" + j,
Collections.singleton(getNullableAnyType())));
}
TUPLE[i] = new ClassDescriptorImpl(
Collections.<Attribute>emptyList(),
TUPLE[i] = classDescriptor.initialize(
true,
"Tuple" + i,
parameters,
Collections.singleton(getAnyType()), STUB);
}
@@ -100,36 +107,49 @@ public class JetStandardClasses {
static {
for (int i = 0; i < FUNCTION_COUNT; i++) {
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
for (int j = 0; j < i; j++) {
parameters.add(new TypeParameterDescriptor(
Collections.<Attribute>emptyList(),
Variance.IN_VARIANCE, "P" + j,
Collections.singleton(getNullableAnyType())));
}
parameters.add(new TypeParameterDescriptor(
Collections.<Attribute>emptyList(),
Variance.OUT_VARIANCE, "R",
Collections.singleton(getNullableAnyType())));
FUNCTION[i] = new ClassDescriptorImpl(
ClassDescriptorImpl function = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Attribute>emptyList(),
"Function" + i);
FUNCTION[i] = function.initialize(
false,
"Function" + i,
parameters,
createTypeParameters(i, function),
Collections.singleton(getAnyType()), STUB);
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Attribute>emptyList(),
"ReceiverFunction" + i);
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
parameters.add(0, new TypeParameterDescriptor(
receiverFunction,
Collections.<Attribute>emptyList(),
Variance.IN_VARIANCE, "T",
Collections.singleton(getNullableAnyType())));
RECEIVER_FUNCTION[i] = new ClassDescriptorImpl(
Collections.<Attribute>emptyList(),
Variance.IN_VARIANCE, "T",
Collections.singleton(getNullableAnyType())));
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
false,
"ReceiverFunction" + i,
parameters,
Collections.singleton(getAnyType()), STUB);
}
}
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
for (int j = 0; j < parameterCount; j++) {
parameters.add(new TypeParameterDescriptor(
function,
Collections.<Attribute>emptyList(),
Variance.IN_VARIANCE, "P" + j,
Collections.singleton(getNullableAnyType())));
}
parameters.add(new TypeParameterDescriptor(
function,
Collections.<Attribute>emptyList(),
Variance.OUT_VARIANCE, "R",
Collections.singleton(getNullableAnyType())));
return parameters;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private static final Type UNIT_TYPE = new TypeImpl(getTuple(0));
@@ -140,7 +160,7 @@ public class JetStandardClasses {
/*package*/ static final JetScope STANDARD_CLASSES;
static {
WritableScope writableScope = new WritableScope(JetScope.EMPTY);
WritableScope writableScope = new WritableScope(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE);
STANDARD_CLASSES = writableScope;
writableScope.addClassAlias("Unit", getTuple(0));
@@ -69,6 +69,8 @@ public class JetTypeInferrer {
return;
}
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(scope.getContainingDeclaration(), Collections.<Attribute>emptyList(), "<anonymous>");
JetTypeReference returnTypeRef = expression.getReturnTypeRef();
JetTypeReference receiverTypeRef = expression.getReceiverTypeRef();
@@ -87,7 +89,7 @@ public class JetTypeInferrer {
if (typeReference == null) {
throw new UnsupportedOperationException("Type inference for parameters is not implemented yet");
}
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(scope, parameter);
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(functionDescriptor, scope, parameter);
parameterDescriptors.put(parameter.getName(), propertyDescriptor);
parameterTypes.add(propertyDescriptor.getType());
}
@@ -95,7 +97,7 @@ public class JetTypeInferrer {
if (returnTypeRef != null) {
returnType = typeResolver.resolveType(scope, returnTypeRef);
} else {
WritableScope writableScope = new WritableScope(scope);
WritableScope writableScope = new WritableScope(scope, functionDescriptor);
for (PropertyDescriptor propertyDescriptor : parameterDescriptors.values()) {
writableScope.addPropertyDescriptor(propertyDescriptor);
}
@@ -147,6 +149,10 @@ public class JetTypeInferrer {
@Override
public void visitReturnExpression(JetReturnExpression expression) {
JetExpression returnedExpression = expression.getReturnedExpression();
if (returnedExpression != null) {
getType(scope, returnedExpression, false);
}
result[0] = JetStandardClasses.getNothingType();
}
@@ -535,12 +541,13 @@ public class JetTypeInferrer {
if (block.isEmpty()) {
return JetStandardClasses.getUnitType();
} else {
WritableScope scope = new WritableScope(outerScope);
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
WritableScope scope = new WritableScope(outerScope, containingDescriptor);
for (JetElement statement : block) {
// TODO: consider other declarations
if (statement instanceof JetProperty) {
JetProperty property = (JetProperty) statement;
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(scope, property);
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(containingDescriptor, scope, property);
scope.addPropertyDescriptor(propertyDescriptor);
trace.recordDeclarationResolution(property, propertyDescriptor);
}
@@ -37,11 +37,18 @@ public class LazySubstitutedPropertyDescriptorImpl implements PropertyDescriptor
return propertyDescriptor.getName();
}
@NotNull
@Override
public DeclarationDescriptor getOriginal() {
return propertyDescriptor.getOriginal();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return propertyDescriptor.getContainingDeclaration();
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitPropertyDescriptor(this, data);
@@ -25,6 +25,7 @@ public class LazySubstitutingFunctionDescriptor implements FunctionDescriptor {
for (TypeParameterDescriptor parameterDescriptor : functionDescriptor.getTypeParameters()) {
// TODO : lazy?
result.add(new TypeParameterDescriptor(
this,
parameterDescriptor.getAttributes(),
parameterDescriptor.getVariance(),
parameterDescriptor.getName(),
@@ -41,6 +42,7 @@ public class LazySubstitutingFunctionDescriptor implements FunctionDescriptor {
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
ValueParameterDescriptor parameterDescriptor = unsubstitutedValueParameters.get(i);
result.add(new ValueParameterDescriptorImpl(
this,
i,
parameterDescriptor.getAttributes(),
parameterDescriptor.getName(),
@@ -58,6 +60,7 @@ public class LazySubstitutingFunctionDescriptor implements FunctionDescriptor {
return TypeSubstitutor.INSTANCE.substitute(substitutionContext, functionDescriptor.getUnsubstitutedReturnType(), Variance.OUT_VARIANCE);
}
@NotNull
@Override
public FunctionDescriptor getOriginal() {
return functionDescriptor.getOriginal();
@@ -74,6 +77,12 @@ public class LazySubstitutingFunctionDescriptor implements FunctionDescriptor {
return functionDescriptor.getName();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return functionDescriptor.getContainingDeclaration();
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitFunctionDescriptor(this, data);
@@ -1,5 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.JetScope;
import java.util.List;
@@ -9,17 +11,23 @@ import java.util.List;
*/
public class NamespaceDescriptor extends DeclarationDescriptorImpl {
private NamespaceType namespaceType;
private final JetScope memberScope;
public NamespaceDescriptor(List<Attribute> attributes, String name, JetScope memberScope) {
super(attributes, name);
private JetScope memberScope;
public NamespaceDescriptor(@Nullable DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name) {
super(containingDeclaration, attributes, name);
}
public void initialize(@NotNull JetScope memberScope) {
this.memberScope = memberScope;
}
@NotNull
public JetScope getMemberScope() {
return memberScope;
}
@NotNull
public NamespaceType getNamespaceType() {
if (namespaceType == null) {
namespaceType = new NamespaceType(getName(), memberScope);
@@ -1,10 +1,14 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public interface PropertyDescriptor extends DeclarationDescriptor {
Type getType();
@Override
@NotNull
DeclarationDescriptor getContainingDeclaration();
}
@@ -1,5 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
@@ -8,8 +10,8 @@ import java.util.List;
public class PropertyDescriptorImpl extends DeclarationDescriptorImpl implements PropertyDescriptor {
private Type type;
public PropertyDescriptorImpl(List<Attribute> attributes, String name, Type type) {
super(attributes, name);
public PropertyDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name, Type type) {
super(containingDeclaration, attributes, name);
this.type = type;
}
@@ -1,5 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -12,8 +14,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
private final Set<Type> upperBounds;
private final TypeConstructor typeConstructor;
public TypeParameterDescriptor(List<Attribute> attributes, Variance variance, String name, Set<Type> upperBounds) {
super(attributes, name);
public TypeParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, Variance variance, String name, Set<Type> upperBounds) {
super(containingDeclaration, attributes, name);
this.variance = variance;
this.upperBounds = upperBounds;
// TODO: Should we actually pass the attributes on to the type constructor?
@@ -25,8 +27,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
upperBounds);
}
public TypeParameterDescriptor(List<Attribute> attributes, Variance variance, String name) {
this(attributes, variance, name, Collections.singleton(JetStandardClasses.getNullableAnyType()));
public TypeParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, List<Attribute> attributes, Variance variance, String name) {
this(containingDeclaration, attributes, variance, name, Collections.singleton(JetStandardClasses.getNullableAnyType()));
}
public Variance getVariance() {
@@ -1,8 +1,6 @@
package org.jetbrains.jet.lang.types;
import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetParameterList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -14,8 +12,8 @@ public class ValueParameterDescriptorImpl extends PropertyDescriptorImpl impleme
private final boolean isVararg;
private final int index;
public ValueParameterDescriptorImpl(int index, List<Attribute> attributes, String name, Type type, boolean hasDefaultValue, boolean isVararg) {
super(attributes, name, type);
public ValueParameterDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, int index, List<Attribute> attributes, String name, Type type, boolean hasDefaultValue, boolean isVararg) {
super(containingDeclaration, attributes, name, type);
this.index = index;
this.hasDefaultValue = hasDefaultValue;
this.isVararg = isVararg;
@@ -542,7 +542,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
public FunctionGroup getFunctionGroup(@NotNull String name) {
WritableFunctionGroup writableFunctionGroup = new WritableFunctionGroup(name);
for (String funDecl : FUNCTION_DECLARATIONS) {
FunctionDescriptor functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(this, JetChangeUtil.createFunction(getProject(), funDecl));
FunctionDescriptor functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(JetStandardClasses.getAny(), this, JetChangeUtil.createFunction(getProject(), funDecl));
if (name.equals(functionDescriptor.getName())) {
writableFunctionGroup.addFunction(functionDescriptor);
}