Merge branch 'master' of ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -10,12 +10,8 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.*;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
import org.objectweb.asm.commons.Method;
|
||||
|
||||
@@ -101,6 +97,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
interfaces.toArray(new String[interfaces.size()])
|
||||
);
|
||||
v.visitSource(myClass.getContainingFile().getName(), null);
|
||||
|
||||
if(myClass instanceof JetClass) {
|
||||
AnnotationVisitor annotationVisitor = v.visitAnnotation("Ljet/typeinfo/JetSignature;", true);
|
||||
annotationVisitor.visit("value", SignatureUtil.classToSignature((JetClass)myClass, state.getBindingContext(), state.getTypeMapper()));
|
||||
annotationVisitor.visitEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private String jvmName() {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class SignatureUtil {
|
||||
public static String classToSignature(JetClass type, BindingContext bindingContext, JetTypeMapper typeMapper) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
genTypeParams(type, sb);
|
||||
List<JetDelegationSpecifier> delegationSpecifiers = type.getDelegationSpecifiers();
|
||||
for (JetDelegationSpecifier specifier : delegationSpecifiers) {
|
||||
JetTypeReference typeReference = specifier.getTypeReference();
|
||||
JetType jetType = bindingContext.get(BindingContext.TYPE, typeReference);
|
||||
genJetType(sb, jetType, typeMapper);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void genJetType(StringBuilder sb, JetType jetType, JetTypeMapper typeMapper) {
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if(descriptor instanceof ClassDescriptor) {
|
||||
JetType defaultType = ((ClassDescriptor) descriptor).getDefaultType();
|
||||
org.objectweb.asm.Type type = typeMapper.mapType(defaultType, OwnerKind.IMPLEMENTATION);
|
||||
if(JetTypeMapper.isPrimitive(type)) {
|
||||
type = JetTypeMapper.boxType(type);
|
||||
}
|
||||
sb.append(type.getDescriptor());
|
||||
}
|
||||
else {
|
||||
sb.append("T").append(descriptor.getName()).append(";");
|
||||
}
|
||||
if(!jetType.getArguments().isEmpty()) {
|
||||
sb.append("<");
|
||||
for (TypeProjection typeProjection : jetType.getArguments()) {
|
||||
if(typeProjection.getProjectionKind() == Variance.IN_VARIANCE)
|
||||
sb.append("in ");
|
||||
if(typeProjection.getProjectionKind() == Variance.OUT_VARIANCE)
|
||||
sb.append("out ");
|
||||
genJetType(sb, typeProjection.getType(), typeMapper);
|
||||
}
|
||||
sb.append(">");
|
||||
}
|
||||
if(jetType.isNullable())
|
||||
sb.append("?");
|
||||
}
|
||||
|
||||
private static void genTypeParams(JetClass type, StringBuilder sb) {
|
||||
List<JetTypeParameter> parameters = type.getTypeParameterList().getParameters();
|
||||
for(JetTypeParameter param : parameters) {
|
||||
sb.append("T");
|
||||
Variance variance = param.getVariance();
|
||||
if(variance == Variance.IN_VARIANCE)
|
||||
sb.append("in ");
|
||||
else if(variance == Variance.OUT_VARIANCE)
|
||||
sb.append("out ");
|
||||
sb.append(param.getName());
|
||||
sb.append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
+12
-5
@@ -5,11 +5,12 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -64,6 +65,7 @@ public class JavaClassMembersScope implements JetScope {
|
||||
return classifierDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
@@ -123,7 +125,7 @@ public class JavaClassMembersScope implements JetScope {
|
||||
return null;
|
||||
}
|
||||
|
||||
return semanticServices.getDescriptorResolver().resolveFieldToVariableDescriptor((ClassDescriptor) containingDeclaration, field);
|
||||
return semanticServices.getDescriptorResolver().resolveFieldToVariableDescriptor(containingDeclaration, field);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -149,7 +151,12 @@ public class JavaClassMembersScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
return null;
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
throw new UnsupportedOperationException(); // Should never occur, we don't sit in a Java class...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
throw new UnsupportedOperationException(); // Should never occur, we don't sit in a Java class...
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.ImportingStrategy;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.AbstractNamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
+7
-8
@@ -5,16 +5,15 @@ import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionCallableReceiver;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.types.TypeSubstitutor.TypeSubstitution;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -97,10 +96,10 @@ public class FunctionDescriptorUtil {
|
||||
|
||||
@NotNull
|
||||
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
||||
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace).setDebugName("Function inner scope");
|
||||
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function inner scope");
|
||||
JetType receiverType = descriptor.getReceiverType();
|
||||
if (receiverType != null) {
|
||||
parameterScope.setThisType(receiverType);
|
||||
parameterScope.setImplicitReceiver(new ExtensionCallableReceiver(descriptor));
|
||||
}
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
parameterScope.addTypeParameterDescriptor(typeParameter);
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
+10
-4
@@ -6,6 +6,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
@@ -40,9 +45,10 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
||||
super(containingDeclaration);
|
||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, trace).setDebugName("MemberLookup");
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, trace).setDebugName("SupertypeResolution");
|
||||
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, trace).setDebugName("MemberResolution");
|
||||
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
||||
this.scopeForMemberLookup = new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup");
|
||||
this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution");
|
||||
this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler).setDebugName("MemberResolution");
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@@ -159,7 +165,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
getName(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
scopeForMemberResolution.setThisType(getDefaultType());
|
||||
scopeForMemberResolution.setImplicitReceiver(new ClassReceiver(this));
|
||||
for (FunctionDescriptor functionDescriptor : constructors.getFunctionDescriptors()) {
|
||||
((ConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
|
||||
+2
-4
@@ -1,9 +1,7 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -29,11 +27,11 @@ public abstract class DiagnosticFactoryWithPsiElement1<T extends PsiElement, A>
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(argument), element, node.getTextRange());
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), element, node.getTextRange());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull PsiElement psiElement, @NotNull A argument) {
|
||||
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(argument), element, psiElement.getTextRange());
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(argument), element, psiElement.getTextRange());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -33,6 +33,6 @@ public abstract class DiagnosticFactoryWithPsiElement2<T extends PsiElement, A,
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node, @NotNull A a, @NotNull B b) {
|
||||
return new DiagnosticWithPsiElement<T>(this, severity, makeMessage(a, b), element, node.getTextRange());
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, makeMessage(a, b), element, node.getTextRange());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -42,8 +41,14 @@ public class DiagnosticUtils {
|
||||
return closestPsiElement.getContainingFile();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String atLocation(@NotNull PsiFile file, @NotNull TextRange textRange) {
|
||||
Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
|
||||
Document document = file.getViewProvider().getDocument();//PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
|
||||
return atLocation(file, textRange, document);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String atLocation(PsiFile file, TextRange textRange, Document document) {
|
||||
int offset = textRange.getStartOffset();
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
String pathSuffix = virtualFile == null ? "" : " in " + virtualFile.getPath();
|
||||
|
||||
+3
-18
@@ -1,27 +1,12 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DiagnosticWithPsiElement<T extends PsiElement> extends GenericDiagnostic {
|
||||
private final T psiElement;
|
||||
|
||||
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
|
||||
this(factory, severity, message, psiElement, psiElement.getTextRange());
|
||||
}
|
||||
|
||||
public DiagnosticWithPsiElement(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
|
||||
super(factory, severity, message, psiElement.getContainingFile(), textRange);
|
||||
this.psiElement = psiElement;
|
||||
}
|
||||
|
||||
public interface DiagnosticWithPsiElement<T extends PsiElement> extends DiagnosticWithTextRange {
|
||||
@NotNull
|
||||
public T getPsiElement() {
|
||||
return psiElement;
|
||||
}
|
||||
T getPsiElement();
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithPsiElementImpl<T extends PsiElement> extends GenericDiagnostic implements DiagnosticWithPsiElement<T> {
|
||||
private final T psiElement;
|
||||
|
||||
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement) {
|
||||
this(factory, severity, message, psiElement, psiElement.getTextRange());
|
||||
}
|
||||
|
||||
public DiagnosticWithPsiElementImpl(DiagnosticFactory factory, Severity severity, String message, T psiElement, @NotNull TextRange textRange) {
|
||||
super(factory, severity, message, psiElement.getContainingFile(), textRange);
|
||||
this.psiElement = psiElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public T getPsiElement() {
|
||||
return psiElement;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class ParameterizedDiagnosticFactory3<A, B, C> extends DiagnosticFactoryW
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b, @NotNull C c) {
|
||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b, c), element);
|
||||
return new DiagnosticWithPsiElementImpl<PsiElement>(this, severity, makeMessage(a, b, c), element);
|
||||
}
|
||||
}
|
||||
|
||||
+65
-32
@@ -1,46 +1,79 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class RedeclarationDiagnostic implements Diagnostic {
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
|
||||
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
|
||||
|
||||
private final DeclarationDescriptor a;
|
||||
private final DeclarationDescriptor b;
|
||||
|
||||
public RedeclarationDiagnostic(DeclarationDescriptor a, DeclarationDescriptor b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement) {
|
||||
super(RedeclarationDiagnosticFactory.INSTANCE, ERROR, "Redeclaration", psiElement);
|
||||
}
|
||||
}
|
||||
|
||||
public DeclarationDescriptor getA() {
|
||||
return a;
|
||||
public class RedeclarationDiagnosticWithDeferredResolution implements RedeclarationDiagnostic {
|
||||
|
||||
private final DeclarationDescriptor duplicatingDescriptor;
|
||||
private final BindingContext contextToResolveToDeclaration;
|
||||
private PsiElement element;
|
||||
|
||||
public RedeclarationDiagnosticWithDeferredResolution(@NotNull DeclarationDescriptor duplicatingDescriptor, @NotNull BindingContext contextToResolveToDeclaration) {
|
||||
this.duplicatingDescriptor = duplicatingDescriptor;
|
||||
this.contextToResolveToDeclaration = contextToResolveToDeclaration;
|
||||
}
|
||||
|
||||
private PsiElement resolve() {
|
||||
if (element == null) {
|
||||
element = contextToResolveToDeclaration.get(BindingContext.DESCRIPTOR_TO_DECLARATION, duplicatingDescriptor);
|
||||
assert element != null : "No element for descriptor: " + duplicatingDescriptor;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getPsiElement() {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getTextRange() {
|
||||
return resolve().getTextRange();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiFile getPsiFile() {
|
||||
return resolve().getContainingFile();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DiagnosticFactory getFactory() {
|
||||
return Errors.REDECLARATION;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Redeclaration";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Severity getSeverity() {
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public DeclarationDescriptor getB() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DiagnosticFactory getFactory() {
|
||||
return RedeclarationDiagnosticFactory.INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Redeclaration";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Severity getSeverity() {
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-11
@@ -1,33 +1,40 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class RedeclarationDiagnosticFactory implements DiagnosticFactory {
|
||||
public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
||||
|
||||
public static final RedeclarationDiagnosticFactory INSTANCE = new RedeclarationDiagnosticFactory();
|
||||
|
||||
public RedeclarationDiagnosticFactory() {}
|
||||
|
||||
public RedeclarationDiagnostic on(DeclarationDescriptor a, DeclarationDescriptor b) {
|
||||
return new RedeclarationDiagnostic(a, b);
|
||||
public RedeclarationDiagnostic on(@NotNull PsiElement duplicatingElement) {
|
||||
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement);
|
||||
}
|
||||
|
||||
public Diagnostic on(DeclarationDescriptor duplicatingDescriptor, BindingContext contextToResolveToDeclaration) {
|
||||
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TextRange getTextRange(@NotNull Diagnostic diagnostic) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiFile getPsiFile(@NotNull Diagnostic diagnostic) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
PsiElement redeclaration = ((RedeclarationDiagnostic) diagnostic).getPsiElement();
|
||||
if (redeclaration instanceof JetNamedDeclaration) {
|
||||
PsiElement nameIdentifier = ((JetNamedDeclaration) redeclaration).getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
return nameIdentifier.getTextRange();
|
||||
}
|
||||
}
|
||||
return redeclaration.getTextRange();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public abstract class SimpleDiagnosticFactoryWithPsiElement<T extends PsiElement
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull T element, @NotNull ASTNode node) {
|
||||
return new DiagnosticWithPsiElement<T>(this, severity, message, element, node.getTextRange());
|
||||
return new DiagnosticWithPsiElementImpl<T>(this, severity, message, element, node.getTextRange());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElement<JetReferenceExpression> {
|
||||
public class UnresolvedReferenceDiagnostic extends DiagnosticWithPsiElementImpl<JetReferenceExpression> {
|
||||
|
||||
public UnresolvedReferenceDiagnostic(JetReferenceExpression referenceExpression) {
|
||||
super(Errors.UNRESOLVED_REFERENCE, ERROR, "Unresolved reference", referenceExpression);
|
||||
|
||||
@@ -106,7 +106,9 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
COLON_AS(COLON, AS_KEYWORD, AS_SAFE) {
|
||||
@Override
|
||||
public JetNodeType parseRightHandSide(IElementType operation, JetExpressionParsing parser) {
|
||||
parser.myBuilder.disableJoiningComplexTokens();
|
||||
parser.myJetParsing.parseTypeRef();
|
||||
parser.myBuilder.enableJoiningComplexTokens();
|
||||
return BINARY_WITH_TYPE;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
@@ -36,4 +37,20 @@ public class JetFunctionLiteral extends JetFunction {
|
||||
public JetBlockExpression getBodyExpression() {
|
||||
return (JetBlockExpression) super.getBodyExpression();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ASTNode getOpenBraceNode() {
|
||||
return getNode().findChildByType(JetTokens.LBRACE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@IfNotParsed
|
||||
public ASTNode getClosingBraceNode() {
|
||||
return getNode().findChildByType(JetTokens.RBRACE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ASTNode getArrowNode() {
|
||||
return getNode().findChildByType(JetTokens.DOUBLE_ARROW);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -47,4 +49,5 @@ public class JetFunctionLiteralExpression extends JetExpression implements JetDe
|
||||
public JetElement asElement() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -15,8 +17,13 @@ public abstract class AbstractScopeAdapter implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
return getWorkerScope().getThisType();
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
return getWorkerScope().getImplicitReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
getWorkerScope().getImplicitReceiversHierarchy(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -62,6 +69,7 @@ public abstract class AbstractScopeAdapter implements JetScope {
|
||||
return getWorkerScope().getDeclarationDescriptorForUnqualifiedThis();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return getWorkerScope().getAllDescriptors();
|
||||
|
||||
@@ -18,6 +18,9 @@ import org.jetbrains.jet.lang.diagnostics.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -69,7 +72,7 @@ public class AnalyzingUtils {
|
||||
|
||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||
final WritableScope scope = new WritableScopeImpl(libraryScope, owner, bindingTraceContext).setDebugName("Root scope in analyzeNamespace");
|
||||
final WritableScope scope = new WritableScopeImpl(libraryScope, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||
importingStrategy.addImports(project, semanticServices, bindingTraceContext, scope);
|
||||
TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeInferrer;
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.util.slicedmap.*;
|
||||
|
||||
@@ -32,7 +33,8 @@ public interface BindingContext {
|
||||
WritableSlice<JetExpression, JetScope> RESOLUTION_SCOPE = Slices.createSimpleSlice("RESOLUTION_SCOPE");
|
||||
|
||||
WritableSlice<JetExpression, Boolean> VARIABLE_REASSIGNMENT = Slices.createSimpleSetSlice("VARIABLE_REASSIGNMENT");
|
||||
WritableSlice<JetExpression, DeclarationDescriptor> VARIABLE_ASSIGNMENT = Slices.createSimpleSlice("VARIABLE_ASSIGNMENT");
|
||||
WritableSlice<ValueParameterDescriptor, Boolean> AUTO_CREATED_IT = Slices.createSimpleSetSlice("AUTO_CREATED_IT");
|
||||
WritableSlice<JetExpression, DeclarationDescriptor> VARIABLE_ASSIGNMENT = Slices.createSimpleSlice("VARIABLE_ASSIGNMENT");
|
||||
WritableSlice<JetExpression, Boolean> PROCESSED = Slices.createSimpleSetSlice("PROCESSED");
|
||||
WritableSlice<JetElement, Boolean> STATEMENT = Slices.createRemovableSetSlice("STATEMENT");
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionCallableReceiver;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
@@ -500,12 +505,12 @@ public class BodyResolver {
|
||||
|
||||
@NotNull
|
||||
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope, boolean primary) {
|
||||
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Inner scope for constructor");
|
||||
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Inner scope for constructor");
|
||||
for (PropertyDescriptor propertyDescriptor : ((MutableClassDescriptor) descriptor.getContainingDeclaration()).getProperties()) {
|
||||
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||
}
|
||||
|
||||
constructorScope.setThisType(descriptor.getContainingDeclaration().getDefaultType());
|
||||
// constructorScope.setImplicitReceiver(new ClassReceiver(descriptor.getContainingDeclaration()));
|
||||
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
JetParameter parameter = (JetParameter) context.getTrace().getBindingContext().get(BindingContext.DESCRIPTOR_TO_DECLARATION, valueParameterDescriptor);
|
||||
@@ -567,13 +572,13 @@ public class BodyResolver {
|
||||
}
|
||||
|
||||
private JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, context.getTrace()).setDebugName("Property declaration inner scope");
|
||||
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Property declaration inner scope");
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) {
|
||||
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
JetType receiverType = propertyDescriptor.getReceiverType();
|
||||
if (receiverType != null) {
|
||||
result.setThisType(receiverType);
|
||||
result.setImplicitReceiver(new ExtensionCallableReceiver(propertyDescriptor));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -581,7 +586,7 @@ public class BodyResolver {
|
||||
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, JetScope declaringScope) {
|
||||
BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
|
||||
|
||||
WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), context.getTrace()).setDebugName("Accessor scope");
|
||||
WritableScope accessorScope = new WritableScopeImpl(getPropertyDeclarationInnerScope(declaringScope, propertyDescriptor), declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
|
||||
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
|
||||
@@ -17,6 +17,9 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
@@ -142,7 +145,7 @@ public class ClassDescriptorResolver {
|
||||
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
|
||||
JetPsiUtil.safeName(function.getName())
|
||||
);
|
||||
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace).setDebugName("Function descriptor header scope");
|
||||
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
|
||||
innerScope.addLabeledDeclaration(functionDescriptor);
|
||||
|
||||
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
|
||||
@@ -451,7 +454,7 @@ public class ClassDescriptorResolver {
|
||||
typeParameterDescriptors = Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, trace).setDebugName("Scope with type parameters of a property");
|
||||
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
|
||||
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
|
||||
resolveGenericBounds(property, writableScope, typeParameterDescriptors);
|
||||
scopeWithTypeParameters = writableScope;
|
||||
@@ -659,7 +662,7 @@ public class ClassDescriptorResolver {
|
||||
typeParameters,
|
||||
resolveValueParameters(
|
||||
constructorDescriptor,
|
||||
new WritableScopeImpl(scope, classDescriptor, trace).setDebugName("Scope with value parameters of a constructor"),
|
||||
new WritableScopeImpl(scope, classDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with value parameters of a constructor"),
|
||||
valueParameters),
|
||||
Modality.FINAL);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class TraceBasedRedeclarationHandler implements RedeclarationHandler {
|
||||
private final BindingTrace trace;
|
||||
|
||||
public TraceBasedRedeclarationHandler(@NotNull BindingTrace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||
report(first);
|
||||
report(second);
|
||||
}
|
||||
|
||||
private void report(DeclarationDescriptor first) {
|
||||
PsiElement firstElement = trace.get(BindingContext.DESCRIPTOR_TO_DECLARATION, first);
|
||||
if (firstElement != null) {
|
||||
trace.report(REDECLARATION.on(firstElement));
|
||||
}
|
||||
else {
|
||||
trace.report(REDECLARATION.on(first, trace.getBindingContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,9 @@ import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
@@ -71,13 +74,13 @@ public class TypeHierarchyResolver {
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO: annotations
|
||||
name
|
||||
);
|
||||
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, context.getTrace()).setDebugName("Namespace member scope"));
|
||||
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope"));
|
||||
owner.addNamespace(namespaceDescriptor);
|
||||
context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
|
||||
}
|
||||
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
|
||||
|
||||
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), context.getTrace());
|
||||
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(context.getTrace()));
|
||||
context.getNamespaceScopes().put(namespace, namespaceScope);
|
||||
|
||||
processImports(namespace, namespaceScope, outerScope);
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -12,9 +12,9 @@ import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -355,6 +355,7 @@ public class CallResolver {
|
||||
|
||||
if (error) {
|
||||
failedCandidates.add(candidate);
|
||||
checkTypesWithNoCallee(temporaryTrace, scope, task.getTypeArguments(), task.getValueArguments(), task.getFunctionLiteralArguments());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -490,7 +491,7 @@ public class CallResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private <Descriptor extends CallableDescriptor> Function<ValueParameterDescriptor, ValueParameterDescriptor> createMapFunction(Descriptor substitutedFunctionDescriptor) {
|
||||
private <D extends CallableDescriptor> Function<ValueParameterDescriptor, ValueParameterDescriptor> createMapFunction(D substitutedFunctionDescriptor) {
|
||||
assert substitutedFunctionDescriptor != null;
|
||||
final Map<ValueParameterDescriptor, ValueParameterDescriptor> parameterMap = Maps.newHashMap();
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : substitutedFunctionDescriptor.getValueParameters()) {
|
||||
@@ -505,7 +506,7 @@ public class CallResolver {
|
||||
};
|
||||
}
|
||||
|
||||
private <Descriptor extends CallableDescriptor> boolean checkReceiver(ResolutionTask<Descriptor> task, TracingStrategy tracing, Descriptor candidate, TemporaryBindingTrace temporaryTrace) {
|
||||
private <D extends CallableDescriptor> boolean checkReceiver(ResolutionTask<D> task, TracingStrategy tracing, D candidate, TemporaryBindingTrace temporaryTrace) {
|
||||
if (!checkReceiverAbsence(task, tracing, candidate, temporaryTrace)) return false;
|
||||
JetType receiverType = task.getReceiverType();
|
||||
JetType candidateReceiverType = candidate.getReceiverType();
|
||||
@@ -518,7 +519,7 @@ public class CallResolver {
|
||||
return true;
|
||||
}
|
||||
|
||||
private <Descriptor extends CallableDescriptor> boolean checkReceiverAbsence(ResolutionTask<Descriptor> task, TracingStrategy tracing, Descriptor candidate, TemporaryBindingTrace temporaryTrace) {
|
||||
private <D extends CallableDescriptor> boolean checkReceiverAbsence(ResolutionTask<D> task, TracingStrategy tracing, D candidate, TemporaryBindingTrace temporaryTrace) {
|
||||
JetType receiverType = task.getReceiverType();
|
||||
JetType candidateReceiverType = candidate.getReceiverType();
|
||||
if (receiverType != null) {
|
||||
@@ -535,26 +536,26 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private <Descriptor extends CallableDescriptor> OverloadResolutionResult<Descriptor> computeResultAndReportErrors(BindingTrace trace, TracingStrategy tracing, Map<Descriptor, Descriptor> successfulCandidates, Set<Descriptor> failedCandidates, Set<Descriptor> dirtyCandidates, Map<Descriptor, TemporaryBindingTrace> traces) {
|
||||
private <D extends CallableDescriptor> OverloadResolutionResult<D> computeResultAndReportErrors(BindingTrace trace, TracingStrategy tracing, Map<D, D> successfulCandidates, Set<D> failedCandidates, Set<D> dirtyCandidates, Map<D, TemporaryBindingTrace> traces) {
|
||||
// TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific
|
||||
if (successfulCandidates.size() > 0) {
|
||||
if (successfulCandidates.size() != 1) {
|
||||
Map<Descriptor, Descriptor> cleanCandidates = Maps.newLinkedHashMap(successfulCandidates);
|
||||
Map<D, D> cleanCandidates = Maps.newLinkedHashMap(successfulCandidates);
|
||||
cleanCandidates.keySet().removeAll(dirtyCandidates);
|
||||
if (cleanCandidates.isEmpty()) {
|
||||
cleanCandidates = successfulCandidates;
|
||||
}
|
||||
Descriptor maximallySpecific = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, traces, false);
|
||||
D maximallySpecific = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, traces, false);
|
||||
if (maximallySpecific != null) {
|
||||
return OverloadResolutionResult.success(maximallySpecific);
|
||||
}
|
||||
|
||||
Descriptor maximallySpecificGenericsDiscriminated = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, traces, true);
|
||||
D maximallySpecificGenericsDiscriminated = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, traces, true);
|
||||
if (maximallySpecificGenericsDiscriminated != null) {
|
||||
return OverloadResolutionResult.success(maximallySpecificGenericsDiscriminated);
|
||||
}
|
||||
|
||||
Set<Descriptor> noOverrides = filterOverrides(successfulCandidates.keySet());
|
||||
Set<D> noOverrides = filterOverrides(successfulCandidates.keySet());
|
||||
if (dirtyCandidates.isEmpty()) {
|
||||
// tracing.reportOverallResolutionError(trace, "Overload resolution ambiguity: "
|
||||
// + makeErrorMessageForMultipleDescriptors(noOverrides));
|
||||
@@ -566,9 +567,9 @@ public class CallResolver {
|
||||
return OverloadResolutionResult.ambiguity(noOverrides);
|
||||
}
|
||||
else {
|
||||
Map.Entry<Descriptor, Descriptor> entry = successfulCandidates.entrySet().iterator().next();
|
||||
Descriptor functionDescriptor = entry.getKey();
|
||||
Descriptor result = entry.getValue();
|
||||
Map.Entry<D, D> entry = successfulCandidates.entrySet().iterator().next();
|
||||
D functionDescriptor = entry.getKey();
|
||||
D result = entry.getValue();
|
||||
|
||||
TemporaryBindingTrace temporaryTrace = traces.get(functionDescriptor);
|
||||
temporaryTrace.commit();
|
||||
@@ -577,7 +578,7 @@ public class CallResolver {
|
||||
}
|
||||
else if (!failedCandidates.isEmpty()) {
|
||||
if (failedCandidates.size() != 1) {
|
||||
Set<Descriptor> noOverrides = filterOverrides(failedCandidates);
|
||||
Set<D> noOverrides = filterOverrides(failedCandidates);
|
||||
if (noOverrides.size() != 1) {
|
||||
// tracing.reportOverallResolutionError(trace, "None of the following functions can be called with the arguments supplied: "
|
||||
// + makeErrorMessageForMultipleDescriptors(noOverrides));
|
||||
@@ -587,7 +588,7 @@ public class CallResolver {
|
||||
}
|
||||
failedCandidates = noOverrides;
|
||||
}
|
||||
Descriptor functionDescriptor = failedCandidates.iterator().next();
|
||||
D functionDescriptor = failedCandidates.iterator().next();
|
||||
TemporaryBindingTrace temporaryTrace = traces.get(functionDescriptor);
|
||||
temporaryTrace.commit();
|
||||
return OverloadResolutionResult.singleFailedCandidate(failedCandidates.iterator().next());
|
||||
@@ -598,19 +599,11 @@ public class CallResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private <Descriptor extends CallableDescriptor> StringBuilder makeErrorMessageForMultipleDescriptors(Set<Descriptor> candidates) {
|
||||
StringBuilder stringBuilder = new StringBuilder("\n");
|
||||
for (Descriptor functionDescriptor : candidates) {
|
||||
stringBuilder.append(DescriptorRenderer.TEXT.render(functionDescriptor)).append("\n");
|
||||
}
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
private <Descriptor extends CallableDescriptor> Set<Descriptor> filterOverrides(Set<Descriptor> candidateSet) {
|
||||
Set<Descriptor> candidates = Sets.newLinkedHashSet();
|
||||
private <D extends CallableDescriptor> Set<D> filterOverrides(Set<D> candidateSet) {
|
||||
Set<D> candidates = Sets.newLinkedHashSet();
|
||||
outerLoop:
|
||||
for (Descriptor me : candidateSet) {
|
||||
for (Descriptor other : candidateSet) {
|
||||
for (D me : candidateSet) {
|
||||
for (D other : candidateSet) {
|
||||
if (OverloadingConflictResolver.overrides(other, me)) {
|
||||
continue outerLoop;
|
||||
}
|
||||
@@ -718,18 +711,6 @@ public class CallResolver {
|
||||
return found;
|
||||
}
|
||||
|
||||
private OverloadResolutionResult<FunctionDescriptor> listToOverloadResolutionResult(List<FunctionDescriptor> result) {
|
||||
if (result.isEmpty()) {
|
||||
return OverloadResolutionResult.nameNotFound();
|
||||
}
|
||||
else if (result.size() == 1) {
|
||||
return OverloadResolutionResult.success(result.get(0));
|
||||
}
|
||||
else {
|
||||
return OverloadResolutionResult.ambiguity(result);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean findExtensionFunctions(Collection<FunctionDescriptor> candidates, JetType receiverType, List<JetType> parameterTypes, List<FunctionDescriptor> result) {
|
||||
boolean found = false;
|
||||
for (FunctionDescriptor functionDescriptor : candidates) {
|
||||
@@ -755,7 +736,6 @@ public class CallResolver {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static TaskPrioritizer<FunctionDescriptor> FUNCTION_TASK_PRIORITIZER = new TaskPrioritizer<FunctionDescriptor>() {
|
||||
|
||||
@NotNull
|
||||
@@ -825,7 +805,6 @@ public class CallResolver {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private static TaskPrioritizer<VariableDescriptor> PROPERTY_TASK_PRIORITIZER = new TaskPrioritizer<VariableDescriptor>() {
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -6,8 +6,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -44,6 +46,9 @@ import java.util.List;
|
||||
* local extension prevail over members (and members prevail over all non-local extensions)
|
||||
*/
|
||||
public static boolean isLocal(DeclarationDescriptor containerOfTheCurrentLocality, DeclarationDescriptor candidate) {
|
||||
if (candidate instanceof ValueParameterDescriptor) {
|
||||
return true;
|
||||
}
|
||||
DeclarationDescriptor parent = candidate.getContainingDeclaration();
|
||||
if (!(parent instanceof FunctionDescriptor)) {
|
||||
return false;
|
||||
@@ -59,11 +64,17 @@ import java.util.List;
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ResolutionTask<D>> computePrioritizedTasks(JetScope scope, JetType receiverType, Call call, String name) {
|
||||
public List<ResolutionTask<D>> computePrioritizedTasks(@NotNull JetScope scope, @Nullable JetType receiverType, @NotNull Call call, @NotNull String name) {
|
||||
List<ResolutionTask<D>> result = Lists.newArrayList();
|
||||
doComputeTasks(scope, receiverType, call, name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void doComputeTasks(JetScope scope, JetType receiverType, Call call, String name, List<ResolutionTask<D>> result) {
|
||||
List<ReceiverDescriptor> receivers = Lists.newArrayList();
|
||||
scope.getImplicitReceiversHierarchy(receivers);
|
||||
if (receiverType != null) {
|
||||
Collection<D> extensionFunctions = getExtensionsByName(scope, name);
|
||||
|
||||
List<D> nonlocals = Lists.newArrayList();
|
||||
List<D> locals = Lists.newArrayList();
|
||||
//noinspection unchecked,RedundantTypeArguments
|
||||
@@ -73,6 +84,12 @@ import java.util.List;
|
||||
|
||||
addTask(result, receiverType, call, locals);
|
||||
addTask(result, null, call, members);
|
||||
|
||||
for (ReceiverDescriptor receiver : receivers) {
|
||||
Collection<D> memberExtensions = getExtensionsByName(receiver.getReceiverType().getMemberScope(), name);
|
||||
addTask(result, receiverType, call, memberExtensions);
|
||||
}
|
||||
|
||||
addTask(result, receiverType, call, nonlocals);
|
||||
}
|
||||
else {
|
||||
@@ -85,9 +102,12 @@ import java.util.List;
|
||||
|
||||
addTask(result, receiverType, call, locals);
|
||||
|
||||
for (ReceiverDescriptor receiver : receivers) {
|
||||
doComputeTasks(scope, receiver.getReceiverType(), call, name, result);
|
||||
}
|
||||
|
||||
addTask(result, receiverType, call, nonlocals);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+13
-3
@@ -1,12 +1,14 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -69,10 +71,17 @@ public class ChainedScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
for (JetScope jetScope : scopeChain) {
|
||||
jetScope.getImplicitReceiversHierarchy(result);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
@@ -115,6 +124,7 @@ public class ChainedScope implements JetScope {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
+17
-6
@@ -1,11 +1,12 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -15,7 +16,7 @@ public interface JetScope {
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,9 +37,6 @@ public interface JetScope {
|
||||
@NotNull
|
||||
FunctionGroup getFunctionGroup(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
JetType getThisType();
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
@@ -55,5 +53,18 @@ public interface JetScope {
|
||||
@Nullable
|
||||
DeclarationDescriptor getDeclarationDescriptorForUnqualifiedThis();
|
||||
|
||||
@NotNull
|
||||
Collection<DeclarationDescriptor> getAllDescriptors();
|
||||
|
||||
/**
|
||||
* @return EFFECTIVE implicit receiver at this point (may be corresponding to an outer scope)
|
||||
*/
|
||||
@NotNull
|
||||
ReceiverDescriptor getImplicitReceiver();
|
||||
|
||||
/**
|
||||
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
|
||||
* @param result
|
||||
*/
|
||||
void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result);
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
+10
-4
@@ -1,11 +1,12 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -28,8 +29,8 @@ public abstract class JetScopeImpl implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
return JetStandardClasses.getNothingType();
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
return ReceiverDescriptor.NO_RECEIVER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -54,8 +55,13 @@ public abstract class JetScopeImpl implements JetScope {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.LazyValue;
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface RedeclarationHandler {
|
||||
RedeclarationHandler DO_NOTHING = new RedeclarationHandler() {
|
||||
@Override
|
||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||
}
|
||||
};
|
||||
RedeclarationHandler THROW_EXCEPTION = new RedeclarationHandler() {
|
||||
@Override
|
||||
public void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||
throw new IllegalStateException("Redeclaration: " + first + " and " + second + "(no line info available)");
|
||||
}
|
||||
};
|
||||
|
||||
void handleRedeclaration(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second);
|
||||
}
|
||||
+10
-3
@@ -1,14 +1,15 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,12 @@ public class SubstitutingScope implements JetScope {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@@ -109,6 +115,7 @@ public class SubstitutingScope implements JetScope {
|
||||
return workerScope.getDeclarationDescriptorForUnqualifiedThis();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ImplicitReceiverDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -30,5 +30,5 @@ public interface WritableScope extends JetScope {
|
||||
|
||||
void importScope(@NotNull JetScope imported);
|
||||
|
||||
void setThisType(@NotNull JetType thisType);
|
||||
void setImplicitReceiver(@NotNull ImplicitReceiverDescriptor implicitReceiver);
|
||||
}
|
||||
+36
-39
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -6,13 +6,12 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ImplicitReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -35,13 +34,12 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
|
||||
@Nullable
|
||||
private Map<String, List<DeclarationDescriptor>> labelsToDescriptors;
|
||||
|
||||
@Nullable
|
||||
private JetType thisType;
|
||||
private ImplicitReceiverDescriptor implicitReceiver;
|
||||
|
||||
private List<VariableDescriptor> variableDescriptors;
|
||||
|
||||
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull DiagnosticHolder diagnosticHolder) {
|
||||
super(scope, diagnosticHolder);
|
||||
public WritableScopeImpl(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull RedeclarationHandler redeclarationHandler) {
|
||||
super(scope, redeclarationHandler);
|
||||
this.ownerDeclarationDescriptor = owner;
|
||||
}
|
||||
|
||||
@@ -70,6 +68,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
super.importClassifierAlias(importedClassifierName, classifierDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (!allDescriptorsDone) {
|
||||
@@ -126,26 +125,16 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
return variableClassOrNamespaceDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<VariableDescriptor> getVariableDescriptors() {
|
||||
if (variableDescriptors == null) {
|
||||
variableDescriptors = Lists.newArrayList();
|
||||
}
|
||||
return variableDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVariableDescriptor(@NotNull VariableDescriptor variableDescriptor) {
|
||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
DeclarationDescriptor existingDescriptor = variableClassOrNamespaceDescriptors.get(variableDescriptor.getName());
|
||||
if (existingDescriptor != null) {
|
||||
diagnosticHolder.report(REDECLARATION.on(existingDescriptor, variableDescriptor));
|
||||
redeclarationHandler.handleRedeclaration(existingDescriptor, variableDescriptor);
|
||||
}
|
||||
// TODO : Should this always happen?
|
||||
variableClassOrNamespaceDescriptors.put(variableDescriptor.getName(), variableDescriptor);
|
||||
allDescriptors.add(variableDescriptor);
|
||||
|
||||
getVariableDescriptors().add(variableDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,12 +145,12 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
return (VariableDescriptor) descriptor;
|
||||
}
|
||||
|
||||
if (thisType != null) {
|
||||
VariableDescriptor variable = getThisType().getMemberScope().getVariable(name);
|
||||
if (variable != null) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
// if (implicitReceiver != null) {
|
||||
// VariableDescriptor variable = getImplicitReceiver().getMemberScope().getVariable(name);
|
||||
// if (variable != null) {
|
||||
// return variable;
|
||||
// }
|
||||
// }
|
||||
|
||||
VariableDescriptor variableDescriptor = getWorkerScope().getVariable(name);
|
||||
if (variableDescriptor != null) {
|
||||
@@ -203,9 +192,9 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
result.addAllFunctions(functionGroup);
|
||||
}
|
||||
|
||||
if (thisType != null) {
|
||||
result.addAllFunctions(getThisType().getMemberScope().getFunctionGroup(name));
|
||||
}
|
||||
// if (implicitReceiver != null) {
|
||||
// result.addAllFunctions(getImplicitReceiver().getMemberScope().getFunctionGroup(name));
|
||||
// }
|
||||
|
||||
result.addAllFunctions(getWorkerScope().getFunctionGroup(name));
|
||||
|
||||
@@ -230,7 +219,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
DeclarationDescriptor originalDescriptor = variableClassOrNamespaceDescriptors.get(name);
|
||||
if (originalDescriptor != null) {
|
||||
diagnosticHolder.report(REDECLARATION.on(originalDescriptor, classifierDescriptor));
|
||||
redeclarationHandler.handleRedeclaration(originalDescriptor, classifierDescriptor);
|
||||
}
|
||||
variableClassOrNamespaceDescriptors.put(name, classifierDescriptor);
|
||||
allDescriptors.add(classifierDescriptor);
|
||||
@@ -250,11 +239,11 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
if (thisType == null) {
|
||||
return super.getThisType();
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
if (implicitReceiver == null) {
|
||||
return super.getImplicitReceiver();
|
||||
}
|
||||
return thisType;
|
||||
return implicitReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -262,7 +251,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||
DeclarationDescriptor oldValue = variableClassOrNamespaceDescriptors.put(namespaceDescriptor.getName(), namespaceDescriptor);
|
||||
if (oldValue != null) {
|
||||
diagnosticHolder.report(REDECLARATION.on(oldValue, namespaceDescriptor));
|
||||
redeclarationHandler.handleRedeclaration(oldValue, namespaceDescriptor);
|
||||
}
|
||||
allDescriptors.add(namespaceDescriptor);
|
||||
}
|
||||
@@ -286,11 +275,19 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThisType(@NotNull JetType thisType) {
|
||||
if (this.thisType != null) {
|
||||
public void setImplicitReceiver(@NotNull ImplicitReceiverDescriptor implicitReceiver) {
|
||||
if (this.implicitReceiver != null) {
|
||||
throw new UnsupportedOperationException("Receiver redeclared");
|
||||
}
|
||||
this.thisType = thisType;
|
||||
this.implicitReceiver = implicitReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
if (implicitReceiver != null && implicitReceiver != ReceiverDescriptor.NO_RECEIVER) {
|
||||
result.add(implicitReceiver);
|
||||
}
|
||||
super.getImplicitReceiversHierarchy(result);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"NullableProblems"})
|
||||
+5
-6
@@ -1,9 +1,8 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -18,11 +17,11 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
@Nullable
|
||||
private List<JetScope> imports;
|
||||
private WritableScope currentIndividualImportScope;
|
||||
protected final DiagnosticHolder diagnosticHolder;
|
||||
protected final RedeclarationHandler redeclarationHandler;
|
||||
|
||||
public WritableScopeWithImports(@NotNull JetScope scope, @NotNull DiagnosticHolder diagnosticHolder) {
|
||||
public WritableScopeWithImports(@NotNull JetScope scope, @NotNull RedeclarationHandler redeclarationHandler) {
|
||||
super(scope);
|
||||
this.diagnosticHolder = diagnosticHolder;
|
||||
this.redeclarationHandler = redeclarationHandler;
|
||||
}
|
||||
|
||||
public WritableScopeWithImports setDebugName(@NotNull String debugName) {
|
||||
@@ -97,7 +96,7 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
||||
|
||||
public void importClassifierAlias(@NotNull String importedClassifierName, @NotNull ClassifierDescriptor classifierDescriptor) {
|
||||
if (currentIndividualImportScope == null) {
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, getContainingDeclaration(), DiagnosticHolder.DO_NOTHING).setDebugName("Individual import scope");
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(EMPTY, getContainingDeclaration(), RedeclarationHandler.DO_NOTHING).setDebugName("Individual import scope");
|
||||
importScope(writableScope);
|
||||
currentIndividualImportScope = writableScope;
|
||||
}
|
||||
+10
-9
@@ -1,11 +1,11 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
package org.jetbrains.jet.lang.resolve.scopes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ImplicitReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -16,8 +16,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
||||
private final WritableScope writableWorker;
|
||||
private Collection<DeclarationDescriptor> allDescriptors;
|
||||
|
||||
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull DiagnosticHolder diagnosticHolder) {
|
||||
super(outerScope, diagnosticHolder);
|
||||
public WriteThroughScope(@NotNull JetScope outerScope, @NotNull WritableScope scope, @NotNull RedeclarationHandler redeclarationHandler) {
|
||||
super(outerScope, redeclarationHandler);
|
||||
this.writableWorker = scope;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getThisType() {
|
||||
return writableWorker.getThisType();
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
return writableWorker.getImplicitReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,10 +147,11 @@ public class WriteThroughScope extends WritableScopeWithImports {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThisType(@NotNull JetType thisType) {
|
||||
writableWorker.setThisType(thisType);
|
||||
public void setImplicitReceiver(@NotNull ImplicitReceiverDescriptor implicitReceiver) {
|
||||
writableWorker.setImplicitReceiver(implicitReceiver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
if (allDescriptors == null) {
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ClassReceiver extends ImplicitReceiverDescriptor {
|
||||
|
||||
public ClassReceiver(ClassDescriptor classDescriptor) {
|
||||
super(classDescriptor, classDescriptor.getDefaultType());
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ExplicitReceiver implements ReceiverDescriptor {
|
||||
|
||||
private final JetType type;
|
||||
|
||||
public ExplicitReceiver(@NotNull JetType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReceiverType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ExtensionCallableReceiver extends ImplicitReceiverDescriptor {
|
||||
|
||||
public ExtensionCallableReceiver(CallableDescriptor callableDescriptor) {
|
||||
super(callableDescriptor, callableDescriptor.getReceiverType());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
* Describes a "this" receiver
|
||||
*
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class ImplicitReceiverDescriptor implements ReceiverDescriptor {
|
||||
private final JetType receiverType;
|
||||
private final DeclarationDescriptor declarationDescriptor;
|
||||
|
||||
protected ImplicitReceiverDescriptor(DeclarationDescriptor declarationDescriptor, JetType receiverType) {
|
||||
this.receiverType = receiverType;
|
||||
this.declarationDescriptor = declarationDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetType getReceiverType() {
|
||||
return receiverType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclarationDescriptor getDeclarationDescriptor() {
|
||||
return declarationDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface ReceiverDescriptor {
|
||||
|
||||
ReceiverDescriptor NO_RECEIVER = new ReceiverDescriptor() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReceiverType() {
|
||||
return JetStandardClasses.getNothingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NO_RECEIVER";
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
JetType getReceiverType();
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ package org.jetbrains.jet.lang.types;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -32,8 +33,12 @@ public class ErrorUtils {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
return createErrorType("<ERROR TYPE>");
|
||||
public ReceiverDescriptor getImplicitReceiver() {
|
||||
return ReceiverDescriptor.NO_RECEIVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -64,6 +69,7 @@ public class ErrorUtils {
|
||||
return ERROR_CLASS; // TODO : review
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -6,11 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -198,7 +194,7 @@ public class JetStandardClasses {
|
||||
/*package*/ static final JetScope STANDARD_CLASSES;
|
||||
|
||||
static {
|
||||
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
|
||||
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
|
||||
STANDARD_CLASSES = writableScope;
|
||||
writableScope.addClassifierAlias("Unit", getTuple(0));
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionGroup;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticHolder;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -99,7 +101,7 @@ public class JetStandardLibrary {
|
||||
|
||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, DiagnosticHolder.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
||||
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
||||
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
|
||||
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResult;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
@@ -367,7 +370,7 @@ public class JetTypeInferrer {
|
||||
}
|
||||
|
||||
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
||||
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, context.trace).setDebugName("getBlockReturnedType");
|
||||
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
||||
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
|
||||
}
|
||||
|
||||
@@ -891,7 +894,7 @@ public class JetTypeInferrer {
|
||||
if (receiverTypeRef != null) {
|
||||
receiverType = context.typeResolver.resolveType(context.scope, receiverTypeRef);
|
||||
} else {
|
||||
receiverType = context.scope.getThisType();
|
||||
receiverType = context.scope.getImplicitReceiver().getReceiverType();
|
||||
}
|
||||
|
||||
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
|
||||
@@ -899,36 +902,46 @@ public class JetTypeInferrer {
|
||||
|
||||
List<JetType> parameterTypes = new ArrayList<JetType>();
|
||||
List<ValueParameterDescriptor> valueParameterDescriptors = Lists.newArrayList();
|
||||
List<JetParameter> parameters = functionLiteral.getValueParameters();
|
||||
List<JetParameter> declaredValueParameters = functionLiteral.getValueParameters();
|
||||
JetType expectedType = context.expectedType;
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = null;
|
||||
|
||||
boolean functionTypeExpected = expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(expectedType);
|
||||
if (functionTypeExpected) {
|
||||
valueParameters = JetStandardClasses.getValueParameters(functionDescriptor, expectedType);
|
||||
List<ValueParameterDescriptor> expectedValueParameters = (functionTypeExpected)
|
||||
? JetStandardClasses.getValueParameters(functionDescriptor, expectedType)
|
||||
: null;
|
||||
|
||||
if (functionTypeExpected && declaredValueParameters.isEmpty() && expectedValueParameters.size() == 1) {
|
||||
ValueParameterDescriptor valueParameterDescriptor = expectedValueParameters.get(0);
|
||||
ValueParameterDescriptor it = new ValueParameterDescriptorImpl(
|
||||
functionDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "it", valueParameterDescriptor.getInType(), valueParameterDescriptor.getOutType(), valueParameterDescriptor.hasDefaultValue(), valueParameterDescriptor.isVararg()
|
||||
);
|
||||
valueParameterDescriptors.add(it);
|
||||
parameterTypes.add(it.getOutType());
|
||||
context.trace.record(AUTO_CREATED_IT, it);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < declaredValueParameters.size(); i++) {
|
||||
JetParameter declaredParameter = declaredValueParameters.get(i);
|
||||
JetTypeReference typeReference = declaredParameter.getTypeReference();
|
||||
|
||||
for (int i = 0, parametersSize = parameters.size(); i < parametersSize; i++) {
|
||||
JetParameter parameter = parameters.get(i);
|
||||
JetTypeReference typeReference = parameter.getTypeReference();
|
||||
|
||||
JetType type;
|
||||
if (typeReference != null) {
|
||||
type = context.typeResolver.resolveType(context.scope, typeReference);
|
||||
}
|
||||
else {
|
||||
if (valueParameters != null) {
|
||||
type = valueParameters.get(i).getOutType();
|
||||
JetType type;
|
||||
if (typeReference != null) {
|
||||
type = context.typeResolver.resolveType(context.scope, typeReference);
|
||||
}
|
||||
else {
|
||||
// context.trace.getErrorHandler().genericError(parameter.getNode(), "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
||||
context.trace.report(CANNOT_INFER_PARAMETER_TYPE.on(parameter));
|
||||
type = ErrorUtils.createErrorType("Cannot be inferred");
|
||||
if (expectedValueParameters != null && i < expectedValueParameters.size()) {
|
||||
type = expectedValueParameters.get(i).getOutType();
|
||||
}
|
||||
else {
|
||||
// context.trace.getErrorHandler().genericError(declaredParameter.getNode(), "Cannot infer a type for this declaredParameter. To specify it explicitly use the {(p : Type) => ...} notation");
|
||||
context.trace.report(CANNOT_INFER_PARAMETER_TYPE.on(declaredParameter));
|
||||
type = ErrorUtils.createErrorType("Cannot be inferred");
|
||||
}
|
||||
}
|
||||
ValueParameterDescriptor valueParameterDescriptor = context.classDescriptorResolver.resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type);
|
||||
parameterTypes.add(valueParameterDescriptor.getOutType());
|
||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
||||
}
|
||||
ValueParameterDescriptor valueParameterDescriptor = context.classDescriptorResolver.resolveValueParameterDescriptor(functionDescriptor, parameter, i, type);
|
||||
parameterTypes.add(valueParameterDescriptor.getOutType());
|
||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
JetType effectiveReceiverType;
|
||||
@@ -974,7 +987,11 @@ public class JetTypeInferrer {
|
||||
|
||||
@Override
|
||||
public JetType visitParenthesizedExpression(JetParenthesizedExpression expression, TypeInferenceContext context) {
|
||||
return context.services.checkType(getType(expression.getExpression(), context.replaceScope(context.scope)), expression, context);
|
||||
JetExpression innerExpression = expression.getExpression();
|
||||
if (innerExpression == null) {
|
||||
return null;
|
||||
}
|
||||
return context.services.checkType(getType(innerExpression, context.replaceScope(context.scope)), expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1251,7 +1268,7 @@ public class JetTypeInferrer {
|
||||
}
|
||||
}
|
||||
else {
|
||||
thisType = context.scope.getThisType();
|
||||
thisType = context.scope.getImplicitReceiver().getReceiverType();
|
||||
|
||||
DeclarationDescriptor declarationDescriptorForUnqualifiedThis = context.scope.getDeclarationDescriptorForUnqualifiedThis();
|
||||
if (declarationDescriptorForUnqualifiedThis != null) {
|
||||
@@ -1814,7 +1831,7 @@ public class JetTypeInferrer {
|
||||
}
|
||||
|
||||
protected WritableScopeImpl newWritableScopeImpl(JetScope scope, BindingTrace trace) {
|
||||
return new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace);
|
||||
return new WritableScopeImpl(scope, scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang.types;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.ChainedScope;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -19,6 +19,11 @@
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="control shift Q"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
</action>
|
||||
<action id="CopyAsDiagnosticTest" class="org.jetbrains.jet.plugin.actions.CopyAsDiagnosticTestAction"
|
||||
text="Copy Current File As Diagnostic Test">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift T"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
</action>
|
||||
<action id="ToggleJetErrorReporting" class="org.jetbrains.jet.plugin.actions.ToggleErrorReportingAction"
|
||||
text="Toggle Error Reporting">
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift E"/>
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
package org.jetbrains.jet.checkers;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class CheckerTestUtil {
|
||||
public static final Comparator<Diagnostic> DIAGNOSTIC_COMPARATOR = new Comparator<Diagnostic>() {
|
||||
@Override
|
||||
public int compare(Diagnostic o1, Diagnostic o2) {
|
||||
TextRange range1 = getTextRange(o1);
|
||||
TextRange range2 = getTextRange(o2);
|
||||
int startOffset1 = range1.getStartOffset();
|
||||
int startOffset2 = range2.getStartOffset();
|
||||
if (startOffset1 != startOffset2) {
|
||||
// Start early -- go first
|
||||
return startOffset1 - range2.getStartOffset();
|
||||
}
|
||||
// start at the same offset, the one who end later is the outer, i.e. goes first
|
||||
return range2.getEndOffset() - range1.getEndOffset();
|
||||
}
|
||||
};
|
||||
private static final Pattern RANGE_START_OR_END_PATTERN = Pattern.compile("(<!\\w+(,\\s*\\w+)*!>)|(<!>)");
|
||||
private static final Pattern INDIVIDUAL_DIAGNOSTIC_PATTERN = Pattern.compile("\\w+");
|
||||
|
||||
public interface DiagnosticDiffCallbacks {
|
||||
void missingDiagnostic(String type, int expectedStart, int expectedEnd);
|
||||
void unexpectedDiagnostic(String type, int actualStart, int actualEnd);
|
||||
}
|
||||
|
||||
public static void diagnosticsDiff(List<DiagnosedRange> expected, Collection<Diagnostic> actual, DiagnosticDiffCallbacks callbacks) {
|
||||
Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
|
||||
List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
|
||||
Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();
|
||||
|
||||
DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
|
||||
DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
|
||||
while (currentExpected != null || currentActual != null) {
|
||||
if (currentExpected != null) {
|
||||
if (currentActual == null) {
|
||||
missingDiagnostics(callbacks, currentExpected);
|
||||
currentExpected = safeAdvance(expectedDiagnostics);
|
||||
}
|
||||
else {
|
||||
int expectedStart = currentExpected.getStart();
|
||||
int actualStart = currentActual.getStart();
|
||||
int expectedEnd = currentExpected.getEnd();
|
||||
int actualEnd = currentActual.getEnd();
|
||||
if (expectedStart < actualStart) {
|
||||
missingDiagnostics(callbacks, currentExpected);
|
||||
currentExpected = safeAdvance(expectedDiagnostics);
|
||||
}
|
||||
else if (expectedStart > actualStart) {
|
||||
unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
|
||||
currentActual = safeAdvance(actualDiagnostics);
|
||||
}
|
||||
else if (expectedEnd > actualEnd) {
|
||||
assert expectedStart == actualStart;
|
||||
missingDiagnostics(callbacks, currentExpected);
|
||||
currentExpected = safeAdvance(expectedDiagnostics);
|
||||
}
|
||||
else if (expectedEnd < actualEnd) {
|
||||
assert expectedStart == actualStart;
|
||||
unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
|
||||
currentActual = safeAdvance(actualDiagnostics);
|
||||
}
|
||||
else {
|
||||
assert expectedStart == actualStart && expectedEnd == actualEnd;
|
||||
Multiset<String> actualDiagnosticTypes = currentActual.getDiagnosticTypeStrings();
|
||||
Multiset<String> expectedDiagnosticTypes = currentExpected.getDiagnostics();
|
||||
if (!actualDiagnosticTypes.equals(expectedDiagnosticTypes)) {
|
||||
Multiset<String> expectedCopy = HashMultiset.create(expectedDiagnosticTypes);
|
||||
expectedCopy.removeAll(actualDiagnosticTypes);
|
||||
Multiset<String> actualCopy = HashMultiset.create(actualDiagnosticTypes);
|
||||
actualCopy.removeAll(expectedDiagnosticTypes);
|
||||
|
||||
for (String type : expectedCopy) {
|
||||
callbacks.missingDiagnostic(type, expectedStart, expectedEnd);
|
||||
}
|
||||
for (String type : actualCopy) {
|
||||
callbacks.unexpectedDiagnostic(type, actualStart, actualEnd);
|
||||
}
|
||||
}
|
||||
currentExpected = safeAdvance(expectedDiagnostics);
|
||||
currentActual = safeAdvance(actualDiagnostics);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (currentActual != null) {
|
||||
unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
|
||||
currentActual = safeAdvance(actualDiagnostics);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// assert expectedDiagnostics.hasNext() || actualDiagnostics.hasNext();
|
||||
}
|
||||
}
|
||||
|
||||
private static void unexpectedDiagnostics(List<Diagnostic> actual, DiagnosticDiffCallbacks callbacks) {
|
||||
for (Diagnostic diagnostic : actual) {
|
||||
TextRange textRange = getTextRange(diagnostic);
|
||||
callbacks.unexpectedDiagnostic(diagnostic.getFactory().getName(), textRange.getStartOffset(), textRange.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
private static void missingDiagnostics(DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) {
|
||||
for (String type : currentExpected.getDiagnostics()) {
|
||||
callbacks.missingDiagnostic(type, currentExpected.getStart(), currentExpected.getEnd());
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T safeAdvance(Iterator<T> iterator) {
|
||||
return iterator.hasNext() ? iterator.next() : null;
|
||||
}
|
||||
|
||||
public static String parseDiagnosedRanges(String text, List<DiagnosedRange> result) {
|
||||
Matcher matcher = RANGE_START_OR_END_PATTERN.matcher(text);
|
||||
|
||||
Stack<DiagnosedRange> opened = new Stack<DiagnosedRange>();
|
||||
|
||||
int offsetCompensation = 0;
|
||||
|
||||
while (matcher.find()) {
|
||||
int effectiveOffset = matcher.start() - offsetCompensation;
|
||||
String matchedText = matcher.group();
|
||||
if ("<!>".equals(matchedText)) {
|
||||
opened.pop().setEnd(effectiveOffset);
|
||||
}
|
||||
else {
|
||||
Matcher diagnosticTypeMatcher = INDIVIDUAL_DIAGNOSTIC_PATTERN.matcher(matchedText);
|
||||
DiagnosedRange range = new DiagnosedRange(effectiveOffset);
|
||||
while (diagnosticTypeMatcher.find()) {
|
||||
range.addDiagnostic(diagnosticTypeMatcher.group());
|
||||
}
|
||||
opened.push(range);
|
||||
result.add(range);
|
||||
}
|
||||
offsetCompensation += matchedText.length();
|
||||
}
|
||||
|
||||
assert opened.isEmpty() : "Stack is not empty";
|
||||
|
||||
matcher.reset();
|
||||
return matcher.replaceAll("");
|
||||
}
|
||||
|
||||
public static StringBuffer addDiagnosticMarkersToText(PsiFile psiFile, BindingContext bindingContext) {
|
||||
Collection<Diagnostic> diagnostics = bindingContext.getDiagnostics();
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
String text = psiFile.getText();
|
||||
if (!diagnostics.isEmpty()) {
|
||||
List<DiagnosticDescriptor> diagnosticDescriptors = getSortedDiagnosticDescriptors(diagnostics);
|
||||
|
||||
Stack<DiagnosticDescriptor> opened = new Stack<DiagnosticDescriptor>();
|
||||
ListIterator<DiagnosticDescriptor> iterator = diagnosticDescriptors.listIterator();
|
||||
DiagnosticDescriptor currentDescriptor = iterator.next();
|
||||
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
while (!opened.isEmpty() && i == opened.peek().end) {
|
||||
closeDiagnosticString(result);
|
||||
opened.pop();
|
||||
}
|
||||
while (currentDescriptor != null && i == currentDescriptor.start) {
|
||||
openDiagnosticsString(result, currentDescriptor);
|
||||
if (currentDescriptor.getEnd() == i) {
|
||||
closeDiagnosticString(result);
|
||||
}
|
||||
else {
|
||||
opened.push(currentDescriptor);
|
||||
}
|
||||
if (iterator.hasNext()) {
|
||||
currentDescriptor = iterator.next();
|
||||
}
|
||||
else {
|
||||
currentDescriptor = null;
|
||||
}
|
||||
}
|
||||
result.append(c);
|
||||
}
|
||||
while (!opened.isEmpty() && text.length() == opened.peek().end) {
|
||||
closeDiagnosticString(result);
|
||||
opened.pop();
|
||||
}
|
||||
|
||||
assert opened.isEmpty() : "Stack is not empty";
|
||||
|
||||
}
|
||||
else {
|
||||
result.append(text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void openDiagnosticsString(StringBuffer result, DiagnosticDescriptor currentDescriptor) {
|
||||
result.append("<!");
|
||||
for (Iterator<Diagnostic> iterator = currentDescriptor.diagnostics.iterator(); iterator.hasNext(); ) {
|
||||
Diagnostic diagnostic = iterator.next();
|
||||
result.append(diagnostic.getFactory().getName());
|
||||
if (iterator.hasNext()) {
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
result.append("!>");
|
||||
}
|
||||
|
||||
private static void closeDiagnosticString(StringBuffer result) {
|
||||
result.append("<!>");
|
||||
}
|
||||
|
||||
private static List<DiagnosticDescriptor> getSortedDiagnosticDescriptors(Collection<Diagnostic> diagnostics) {
|
||||
List<Diagnostic> list = Lists.newArrayList(diagnostics);
|
||||
Collections.sort(list, DIAGNOSTIC_COMPARATOR);
|
||||
|
||||
List<DiagnosticDescriptor> diagnosticDescriptors = Lists.newArrayList();
|
||||
DiagnosticDescriptor currentDiagnosticDescriptor = null;
|
||||
for (Iterator<Diagnostic> iterator = list.iterator(); iterator.hasNext(); ) {
|
||||
Diagnostic diagnostic = iterator.next();
|
||||
|
||||
TextRange textRange = getTextRange(diagnostic);
|
||||
if (currentDiagnosticDescriptor != null && currentDiagnosticDescriptor.equalRange(textRange)) {
|
||||
currentDiagnosticDescriptor.diagnostics.add(diagnostic);
|
||||
}
|
||||
else {
|
||||
currentDiagnosticDescriptor = new DiagnosticDescriptor(textRange.getStartOffset(), textRange.getEndOffset(), diagnostic);
|
||||
diagnosticDescriptors.add(currentDiagnosticDescriptor);
|
||||
}
|
||||
}
|
||||
return diagnosticDescriptors;
|
||||
}
|
||||
|
||||
private static TextRange getTextRange(Diagnostic currentDiagnostic) {
|
||||
return currentDiagnostic.getFactory().getTextRange(currentDiagnostic);
|
||||
}
|
||||
|
||||
private static class DiagnosticDescriptor {
|
||||
private final int start;
|
||||
private final int end;
|
||||
private final List<Diagnostic> diagnostics = Lists.newArrayList();
|
||||
|
||||
DiagnosticDescriptor(int start, int end, Diagnostic diagnostic) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.diagnostics.add(diagnostic);
|
||||
}
|
||||
|
||||
public boolean equalRange(TextRange textRange) {
|
||||
return start == textRange.getStartOffset() && end == textRange.getEndOffset();
|
||||
}
|
||||
|
||||
public Multiset<String> getDiagnosticTypeStrings() {
|
||||
Multiset<String> actualDiagnosticTypes = HashMultiset.create();
|
||||
for (Diagnostic diagnostic : diagnostics) {
|
||||
actualDiagnosticTypes.add(diagnostic.getFactory().getName());
|
||||
}
|
||||
return actualDiagnosticTypes;
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public int getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public List<Diagnostic> getDiagnostics() {
|
||||
return diagnostics;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DiagnosedRange {
|
||||
private final int start;
|
||||
private int end;
|
||||
private final Multiset<String> diagnostics = HashMultiset.create();
|
||||
|
||||
private DiagnosedRange(int start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public int getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public Multiset<String> getDiagnostics() {
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
public void setEnd(int end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public void addDiagnostic(String diagnostic) {
|
||||
diagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,24 @@ public class JetHighlighter extends SyntaxHighlighterBase {
|
||||
JET_AUTO_CAST_EXPRESSION = TextAttributesKey.createTextAttributesKey("JET.AUTO.CAST.EXPRESSION", clone);
|
||||
}
|
||||
|
||||
public static final TextAttributesKey JET_AUTOCREATED_IT;
|
||||
|
||||
static {
|
||||
TextAttributes attributes = new TextAttributes();
|
||||
attributes.setFontType(Font.BOLD);
|
||||
// TODO: proper attributes
|
||||
JET_AUTOCREATED_IT = TextAttributesKey.createTextAttributesKey("JET.AUTO.CREATED.IT", attributes);
|
||||
}
|
||||
|
||||
public static final TextAttributesKey JET_FUNCTION_LITERAL_DELIMITER;
|
||||
|
||||
static {
|
||||
TextAttributes attributes = new TextAttributes();
|
||||
attributes.setFontType(Font.BOLD);
|
||||
// TODO: proper attributes
|
||||
JET_FUNCTION_LITERAL_DELIMITER = TextAttributesKey.createTextAttributesKey("JET.AUTO.CREATED.IT", attributes);
|
||||
}
|
||||
|
||||
public static final TextAttributesKey JET_DEBUG_INFO;
|
||||
|
||||
static {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.jetbrains.jet.plugin.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.checkers.CheckerTestUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.AnalyzerFacade;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class CopyAsDiagnosticTestAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Editor editor = e.getData(PlatformDataKeys.EDITOR);
|
||||
PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
|
||||
assert editor != null && psiFile != null;
|
||||
|
||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache((JetFile) psiFile);
|
||||
|
||||
String result = CheckerTestUtil.addDiagnosticMarkersToText(psiFile, bindingContext).toString();
|
||||
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(result), new ClipboardOwner() {
|
||||
@Override
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Editor editor = e.getData(PlatformDataKeys.EDITOR);
|
||||
PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
|
||||
e.getPresentation().setEnabled(editor != null && psiFile instanceof JetFile && ApplicationManager.getApplication().isInternal());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.intellij.psi.PsiReference;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -28,6 +29,10 @@ import org.jetbrains.jet.plugin.quickfix.QuickFixes;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTOCAST;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTO_CREATED_IT;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -52,7 +57,7 @@ public class JetPsiChecker implements Annotator {
|
||||
|
||||
if (errorReportingEnabled) {
|
||||
Collection<Diagnostic> diagnostics = bindingContext.getDiagnostics();
|
||||
Set<DeclarationDescriptor> redeclarations = Sets.newHashSet();
|
||||
Set<PsiElement> redeclarations = Sets.newHashSet();
|
||||
for (Diagnostic diagnostic : diagnostics) {
|
||||
Annotation annotation = null;
|
||||
if (diagnostic.getSeverity() == Severity.ERROR) {
|
||||
@@ -72,8 +77,7 @@ public class JetPsiChecker implements Annotator {
|
||||
}
|
||||
else if (diagnostic instanceof RedeclarationDiagnostic) {
|
||||
RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic;
|
||||
markRedeclaration(redeclarations, redeclarationDiagnostic.getA(), bindingContext, holder);
|
||||
markRedeclaration(redeclarations, redeclarationDiagnostic.getB(), bindingContext, holder);
|
||||
annotation = markRedeclaration(redeclarations, redeclarationDiagnostic, holder);
|
||||
}
|
||||
else {
|
||||
annotation = holder.createErrorAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
||||
@@ -82,7 +86,7 @@ public class JetPsiChecker implements Annotator {
|
||||
else if (diagnostic.getSeverity() == Severity.WARNING) {
|
||||
annotation = holder.createWarningAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
||||
}
|
||||
if (annotation != null && diagnostic instanceof DiagnosticWithPsiElement) {
|
||||
if (annotation != null && diagnostic instanceof DiagnosticWithPsiElementImpl) {
|
||||
DiagnosticWithPsiElement diagnosticWithPsiElement = (DiagnosticWithPsiElement) diagnostic;
|
||||
if (diagnostic.getFactory() instanceof PsiElementOnlyDiagnosticFactory) {
|
||||
PsiElementOnlyDiagnosticFactory factory = (PsiElementOnlyDiagnosticFactory) diagnostic.getFactory();
|
||||
@@ -102,9 +106,21 @@ public class JetPsiChecker implements Annotator {
|
||||
highlightBackingFields(holder, file, bindingContext);
|
||||
|
||||
file.acceptChildren(new JetVisitorVoid() {
|
||||
@Override
|
||||
public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
|
||||
DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression);
|
||||
if (target instanceof ValueParameterDescriptor) {
|
||||
ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target;
|
||||
if (bindingContext.get(AUTO_CREATED_IT, parameterDescriptor)) {
|
||||
holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlighter.JET_AUTOCREATED_IT);
|
||||
}
|
||||
}
|
||||
super.visitSimpleNameExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpression(JetExpression expression) {
|
||||
JetType autoCast = bindingContext.get(BindingContext.AUTOCAST, expression);
|
||||
JetType autoCast = bindingContext.get(AUTOCAST, expression);
|
||||
if (autoCast != null) {
|
||||
holder.createInfoAnnotation(expression, "Automatically cast to " + autoCast).setTextAttributes(JetHighlighter.JET_AUTO_CAST_EXPRESSION);
|
||||
}
|
||||
@@ -135,19 +151,10 @@ public class JetPsiChecker implements Annotator {
|
||||
return diagnostic.getMessage();
|
||||
}
|
||||
|
||||
private void markRedeclaration(Set<DeclarationDescriptor> redeclarations, DeclarationDescriptor redeclaration, BindingContext bindingContext, AnnotationHolder holder) {
|
||||
if (!redeclarations.add(redeclaration)) return;
|
||||
PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, redeclaration);
|
||||
if (declarationPsiElement instanceof JetNamedDeclaration) {
|
||||
PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
holder.createErrorAnnotation(nameIdentifier, "Redeclaration");
|
||||
}
|
||||
}
|
||||
else if (declarationPsiElement != null) {
|
||||
holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
|
||||
}
|
||||
}
|
||||
private Annotation markRedeclaration(Set<PsiElement> redeclarations, RedeclarationDiagnostic diagnostic, AnnotationHolder holder) {
|
||||
if (!redeclarations.add(diagnostic.getPsiElement())) return null;
|
||||
return holder.createErrorAnnotation(diagnostic.getFactory().getTextRange(diagnostic), getMessage(diagnostic));
|
||||
}
|
||||
|
||||
|
||||
private void highlightBackingFields(final AnnotationHolder holder, JetFile file, final BindingContext bindingContext) {
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.annotations;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,20 +15,41 @@ import org.jetbrains.jet.plugin.JetHighlighter;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class SoftKeywordsAnnotator implements Annotator {
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if (element instanceof LeafPsiElement) {
|
||||
if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) {
|
||||
holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlighter.JET_SOFT_KEYWORD);
|
||||
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
||||
element.accept(new JetVisitorVoid() {
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
if (element instanceof LeafPsiElement) {
|
||||
if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) {
|
||||
holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlighter.JET_SOFT_KEYWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element instanceof JetAnnotationEntry) {
|
||||
JetAnnotationEntry entry = (JetAnnotationEntry) element;
|
||||
JetTypeReference typeReference = entry.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
markAnnotationIdentifiers(typeElement, holder);
|
||||
|
||||
@Override
|
||||
public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) {
|
||||
JetTypeReference typeReference = annotationEntry.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
markAnnotationIdentifiers(typeElement, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
holder.createInfoAnnotation(functionLiteral.getOpenBraceNode(), null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER);
|
||||
ASTNode closingBraceNode = functionLiteral.getClosingBraceNode();
|
||||
if (closingBraceNode != null) {
|
||||
holder.createInfoAnnotation(closingBraceNode, null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER);
|
||||
}
|
||||
ASTNode arrowNode = functionLiteral.getArrowNode();
|
||||
if (arrowNode != null) {
|
||||
holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlighter.JET_FUNCTION_LITERAL_DELIMITER);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
||||
JetFile file = (JetFile) getElement().getContainingFile();
|
||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(file);
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
|
||||
assert declarationDescriptors != null;
|
||||
if (declarationDescriptors != null) return ResolveResult.EMPTY_ARRAY;
|
||||
ResolveResult[] results = new ResolveResult[declarationDescriptors.size()];
|
||||
int i = 0;
|
||||
for (DeclarationDescriptor descriptor : declarationDescriptors) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.AnalyzerFacade;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
foo(1)
|
||||
val a : fun() : Unit = {
|
||||
foo(1)
|
||||
}
|
||||
return 1 - "1"
|
||||
}
|
||||
|
||||
class A() {
|
||||
val x : Int = foo1(xx)
|
||||
}
|
||||
|
||||
fun foo1() {}
|
||||
@@ -0,0 +1,241 @@
|
||||
namespace abstract
|
||||
|
||||
class MyClass() {
|
||||
//properties
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>a<!>: Int
|
||||
val a1: Int = 1
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val a2: Int
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val a3: Int = 1
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>b<!>: Int private set
|
||||
var b1: Int = 0; private set
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> var b2: Int private set
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> var b3: Int = 0; private set
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>c<!>: Int set(v: Int) { $c = v }
|
||||
var c1: Int = 0; set(v: Int) { $c1 = v }
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> var c2: Int set(v: Int) { $c2 = v }
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> var c3: Int = 0; set(v: Int) { $c3 = v }
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = a
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val e2: Int get() = a
|
||||
<!ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS!>abstract<!> val e3: Int = 0; get() = a
|
||||
|
||||
//methods
|
||||
fun <!NON_ABSTRACT_FUNCTION_WITH_NO_BODY!>f<!>()
|
||||
fun g() {}
|
||||
<!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> fun h()
|
||||
<!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
|
||||
var j: Int get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
var k1: Int = 0; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
|
||||
var l: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> set
|
||||
|
||||
var n: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> set(v: Int) {}
|
||||
}
|
||||
|
||||
abstract class MyAbstractClass() {
|
||||
//properties
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>a<!>: Int
|
||||
val a1: Int = 1
|
||||
abstract val a2: Int
|
||||
abstract val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>b<!>: Int private set
|
||||
var b1: Int = 0; private set
|
||||
abstract var b2: Int private set
|
||||
abstract var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>c<!>: Int set(v: Int) { $c = v }
|
||||
var c1: Int = 0; set(v: Int) { $c1 = v }
|
||||
abstract var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
|
||||
abstract var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = a
|
||||
abstract val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
abstract val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
|
||||
//methods
|
||||
fun <!NON_ABSTRACT_FUNCTION_WITH_NO_BODY!>f<!>()
|
||||
fun g() {}
|
||||
abstract fun h()
|
||||
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int abstract get abstract set
|
||||
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; abstract get abstract set
|
||||
|
||||
var j: Int get() = i; abstract set
|
||||
var j1: Int get() = i; abstract set
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int abstract set
|
||||
var k1: Int = 0; abstract set
|
||||
|
||||
var l: Int abstract get abstract set
|
||||
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; abstract get abstract set
|
||||
|
||||
var n: Int abstract get <!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> set(v: Int) {}
|
||||
}
|
||||
|
||||
trait MyTrait {
|
||||
//properties
|
||||
val a: Int
|
||||
val a1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>1<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val a2: Int
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
|
||||
|
||||
var b: Int private set
|
||||
var b1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; private set
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var b2: Int private set
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
|
||||
|
||||
var <!BACKING_FIELD_IN_TRAIT!>c<!>: Int set(v: Int) { $c = v }
|
||||
var <!BACKING_FIELD_IN_TRAIT!>c1<!>: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; set(v: Int) { $c1 = v }
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = a
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
|
||||
//methods
|
||||
fun f()
|
||||
fun g() {}
|
||||
<!REDUNDANT_ABSTRACT!>abstract<!> fun h()
|
||||
<!REDUNDANT_ABSTRACT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int abstract get abstract set
|
||||
var i1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; abstract get abstract set
|
||||
|
||||
var j: Int get() = i; abstract set
|
||||
var j1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = i; abstract set
|
||||
|
||||
var k: Int abstract set
|
||||
var k1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; abstract set
|
||||
|
||||
var l: Int abstract get abstract set
|
||||
var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; abstract get abstract set
|
||||
|
||||
var n: Int abstract get <!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> set(v: Int) {}
|
||||
}
|
||||
|
||||
enum class MyEnum() {
|
||||
//properties
|
||||
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>a<!>: Int
|
||||
val a1: Int = 1
|
||||
abstract val a2: Int
|
||||
abstract val a3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>1<!>
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>b<!>: Int private set
|
||||
var b1: Int = 0; private set
|
||||
abstract var b2: Int private set
|
||||
abstract var b3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; private set
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>c<!>: Int set(v: Int) { $c = v }
|
||||
var c1: Int = 0; set(v: Int) { $c1 = v }
|
||||
abstract var c2: Int <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c2 = v }<!>
|
||||
abstract var c3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_SETTER!>set(v: Int) { $c3 = v }<!>
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = a
|
||||
abstract val e2: Int <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
abstract val e3: Int = <!ABSTRACT_PROPERTY_WITH_INITIALIZER!>0<!>; <!ABSTRACT_PROPERTY_WITH_GETTER!>get() = a<!>
|
||||
|
||||
//methods
|
||||
fun <!NON_ABSTRACT_FUNCTION_WITH_NO_BODY!>f<!>()
|
||||
fun g() {}
|
||||
abstract fun h()
|
||||
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int abstract get abstract set
|
||||
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; abstract get abstract set
|
||||
|
||||
var j: Int get() = i; abstract set
|
||||
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; abstract set
|
||||
|
||||
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int abstract set
|
||||
var k1: Int = 0; abstract set
|
||||
|
||||
var l: Int abstract get abstract set
|
||||
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; abstract get abstract set
|
||||
|
||||
var n: Int abstract get <!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> set(v: Int) {}
|
||||
}
|
||||
|
||||
abstract enum class MyAbstractEnum() {}
|
||||
|
||||
namespace MyNamespace {
|
||||
//properties
|
||||
val <!MUST_BE_INITIALIZED!>a<!>: Int
|
||||
val a1: Int = 1
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> val a2: Int
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> val a3: Int = 1
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>b<!>: Int private set
|
||||
var b1: Int = 0; private set
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> var b2: Int private set
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> var b3: Int = 0; private set
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>c<!>: Int set(v: Int) { $c = v }
|
||||
var c1: Int = 0; set(v: Int) { $c1 = v }
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> var c2: Int set(v: Int) { $c2 = v }
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> var c3: Int = 0; set(v: Int) { $c3 = v }
|
||||
|
||||
val e: Int get() = a
|
||||
val e1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = a
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> val e2: Int get() = a
|
||||
<!ABSTRACT_PROPERTY_NOT_IN_CLASS!>abstract<!> val e3: Int = 0; get() = a
|
||||
|
||||
//methods
|
||||
fun <!NON_MEMBER_FUNCTION_NO_BODY!>f<!>()
|
||||
fun g() {}
|
||||
<!NON_MEMBER_ABSTRACT_FUNCTION!>abstract<!> fun h()
|
||||
<!NON_MEMBER_ABSTRACT_FUNCTION!>abstract<!> fun j() {}
|
||||
|
||||
//property accessors
|
||||
var i: Int <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
|
||||
var j: Int get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
|
||||
var <!MUST_BE_INITIALIZED!>k<!>: Int <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
var k1: Int = 0; <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
|
||||
var l: Int <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set
|
||||
|
||||
var n: Int <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR!>abstract<!> set(v: Int) {}
|
||||
}
|
||||
|
||||
//creating an instance
|
||||
abstract class B1(
|
||||
val i: Int,
|
||||
val s: String
|
||||
) {
|
||||
}
|
||||
|
||||
class B2() : B1(1, "r") {}
|
||||
|
||||
abstract class B3(i: Int) {
|
||||
this(): this(1)
|
||||
}
|
||||
|
||||
fun foo(a: B3) {
|
||||
val a = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
|
||||
val b = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
class NoC {
|
||||
<!ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR!>{
|
||||
|
||||
}<!>
|
||||
|
||||
val a : Int get() = 1
|
||||
|
||||
<!ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR!>{
|
||||
|
||||
}<!>
|
||||
}
|
||||
|
||||
class WithC() {
|
||||
val x : Int
|
||||
{
|
||||
$x = 1
|
||||
<!UNRESOLVED_REFERENCE!>$y<!> = 2
|
||||
val b = x
|
||||
|
||||
}
|
||||
|
||||
val a : Int get() = 1
|
||||
|
||||
{
|
||||
val z = <!UNRESOLVED_REFERENCE!>b<!>
|
||||
val zz = x
|
||||
val zzz = <!NO_BACKING_FIELD!>$a<!>
|
||||
}
|
||||
|
||||
this(a : Int) : this() {
|
||||
val b = x
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
class A() {
|
||||
fun equals(a : Any?) : Boolean = false
|
||||
}
|
||||
|
||||
class B() {
|
||||
fun equals(a : Any?) : Boolean? = false
|
||||
}
|
||||
|
||||
class C() {
|
||||
fun equals(a : Any?) : Int = 0
|
||||
}
|
||||
|
||||
fun f(): Unit {
|
||||
var x: Int? = 1
|
||||
x = 1
|
||||
x <!UNSAFE_INFIX_CALL!>+<!> 1
|
||||
x <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||
x <!UNSAFE_INFIX_CALL!><<!> 1
|
||||
x <!UNSAFE_INFIX_CALL!>+=<!> 1
|
||||
|
||||
x == 1
|
||||
x != 1
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>A() == 1<!>
|
||||
B() <!RESULT_TYPE_MISMATCH!>==<!> 1
|
||||
C() <!RESULT_TYPE_MISMATCH!>==<!> 1
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>x === "1"<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>x !== "1"<!>
|
||||
|
||||
x === 1
|
||||
x !== 1
|
||||
|
||||
x<!UNSAFE_INFIX_CALL!>..<!>2
|
||||
<!TYPE_MISMATCH!>x<!> in 1..2
|
||||
|
||||
val y : Boolean? = true
|
||||
false || <!TYPE_MISMATCH!>y<!>
|
||||
<!TYPE_MISMATCH!>y<!> && true
|
||||
<!TYPE_MISMATCH!>y<!> && <!TYPE_MISMATCH!>1<!>
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace boundsWithSubstitutors {
|
||||
open class A<T>
|
||||
class B<X : A<X>>()
|
||||
|
||||
class C : A<C>
|
||||
|
||||
val a = B<C>()
|
||||
val a1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>()
|
||||
|
||||
class X<A, B : A>()
|
||||
|
||||
val b = X<Any, X<A<C>, C>>
|
||||
val b0 = X<Any, <!UPPER_BOUND_VIOLATED!>Any?<!>>
|
||||
val b1 = X<Any, X<A<C>, <!UPPER_BOUND_VIOLATED!>String<!>>>
|
||||
|
||||
}
|
||||
|
||||
open class A {}
|
||||
open class B<T : A>()
|
||||
|
||||
abstract class C<T : B<<!UPPER_BOUND_VIOLATED!>Int<!>>, X : fun (B<<!UPPER_BOUND_VIOLATED!>Char<!>>) : (B<<!UPPER_BOUND_VIOLATED!>Any<!>>, B<A>)>() : B<<!UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED!>Any<!>>() { // 2 errors
|
||||
val a = B<<!UPPER_BOUND_VIOLATED!>Char<!>>() // error
|
||||
|
||||
abstract val x : fun (B<<!UPPER_BOUND_VIOLATED!>Char<!>>) : B<<!UPPER_BOUND_VIOLATED!>Any<!>>
|
||||
}
|
||||
|
||||
|
||||
fun test() {
|
||||
foo<<!UPPER_BOUND_VIOLATED!>Int?<!>>()
|
||||
foo<Int>()
|
||||
bar<Int?>()
|
||||
bar<Int>()
|
||||
bar<<!UPPER_BOUND_VIOLATED!>Double?<!>>()
|
||||
bar<<!UPPER_BOUND_VIOLATED!>Double<!>>()
|
||||
1.buzz<<!UPPER_BOUND_VIOLATED!>Double<!>>()
|
||||
}
|
||||
|
||||
fun foo<T : Any>() {}
|
||||
fun bar<T : Int?>() {}
|
||||
fun <T : <!FINAL_UPPER_BOUND!>Int<!>> Int.buzz() : Unit {}
|
||||
@@ -0,0 +1,28 @@
|
||||
class C {
|
||||
|
||||
fun f (a : Boolean, b : Boolean) {
|
||||
@b (while (true)
|
||||
@a {
|
||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||
break
|
||||
break@b
|
||||
<!NOT_A_LOOP_LABEL!>break@a<!>
|
||||
})
|
||||
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>
|
||||
|
||||
@b (while (true)
|
||||
@a {
|
||||
<!NOT_A_LOOP_LABEL!>continue@f<!>
|
||||
continue
|
||||
continue@b
|
||||
<!NOT_A_LOOP_LABEL!>continue@a<!>
|
||||
})
|
||||
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>
|
||||
|
||||
<!NOT_A_LOOP_LABEL!>continue@f<!>
|
||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import java.util.*
|
||||
|
||||
namespace html {
|
||||
|
||||
abstract class Factory<T> {
|
||||
abstract fun create() : T
|
||||
}
|
||||
|
||||
abstract class Element
|
||||
|
||||
class TextElement(val text : String) : Element
|
||||
|
||||
abstract class Tag(val name : String) : Element {
|
||||
val children = ArrayList<Element>()
|
||||
val attributes = HashMap<String, String>()
|
||||
|
||||
protected fun initTag<T : Element>(init : fun T.() : Unit) : T
|
||||
where class object T : Factory<T>{
|
||||
val tag = T.create()
|
||||
tag.init()
|
||||
children.add(tag)
|
||||
return tag
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TagWithText(name : String) : Tag(name) {
|
||||
fun String.plus() {
|
||||
children.add(TextElement(this))
|
||||
}
|
||||
}
|
||||
|
||||
class HTML() : TagWithText("html") {
|
||||
class object : Factory<HTML> {
|
||||
override fun create() = HTML()
|
||||
}
|
||||
|
||||
fun head(init : fun Head.() : Unit) = initTag<Head>(init)
|
||||
|
||||
fun body(init : fun Body.() : Unit) = initTag<Body>(init)
|
||||
}
|
||||
|
||||
class Head() : TagWithText("head") {
|
||||
class object : Factory<Head> {
|
||||
override fun create() = Head()
|
||||
}
|
||||
|
||||
fun title(init : fun Title.() : Unit) = initTag<Title>(init)
|
||||
}
|
||||
|
||||
class Title() : TagWithText("title")
|
||||
|
||||
abstract class BodyTag(name : String) : TagWithText(name) {
|
||||
}
|
||||
|
||||
class Body() : BodyTag("body") {
|
||||
class object : Factory<Body> {
|
||||
override fun create() = Body()
|
||||
}
|
||||
|
||||
fun b(init : fun B.() : Unit) = initTag<B>(init)
|
||||
fun p(init : fun P.() : Unit) = initTag<P>(init)
|
||||
fun h1(init : fun H1.() : Unit) = initTag<H1>(init)
|
||||
fun a(href : String, init : fun A.() : Unit) {
|
||||
val a = initTag<A>(init)
|
||||
a.href = href
|
||||
}
|
||||
}
|
||||
|
||||
class B() : BodyTag("b")
|
||||
class P() : BodyTag("p")
|
||||
class H1() : BodyTag("h1")
|
||||
class A() : BodyTag("a") {
|
||||
var href : String
|
||||
get() = attributes["href"]
|
||||
set(value) { attributes["href"] = value }
|
||||
}
|
||||
|
||||
fun Map<String, String>.set(key : String, value : String) = this.put(key, value)
|
||||
|
||||
fun html(init : fun HTML.() : Unit) : HTML {
|
||||
val html = HTML()
|
||||
html.init()
|
||||
return html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace foo {
|
||||
|
||||
import html.*
|
||||
|
||||
fun result(args : Array<String>) =
|
||||
html {
|
||||
head {
|
||||
title {+"XML encoding with Groovy"}
|
||||
}
|
||||
body {
|
||||
h1 {+"XML encoding with Groovy"}
|
||||
p {+"this format can be used as an alternative markup to XML"}
|
||||
|
||||
// an element with attributes and text content
|
||||
a(href = "http://groovy.codehaus.org") {+"Groovy"}
|
||||
|
||||
// mixed content
|
||||
p {
|
||||
+"This is some"
|
||||
b {+"mixed"}
|
||||
+"text. For more see the"
|
||||
a(href = "http://groovy.codehaus.org") {+"Groovy"}
|
||||
+"project"
|
||||
}
|
||||
p {+"some text"}
|
||||
|
||||
// content generated by
|
||||
p {
|
||||
for (arg in args)
|
||||
+arg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun test() : Unit {
|
||||
var x : Int? = 0
|
||||
var y : Int = 0
|
||||
|
||||
x : Int?
|
||||
y : Int
|
||||
x as Int : Int
|
||||
y <!USELESS_CAST!>as<!> Int : Int
|
||||
x <!USELESS_CAST!>as<!> Int? : Int?
|
||||
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as<!> Int? : Int?
|
||||
x as? Int : Int?
|
||||
y <!USELESS_CAST!>as?<!> Int : Int?
|
||||
x <!USELESS_CAST!>as?<!> Int? : Int?
|
||||
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as?<!> Int? : Int?
|
||||
()
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Jet86
|
||||
|
||||
class A {
|
||||
class object {
|
||||
val x = 1
|
||||
}
|
||||
<!MANY_CLASS_OBJECTS!>class object { // error
|
||||
val x = 1
|
||||
}<!>
|
||||
}
|
||||
|
||||
class B() {
|
||||
val x = 12
|
||||
}
|
||||
|
||||
object b {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object {
|
||||
val x = 1
|
||||
}<!> // error
|
||||
}
|
||||
|
||||
val a = A.x
|
||||
val c = <!NO_CLASS_OBJECT!>B<!>.x
|
||||
val d = b.<!UNRESOLVED_REFERENCE!>x<!>
|
||||
|
||||
val s = <!NO_CLASS_OBJECT!>System<!> // error
|
||||
fun test() {
|
||||
System.out?.println()
|
||||
java.lang.System.out?.println()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
1 : Byte
|
||||
1 : Int
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH!>1<!> : Double
|
||||
1 <!USELESS_CAST!>as<!> Byte
|
||||
1 <!USELESS_CAST!>as<!> Int
|
||||
<!ERROR_COMPILE_TIME_VALUE!>1<!> <!CAST_NEVER_SUCCEEDS!>as<!> Double
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
open class NoC
|
||||
class NoC1 : NoC
|
||||
|
||||
class WithC0() : NoC<!NO_CONSTRUCTOR!>()<!>
|
||||
open class WithC1() : NoC
|
||||
class NoC2 : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!>
|
||||
class NoC3 : WithC1<!PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL!>()<!>
|
||||
class WithC2() : <!SUPERTYPE_NOT_INITIALIZED!>WithC1<!>
|
||||
|
||||
class NoPC {
|
||||
<!SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY!>this<!>() {}
|
||||
}
|
||||
|
||||
class WithPC0() {
|
||||
this(a : Int) : this() {}
|
||||
}
|
||||
|
||||
class WithPC1(a : Int) {
|
||||
<!SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST!>this<!>() {}
|
||||
|
||||
this(b : Long) : this("") {}
|
||||
|
||||
this(s : String) : this(1) {}
|
||||
|
||||
this(b : Char) : <!NONE_APPLICABLE!>this("", 2)<!> {}
|
||||
|
||||
this(b : Byte) : this(""), <!MANY_CALLS_TO_THIS!>this(1)<!> {}
|
||||
}
|
||||
|
||||
|
||||
class Foo() : <!SUPERTYPE_NOT_INITIALIZED, FINAL_SUPERTYPE!>WithPC0<!>, <!MANY_CLASSES_IN_SUPERTYPE_LIST!>this<!>() {
|
||||
|
||||
}
|
||||
|
||||
class WithCPI_Dup(<!REDECLARATION, REDECLARATION!>x<!> : Int) {
|
||||
var <!REDECLARATION, REDECLARATION, MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>x<!> : Int
|
||||
}
|
||||
|
||||
class WithCPI(x : Int) {
|
||||
val a = 1
|
||||
val b : Int = $a
|
||||
val xy : Int = x
|
||||
}
|
||||
|
||||
class <!PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY!>NoCPI<!> {
|
||||
val a = <!PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR!>1<!>
|
||||
var ab = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!>
|
||||
get() = 1
|
||||
set(v) {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
open trait A {
|
||||
fun foo() {}
|
||||
}
|
||||
open trait B : A, <!CYCLIC_INHERITANCE_HIERARCHY!>E<!> {}
|
||||
open trait C : B {}
|
||||
open trait D : <!CYCLIC_INHERITANCE_HIERARCHY!>B<!> {}
|
||||
open trait E : <!CYCLIC_INHERITANCE_HIERARCHY!>F<!> {}
|
||||
open trait F : <!CYCLIC_INHERITANCE_HIERARCHY!>D<!>, C {}
|
||||
open trait G : F {}
|
||||
open trait H : F {}
|
||||
|
||||
val a : A? = null
|
||||
val b : B? = null
|
||||
val c : C? = null
|
||||
val d : D? = null
|
||||
val e : E? = null
|
||||
val f : F? = null
|
||||
val g : G? = null
|
||||
val h : H? = null
|
||||
|
||||
fun test() {
|
||||
a?.foo()
|
||||
b?.foo()
|
||||
c?.foo()
|
||||
d?.foo()
|
||||
e?.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
f?.foo()
|
||||
g?.foo()
|
||||
h?.foo()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
enum class List<out T>(val size : Int) {
|
||||
Nil : List<Nothing>(0) {
|
||||
val a = 1
|
||||
}
|
||||
Cons<out T>(val head : T, val tail : List<T>) : List<T>(tail.size + 1)
|
||||
|
||||
}
|
||||
|
||||
val foo = List.Nil
|
||||
val foo1 = foo.a
|
||||
@@ -0,0 +1,71 @@
|
||||
fun Int?.optint() : Unit {}
|
||||
val Int?.optval : Unit = ()
|
||||
|
||||
fun <T, E> T.foo(x : E, y : A) : T {
|
||||
y.plus(1)
|
||||
y plus 1
|
||||
y + 1.0
|
||||
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>minus<T>(this)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.plus(a : Any) {
|
||||
|
||||
1.foo()
|
||||
true.<!NONE_APPLICABLE!>foo()<!>
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
fun A.plus(a : Int) {
|
||||
1
|
||||
}
|
||||
|
||||
fun <T> T.minus(t : T) : Int = 1
|
||||
|
||||
fun test() {
|
||||
val y = 1.abs
|
||||
}
|
||||
val Int.abs : Int
|
||||
get() = if (this > 0) this else -this;
|
||||
|
||||
val <T> T.<!MUST_BE_INITIALIZED!>foo<!> : T
|
||||
|
||||
fun Int.foo() = this
|
||||
|
||||
namespace null_safety {
|
||||
|
||||
fun parse(cmd: String): Command? { return null }
|
||||
class Command() {
|
||||
// fun equals(other : Any?) : Boolean
|
||||
val foo : Int = 0
|
||||
}
|
||||
|
||||
fun Any.equals(other : Any?) : Boolean = true
|
||||
fun Any?.equals1(other : Any?) : Boolean = true
|
||||
fun Any.equals2(other : Any?) : Boolean = true
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
System.out?.print(1)
|
||||
|
||||
val command = parse("")
|
||||
|
||||
command<!UNSAFE_CALL!>.<!>foo
|
||||
|
||||
command.equals(null)
|
||||
command<!UNNECESSARY_SAFE_CALL!>?.<!>equals(null)
|
||||
command.equals1(null)
|
||||
command<!UNNECESSARY_SAFE_CALL!>?.<!>equals1(null)
|
||||
|
||||
val c = Command()
|
||||
c<!UNNECESSARY_SAFE_CALL!>?.<!>equals2(null)
|
||||
|
||||
if (command == null) 1
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import java.util.*;
|
||||
|
||||
class NotRange1() {
|
||||
|
||||
}
|
||||
|
||||
abstract class NotRange2() {
|
||||
abstract fun iterator() : Unit
|
||||
}
|
||||
|
||||
abstract class ImproperIterator1 {
|
||||
abstract fun hasNext() : Boolean
|
||||
}
|
||||
|
||||
abstract class NotRange3() {
|
||||
abstract fun iterator() : ImproperIterator1
|
||||
}
|
||||
|
||||
abstract class ImproperIterator2 {
|
||||
abstract fun next() : Boolean
|
||||
}
|
||||
|
||||
abstract class NotRange4() {
|
||||
abstract fun iterator() : ImproperIterator2
|
||||
}
|
||||
|
||||
abstract class ImproperIterator3 {
|
||||
abstract fun hasNext() : Int
|
||||
abstract fun next() : Int
|
||||
}
|
||||
|
||||
abstract class NotRange5() {
|
||||
abstract fun iterator() : ImproperIterator3
|
||||
}
|
||||
|
||||
abstract class AmbiguousHasNextIterator {
|
||||
abstract fun hasNext() : Boolean
|
||||
val hasNext : Boolean get() = false
|
||||
abstract fun next() : Int
|
||||
}
|
||||
|
||||
abstract class NotRange6() {
|
||||
abstract fun iterator() : AmbiguousHasNextIterator
|
||||
}
|
||||
|
||||
abstract class ImproperIterator4 {
|
||||
val hasNext : Int get() = 1
|
||||
abstract fun next() : Int
|
||||
}
|
||||
|
||||
abstract class NotRange7() {
|
||||
abstract fun iterator() : ImproperIterator3
|
||||
}
|
||||
|
||||
abstract class GoodIterator {
|
||||
abstract fun hasNext() : Boolean
|
||||
abstract fun next() : Int
|
||||
}
|
||||
|
||||
abstract class Range0() {
|
||||
abstract fun iterator() : GoodIterator
|
||||
}
|
||||
|
||||
abstract class Range1() {
|
||||
abstract fun iterator() : Iterator<Int>
|
||||
}
|
||||
|
||||
fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRange4: NotRange4, notRange5: NotRange5, notRange6: NotRange6, notRange7: NotRange7, range0: Range0, range1: Range1) {
|
||||
for (i in <!ITERATOR_MISSING!>notRange1<!>);
|
||||
for (i in <!HAS_NEXT_MISSING, NEXT_MISSING!>notRange2<!>);
|
||||
for (i in <!NEXT_MISSING!>notRange3<!>);
|
||||
for (i in <!HAS_NEXT_MISSING!>notRange4<!>);
|
||||
for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange5<!>);
|
||||
for (i in <!HAS_NEXT_PROPERTY_AND_FUNCTION_AMBIGUITY!>notRange6<!>);
|
||||
for (i in <!HAS_NEXT_FUNCTION_TYPE_MISMATCH!>notRange7<!>);
|
||||
for (i in range0);
|
||||
for (i in range1);
|
||||
|
||||
for (i in (ArrayList<Int>() : List<Int>));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
fun none() {}
|
||||
|
||||
fun unitEmptyInfer() {}
|
||||
fun unitEmpty() : Unit {}
|
||||
fun unitEmptyReturn() : Unit {return}
|
||||
fun unitIntReturn() : Unit {return <!TYPE_MISMATCH!>1<!>}
|
||||
fun unitUnitReturn() : Unit {return ()}
|
||||
fun test1() : Any = {<!RETURN_NOT_ALLOWED, RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!>}
|
||||
fun test2() : Any = @a {return@a 1}
|
||||
fun test3() : Any { <!RETURN_TYPE_MISMATCH!>return<!> }
|
||||
|
||||
fun bbb() {
|
||||
return <!TYPE_MISMATCH!>1<!>
|
||||
}
|
||||
|
||||
fun foo(expr: StringBuilder): Int {
|
||||
val c = 'a'
|
||||
when(c) {
|
||||
0.chr => throw Exception("zero")
|
||||
else => throw Exception("nonzero" + c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun unitShort() : Unit = ()
|
||||
fun unitShortConv() : Unit = <!TYPE_MISMATCH!>1<!>
|
||||
fun unitShortNull() : Unit = <!TYPE_MISMATCH!>null<!>
|
||||
|
||||
fun intEmpty() : Int <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
fun intShortInfer() = 1
|
||||
fun intShort() : Int = 1
|
||||
//fun intBlockInfer() {1}
|
||||
fun intBlock() : Int {return 1}
|
||||
fun intBlock() : Int {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1<!>}
|
||||
|
||||
fun intString(): Int = <!TYPE_MISMATCH!>"s"<!>
|
||||
fun intFunctionLiteral(): Int = <!TYPE_MISMATCH!>{ 10 }<!>
|
||||
|
||||
fun blockReturnUnitMismatch() : Int {<!RETURN_TYPE_MISMATCH!>return<!>}
|
||||
fun blockReturnValueTypeMismatch() : Int {return <!ERROR_COMPILE_TIME_VALUE!>3.4<!>}
|
||||
fun blockReturnValueTypeMatch() : Int {return 1}
|
||||
fun blockReturnValueTypeMismatchUnit() : Int {return <!TYPE_MISMATCH!>()<!>}
|
||||
|
||||
fun blockAndAndMismatch() : Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true && false<!>
|
||||
}
|
||||
fun blockAndAndMismatch() : Int {
|
||||
return <!TYPE_MISMATCH!>true && false<!>
|
||||
}
|
||||
fun blockAndAndMismatch() : Int {
|
||||
<!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) && (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!>
|
||||
}
|
||||
|
||||
fun blockAndAndMismatch() : Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>true || false<!>
|
||||
}
|
||||
fun blockAndAndMismatch() : Int {
|
||||
return <!TYPE_MISMATCH!>true || false<!>
|
||||
}
|
||||
fun blockAndAndMismatch() : Int {
|
||||
<!UNREACHABLE_CODE!>(return <!ERROR_COMPILE_TIME_VALUE!>true<!>) || (return <!ERROR_COMPILE_TIME_VALUE!>false<!>)<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
return if (1 > 2) <!ERROR_COMPILE_TIME_VALUE!>1.0<!> else <!ERROR_COMPILE_TIME_VALUE!>2.0<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
return <!TYPE_MISMATCH!>if (1 > 2) 1<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
return <!TYPE_MISMATCH!>if (1 > 2) else 1<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
|
||||
else return <!ERROR_COMPILE_TIME_VALUE!>2.0<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
|
||||
return <!ERROR_COMPILE_TIME_VALUE!>2.0<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
|
||||
return <!ERROR_COMPILE_TIME_VALUE!>2.0<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!>
|
||||
else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>2.0<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
1.0
|
||||
else 2.0
|
||||
return 1
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2)
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
return <!TYPE_MISMATCH!>if (1 > 2)
|
||||
1<!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>if (1 > 2)
|
||||
else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>1.0<!><!>
|
||||
}
|
||||
fun blockReturnValueTypeMatch() : Int {
|
||||
if (1 > 2)
|
||||
return 1
|
||||
else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
|
||||
}
|
||||
fun blockNoReturnIfValDeclaration(): Int {
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val x = 1<!>
|
||||
}
|
||||
fun blockNoReturnIfEmptyIf(): Int {
|
||||
if (1 < 2) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
}
|
||||
fun blockNoReturnIfUnitInOneBranch(): Int {
|
||||
if (1 < 2) {
|
||||
return 1
|
||||
} else {
|
||||
if (3 < 4) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{
|
||||
}<!> else {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!>
|
||||
fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2
|
||||
|
||||
val a = <!RETURN_NOT_ALLOWED!>return 1<!>
|
||||
|
||||
class A() {
|
||||
this(a : Int) : this() {
|
||||
if (a == 1)
|
||||
return
|
||||
return <!TYPE_MISMATCH!>1<!>
|
||||
}
|
||||
|
||||
}
|
||||
fun illegalConstantBody(): Int = <!TYPE_MISMATCH!>"s"<!>
|
||||
fun illegalConstantBlock(): String {
|
||||
return <!ERROR_COMPILE_TIME_VALUE!>1<!>
|
||||
}
|
||||
fun illegalIfBody(): Int =
|
||||
if (1 < 2) <!ERROR_COMPILE_TIME_VALUE!>'a'<!> else { <!ERROR_COMPILE_TIME_VALUE!>1.0<!> }
|
||||
fun illegalIfBlock(): Boolean {
|
||||
if (1 < 2)
|
||||
return false
|
||||
else { return <!ERROR_COMPILE_TIME_VALUE!>1<!> }
|
||||
}
|
||||
fun illegalReturnIf(): Char {
|
||||
return if (1 < 2) 'a' else { <!ERROR_COMPILE_TIME_VALUE!>1<!> }
|
||||
}
|
||||
|
||||
fun returnNothing(): Nothing {
|
||||
throw 1
|
||||
}
|
||||
fun f(): Int {
|
||||
if (1 < 2) { return 1 } else returnNothing()
|
||||
}
|
||||
|
||||
fun f(): Int = if (1 < 2) 1 else returnNothing()
|
||||
@@ -0,0 +1,42 @@
|
||||
trait A<in T> {}
|
||||
trait B<T> : A<Int> {}
|
||||
trait C<T> : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>B<T>, A<T><!> {}
|
||||
trait C1<T> : B<T>, A<Any> {}
|
||||
trait D : <!INCONSISTENT_TYPE_PARAMETER_VALUES, INCONSISTENT_TYPE_PARAMETER_VALUES!>C<Boolean>, B<Double><!>{}
|
||||
|
||||
trait A1<out T> {}
|
||||
trait B1 : A1<Int> {}
|
||||
trait B2 : A1<Any>, B1 {}
|
||||
|
||||
trait BA1<T> {}
|
||||
trait BB1 : BA1<Int> {}
|
||||
trait BB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>BA1<Any>, BB1<!> {}
|
||||
|
||||
|
||||
namespace x {
|
||||
trait AA1<out T> {}
|
||||
trait AB1 : AA1<Int> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : AA1<Number>, AB1, AB3 {}
|
||||
}
|
||||
|
||||
namespace x2 {
|
||||
trait AA1<out T> {}
|
||||
trait AB1 : AA1<Any> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
}
|
||||
|
||||
namespace x3 {
|
||||
trait AA1<in T> {}
|
||||
trait AB1 : AA1<Any> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : AA1<Number>, AB1, AB3 {}
|
||||
}
|
||||
|
||||
namespace sx2 {
|
||||
trait AA1<in T> {}
|
||||
trait AB1 : AA1<Int> {}
|
||||
trait AB3 : AA1<Comparable<Int>> {}
|
||||
trait AB2 : <!INCONSISTENT_TYPE_PARAMETER_VALUES!>AA1<Number>, AB1, AB3<!> {}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user