Merge branch 'master' of ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -24,7 +24,7 @@ public class ErrorHandler {
|
||||
|
||||
@Override
|
||||
public void genericError(@NotNull ASTNode node, @NotNull String errorMessage) {
|
||||
throw new IllegalStateException(errorMessage + " at " + node.getText());
|
||||
throw new IllegalStateException(errorMessage + " at " + node.getText() + atLocation(node));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,14 +37,28 @@ public class ErrorHandler {
|
||||
throw new IllegalStateException("Redeclaration: " + existingDescriptor.getName());
|
||||
}
|
||||
};
|
||||
public static String atLocation(PsiElement element) {
|
||||
|
||||
public static String atLocation(@NotNull PsiElement element) {
|
||||
return atLocation(element.getNode());
|
||||
}
|
||||
|
||||
public static String atLocation(@NotNull ASTNode node) {
|
||||
while (node.getPsi() == null) {
|
||||
node = node.getTreeParent();
|
||||
}
|
||||
PsiElement element = node.getPsi();
|
||||
Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(element.getContainingFile());
|
||||
int offset = element.getTextRange().getStartOffset();
|
||||
int lineNumber = document.getLineNumber(offset);
|
||||
int lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
int column = offset - lineStartOffset;
|
||||
if (document != null) {
|
||||
int lineNumber = document.getLineNumber(offset);
|
||||
int lineStartOffset = document.getLineStartOffset(lineNumber);
|
||||
int column = offset - lineStartOffset;
|
||||
|
||||
return "' at line " + (lineNumber+1) + ":" + column;
|
||||
return "' at line " + (lineNumber+1) + ":" + column;
|
||||
}
|
||||
else {
|
||||
return "' at offset " + offset + " (line unknown)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@ public interface ClassDescriptor extends ClassifierDescriptor {
|
||||
@NotNull
|
||||
JetScope getMemberScope(List<TypeProjection> typeArguments);
|
||||
|
||||
/**
|
||||
* @return the superclass for a class descriptor, and the required class fro a trait descriptor
|
||||
*/
|
||||
@NotNull
|
||||
JetType getSuperclassType();
|
||||
|
||||
@NotNull
|
||||
FunctionGroup getConstructors();
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
private JetScope memberDeclarations;
|
||||
private FunctionGroup constructors;
|
||||
private ConstructorDescriptor primaryConstructor;
|
||||
private JetType superclassType;
|
||||
|
||||
public ClassDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -28,20 +29,42 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
super(containingDeclaration, annotations, name);
|
||||
}
|
||||
|
||||
public final ClassDescriptorImpl initialize(boolean sealed,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull FunctionGroup constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor) {
|
||||
return initialize(sealed, typeParameters, supertypes, memberDeclarations, constructors, primaryConstructor, getClassType(supertypes));
|
||||
}
|
||||
|
||||
public final ClassDescriptorImpl initialize(boolean sealed,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull Collection<JetType> superclasses,
|
||||
@NotNull Collection<JetType> supertypes,
|
||||
@NotNull JetScope memberDeclarations,
|
||||
@NotNull FunctionGroup constructors,
|
||||
@Nullable ConstructorDescriptor primaryConstructor) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName(), typeParameters, superclasses);
|
||||
@Nullable ConstructorDescriptor primaryConstructor,
|
||||
@Nullable JetType superclassType) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName(), typeParameters, supertypes);
|
||||
this.memberDeclarations = memberDeclarations;
|
||||
this.constructors = constructors;
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
this.superclassType = superclassType;
|
||||
// assert !constructors.isEmpty() || primaryConstructor == null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetType getClassType(@NotNull Collection<JetType> types) {
|
||||
for (JetType type : types) {
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(type);
|
||||
if (classDescriptor != null) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return JetStandardClasses.getAnyType();
|
||||
}
|
||||
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) {
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
}
|
||||
@@ -63,6 +86,12 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
|
||||
return new SubstitutingScope(memberDeclarations, TypeSubstitutor.create(substitutionContext));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getSuperclassType() {
|
||||
return superclassType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
|
||||
@@ -20,6 +20,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
private TypeSubstitutor newSubstitutor;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private TypeConstructor typeConstructor;
|
||||
private JetType superclassType;
|
||||
|
||||
public LazySubstitutingClassDescriptor(ClassDescriptor descriptor, TypeSubstitutor substitutor) {
|
||||
this.original = descriptor;
|
||||
@@ -78,6 +79,15 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
return new SubstitutingScope(memberScope, getSubstitutor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getSuperclassType() {
|
||||
if (superclassType == null) {
|
||||
superclassType = getSubstitutor().substitute(original.getSuperclassType(), Variance.INVARIANT);
|
||||
}
|
||||
return superclassType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getDefaultType() {
|
||||
|
||||
@@ -32,6 +32,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
private JetType classObjectType;
|
||||
private JetType defaultType;
|
||||
private final boolean isObject;
|
||||
private JetType superclassType;
|
||||
|
||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
||||
this(trace, containingDeclaration, outerScope, false);
|
||||
@@ -248,6 +249,17 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
return isObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getSuperclassType() {
|
||||
return superclassType;
|
||||
}
|
||||
|
||||
public void setSuperclassType(@NotNull JetType superclassType) {
|
||||
this.superclassType = superclassType;
|
||||
}
|
||||
|
||||
|
||||
public void setClassModifiers(ClassModifiers classModifiers) {
|
||||
this.classModifiers = classModifiers;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
private JetType classObjectType;
|
||||
private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
|
||||
private ClassModifiers modifiers;
|
||||
private JetType superclassType;
|
||||
|
||||
|
||||
public JavaClassDescriptor(DeclarationDescriptor containingDeclaration) {
|
||||
super(containingDeclaration);
|
||||
@@ -73,6 +75,16 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
|
||||
return new SubstitutingScope(unsubstitutedMemberScope, substitutor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getSuperclassType() {
|
||||
return superclassType;
|
||||
}
|
||||
|
||||
public void setSuperclassType(@NotNull JetType superclassType) {
|
||||
this.superclassType = superclassType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getConstructors() {
|
||||
|
||||
@@ -117,6 +117,17 @@ public class JavaDescriptorResolver {
|
||||
classDescriptor.setClassObjectMemberScope(new JavaClassMembersScope(classDescriptor, psiClass, semanticServices, true));
|
||||
// UGLY HACK
|
||||
supertypes.addAll(getSupertypes(psiClass));
|
||||
if (psiClass.isInterface()) {
|
||||
classDescriptor.setSuperclassType(JetStandardClasses.getAnyType()); // TODO : Make it java.lang.Object
|
||||
}
|
||||
else {
|
||||
PsiClassType[] extendsListTypes = psiClass.getExtendsListTypes();
|
||||
assert extendsListTypes.length == 0 || extendsListTypes.length == 1;
|
||||
JetType superclassType = extendsListTypes.length == 0
|
||||
? JetStandardClasses.getAnyType()
|
||||
: semanticServices.getTypeTransformer().transformToType(extendsListTypes[0]);
|
||||
classDescriptor.setSuperclassType(superclassType);
|
||||
}
|
||||
|
||||
PsiMethod[] psiConstructors = psiClass.getConstructors();
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ public class JetStandardClasses {
|
||||
},
|
||||
JetScope.EMPTY,
|
||||
FunctionGroup.EMPTY,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -75,6 +76,7 @@ public class JetStandardClasses {
|
||||
Collections.<JetType>emptySet(),
|
||||
JetScope.EMPTY,
|
||||
FunctionGroup.EMPTY,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
@@ -54,10 +54,12 @@ public class JetPsiChecker implements Annotator {
|
||||
if (reference instanceof MultiRangeReference) {
|
||||
MultiRangeReference mrr = (MultiRangeReference) reference;
|
||||
for (TextRange range : mrr.getRanges()) {
|
||||
System.out.println("Unresolved1");
|
||||
holder.createErrorAnnotation(range.shiftRight(referenceExpression.getTextOffset()), "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("Unresolved2");
|
||||
holder.createErrorAnnotation(referenceExpression, "Unresolved").setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +100,8 @@ public class JetPsiChecker implements Annotator {
|
||||
};
|
||||
|
||||
if (errorReportingEnabled) {
|
||||
System.out.println("Checked: " + bindingContext.getDiagnostics().size());
|
||||
System.out.println(Thread.currentThread().getId());
|
||||
AnalyzingUtils.applyHandler(errorHandler, bindingContext);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user