Merge remote-tracking branch 'origin/master'
This commit is contained in:
Generated
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<option name="DEFAULT_COMPILER" value="Eclipse" />
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
<resourceExtensions />
|
<resourceExtensions />
|
||||||
<wildcardResourcePatterns>
|
<wildcardResourcePatterns>
|
||||||
<entry name="?*.properties" />
|
<entry name="?*.properties" />
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (captureThis) {
|
if (captureThis) {
|
||||||
argTypes[i++] = Type.getObjectType(context.getThisDescriptor().getName());
|
argTypes[i++] = state.getTypeMapper().mapType(context.getThisDescriptor().getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (captureReceiver != null) {
|
if (captureReceiver != null) {
|
||||||
|
|||||||
@@ -608,17 +608,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
final Method cons = closure.getConstructor();
|
final Method cons = closure.getConstructor();
|
||||||
|
|
||||||
|
int k = 0;
|
||||||
if (closure.isCaptureThis()) {
|
if (closure.isCaptureThis()) {
|
||||||
|
k++;
|
||||||
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closure.isCaptureReceiver() != null) {
|
if (closure.isCaptureReceiver() != null) {
|
||||||
|
k++;
|
||||||
v.load(context.getContextDescriptor().getContainingDeclaration() instanceof NamespaceDescriptor ? 0: 1, closure.isCaptureReceiver());
|
v.load(context.getContextDescriptor().getContainingDeclaration() instanceof NamespaceDescriptor ? 0: 1, closure.isCaptureReceiver());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < closure.getArgs().size(); i++) {
|
for (int i = 0; i < closure.getArgs().size(); i++) {
|
||||||
StackValue arg = closure.getArgs().get(i);
|
StackValue arg = closure.getArgs().get(i);
|
||||||
arg.put(cons.getArgumentTypes()[i], v);
|
arg.put(cons.getArgumentTypes()[i+k], v);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.invokespecial(closure.getClassname(), "<init>", cons.getDescriptor());
|
v.invokespecial(closure.getClassname(), "<init>", cons.getDescriptor());
|
||||||
|
|||||||
@@ -157,4 +157,18 @@ public class GenerationState {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String createText() {
|
||||||
|
StringBuilder answer = new StringBuilder();
|
||||||
|
|
||||||
|
final ClassFileFactory factory = getFactory();
|
||||||
|
List<String> files = factory.files();
|
||||||
|
for (String file : files) {
|
||||||
|
if (!file.startsWith("std/")) {
|
||||||
|
answer.append("@").append(file).append('\n');
|
||||||
|
answer.append(factory.asText(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return answer.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public class JetTypeMapper {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Type correctElementType(Type type) {
|
public static Type correctElementType(Type type) {
|
||||||
String internalName = type.getInternalName();
|
String internalName = type.getInternalName();
|
||||||
assert internalName.charAt(0) == '[';
|
assert internalName.charAt(0) == '[';
|
||||||
return Type.getType(internalName.substring(1));
|
return Type.getType(internalName.substring(1));
|
||||||
@@ -173,6 +173,11 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
public String getFQName(DeclarationDescriptor descriptor) {
|
public String getFQName(DeclarationDescriptor descriptor) {
|
||||||
descriptor = descriptor.getOriginal();
|
descriptor = descriptor.getOriginal();
|
||||||
|
|
||||||
|
if(descriptor instanceof FunctionDescriptor) {
|
||||||
|
return getFQName(descriptor.getContainingDeclaration());
|
||||||
|
}
|
||||||
|
|
||||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||||
String name = descriptor.getName();
|
String name = descriptor.getName();
|
||||||
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.jetbrains.jet.codegen.intrinsics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
|
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||||
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.commons.InstructionAdapter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author alex.tkachman
|
||||||
|
*/
|
||||||
|
public class ArrayGet implements IntrinsicMethod {
|
||||||
|
@Override
|
||||||
|
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||||
|
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||||
|
Type type = JetTypeMapper.correctElementType(receiver.type);
|
||||||
|
|
||||||
|
codegen.gen(arguments.get(0), Type.INT_TYPE);
|
||||||
|
|
||||||
|
v.aload(type);
|
||||||
|
|
||||||
|
return StackValue.onStack(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.jetbrains.jet.codegen.intrinsics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.jet.codegen.CodegenUtil;
|
||||||
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
|
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||||
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.commons.InstructionAdapter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author alex.tkachman
|
||||||
|
*/
|
||||||
|
public class ArraySet implements IntrinsicMethod {
|
||||||
|
@Override
|
||||||
|
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||||
|
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||||
|
Type type = JetTypeMapper.correctElementType(receiver.type);
|
||||||
|
|
||||||
|
codegen.gen(arguments.get(0), Type.INT_TYPE);
|
||||||
|
codegen.gen(arguments.get(1), type);
|
||||||
|
|
||||||
|
v.astore(type);
|
||||||
|
|
||||||
|
return StackValue.none();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,8 @@ public class IntrinsicMethods {
|
|||||||
public static final IntrinsicMethod ARRAY_INDICES = new ArrayIndices();
|
public static final IntrinsicMethod ARRAY_INDICES = new ArrayIndices();
|
||||||
public static final Equals EQUALS = new Equals();
|
public static final Equals EQUALS = new Equals();
|
||||||
public static final IteratorNext ITERATOR_NEXT = new IteratorNext();
|
public static final IteratorNext ITERATOR_NEXT = new IteratorNext();
|
||||||
|
public static final ArraySet ARRAY_SET = new ArraySet();
|
||||||
|
public static final ArrayGet ARRAY_GET = new ArrayGet();
|
||||||
|
|
||||||
private final Project myProject;
|
private final Project myProject;
|
||||||
private final JetStandardLibrary myStdLib;
|
private final JetStandardLibrary myStdLib;
|
||||||
@@ -122,6 +124,26 @@ public class IntrinsicMethods {
|
|||||||
declareIntrinsicProperty("CharArray", "indices", ARRAY_INDICES);
|
declareIntrinsicProperty("CharArray", "indices", ARRAY_INDICES);
|
||||||
declareIntrinsicProperty("BooleanArray", "indices", ARRAY_INDICES);
|
declareIntrinsicProperty("BooleanArray", "indices", ARRAY_INDICES);
|
||||||
|
|
||||||
|
declareIntrinsicFunction("Array", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("ByteArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("ShortArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("IntArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("LongArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("FloatArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("DoubleArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("CharArray", "set", 2, ARRAY_SET);
|
||||||
|
declareIntrinsicFunction("BooleanArray", "set", 2, ARRAY_SET);
|
||||||
|
|
||||||
|
declareIntrinsicFunction("Array", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("ByteArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("ShortArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("IntArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("LongArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("FloatArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("DoubleArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("CharArray", "get", 1, ARRAY_GET);
|
||||||
|
declareIntrinsicFunction("BooleanArray", "get", 1, ARRAY_GET);
|
||||||
|
|
||||||
declareIterator(myStdLib.getArray());
|
declareIterator(myStdLib.getArray());
|
||||||
declareIterator(myStdLib.getByteArrayClass());
|
declareIterator(myStdLib.getByteArrayClass());
|
||||||
declareIterator(myStdLib.getShortArrayClass());
|
declareIterator(myStdLib.getShortArrayClass());
|
||||||
|
|||||||
@@ -99,4 +99,9 @@ public class CompileSession {
|
|||||||
return generationState.getFactory();
|
return generationState.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String generateText() {
|
||||||
|
GenerationState generationState = new GenerationState(myEnvironment.getProject(), ClassBuilderFactory.TEXT);
|
||||||
|
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces);
|
||||||
|
return generationState.createText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lang.types.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
@@ -34,8 +34,8 @@ public class JetSemanticServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptorResolver getClassDescriptorResolver(BindingTrace trace) {
|
public DescriptorResolver getClassDescriptorResolver(BindingTrace trace) {
|
||||||
return new ClassDescriptorResolver(this, trace);
|
return new DescriptorResolver(this, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.jetbrains.jet.lang.descriptors;
|
package org.jetbrains.jet.lang.descriptors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
@@ -24,6 +25,9 @@ public interface CallableDescriptor extends DeclarationDescriptor {
|
|||||||
@NotNull
|
@NotNull
|
||||||
JetType getReturnType();
|
JetType getReturnType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
JetType getReturnTypeSafe();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
CallableDescriptor getOriginal();
|
CallableDescriptor getOriginal();
|
||||||
|
|||||||
@@ -125,6 +125,12 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
|||||||
return unsubstitutedReturnType;
|
return unsubstitutedReturnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JetType getReturnTypeSafe() {
|
||||||
|
return unsubstitutedReturnType;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public FunctionDescriptor getOriginal() {
|
public FunctionDescriptor getOriginal() {
|
||||||
|
|||||||
+20
-5
@@ -5,7 +5,9 @@ import com.google.common.collect.Sets;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
@@ -43,10 +45,6 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
private JetType superclassType;
|
private JetType superclassType;
|
||||||
private ClassReceiver implicitReceiver;
|
private ClassReceiver implicitReceiver;
|
||||||
|
|
||||||
// public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
|
||||||
// this(trace, containingDeclaration, outerScope, ClassKind.CLASS);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
|
||||||
super(containingDeclaration);
|
super(containingDeclaration);
|
||||||
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
|
||||||
@@ -66,6 +64,23 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
}
|
}
|
||||||
assert classObjectDescriptor.getKind() == ClassKind.OBJECT;
|
assert classObjectDescriptor.getKind() == ClassKind.OBJECT;
|
||||||
this.classObjectDescriptor = classObjectDescriptor;
|
this.classObjectDescriptor = classObjectDescriptor;
|
||||||
|
|
||||||
|
// Members of the class object are accessible from the class
|
||||||
|
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||||
|
scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected JetScope getWorkerScope() {
|
||||||
|
return MutableClassDescriptor.this.classObjectDescriptor.getDefaultType().getMemberScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getImplicitReceiver() {
|
||||||
|
return MutableClassDescriptor.this.classObjectDescriptor.getImplicitReceiver();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
return ClassObjectStatus.OK;
|
return ClassObjectStatus.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
|||||||
return getOutType();
|
return getOutType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JetType getReturnTypeSafe() {
|
||||||
|
return getOutType();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVar() {
|
public boolean isVar() {
|
||||||
return isVar;
|
return isVar;
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
|||||||
return returnType;
|
return returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JetType getReturnTypeSafe() {
|
||||||
|
return returnType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||||
return visitor.visitPropertyGetterDescriptor(this, data);
|
return visitor.visitPropertyGetterDescriptor(this, data);
|
||||||
|
|||||||
@@ -48,6 +48,11 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
|||||||
return JetStandardClasses.getUnitType();
|
return JetStandardClasses.getUnitType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetType getReturnTypeSafe() {
|
||||||
|
return getReturnType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||||
return visitor.visitPropertySetterDescriptor(this, data);
|
return visitor.visitPropertySetterDescriptor(this, data);
|
||||||
|
|||||||
@@ -89,4 +89,10 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
|
|||||||
public JetType getReturnType() {
|
public JetType getReturnType() {
|
||||||
return getOutType();
|
return getOutType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JetType getReturnTypeSafe() {
|
||||||
|
return getOutType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class BodyResolver {
|
|||||||
resolveSecondaryConstructorBodies();
|
resolveSecondaryConstructorBodies();
|
||||||
resolveFunctionBodies();
|
resolveFunctionBodies();
|
||||||
|
|
||||||
computeDeferredTypes();
|
computeDeferredTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveDelegationSpecifierLists() {
|
private void resolveDelegationSpecifierLists() {
|
||||||
@@ -357,8 +357,8 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
JetExpression bodyExpression = declaration.getBodyExpression();
|
JetExpression bodyExpression = declaration.getBodyExpression();
|
||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
//context.getClassDescriptorResolver().computeFlowData(declaration, bodyExpression);
|
//context.getDescriptorResolver().computeFlowData(declaration, bodyExpression);
|
||||||
//JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData(declaration, bodyExpression);
|
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(declaration, bodyExpression);
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
||||||
|
|
||||||
typeInferrer.checkFunctionReturnType(functionInnerScope, declaration, JetStandardClasses.getUnitType());
|
typeInferrer.checkFunctionReturnType(functionInnerScope, declaration, JetStandardClasses.getUnitType());
|
||||||
@@ -482,7 +482,7 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
||||||
//JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(traceForConstructors);
|
||||||
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getOutType() : NO_EXPECTED_TYPE;
|
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getOutType() : NO_EXPECTED_TYPE;
|
||||||
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, expectedTypeForInitializer);
|
JetType type = typeInferrer.getType(getPropertyDeclarationInnerScope(scope, propertyDescriptor), initializer, expectedTypeForInitializer);
|
||||||
@@ -501,6 +501,18 @@ public class BodyResolver {
|
|||||||
for (Map.Entry<JetNamedFunction, FunctionDescriptorImpl> entry : this.context.getFunctions().entrySet()) {
|
for (Map.Entry<JetNamedFunction, FunctionDescriptorImpl> entry : this.context.getFunctions().entrySet()) {
|
||||||
JetNamedFunction declaration = entry.getKey();
|
JetNamedFunction declaration = entry.getKey();
|
||||||
FunctionDescriptor descriptor = entry.getValue();
|
FunctionDescriptor descriptor = entry.getValue();
|
||||||
|
|
||||||
|
if (descriptor.getReturnType() instanceof DeferredType) {
|
||||||
|
// handle type inference loop: function body contains a closure that calls that function
|
||||||
|
//
|
||||||
|
// fun f() = { f() }
|
||||||
|
//
|
||||||
|
// function type resolution must be started before function body resolution
|
||||||
|
//
|
||||||
|
|
||||||
|
DeferredType returnType = (DeferredType) descriptor.getReturnType();
|
||||||
|
returnType.getActualType();
|
||||||
|
}
|
||||||
|
|
||||||
JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
|
JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
|
||||||
assert declaringScope != null;
|
assert declaringScope != null;
|
||||||
@@ -520,7 +532,7 @@ public class BodyResolver {
|
|||||||
|
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
//JetFlowInformationProvider flowInformationProvider = context.getClassDescriptorResolver().computeFlowData(function.asElement(), bodyExpression);
|
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(function.asElement(), bodyExpression);
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
||||||
|
|
||||||
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
||||||
@@ -545,7 +557,8 @@ public class BodyResolver {
|
|||||||
private void computeDeferredTypes() {
|
private void computeDeferredTypes() {
|
||||||
Collection<Box<DeferredType>> deferredTypes = context.getTrace().getKeys(DEFERRED_TYPE);
|
Collection<Box<DeferredType>> deferredTypes = context.getTrace().getKeys(DEFERRED_TYPE);
|
||||||
if (deferredTypes != null) {
|
if (deferredTypes != null) {
|
||||||
final Queue<DeferredType> queue = new Queue<DeferredType>(deferredTypes.size());
|
// +1 is a work around agains new Queue(0).addLast(...) bug // stepan.koltsov@ 2011-11-21
|
||||||
|
final Queue<DeferredType> queue = new Queue<DeferredType>(deferredTypes.size() + 1);
|
||||||
context.getTrace().addHandler(DEFERRED_TYPE, new ObservableBindingTrace.RecordHandler<Box<DeferredType>, Boolean>() {
|
context.getTrace().addHandler(DEFERRED_TYPE, new ObservableBindingTrace.RecordHandler<Box<DeferredType>, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void handleRecord(WritableSlice<Box<DeferredType>, Boolean> deferredTypeKeyDeferredTypeWritableSlice, Box<DeferredType> key, Boolean value) {
|
public void handleRecord(WritableSlice<Box<DeferredType>, Boolean> deferredTypeKeyDeferredTypeWritableSlice, Box<DeferredType> key, Boolean value) {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class DeclarationResolver {
|
|||||||
declaration.accept(new JetVisitorVoid() {
|
declaration.accept(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
FunctionDescriptorImpl functionDescriptor = context.getClassDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scope, function);
|
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scope, function);
|
||||||
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
||||||
context.getFunctions().put(function, functionDescriptor);
|
context.getFunctions().put(function, functionDescriptor);
|
||||||
context.getDeclaringScopes().put(function, scope);
|
context.getDeclaringScopes().put(function, scope);
|
||||||
@@ -102,7 +102,7 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scope, property);
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scope, property);
|
||||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
context.getProperties().put(property, propertyDescriptor);
|
context.getProperties().put(property, propertyDescriptor);
|
||||||
context.getDeclaringScopes().put(property, scope);
|
context.getDeclaringScopes().put(property, scope);
|
||||||
@@ -110,7 +110,7 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
|
||||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ public class DeclarationResolver {
|
|||||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||||
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
|
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
|
||||||
assert classObjectDescriptor != null;
|
assert classObjectDescriptor != null;
|
||||||
PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry));
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry));
|
||||||
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
|
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,10 +137,10 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
// TODO : not all the parameters are real properties
|
// TODO : not all the parameters are real properties
|
||||||
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
|
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
|
||||||
ConstructorDescriptor constructorDescriptor = context.getClassDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
|
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
|
||||||
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
|
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
|
||||||
if (parameter.getValOrVarNode() != null) {
|
if (parameter.getValOrVarNode() != null) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
memberScope,
|
memberScope,
|
||||||
parameter
|
parameter
|
||||||
@@ -159,7 +159,7 @@ public class DeclarationResolver {
|
|||||||
// context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A trait may not have a constructor");
|
// context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A trait may not have a constructor");
|
||||||
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode()));
|
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode()));
|
||||||
}
|
}
|
||||||
ConstructorDescriptor constructorDescriptor = context.getClassDescriptorResolver().resolveSecondaryConstructorDescriptor(
|
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor(
|
||||||
classDescriptor.getScopeForMemberResolution(),
|
classDescriptor.getScopeForMemberResolution(),
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
constructor);
|
constructor);
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ public class DeclarationsChecker {
|
|||||||
PsiElement nameIdentifier = member.getNameIdentifier();
|
PsiElement nameIdentifier = member.getNameIdentifier();
|
||||||
boolean hasDeferredType;
|
boolean hasDeferredType;
|
||||||
if (member instanceof JetProperty) {
|
if (member instanceof JetProperty) {
|
||||||
hasDeferredType = ((JetProperty) member).getPropertyTypeRef() == null && ClassDescriptorResolver.hasBody((JetProperty) member);
|
hasDeferredType = ((JetProperty) member).getPropertyTypeRef() == null && DescriptorResolver.hasBody((JetProperty) member);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert member instanceof JetFunction;
|
assert member instanceof JetFunction;
|
||||||
|
|||||||
+23
-11
@@ -27,14 +27,14 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ClassDescriptorResolver {
|
public class DescriptorResolver {
|
||||||
private final JetSemanticServices semanticServices;
|
private final JetSemanticServices semanticServices;
|
||||||
private final TypeResolver typeResolver;
|
private final TypeResolver typeResolver;
|
||||||
private final TypeResolver typeResolverNotCheckingBounds;
|
private final TypeResolver typeResolverNotCheckingBounds;
|
||||||
private final BindingTrace trace;
|
private final BindingTrace trace;
|
||||||
private final AnnotationResolver annotationResolver;
|
private final AnnotationResolver annotationResolver;
|
||||||
|
|
||||||
public ClassDescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace) {
|
public DescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace) {
|
||||||
this.semanticServices = semanticServices;
|
this.semanticServices = semanticServices;
|
||||||
this.typeResolver = new TypeResolver(semanticServices, trace, true);
|
this.typeResolver = new TypeResolver(semanticServices, trace, true);
|
||||||
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
|
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
|
||||||
@@ -682,10 +682,7 @@ public class ClassDescriptorResolver {
|
|||||||
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
|
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
|
||||||
}
|
}
|
||||||
else if (property.isVar()) {
|
else if (property.isVar()) {
|
||||||
setterDescriptor = new PropertySetterDescriptor(
|
setterDescriptor = createDefaultSetter(propertyDescriptor);
|
||||||
propertyDescriptor.getModality(),
|
|
||||||
propertyDescriptor.getVisibility(),
|
|
||||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), false, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! property.isVar()) {
|
if (! property.isVar()) {
|
||||||
@@ -697,6 +694,15 @@ public class ClassDescriptorResolver {
|
|||||||
return setterDescriptor;
|
return setterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PropertySetterDescriptor createDefaultSetter(PropertyDescriptor propertyDescriptor) {
|
||||||
|
PropertySetterDescriptor setterDescriptor;
|
||||||
|
setterDescriptor = new PropertySetterDescriptor(
|
||||||
|
propertyDescriptor.getModality(),
|
||||||
|
propertyDescriptor.getVisibility(),
|
||||||
|
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), false, true);
|
||||||
|
return setterDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
PropertyGetterDescriptor getterDescriptor;
|
PropertyGetterDescriptor getterDescriptor;
|
||||||
@@ -722,14 +728,20 @@ public class ClassDescriptorResolver {
|
|||||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getterDescriptor = new PropertyGetterDescriptor(
|
getterDescriptor = createDefaultGetter(propertyDescriptor);
|
||||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
|
||||||
propertyDescriptor.getVisibility(),
|
|
||||||
propertyDescriptor.getOutType(), false, true);
|
|
||||||
}
|
}
|
||||||
return getterDescriptor;
|
return getterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PropertyGetterDescriptor createDefaultGetter(PropertyDescriptor propertyDescriptor) {
|
||||||
|
PropertyGetterDescriptor getterDescriptor;
|
||||||
|
getterDescriptor = new PropertyGetterDescriptor(
|
||||||
|
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||||
|
propertyDescriptor.getVisibility(),
|
||||||
|
propertyDescriptor.getOutType(), false, true);
|
||||||
|
return getterDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstructorDescriptorImpl resolveSecondaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetSecondaryConstructor constructor) {
|
public ConstructorDescriptorImpl resolveSecondaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetSecondaryConstructor constructor) {
|
||||||
return createConstructorDescriptor(scope, classDescriptor, false, constructor.getModifierList(), constructor, classDescriptor.getTypeConstructor().getParameters(), constructor.getValueParameters());
|
return createConstructorDescriptor(scope, classDescriptor, false, constructor.getModifierList(), constructor, classDescriptor.getTypeConstructor().getParameters(), constructor.getValueParameters());
|
||||||
@@ -800,7 +812,7 @@ public class ClassDescriptorResolver {
|
|||||||
name == null ? "<no name>" : name,
|
name == null ? "<no name>" : name,
|
||||||
isMutable ? type : null,
|
isMutable ? type : null,
|
||||||
type);
|
type);
|
||||||
propertyDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), null, null);
|
propertyDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), createDefaultGetter(propertyDescriptor), createDefaultSetter(propertyDescriptor));
|
||||||
trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor);
|
trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor);
|
||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
private final ObservableBindingTrace trace;
|
private final ObservableBindingTrace trace;
|
||||||
private final JetSemanticServices semanticServices;
|
private final JetSemanticServices semanticServices;
|
||||||
private final ClassDescriptorResolver classDescriptorResolver;
|
private final DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
||||||
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
||||||
@@ -46,7 +46,7 @@ import java.util.Set;
|
|||||||
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely) {
|
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely) {
|
||||||
this.trace = new ObservableBindingTrace(trace);
|
this.trace = new ObservableBindingTrace(trace);
|
||||||
this.semanticServices = semanticServices;
|
this.semanticServices = semanticServices;
|
||||||
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
this.descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
||||||
this.analyzeCompletely = analyzeCompletely;
|
this.analyzeCompletely = analyzeCompletely;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +93,8 @@ import java.util.Set;
|
|||||||
return semanticServices;
|
return semanticServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassDescriptorResolver getClassDescriptorResolver() {
|
public DescriptorResolver getDescriptorResolver() {
|
||||||
return classDescriptorResolver;
|
return descriptorResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<JetClass, MutableClassDescriptor> getClasses() {
|
public Map<JetClass, MutableClassDescriptor> getClasses() {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class TypeHierarchyResolver {
|
|||||||
MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(context.getTrace(), mutableClassDescriptor, outerScope, ClassKind.OBJECT);
|
MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(context.getTrace(), mutableClassDescriptor, outerScope, ClassKind.OBJECT);
|
||||||
classObjectDescriptor.setName("class-object-for-" + klass.getName());
|
classObjectDescriptor.setName("class-object-for-" + klass.getName());
|
||||||
classObjectDescriptor.setModality(Modality.FINAL);
|
classObjectDescriptor.setModality(Modality.FINAL);
|
||||||
classObjectDescriptor.setVisibility(ClassDescriptorResolver.resolveVisibilityFromModifiers(klass.getModifierList()));
|
classObjectDescriptor.setVisibility(DescriptorResolver.resolveVisibilityFromModifiers(klass.getModifierList()));
|
||||||
classObjectDescriptor.createTypeConstructor();
|
classObjectDescriptor.createTypeConstructor();
|
||||||
createPrimaryConstructorForObject(null, classObjectDescriptor);
|
createPrimaryConstructorForObject(null, classObjectDescriptor);
|
||||||
mutableClassDescriptor.setClassObjectDescriptor(classObjectDescriptor);
|
mutableClassDescriptor.setClassObjectDescriptor(classObjectDescriptor);
|
||||||
@@ -290,14 +290,14 @@ public class TypeHierarchyResolver {
|
|||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getClassDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor);
|
context.getDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor);
|
||||||
descriptor.createTypeConstructor();
|
descriptor.createTypeConstructor();
|
||||||
}
|
}
|
||||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||||
JetObjectDeclaration objectDeclaration = entry.getKey();
|
JetObjectDeclaration objectDeclaration = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
descriptor.setModality(Modality.FINAL);
|
descriptor.setModality(Modality.FINAL);
|
||||||
descriptor.setVisibility(ClassDescriptorResolver.resolveVisibilityFromModifiers(objectDeclaration.getModifierList()));
|
descriptor.setVisibility(DescriptorResolver.resolveVisibilityFromModifiers(objectDeclaration.getModifierList()));
|
||||||
descriptor.createTypeConstructor();
|
descriptor.createTypeConstructor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,13 +306,13 @@ public class TypeHierarchyResolver {
|
|||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getClassDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters());
|
context.getDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters());
|
||||||
context.getClassDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
||||||
}
|
}
|
||||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||||
JetClassOrObject jetClass = entry.getKey();
|
JetClassOrObject jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getClassDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +517,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getClassDescriptorResolver().checkBounds(typeReference, type);
|
context.getDescriptorResolver().checkBounds(typeReference, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -527,7 +527,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getClassDescriptorResolver().checkBounds(extendsBound, type);
|
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,7 +537,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getClassDescriptorResolver().checkBounds(extendsBound, type);
|
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,16 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
}
|
}
|
||||||
doComputeTasks(scope, explicitReceiver, call, name, result, AutoCastService.NO_AUTO_CASTS);
|
doComputeTasks(scope, explicitReceiver, call, name, result, AutoCastService.NO_AUTO_CASTS);
|
||||||
|
|
||||||
ReceiverDescriptor receiverToCast = explicitReceiver.exists() ? explicitReceiver : scope.getImplicitReceiver();
|
List<ReceiverDescriptor> receivers;
|
||||||
if (receiverToCast.exists()) {
|
if (explicitReceiver.exists()) {
|
||||||
|
receivers = Collections.singletonList(explicitReceiver);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receivers = Lists.newArrayList();
|
||||||
|
scope.getImplicitReceiversHierarchy(receivers);
|
||||||
|
}
|
||||||
|
for (ReceiverDescriptor receiverToCast : receivers) {
|
||||||
|
assert receiverToCast.exists();
|
||||||
doComputeTasks(scope, receiverToCast, call, name, result, new AutoCastServiceImpl(dataFlowInfo, bindingContext));
|
doComputeTasks(scope, receiverToCast, call, name, result, new AutoCastServiceImpl(dataFlowInfo, bindingContext));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -232,15 +232,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
return super.getClassifier(name);
|
return super.getClassifier(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public ReceiverDescriptor getImplicitReceiver() {
|
|
||||||
if (implicitReceiver == null) {
|
|
||||||
return super.getImplicitReceiver();
|
|
||||||
}
|
|
||||||
return implicitReceiver;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||||
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
Map<String, DeclarationDescriptor> variableClassOrNamespaceDescriptors = getVariableClassOrNamespaceDescriptors();
|
||||||
@@ -272,6 +263,15 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
|||||||
return super.getNamespace(name);
|
return super.getNamespace(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getImplicitReceiver() {
|
||||||
|
if (implicitReceiver == null) {
|
||||||
|
return super.getImplicitReceiver();
|
||||||
|
}
|
||||||
|
return implicitReceiver;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
public void setImplicitReceiver(@NotNull ReceiverDescriptor implicitReceiver) {
|
||||||
if (this.implicitReceiver != null) {
|
if (this.implicitReceiver != null) {
|
||||||
|
|||||||
+15
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -50,6 +51,20 @@ public abstract class WritableScopeWithImports extends JetScopeAdapter implement
|
|||||||
currentIndividualImportScope = null;
|
currentIndividualImportScope = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
|
||||||
|
super.getImplicitReceiversHierarchy(result);
|
||||||
|
// Imported scopes come with their receivers
|
||||||
|
// Example: class member resolution scope imports a scope of it's class object
|
||||||
|
// members of the class object must be able to find it as an implicit receiver
|
||||||
|
for (JetScope scope : getImports()) {
|
||||||
|
ReceiverDescriptor definedReceiver = scope.getImplicitReceiver();
|
||||||
|
if (definedReceiver.exists()) {
|
||||||
|
result.add(0, definedReceiver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VariableDescriptor getVariable(@NotNull String name) {
|
public VariableDescriptor getVariable(@NotNull String name) {
|
||||||
// Meaningful lookup goes here
|
// Meaningful lookup goes here
|
||||||
|
|||||||
+2
-9
@@ -111,13 +111,6 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
private FunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) {
|
private FunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) {
|
||||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||||
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
|
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
|
||||||
final JetType receiverType;
|
|
||||||
if (receiverTypeRef != null) {
|
|
||||||
receiverType = context.getTypeResolver().resolveType(context.scope, receiverTypeRef);
|
|
||||||
} else {
|
|
||||||
ReceiverDescriptor implicitReceiver = context.scope.getImplicitReceiver();
|
|
||||||
receiverType = implicitReceiver.exists() ? implicitReceiver.getType() : null;
|
|
||||||
}
|
|
||||||
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
|
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
|
||||||
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>");
|
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>");
|
||||||
|
|
||||||
@@ -133,7 +126,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
effectiveReceiverType = receiverType;
|
effectiveReceiverType = context.getTypeResolver().resolveType(context.scope, receiverTypeRef);
|
||||||
}
|
}
|
||||||
functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, Collections.<TypeParameterDescriptor>emptyList(), valueParameterDescriptors, null, Modality.FINAL, Visibility.LOCAL);
|
functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, Collections.<TypeParameterDescriptor>emptyList(), valueParameterDescriptors, null, Modality.FINAL, Visibility.LOCAL);
|
||||||
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
||||||
@@ -175,7 +168,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
type = ErrorUtils.createErrorType("Cannot be inferred");
|
type = ErrorUtils.createErrorType("Cannot be inferred");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueParameterDescriptor valueParameterDescriptor = context.getClassDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type);
|
ValueParameterDescriptor valueParameterDescriptor = context.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type);
|
||||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
valueParameterDescriptors.add(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -197,7 +197,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetTypeReference typeReference = loopParameter.getTypeReference();
|
JetTypeReference typeReference = loopParameter.getTypeReference();
|
||||||
VariableDescriptor variableDescriptor;
|
VariableDescriptor variableDescriptor;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
variableDescriptor = context.getClassDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter);
|
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter);
|
||||||
JetType actualParameterType = variableDescriptor.getOutType();
|
JetType actualParameterType = variableDescriptor.getOutType();
|
||||||
if (expectedParameterType != null &&
|
if (expectedParameterType != null &&
|
||||||
actualParameterType != null &&
|
actualParameterType != null &&
|
||||||
@@ -209,7 +209,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (expectedParameterType == null) {
|
if (expectedParameterType == null) {
|
||||||
expectedParameterType = ErrorUtils.createErrorType("Error");
|
expectedParameterType = ErrorUtils.createErrorType("Error");
|
||||||
}
|
}
|
||||||
variableDescriptor = context.getClassDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
||||||
}
|
}
|
||||||
loopScope.addVariableDescriptor(variableDescriptor);
|
loopScope.addVariableDescriptor(variableDescriptor);
|
||||||
}
|
}
|
||||||
@@ -320,7 +320,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetParameter catchParameter = catchClause.getCatchParameter();
|
JetParameter catchParameter = catchClause.getCatchParameter();
|
||||||
JetExpression catchBody = catchClause.getCatchBody();
|
JetExpression catchBody = catchClause.getCatchBody();
|
||||||
if (catchParameter != null) {
|
if (catchParameter != null) {
|
||||||
VariableDescriptor variableDescriptor = context.getClassDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter);
|
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter);
|
||||||
if (catchBody != null) {
|
if (catchBody != null) {
|
||||||
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
|
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
|
||||||
catchScope.addVariableDescriptor(variableDescriptor);
|
catchScope.addVariableDescriptor(variableDescriptor);
|
||||||
|
|||||||
+6
-6
@@ -8,7 +8,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||||
@@ -71,7 +71,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
private CallResolver callResolver;
|
private CallResolver callResolver;
|
||||||
private TypeResolver typeResolver;
|
private TypeResolver typeResolver;
|
||||||
private ClassDescriptorResolver classDescriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
private ExpressionTypingServices services;
|
private ExpressionTypingServices services;
|
||||||
private CompileTimeConstantResolver compileTimeConstantResolver;
|
private CompileTimeConstantResolver compileTimeConstantResolver;
|
||||||
|
|
||||||
@@ -156,11 +156,11 @@ import java.util.Map;
|
|||||||
return typeResolver;
|
return typeResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassDescriptorResolver getClassDescriptorResolver() {
|
public DescriptorResolver getDescriptorResolver() {
|
||||||
if (classDescriptorResolver == null) {
|
if (descriptorResolver == null) {
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
||||||
}
|
}
|
||||||
return classDescriptorResolver;
|
return descriptorResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
||||||
|
|||||||
+3
-3
@@ -59,7 +59,7 @@ public class ExpressionTypingVisitorForStatements extends BasicExpressionTypingV
|
|||||||
TopDownAnalyzer.processObject(context.semanticServices, context.trace, scope, scope.getContainingDeclaration(), declaration);
|
TopDownAnalyzer.processObject(context.semanticServices, context.trace, scope, scope.getContainingDeclaration(), declaration);
|
||||||
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
|
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
|
||||||
if (classDescriptor != null) {
|
if (classDescriptor != null) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(scope.getContainingDeclaration(), declaration, classDescriptor);
|
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(scope.getContainingDeclaration(), declaration, classDescriptor);
|
||||||
scope.addVariableDescriptor(propertyDescriptor);
|
scope.addVariableDescriptor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
return checkExpectedType(declaration, context);
|
return checkExpectedType(declaration, context);
|
||||||
@@ -82,7 +82,7 @@ public class ExpressionTypingVisitorForStatements extends BasicExpressionTypingV
|
|||||||
context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter));
|
context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter));
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property);
|
VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property);
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (property.getPropertyTypeRef() != null && initializer != null) {
|
if (property.getPropertyTypeRef() != null && initializer != null) {
|
||||||
JetType outType = propertyDescriptor.getOutType();
|
JetType outType = propertyDescriptor.getOutType();
|
||||||
@@ -95,7 +95,7 @@ public class ExpressionTypingVisitorForStatements extends BasicExpressionTypingV
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
||||||
FunctionDescriptorImpl functionDescriptor = context.getClassDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
|
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
|
||||||
scope.addFunctionDescriptor(functionDescriptor);
|
scope.addFunctionDescriptor(functionDescriptor);
|
||||||
context.getServices().checkFunctionReturnType(context.scope, function, functionDescriptor, context.dataFlowInfo);
|
context.getServices().checkFunctionReturnType(context.scope, function, functionDescriptor, context.dataFlowInfo);
|
||||||
return checkExpectedType(function, context);
|
return checkExpectedType(function, context);
|
||||||
|
|||||||
+1
-1
@@ -226,7 +226,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetProperty variableDeclaration = pattern.getVariableDeclaration();
|
JetProperty variableDeclaration = pattern.getVariableDeclaration();
|
||||||
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef();
|
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef();
|
||||||
JetType type = propertyTypeRef == null ? subjectType : context.getTypeResolver().resolveType(context.scope, propertyTypeRef);
|
JetType type = propertyTypeRef == null ? subjectType : context.getTypeResolver().resolveType(context.scope, propertyTypeRef);
|
||||||
VariableDescriptor variableDescriptor = context.getClassDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type);
|
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type);
|
||||||
scopeToExtend.addVariableDescriptor(variableDescriptor);
|
scopeToExtend.addVariableDescriptor(variableDescriptor);
|
||||||
if (propertyTypeRef != null) {
|
if (propertyTypeRef != null) {
|
||||||
if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectType, type)) {
|
if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectType, type)) {
|
||||||
|
|||||||
@@ -73,7 +73,11 @@ public class DescriptorRenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String renderType(JetType type) {
|
public String renderType(JetType type) {
|
||||||
return escape(type.toString());
|
if (type == null) {
|
||||||
|
return escape("<?>");
|
||||||
|
} else {
|
||||||
|
return escape(type.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String escape(String s) {
|
protected String escape(String s) {
|
||||||
@@ -222,7 +226,7 @@ public class DescriptorRenderer implements Renderer {
|
|||||||
|
|
||||||
renderName(descriptor, builder);
|
renderName(descriptor, builder);
|
||||||
renderValueParameters(descriptor, builder);
|
renderValueParameters(descriptor, builder);
|
||||||
builder.append(" : ").append(escape(renderType(descriptor.getReturnType())));
|
builder.append(" : ").append(escape(renderType(descriptor.getReturnTypeSafe())));
|
||||||
return super.visitFunctionDescriptor(descriptor, builder);
|
return super.visitFunctionDescriptor(descriptor, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ namespace a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace b {
|
namespace b {
|
||||||
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
fun foo() = bar()
|
||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>foo()<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace c {
|
namespace c {
|
||||||
fun bazz() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
fun bazz() = bar()
|
||||||
|
|
||||||
fun foo() = bazz()
|
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bazz()<!>
|
||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = foo()
|
||||||
}
|
}
|
||||||
@@ -39,4 +39,4 @@ namespace ok {
|
|||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// KT-588 Unresolved static method
|
||||||
|
class Test() : Thread("Test") {
|
||||||
|
class object {
|
||||||
|
fun init2() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun run() {
|
||||||
|
init2() // unresolved
|
||||||
|
Test.init2() // ok
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun bar() = {
|
||||||
|
<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun bar() = {
|
||||||
|
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// http://youtrack.jetbrains.net/issue/KT-329
|
||||||
|
|
||||||
|
fun block(f : fun() : Unit) = f()
|
||||||
|
|
||||||
|
fun bar() = block{ <!UNRESOLVED_REFERENCE!>foo<!>() // <-- missing closing curly bracket
|
||||||
|
fun foo() = block{ <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> }
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// KT-394 Make class object members visible inside the owning class
|
||||||
|
|
||||||
|
class X() {
|
||||||
|
// class Y {}
|
||||||
|
|
||||||
|
class object{
|
||||||
|
class Y() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val y : Y = Y()
|
||||||
|
}
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
|
import std.io.*
|
||||||
|
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
val ByteArray.inputStream : ByteArrayInputStream
|
|
||||||
get() = ByteArrayInputStream(this)
|
|
||||||
|
|
||||||
fun InputStream.iterator() : ByteIterator =
|
|
||||||
object: ByteIterator() {
|
|
||||||
override val hasNext : Boolean
|
|
||||||
get() = available() > 0
|
|
||||||
|
|
||||||
override fun nextByte() = read().byt
|
|
||||||
}
|
|
||||||
|
|
||||||
fun box() : String {
|
fun box() : String {
|
||||||
val x = ByteArray (10)
|
val x = ByteArray (10)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
namespace mask
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import java.io.*
|
||||||
|
import java.util.*
|
||||||
|
import java.util.Iterator as It
|
||||||
|
import java.lang.Iterable as Itl
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val input = StringReader("/Users/abreslav/work/jet/docs/luhnybin/src/test")
|
||||||
|
|
||||||
|
val luhny = Luhny()
|
||||||
|
input.forEachChar {
|
||||||
|
luhny.charIn(it)
|
||||||
|
}
|
||||||
|
luhny.printAll()
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
class Luhny() {
|
||||||
|
val buffer = LinkedList<Char>()
|
||||||
|
val digits = LinkedList<Int>()
|
||||||
|
|
||||||
|
var toBeMasked = 0
|
||||||
|
|
||||||
|
fun charIn(it : Char) {
|
||||||
|
buffer.addLast(it)
|
||||||
|
when (it) {
|
||||||
|
.isDigit() => digits.addLast(it.int - '0'.int)
|
||||||
|
' ', '-' => {}
|
||||||
|
else => {
|
||||||
|
printAll()
|
||||||
|
digits.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (digits.size() > 16)
|
||||||
|
printOneDigit()
|
||||||
|
check()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun check() {
|
||||||
|
if (digits.size() < 14) return
|
||||||
|
print("check")
|
||||||
|
val sum = digits.sum { i, d =>
|
||||||
|
// println("$i -> $d")
|
||||||
|
if (i % 2 == digits.size()) {
|
||||||
|
val f = d * 2 / 10
|
||||||
|
val s = d * 2 % 10
|
||||||
|
// println("$d: f = $f, s = $s")
|
||||||
|
(f + s).pr {
|
||||||
|
// println("to be doubled: $i -> $d : $it")
|
||||||
|
}
|
||||||
|
} else d
|
||||||
|
}
|
||||||
|
// println(sum)
|
||||||
|
if (sum % 10 == 0) {print("s"); toBeMasked = digits.size()}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printOneDigit() {
|
||||||
|
while (!buffer.isEmpty()) {
|
||||||
|
val c = buffer.removeFirst()
|
||||||
|
out(c)
|
||||||
|
if (c.isDigit()) {
|
||||||
|
digits.removeFirst()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printAll() {
|
||||||
|
while (!buffer.isEmpty())
|
||||||
|
out(buffer.removeFirst())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun out(c : Char) {
|
||||||
|
if (toBeMasked > 0) {
|
||||||
|
print('X')
|
||||||
|
toBeMasked--
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> T.pr(f : fun(T) : Unit) : T {
|
||||||
|
f(this)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun LinkedList<Int>.sum(f : fun(Int, Int ): Int): Int {
|
||||||
|
var sum = 0
|
||||||
|
for (i in 1..size()) {
|
||||||
|
val j = size() - i
|
||||||
|
sum += f(j, get(j))
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
//fun <T> List<T>.backwards() : Itl<T> = object : Itl<T> {
|
||||||
|
// override fun iterator() : It<T> =
|
||||||
|
// object : It<T> {
|
||||||
|
// var current = size()
|
||||||
|
// override fun next() : T = get(--current)
|
||||||
|
// override fun hasNext() : Boolean = current > 0
|
||||||
|
// override fun remove() {throw UnsupportedOperationException()}
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
fun Char.isDigit() = Character.isDigit(this)
|
||||||
|
|
||||||
|
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||||
|
do {
|
||||||
|
var i = read();
|
||||||
|
if (i == -1) break
|
||||||
|
body(i.chr)
|
||||||
|
} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
namespace mask
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import java.io.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val input = StringReader("/Users/abreslav/work/jet/docs/luhnybin/src/test")
|
||||||
|
|
||||||
|
val luhny = Luhny()
|
||||||
|
input.forEachChar {
|
||||||
|
luhny.process(it)
|
||||||
|
}
|
||||||
|
luhny.printAll()
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
class Luhny() {
|
||||||
|
private val buffer = ArrayDeque<Char>()
|
||||||
|
private val digits = ArrayDeque<Int>(16)
|
||||||
|
|
||||||
|
private var toBeMasked = 0
|
||||||
|
|
||||||
|
fun process(it : Char) {
|
||||||
|
buffer.addLast(it)
|
||||||
|
when (it) {
|
||||||
|
.isDigit() => digits.addLast(it.int - '0'.int)
|
||||||
|
' ', '-' => {}
|
||||||
|
else => printAll()
|
||||||
|
}
|
||||||
|
if (digits.size() > 16)
|
||||||
|
printOneDigit()
|
||||||
|
check()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun check() {
|
||||||
|
val size = digits.size()
|
||||||
|
if (size < 14) return
|
||||||
|
val sum = digits.sum {i, d =>
|
||||||
|
if (i % 2 == size % 2) double(d) else d
|
||||||
|
}
|
||||||
|
// var sum = 0
|
||||||
|
// var i = 0
|
||||||
|
// for (d in digits) {
|
||||||
|
// sum += if (i % 2 == size % 2) double(d) else d
|
||||||
|
// i++
|
||||||
|
// }
|
||||||
|
if (sum % 10 == 0) toBeMasked = digits.size()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun double(d : Int) = d * 2 / 10 + d * 2 % 10
|
||||||
|
|
||||||
|
private fun printOneDigit() {
|
||||||
|
while (!buffer.isEmpty()) {
|
||||||
|
val c = buffer.removeFirst()
|
||||||
|
print(c)
|
||||||
|
if (c.isDigit()) {
|
||||||
|
digits.removeFirst()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun printAll() {
|
||||||
|
while (!buffer.isEmpty())
|
||||||
|
print(buffer.removeFirst())
|
||||||
|
digits.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun print(c : Char) {
|
||||||
|
if (c.isDigit() && toBeMasked > 0) {
|
||||||
|
std.io.print('X')
|
||||||
|
toBeMasked--
|
||||||
|
} else {
|
||||||
|
std.io.print(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Char.isDigit() = Character.isDigit(this)
|
||||||
|
|
||||||
|
fun java.lang.Iterable<Int>.sum(f : fun(index : Int, value : Int) : Int) : Int {
|
||||||
|
var sum = 0
|
||||||
|
var i = 0
|
||||||
|
for (d in this) {
|
||||||
|
sum += f(i, d)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||||
|
do {
|
||||||
|
var i = read();
|
||||||
|
if (i == -1) break
|
||||||
|
body(i.chr)
|
||||||
|
} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
namespace mask
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import java.io.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
val input = StringReader("/Users/abreslav/work/jet/docs/luhnybin/src/test")
|
||||||
|
|
||||||
|
val luhny = Luhny()
|
||||||
|
input.forEachChar {
|
||||||
|
luhny.charIn(it)
|
||||||
|
}
|
||||||
|
luhny.printAll()
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Luhny() {
|
||||||
|
val buffer = LinkedList<Char>()
|
||||||
|
val digits = LinkedList<Int>()
|
||||||
|
|
||||||
|
var toBeMasked = 0
|
||||||
|
|
||||||
|
fun charIn(it : Char) {
|
||||||
|
buffer.push(it)
|
||||||
|
when (it) {
|
||||||
|
.isDigit() => digits.push(it.int - '0'.int)
|
||||||
|
' ', '-' => {}
|
||||||
|
else => {
|
||||||
|
printAll()
|
||||||
|
digits.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (digits.size() > 16)
|
||||||
|
printOneDigit()
|
||||||
|
check()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun check() {
|
||||||
|
if (digits.size() < 14) return
|
||||||
|
val sum = digits.sum { i, d =>
|
||||||
|
if (i % 2 != 0)
|
||||||
|
d * 2 / 10 + d * 2 % 10
|
||||||
|
else d
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0) toBeMasked = digits.size()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printOneDigit() {
|
||||||
|
while (!buffer.isEmpty()) {
|
||||||
|
val c = buffer.pop()
|
||||||
|
out(c)
|
||||||
|
if (c.isDigit()) {
|
||||||
|
digits.pop()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun printAll() {
|
||||||
|
while (!buffer.isEmpty())
|
||||||
|
out(buffer.pop())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun out(c : Char) {
|
||||||
|
if (toBeMasked > 0) {
|
||||||
|
print('X')
|
||||||
|
toBeMasked--
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun LinkedList<Int>.sum(f : fun(Int, Int) : Int) : Int {
|
||||||
|
var sum = 0
|
||||||
|
var i = 0
|
||||||
|
for (d in backwards()) {
|
||||||
|
sum += f(i, d)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> List<T>.backwards() : Iterable<T> = object : Iterable<T> {
|
||||||
|
override fun iterator() : Iterator<T> =
|
||||||
|
object : Iterator<T> {
|
||||||
|
var current = size()
|
||||||
|
override fun next() : T = get(--current)
|
||||||
|
override val hasNext : Boolean get() = current > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Char.isDigit() = Character.isDigit(this)
|
||||||
|
|
||||||
|
//class Queue<T>(initialBufSize : Int) {
|
||||||
|
//
|
||||||
|
// private var bufSize = initialBufSize
|
||||||
|
// private val buf = Array<T>(initialBufSize)
|
||||||
|
// private var head = 0
|
||||||
|
// private var tail = 0
|
||||||
|
// private var size = 0
|
||||||
|
//
|
||||||
|
// val empty : Boolean get() = size == 0
|
||||||
|
//
|
||||||
|
// private fun prev(i : Int) = (bufSize + i - 1) % bufSize
|
||||||
|
// private fun next(i : Int) = (i + 1) % bufSize
|
||||||
|
//
|
||||||
|
// fun push(c : T) {
|
||||||
|
// buf[tail] = c
|
||||||
|
// tail = prev(tail)
|
||||||
|
// size++
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fun pop() : T {
|
||||||
|
// if (size == 0) throw IllegalStateException()
|
||||||
|
// size--
|
||||||
|
// val result = buf[head]
|
||||||
|
// head = prev(head)
|
||||||
|
// return result
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// fun clear() {}
|
||||||
|
//}
|
||||||
|
|
||||||
|
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||||
|
do {
|
||||||
|
var i = read();
|
||||||
|
if (i == -1) break
|
||||||
|
body(i.chr)
|
||||||
|
} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace array_test
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
var array : IntArray? = IntArray(10)
|
||||||
|
array?.set(0, 3)
|
||||||
|
if(array?.get(0) != 3) return "fail"
|
||||||
|
|
||||||
|
var a = Array<Array<String?>?>(5)
|
||||||
|
var b = Array<String?>(1)
|
||||||
|
b.set(0, "239")
|
||||||
|
a?.set(0, b)
|
||||||
|
|
||||||
|
if(a?.get(0)?.get(0) != "239") return "fail"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
|||||||
@NonNls
|
@NonNls
|
||||||
protected final String myFullDataPath;
|
protected final String myFullDataPath;
|
||||||
protected JetFile myFile;
|
protected JetFile myFile;
|
||||||
private JetCoreEnvironment myEnvironment;
|
protected JetCoreEnvironment myEnvironment;
|
||||||
|
|
||||||
public JetLiteFixture(@NonNls String dataPath) {
|
public JetLiteFixture(@NonNls String dataPath) {
|
||||||
myFullDataPath = getTestDataPath() + "/" + dataPath;
|
myFullDataPath = getTestDataPath() + "/" + dataPath;
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.ImportingStrategy;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -42,7 +45,11 @@ public class FullJetPsiCheckerTest extends JetLiteFixture {
|
|||||||
String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
String clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||||
|
|
||||||
myFile = createPsiFile(myName, clearText);
|
myFile = createPsiFile(myName, clearText);
|
||||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
|
|
||||||
|
boolean importJdk = !expectedText.contains("-JDK");
|
||||||
|
ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE;
|
||||||
|
|
||||||
|
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), myFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
|
||||||
|
|
||||||
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.ImportingStrategy;
|
import org.jetbrains.jet.lang.resolve.ImportingStrategy;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -40,7 +41,11 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture {
|
|||||||
|
|
||||||
createAndCheckPsiFile(name, clearText);
|
createAndCheckPsiFile(name, clearText);
|
||||||
JetFile jetFile = (JetFile) myFile;
|
JetFile jetFile = (JetFile) myFile;
|
||||||
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(ImportingStrategy.NONE), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
|
|
||||||
|
boolean importJdk = expectedText.contains("+JDK");
|
||||||
|
ImportingStrategy importingStrategy = importJdk ? JavaDefaultImports.JAVA_DEFAULT_IMPORTS : ImportingStrategy.NONE;
|
||||||
|
|
||||||
|
BindingContext bindingContext = AnalyzerFacade.analyzeFileWithCache(AnalyzingUtils.getInstance(importingStrategy), jetFile, AnalyzerFacade.SINGLE_DECLARATION_PROVIDER);
|
||||||
|
|
||||||
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, bindingContext.getDiagnostics(), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -275,4 +275,10 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
public void testKt503() {
|
public void testKt503() {
|
||||||
blackBoxFile("regressions/kt503.jet");
|
blackBoxFile("regressions/kt503.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt594() throws Exception {
|
||||||
|
loadFile("regressions/kt594.jet");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
blackBox();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,25 +93,16 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
|||||||
final JetNamespace namespace = myFile.getRootNamespace();
|
final JetNamespace namespace = myFile.getRootNamespace();
|
||||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
||||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||||
Method method = namespaceClass.getMethod("box");
|
Method method = namespaceClass.getMethod("box");
|
||||||
return (String) method.invoke(null);
|
return (String) method.invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateToText() {
|
protected String generateToText() {
|
||||||
GenerationState state = new GenerationState(getProject(), ClassBuilderFactory.TEXT);
|
GenerationState state = new GenerationState(getProject(), ClassBuilderFactory.TEXT);
|
||||||
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
||||||
state.compile(myFile);
|
state.compile(myFile);
|
||||||
|
|
||||||
StringBuilder answer = new StringBuilder();
|
return state.createText();
|
||||||
|
|
||||||
final ClassFileFactory factory = state.getFactory();
|
|
||||||
List<String> files = factory.files();
|
|
||||||
for (String file : files) {
|
|
||||||
answer.append("@").append(file).append('\n');
|
|
||||||
answer.append(factory.asText(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
return answer.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Class generateNamespaceClass() {
|
protected Class generateNamespaceClass() {
|
||||||
|
|||||||
@@ -1,25 +1,88 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||||
|
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import org.jetbrains.jet.compiler.CompileSession;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class StdlibTest extends CodegenTestCase {
|
public class StdlibTest extends CodegenTestCase {
|
||||||
public void testLib () throws ClassNotFoundException {
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
createEnvironmentWithFullJdk();
|
createEnvironmentWithFullJdk();
|
||||||
loadFile("../../../stdlib/ktSrc/StandardLibrary.kt");
|
}
|
||||||
ClassFileFactory codegens = generateClassesInFile();
|
|
||||||
GeneratedClassLoader loader = new GeneratedClassLoader(codegens);
|
protected String generateToText() {
|
||||||
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
|
|
||||||
final JetNamespace namespace = myFile.getRootNamespace();
|
session.addSources(myFile.getVirtualFile());
|
||||||
String fqName = NamespaceCodegen.getJVMClassName(CodegenUtil.getFQName(namespace)).replace("/", ".");
|
try {
|
||||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
session.addSources(addStdLib());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!session.analyze(System.out)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.generateText();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ClassFileFactory generateClassesInFile() {
|
||||||
|
try {
|
||||||
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
|
|
||||||
|
session.addSources(myFile.getVirtualFile());
|
||||||
|
session.addSources(addStdLib());
|
||||||
|
|
||||||
|
if (!session.analyze(System.out)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return session.generate();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
System.out.println(generateToText());
|
||||||
|
throw e;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualFile addStdLib() throws IOException {
|
||||||
|
String text = FileUtil.loadFile(new File(JetParsingTest.getTestDataDir() + "/../../stdlib/ktSrc/StandardLibrary.kt"), CharsetToolkit.UTF8).trim();
|
||||||
|
text = StringUtil.convertLineSeparators(text);
|
||||||
|
PsiFile stdLibFile = createFile("StandardLibrary.kt", text);
|
||||||
|
return stdLibFile.getVirtualFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInputStreamIterator () {
|
public void testInputStreamIterator () {
|
||||||
blackBoxFile("inputStreamIterator.jet");
|
blackBoxFile("inputStreamIterator.jet");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKt533 () {
|
||||||
|
blackBoxFile("regressions/kt533.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKt529 () {
|
||||||
|
blackBoxFile("regressions/kt529.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKt528 () {
|
||||||
|
blackBoxFile("regressions/kt528.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import org.jetbrains.jet.lang.JetSemanticServices;
|
|||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||||
@@ -29,13 +29,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
public class JetDefaultModalityModifiersTestCase {
|
public class JetDefaultModalityModifiersTestCase {
|
||||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||||
private ClassDescriptorResolver classDescriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
private JetScope scope;
|
private JetScope scope;
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
JetStandardLibrary library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
JetStandardLibrary library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
||||||
scope = createScope(library.getLibraryScope());
|
scope = createScope(library.getLibraryScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) {
|
private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) {
|
||||||
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind);
|
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind);
|
||||||
classDescriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor);
|
descriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor);
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
|
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
|
||||||
FunctionDescriptorImpl functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function);
|
FunctionDescriptorImpl functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function);
|
||||||
|
|
||||||
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
|
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
||||||
|
|
||||||
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
||||||
PropertyAccessorDescriptor propertyAccessor = isGetter
|
PropertyAccessorDescriptor propertyAccessor = isGetter
|
||||||
? propertyDescriptor.getGetter()
|
? propertyDescriptor.getGetter()
|
||||||
: propertyDescriptor.getSetter();
|
: propertyDescriptor.getSetter();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
|
|
||||||
@@ -20,14 +20,14 @@ public class JetOverloadTest extends JetLiteFixture {
|
|||||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
private JetSemanticServices semanticServices;
|
||||||
private ClassDescriptorResolver classDescriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -152,7 +152,7 @@ public class JetOverloadTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||||
return classDescriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
|
|
||||||
@@ -20,14 +20,14 @@ public class JetOverridingTest extends JetLiteFixture {
|
|||||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
private JetSemanticServices semanticServices;
|
||||||
private ClassDescriptorResolver classDescriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,6 +145,6 @@ public class JetOverridingTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||||
return classDescriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
private JetSemanticServices semanticServices;
|
||||||
private ClassDefinitions classDefinitions;
|
private ClassDefinitions classDefinitions;
|
||||||
private ClassDescriptorResolver classDescriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
private JetScope scopeWithImports;
|
private JetScope scopeWithImports;
|
||||||
private TypeResolver typeResolver;
|
private TypeResolver typeResolver;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDefinitions = new ClassDefinitions();
|
classDefinitions = new ClassDefinitions();
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
|
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
|
||||||
typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
|
typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
|
||||||
}
|
}
|
||||||
@@ -604,7 +604,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
||||||
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
|
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
|
||||||
for (String funDecl : FUNCTION_DECLARATIONS) {
|
for (String funDecl : FUNCTION_DECLARATIONS) {
|
||||||
FunctionDescriptor functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl));
|
FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl));
|
||||||
if (name.equals(functionDescriptor.getName())) {
|
if (name.equals(functionDescriptor.getName())) {
|
||||||
writableFunctionGroup.add(functionDescriptor);
|
writableFunctionGroup.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
@@ -628,14 +628,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
|
|
||||||
// This call has side-effects on the parameterScope (fills it in)
|
// This call has side-effects on the parameterScope (fills it in)
|
||||||
List<TypeParameterDescriptor> typeParameters
|
List<TypeParameterDescriptor> typeParameters
|
||||||
= classDescriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
|
= descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
|
||||||
classDescriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters);
|
descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters);
|
||||||
|
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
|
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
|
||||||
// TODO : assuming that the hierarchy is acyclic
|
// TODO : assuming that the hierarchy is acyclic
|
||||||
Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
|
Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
|
||||||
? Collections.singleton(JetStandardClasses.getAnyType())
|
? Collections.singleton(JetStandardClasses.getAnyType())
|
||||||
: classDescriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver);
|
: descriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver);
|
||||||
// for (JetType supertype: supertypes) {
|
// for (JetType supertype: supertypes) {
|
||||||
// if (supertype.getConstructor().isSealed()) {
|
// if (supertype.getConstructor().isSealed()) {
|
||||||
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
|
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
|
||||||
@@ -651,7 +651,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
if (property.getPropertyTypeRef() != null) {
|
if (property.getPropertyTypeRef() != null) {
|
||||||
memberDeclarations.addVariableDescriptor(classDescriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property));
|
memberDeclarations.addVariableDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property));
|
||||||
} else {
|
} else {
|
||||||
// TODO : Caution: a cyclic dependency possible
|
// TODO : Caution: a cyclic dependency possible
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -661,7 +661,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
if (function.getReturnTypeRef() != null) {
|
if (function.getReturnTypeRef() != null) {
|
||||||
memberDeclarations.addFunctionDescriptor(classDescriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function));
|
memberDeclarations.addFunctionDescriptor(descriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function));
|
||||||
} else {
|
} else {
|
||||||
// TODO : Caution: a cyclic dependency possible
|
// TODO : Caution: a cyclic dependency possible
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -685,11 +685,11 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) {
|
for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) {
|
||||||
ConstructorDescriptorImpl functionDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
|
ConstructorDescriptorImpl functionDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
|
||||||
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
|
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||||
constructors.add(functionDescriptor);
|
constructors.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
ConstructorDescriptorImpl primaryConstructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
|
ConstructorDescriptorImpl primaryConstructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
|
||||||
if (primaryConstructorDescriptor != null) {
|
if (primaryConstructorDescriptor != null) {
|
||||||
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||||
constructors.add(primaryConstructorDescriptor);
|
constructors.add(primaryConstructorDescriptor);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ inline fun array(vararg array : Long) = array
|
|||||||
inline fun array(vararg array : Double) = array
|
inline fun array(vararg array : Double) = array
|
||||||
inline fun array(vararg array : Float) = array
|
inline fun array(vararg array : Float) = array
|
||||||
|
|
||||||
fun Any?.identityEquals(other : Any?) = this === other
|
//fun Any?.identityEquals(other : Any?) = this === other
|
||||||
|
|
||||||
inline fun <T : Any> T?.sure() : T {
|
inline fun <T : Any> T?.sure() : T {
|
||||||
if (this == null)
|
if (this == null)
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ fun main(args : Array<String>) {
|
|||||||
println("Animals are equal: " + (pig == dog));
|
println("Animals are equal: " + (pig == dog));
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
println("Animals are equal: " + (pig identityEquals dog));
|
println("Animals are equal: " + (pig identityEquals dog))
|
||||||
}
|
}
|
||||||
@@ -25,4 +25,4 @@ fun main(args : Array<String>) {
|
|||||||
// nipper.bark()
|
// nipper.bark()
|
||||||
Dog.bark()
|
Dog.bark()
|
||||||
Basenji.bark()
|
Basenji.bark()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package _06_classy._53_Do_Your_Thing;
|
||||||
|
|
||||||
|
public class MyThing extends Thing {
|
||||||
|
private final int arg;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This constructor is illegal. Rewrite it so that it has the same
|
||||||
|
* effect but is legal.
|
||||||
|
*/
|
||||||
|
public MyThing() {
|
||||||
|
this((int)System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This constructor is illegal. Rewrite it so that it has the same
|
||||||
|
* effect but is legal.
|
||||||
|
*/
|
||||||
|
public MyThing(int arg) {
|
||||||
|
super(arg);
|
||||||
|
this.arg = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace `do`.your.thing
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.*
|
||||||
|
import _06_classy._53_Do_Your_Thing.Thing
|
||||||
|
|
||||||
|
class MyThing(val arg : Int) : Thing(arg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
println(MyThing(10).arg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package _06_classy._53_Do_Your_Thing;
|
||||||
|
|
||||||
|
// This is meant to represent a library class. You must not modify it.
|
||||||
|
public class Thing {
|
||||||
|
public Thing(int i) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package _06_classy._54_Null_and_Void;
|
||||||
|
|
||||||
|
public class Null {
|
||||||
|
public static void greet() {
|
||||||
|
System.out.println("Hello world!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
((Null) null).greet();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace `null`.and.void
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.*
|
||||||
|
|
||||||
|
class Null() {
|
||||||
|
class object {
|
||||||
|
fun greet() {
|
||||||
|
println("Hello world!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
// The problemati code does not compile:
|
||||||
|
// (null as Null).greet()
|
||||||
|
Null.greet()
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package _06_classy._55_Creationism;
|
||||||
|
|
||||||
|
public class Creator {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// for (int i = 0; i < 100; i++)
|
||||||
|
// Creature creature = new Creature();
|
||||||
|
System.out.println(Creature.numCreated());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Creature {
|
||||||
|
private static long numCreated = 0;
|
||||||
|
|
||||||
|
public Creature() {
|
||||||
|
numCreated++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long numCreated() {
|
||||||
|
return numCreated;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace creationism
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.*
|
||||||
|
|
||||||
|
class Creature() {
|
||||||
|
class object {
|
||||||
|
var numCreated = 0
|
||||||
|
private set
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Creature.numCreated++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
// for (i in 1..100)
|
||||||
|
// val creature = Creature()
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package _07_library._56_Big_Problem;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
public class BigProblem {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
BigInteger fiveThousand = new BigInteger("5000");
|
||||||
|
BigInteger fiftyThousand = new BigInteger("50000");
|
||||||
|
BigInteger fiveHundredThousand
|
||||||
|
= new BigInteger("500000");
|
||||||
|
|
||||||
|
BigInteger total = BigInteger.ZERO;
|
||||||
|
total.add(fiveThousand);
|
||||||
|
total.add(fiftyThousand);
|
||||||
|
total.add(fiveHundredThousand);
|
||||||
|
System.out.println(total);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
namespace big.problem
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.*
|
||||||
|
import java.math.BigInteger
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
val fiveThousand = "5000".bi()
|
||||||
|
val fiftyThousand = "50000".bi()
|
||||||
|
val fiveHundredThousand = "500000".bi()
|
||||||
|
|
||||||
|
val total : BigInteger = "0".bi()//BigInteger.ZERO
|
||||||
|
total + fiveThousand
|
||||||
|
total + fiftyThousand
|
||||||
|
total + fiveHundredThousand
|
||||||
|
println(total) // No surprise
|
||||||
|
|
||||||
|
var total1 : BigInteger = "0".bi()//BigInteger.ZERO
|
||||||
|
total1 += fiveThousand
|
||||||
|
total1 += fiftyThousand
|
||||||
|
total1 += fiveHundredThousand
|
||||||
|
println(total1) // Works
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun String.bi() : BigInteger = BigInteger(this)
|
||||||
|
inline fun BigInteger.plus(other : BigInteger) = this add other
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package _07_library._59_Whats_the_Difference;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Differences {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int vals[] = { 789, 678, 567, 456, 345, 234, 123, 012 };
|
||||||
|
Set<Integer> diffs = new HashSet<Integer>();
|
||||||
|
|
||||||
|
for (int i = 0; i < vals.length; i++)
|
||||||
|
for (int j = i; j < vals.length; j++)
|
||||||
|
diffs.add(vals[i] - vals[j]);
|
||||||
|
System.out.println(diffs.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace whats.the.difference
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
import std.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun iarray(vararg a : Int) = a // BUG
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
// Problematic code does not compile
|
||||||
|
// val vals = iarray(789, 678, 567, 456, 345, 234, 123, 012)
|
||||||
|
val vals = iarray(789, 678, 567, 456, 345, 234, 123, 12)
|
||||||
|
val diffs = HashSet<Int>
|
||||||
|
for (i in vals.indices)
|
||||||
|
for (j in i..vals.lastIndex())
|
||||||
|
diffs.add(vals[i] - vals[j])
|
||||||
|
println(diffs.size())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun IntArray.lastIndex() = size - 1
|
||||||
@@ -57,6 +57,9 @@
|
|||||||
<codeInsight.implementMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler"/>
|
<codeInsight.implementMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler"/>
|
||||||
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
<codeInsight.overrideMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.OverrideMethodsHandler"/>
|
||||||
|
|
||||||
<java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>
|
<!-- <java.elementFinder implementation="org.jetbrains.jet.plugin.java.JavaElementFinder"/>-->
|
||||||
|
<toolWindow id="CodeWindow"
|
||||||
|
factoryClass="org.jetbrains.jet.plugin.internal.codewindow.BytecodeToolwindow$Factory"
|
||||||
|
anchor="right"/>
|
||||||
</extensions>
|
</extensions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
|||||||
@@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* @author max
|
||||||
|
*/
|
||||||
|
package org.jetbrains.jet.plugin.internal.codewindow;
|
||||||
|
|
||||||
|
import com.intellij.ide.highlighter.JavaFileType;
|
||||||
|
import com.intellij.openapi.application.Result;
|
||||||
|
import com.intellij.openapi.command.WriteCommandAction;
|
||||||
|
import com.intellij.openapi.editor.Document;
|
||||||
|
import com.intellij.openapi.editor.Editor;
|
||||||
|
import com.intellij.openapi.editor.EditorFactory;
|
||||||
|
import com.intellij.openapi.editor.ScrollType;
|
||||||
|
import com.intellij.openapi.editor.ex.EditorEx;
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.Comparing;
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
|
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.intellij.psi.PsiManager;
|
||||||
|
import com.intellij.ui.content.ContentFactory;
|
||||||
|
import com.intellij.util.Alarm;
|
||||||
|
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||||
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class BytecodeToolwindow extends JPanel {
|
||||||
|
private static final int UPDATE_DELAY = 500;
|
||||||
|
private final Editor myEditor;
|
||||||
|
private final Alarm myUpdateAlarm;
|
||||||
|
private Location myCurrentLocation;
|
||||||
|
private final Project myProject;
|
||||||
|
|
||||||
|
|
||||||
|
public BytecodeToolwindow(Project project) {
|
||||||
|
super(new BorderLayout());
|
||||||
|
myProject = project;
|
||||||
|
myEditor = EditorFactory.getInstance().createEditor(EditorFactory.getInstance().createDocument(""), project, JavaFileType.INSTANCE, true);
|
||||||
|
add(myEditor.getComponent());
|
||||||
|
myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
|
||||||
|
myUpdateAlarm.addRequest(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
myUpdateAlarm.addRequest(this, UPDATE_DELAY);
|
||||||
|
Location location = Location.fromEditor(FileEditorManager.getInstance(myProject).getSelectedTextEditor());
|
||||||
|
if (!Comparing.equal(location, myCurrentLocation)) {
|
||||||
|
updateBytecode(location, myCurrentLocation);
|
||||||
|
myCurrentLocation = location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, UPDATE_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBytecode(Location location, Location oldLocation) {
|
||||||
|
Editor editor = location.editor;
|
||||||
|
|
||||||
|
if (editor == null) {
|
||||||
|
setText("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
VirtualFile vFile = ((EditorEx) editor).getVirtualFile();
|
||||||
|
if (vFile == null) {
|
||||||
|
setText("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vFile);
|
||||||
|
if (!(psiFile instanceof JetFile)) {
|
||||||
|
setText("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldLocation == null || !Comparing.equal(oldLocation.editor, location.editor) || oldLocation.modificationStamp != location.modificationStamp) {
|
||||||
|
setText(generateToText((JetFile) psiFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
Document document = editor.getDocument();
|
||||||
|
int startLine = document.getLineNumber(location.startOffset);
|
||||||
|
int endLine = document.getLineNumber(location.endOffset);
|
||||||
|
if (endLine > startLine && location.endOffset > 0 && document.getCharsSequence().charAt(location.endOffset - 1) == '\n') endLine--;
|
||||||
|
|
||||||
|
Document byteCodeDocument = myEditor.getDocument();
|
||||||
|
Pair<Integer, Integer> linesRange = mapLines(byteCodeDocument.getText(), startLine, endLine);
|
||||||
|
|
||||||
|
int startOffset = byteCodeDocument.getLineStartOffset(linesRange.first);
|
||||||
|
int endOffset = Math.min(byteCodeDocument.getLineStartOffset(linesRange.second + 1), byteCodeDocument.getTextLength());
|
||||||
|
myEditor.getCaretModel().moveToOffset(endOffset);
|
||||||
|
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||||
|
myEditor.getCaretModel().moveToOffset(startOffset);
|
||||||
|
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||||
|
|
||||||
|
myEditor.getSelectionModel().setSelection(startOffset,
|
||||||
|
endOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Pair<Integer, Integer> mapLines(String text, int startLine, int endLine) {
|
||||||
|
int byteCodeLine = 0;
|
||||||
|
int byteCodeStartLine = -1;
|
||||||
|
int byteCodeEndLine = -1;
|
||||||
|
|
||||||
|
List<Integer> lines = new ArrayList<Integer>();
|
||||||
|
for (String line : text.split("\n")) {
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
if (line.startsWith("LINENUMBER")) {
|
||||||
|
int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1;
|
||||||
|
lines.add(ktLineNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(lines);
|
||||||
|
|
||||||
|
for (Integer line : lines) {
|
||||||
|
if (line >= startLine) {
|
||||||
|
startLine = line;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String line : text.split("\n")) {
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
if (line.startsWith("LINENUMBER")) {
|
||||||
|
int ktLineNum = new Scanner(line.substring("LINENUMBER".length())).nextInt() - 1;
|
||||||
|
|
||||||
|
if (byteCodeStartLine < 0 && ktLineNum == startLine) {
|
||||||
|
byteCodeStartLine = byteCodeLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (byteCodeStartLine > 0&& ktLineNum > endLine) {
|
||||||
|
byteCodeEndLine = byteCodeLine - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (byteCodeStartLine >= 0 && (line.startsWith("MAXSTACK") || line.startsWith("LOCALVARIABLE") || line.isEmpty())) {
|
||||||
|
byteCodeEndLine = byteCodeLine - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
byteCodeLine++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (byteCodeStartLine == -1 || byteCodeEndLine == -1) {
|
||||||
|
return new Pair<Integer, Integer>(0, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new Pair<Integer, Integer>(byteCodeStartLine, byteCodeEndLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setText(final String text) {
|
||||||
|
new WriteCommandAction(myProject) {
|
||||||
|
@Override
|
||||||
|
protected void run(Result result) throws Throwable {
|
||||||
|
myEditor.getDocument().setText(text);
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String generateToText(JetFile file) {
|
||||||
|
GenerationState state = new GenerationState(myProject, ClassBuilderFactory.TEXT);
|
||||||
|
try {
|
||||||
|
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||||
|
state.compile(file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
StringWriter out = new StringWriter(1024);
|
||||||
|
e.printStackTrace(new PrintWriter(out));
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder answer = new StringBuilder();
|
||||||
|
|
||||||
|
final ClassFileFactory factory = state.getFactory();
|
||||||
|
for (String filename : factory.files()) {
|
||||||
|
answer.append("// ================ ");
|
||||||
|
answer.append(filename);
|
||||||
|
answer.append(" =================\n");
|
||||||
|
answer.append(factory.asText(filename)).append("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return answer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Factory implements ToolWindowFactory {
|
||||||
|
@Override
|
||||||
|
public void createToolWindowContent(Project project, ToolWindow toolWindow) {
|
||||||
|
toolWindow.getContentManager().addContent(ContentFactory.SERVICE.getInstance().createContent(new BytecodeToolwindow(project), "", false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Location {
|
||||||
|
final Editor editor;
|
||||||
|
final long modificationStamp;
|
||||||
|
final int startOffset;
|
||||||
|
final int endOffset;
|
||||||
|
|
||||||
|
private Location(Editor editor) {
|
||||||
|
this.editor = editor;
|
||||||
|
modificationStamp = editor != null ? editor.getDocument().getModificationStamp() : 0;
|
||||||
|
startOffset = editor != null ? editor.getSelectionModel().getSelectionStart() : 0;
|
||||||
|
endOffset = editor != null ? editor.getSelectionModel().getSelectionEnd() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location fromEditor(Editor editor) {
|
||||||
|
return new Location(editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Location)) return false;
|
||||||
|
|
||||||
|
Location location = (Location) o;
|
||||||
|
|
||||||
|
if (endOffset != location.endOffset) return false;
|
||||||
|
if (modificationStamp != location.modificationStamp) return false;
|
||||||
|
if (startOffset != location.startOffset) return false;
|
||||||
|
if (editor != null ? !editor.equals(location.editor) : location.editor != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = editor != null ? editor.hashCode() : 0;
|
||||||
|
result = 31 * result + (int) (modificationStamp ^ (modificationStamp >>> 32));
|
||||||
|
result = 31 * result + startOffset;
|
||||||
|
result = 31 * result + endOffset;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
namespace a {
|
namespace a {
|
||||||
val foo = <error>bar()</error>
|
val foo = <error descr="[TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM] Type checking has run into a recursive problem">bar()</error>
|
||||||
|
|
||||||
fun bar() = foo
|
fun bar() = foo
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace b {
|
namespace b {
|
||||||
fun foo() = <error>bar()</error>
|
fun foo() = bar()
|
||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = <error descr="[TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM] Type checking has run into a recursive problem">foo()</error>
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace c {
|
namespace c {
|
||||||
fun bazz() = <error>bar()</error>
|
fun bazz() = bar()
|
||||||
|
|
||||||
fun foo() = bazz()
|
fun foo() = <error descr="[TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM] Type checking has run into a recursive problem">bazz()</error>
|
||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = foo()
|
||||||
}
|
}
|
||||||
@@ -39,4 +39,4 @@ namespace ok {
|
|||||||
|
|
||||||
fun bar() = foo()
|
fun bar() = foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
namespace std
|
namespace std
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
val <T> Collection<T>.size : Int
|
||||||
|
get() = size()
|
||||||
|
|
||||||
|
val <T> Collection<T>.empty : Boolean
|
||||||
|
get() = isEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
namespace io {
|
namespace io {
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.charset.*
|
import java.nio.charset.*
|
||||||
@@ -30,7 +40,15 @@ namespace io {
|
|||||||
val ByteArray.inputStream : ByteArrayInputStream
|
val ByteArray.inputStream : ByteArrayInputStream
|
||||||
get() = ByteArrayInputStream(this)
|
get() = ByteArrayInputStream(this)
|
||||||
|
|
||||||
inline fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStream = ByteArrayInputStream(this, offset, length)
|
// inline fun ByteArray.inputStream(offset: Int, length: Int) = ByteArrayInputStream(this, offset, length)
|
||||||
|
|
||||||
|
fun InputStream.iterator() : ByteIterator =
|
||||||
|
object: ByteIterator() {
|
||||||
|
override val hasNext : Boolean
|
||||||
|
get() = available() > 0
|
||||||
|
|
||||||
|
override fun nextByte() = read().byt
|
||||||
|
}
|
||||||
|
|
||||||
val InputStream.buffered : BufferedInputStream
|
val InputStream.buffered : BufferedInputStream
|
||||||
get() = if(this is BufferedInputStream) this else BufferedInputStream(this)
|
get() = if(this is BufferedInputStream) this else BufferedInputStream(this)
|
||||||
@@ -40,8 +58,8 @@ namespace io {
|
|||||||
val InputStream.reader : InputStreamReader
|
val InputStream.reader : InputStreamReader
|
||||||
get() = InputStreamReader(this)
|
get() = InputStreamReader(this)
|
||||||
|
|
||||||
// val InputStream.bufferedReader : BufferedReader
|
val InputStream.bufferedReader : BufferedReader
|
||||||
// get() = buffered.reader
|
get() = BufferedReader(reader)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
inline fun InputStream.reader(charset: Charset) : InputStreamReader = InputStreamReader(this, charset)
|
inline fun InputStream.reader(charset: Charset) : InputStreamReader = InputStreamReader(this, charset)
|
||||||
@@ -53,18 +71,13 @@ namespace io {
|
|||||||
inline fun InputStream.reader(charsetDecoder: CharsetDecoder) = InputStreamReader(this, charsetDecoder)
|
inline fun InputStream.reader(charsetDecoder: CharsetDecoder) = InputStreamReader(this, charsetDecoder)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fun InputStream.iterator() : ByteIterator = object: ByteIterator() {
|
|
||||||
override val hasNext : Boolean
|
|
||||||
get() = available() > 0
|
|
||||||
|
|
||||||
override fun nextByte() = read().byt
|
|
||||||
}
|
|
||||||
|
|
||||||
// val Reader.buffered : BufferedReader
|
// val Reader.buffered : BufferedReader
|
||||||
// get() = if(this instanceof BufferedReader) this else BufferedReader(this)
|
// get() = if(this instanceof BufferedReader) this else BufferedReader(this)
|
||||||
|
|
||||||
// inline fun Reader.buffered(bufferSize: Int) = BufferedReader(this, bufferSize)
|
// inline fun Reader.buffered(bufferSize: Int) = BufferedReader(this, bufferSize)
|
||||||
|
|
||||||
|
// val String.reader = StringReader(this)
|
||||||
|
|
||||||
private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : InputStream() {
|
private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : InputStream() {
|
||||||
override fun read() : Int {
|
override fun read() : Int {
|
||||||
return System.`in`?.read() ?: -1
|
return System.`in`?.read() ?: -1
|
||||||
|
|||||||
Reference in New Issue
Block a user