Compile-time constants

This commit is contained in:
Andrey Breslav
2011-08-03 14:05:07 +04:00
parent 7b27ac1766
commit 4c8aec3b1b
91 changed files with 1271 additions and 331 deletions
+2 -2
View File
@@ -96,7 +96,7 @@ multiplicativeExpression
;
typeRHS
: prefixUnaryExpression typeOperation prefixUnaryExpression
: prefixUnaryExpression (typeOperation prefixUnaryExpression)*
;
prefixUnaryExpression
@@ -204,7 +204,7 @@ postfixUnaryOperation
: "++" : "--"
: callSuffix
: arrayAccess
: memberAccessOperation postfixUnaryOperation // TODO: Review
: memberAccessOperation postfixUnaryExpression // TODO: Review
;
callSuffix
+3 -4
View File
@@ -41,8 +41,8 @@ public interface JetNodeTypes {
JetNodeType ANNOTATION_ENTRY = new JetNodeType("ANNOTATION_ENTRY", JetAnnotationEntry.class);
JetNodeType TYPE_ARGUMENT_LIST = new JetNodeType("TYPE_ARGUMENT_LIST", JetTypeArgumentList.class);
JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetArgumentList.class);
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetArgument.class);
JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetValueArgumentList.class);
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetValueArgument.class);
JetNodeType TYPE_REFERENCE = new JetNodeType("TYPE_REFERENCE", JetTypeReference.class);
JetNodeType LABELED_TUPLE_ENTRY = new JetNodeType("LABELED_TUPLE_ENTRY");
JetNodeType LABELED_TUPLE_TYPE_ENTRY = new JetNodeType("LABELED_TUPLE_TYPE_ENTRY");
@@ -67,9 +67,8 @@ public interface JetNodeTypes {
JetNodeType BOOLEAN_CONSTANT = new JetNodeType("BOOLEAN_CONSTANT", JetConstantExpression.class);
JetNodeType FLOAT_CONSTANT = new JetNodeType("FLOAT_CONSTANT", JetConstantExpression.class);
JetNodeType CHARACTER_CONSTANT = new JetNodeType("CHARACTER_CONSTANT", JetConstantExpression.class);
JetNodeType STRING_CONSTANT = new JetNodeType("STRING_CONSTANT", JetConstantExpression.class);
JetNodeType RAW_STRING_CONSTANT = new JetNodeType("STRING_CONSTANT", JetConstantExpression.class);
JetNodeType INTEGER_CONSTANT = new JetNodeType("INTEGER_CONSTANT", JetConstantExpression.class);
JetNodeType LONG_CONSTANT = new JetNodeType("LONG_CONSTANT", JetConstantExpression.class);
JetNodeType STRING_TEMPLATE = new JetNodeType("STRING_TEMPLATE", JetStringTemplateExpression.class);
JetNodeType LONG_STRING_TEMPLATE_ENTRY = new JetNodeType("LONG_STRING_TEMPLATE_ENTRY", JetBlockStringTemplateEntry.class);
@@ -14,6 +14,7 @@ import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeProjection;
@@ -489,7 +490,9 @@ public class ExpressionCodegen extends JetVisitor {
@Override
public void visitConstantExpression(JetConstantExpression expression) {
myStack.push(StackValue.constant(expression.getValue(), expressionType(expression)));
CompileTimeConstant<?> compileTimeValue = bindingContext.getCompileTimeValue(expression);
assert compileTimeValue != null;
myStack.push(StackValue.constant(compileTimeValue.getValue(), expressionType(expression)));
}
@Override
@@ -816,7 +819,7 @@ public class ExpressionCodegen extends JetVisitor {
else {
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
List<JetExpression> args = new ArrayList<JetExpression>();
for (JetArgument argument : expression.getValueArguments()) {
for (JetValueArgument argument : expression.getValueArguments()) {
args.add(argument.getArgumentExpression());
}
return intrinsic.generate(this, v, expressionType(expression), expression, args, haveReceiver);
@@ -1006,9 +1009,9 @@ public class ExpressionCodegen extends JetVisitor {
}
private void pushMethodArguments(JetCall expression, List<Type> valueParameterTypes) {
List<JetArgument> args = expression.getValueArguments();
List<JetValueArgument> args = expression.getValueArguments();
for (int i = 0, argsSize = args.size(); i < argsSize; i++) {
JetArgument arg = args.get(i);
JetValueArgument arg = args.get(i);
gen(arg.getArgumentExpression(), valueParameterTypes.get(i));
}
}
@@ -1471,7 +1474,7 @@ public class ExpressionCodegen extends JetVisitor {
}
private void generateNewArray(JetCallExpression expression, Type type) {
List<JetArgument> args = expression.getValueArguments();
List<JetValueArgument> args = expression.getValueArguments();
if (args.size() != 1) {
throw new CompilationException("array constructor requires one value argument");
}
@@ -5,6 +5,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lexer.JetTokens;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
@@ -71,7 +72,9 @@ public class PropertyCodegen {
final JetExpression initializer = p.getInitializer();
if (initializer != null) {
if (initializer instanceof JetConstantExpression) {
value = ((JetConstantExpression) initializer).getValue();
CompileTimeConstant<?> compileTimeValue = state.getBindingContext().getCompileTimeValue(initializer);
assert compileTimeValue != null;
value = compileTimeValue.getValue();
}
}
final int modifiers;
@@ -28,7 +28,6 @@ public class JetSemanticServices {
private final OverloadResolver overloadResolver;
private final JetControlFlowDataTraceFactory flowDataTraceFactory;
private JetSemanticServices(JetStandardLibrary standardLibrary, JetControlFlowDataTraceFactory flowDataTraceFactory) {
this.standardLibrary = standardLibrary;
this.typeChecker = new JetTypeChecker(standardLibrary);
@@ -523,7 +523,7 @@ public class JetControlFlowProcessor {
}
private void visitCall(JetCall call) {
for (JetArgument argument : call.getValueArguments()) {
for (JetValueArgument argument : call.getValueArguments()) {
JetExpression argumentExpression = argument.getArgumentExpression();
if (argumentExpression != null) {
value(argumentExpression, false, false);
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.NamespaceType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -12,7 +13,7 @@ import java.util.List;
public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor {
private NamespaceType namespaceType;
public AbstractNamespaceDescriptorImpl(DeclarationDescriptor containingDeclaration, List<Annotation> annotations, String name) {
public AbstractNamespaceDescriptorImpl(DeclarationDescriptor containingDeclaration, List<AnnotationDescriptor> annotations, String name) {
super(containingDeclaration, annotations, name);
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
import org.jetbrains.jet.lang.types.*;
@@ -22,7 +23,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
public ClassDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name) {
super(containingDeclaration, annotations, name);
}
@@ -114,4 +115,4 @@ public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements Cl
public boolean hasConstructors() {
return !constructors.isEmpty();
}
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collections;
@@ -15,12 +16,12 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
private final boolean isPrimary;
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull List<Annotation> annotations, boolean isPrimary) {
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
super(containingDeclaration, annotations, "<init>");
this.isPrimary = isPrimary;
}
public ConstructorDescriptorImpl(@NotNull ConstructorDescriptor original, @NotNull List<Annotation> annotations, boolean isPrimary) {
public ConstructorDescriptorImpl(@NotNull ConstructorDescriptor original, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
super(original, annotations, "<init>");
this.isPrimary = isPrimary;
}
@@ -74,7 +75,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
protected FunctionDescriptorImpl createSubstitutedCopy() {
return new ConstructorDescriptorImpl(
this,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
isPrimary);
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
/**
@@ -2,6 +2,8 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.util.List;
@@ -14,7 +16,7 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
private final String name;
private final DeclarationDescriptor containingDeclaration;
public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, List<Annotation> annotations, String name) {
public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, List<AnnotationDescriptor> annotations, String name) {
super(annotations);
this.name = name;
this.containingDeclaration = containingDeclaration;
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.Variance;
@@ -26,7 +27,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
public FunctionDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name) {
super(containingDeclaration, annotations, name);
this.original = this;
@@ -34,10 +35,10 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
public FunctionDescriptorImpl(
@NotNull FunctionDescriptor original,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name) {
super(original.getContainingDeclaration(), annotations, name);
this.original = original.getOriginal();
this.original = original;
}
public FunctionDescriptorImpl initialize(
@@ -92,7 +93,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
@NotNull
@Override
public FunctionDescriptor getOriginal() {
return original;
return original == this ? this : original.getOriginal();
}
@Override
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
import org.jetbrains.jet.lang.types.*;
@@ -87,7 +88,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
throw new UnsupportedOperationException(); // TODO
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -13,7 +14,7 @@ import java.util.List;
public class LocalVariableDescriptor extends VariableDescriptorImpl {
public LocalVariableDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
@Nullable JetType type,
boolean mutable) {
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.Collections;
@@ -10,7 +11,7 @@ import java.util.Collections;
*/
public class ModuleDescriptor extends DeclarationDescriptorImpl {
public ModuleDescriptor(String name) {
super(null, Collections.<Annotation>emptyList(), name);
super(null, Collections.<AnnotationDescriptor>emptyList(), name);
}
@NotNull
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.resolve.DescriptorRenderer;
@@ -156,7 +157,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
assert typeConstructor == null : typeConstructor;
this.typeConstructor = new TypeConstructorImpl(
this,
Collections.<Annotation>emptyList(), // TODO : pass annotations from the class?
Collections.<AnnotationDescriptor>emptyList(), // TODO : pass annotations from the class?
!open,
getName(),
typeParameters,
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import java.util.List;
@@ -16,7 +17,7 @@ public abstract class MutableDeclarationDescriptor implements DeclarationDescrip
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
throw new UnsupportedOperationException(); // TODO
}
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.types.NamespaceType;
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.WritableScope;
import java.util.List;
@@ -13,7 +14,7 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp
private WritableScope memberScope;
public NamespaceDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<Annotation> annotations, @NotNull String name) {
public NamespaceDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
super(containingDeclaration, annotations, name);
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.List;
@@ -46,7 +47,7 @@ public interface NamespaceLike extends DeclarationDescriptor {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
return descriptor.getAnnotations();
}
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import java.util.Collections;
@@ -17,7 +18,7 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
protected PropertyAccessorDescriptor(
@NotNull MemberModifiers modifiers,
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
boolean hasBody) {
super(correspondingProperty.getContainingDeclaration(), annotations, name);
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.Variance;
@@ -25,7 +26,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Member
private PropertyDescriptor(
@Nullable PropertyDescriptor original,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull MemberModifiers memberModifiers,
boolean isVar,
@Nullable JetType receiverType,
@@ -43,7 +44,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Member
public PropertyDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull MemberModifiers memberModifiers,
boolean isVar,
@Nullable JetType receiverType,
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collections;
@@ -16,7 +17,7 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
private JetType returnType;
public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, @Nullable JetType returnType, boolean hasBody) {
public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @Nullable JetType returnType, boolean hasBody) {
super(modifiers, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody);
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType;
@@ -17,7 +18,7 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
private MutableValueParameterDescriptor parameter;
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, boolean hasBody) {
public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody) {
super(modifiers, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody);
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.LazyScopeAdapter;
import org.jetbrains.jet.lang.types.*;
@@ -17,7 +18,7 @@ import java.util.Set;
public class TypeParameterDescriptor extends DeclarationDescriptorImpl implements ClassifierDescriptor {
public static TypeParameterDescriptor createWithDefaultBound(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Variance variance,
@NotNull String name,
int index) {
@@ -28,7 +29,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
public static TypeParameterDescriptor createForFurtherModification(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Variance variance,
@NotNull String name,
int index) {
@@ -46,7 +47,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
private TypeParameterDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Variance variance,
@NotNull String name,
int index) {
@@ -116,7 +117,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
public JetType getDefaultType() {
if (defaultType == null) {
defaultType = new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
getTypeConstructor(),
TypeUtils.hasNullableBound(this),
Collections.<TypeProjection>emptyList(),
@@ -155,4 +156,4 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
public int getIndex() {
return index;
}
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -19,7 +20,7 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
public ValueParameterDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
int index,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
@Nullable JetType inType,
@NotNull JetType outType,
@@ -35,7 +36,7 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
public ValueParameterDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
int index,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
boolean isVar,
boolean hasDefaultValue,
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType;
@@ -22,8 +23,8 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
private final VariableDescriptor variableDescriptor;
private VariableAsFunctionDescriptor(VariableDescriptor variableDescriptor) {
super(variableDescriptor.getContainingDeclaration(), Collections.<Annotation>emptyList(), variableDescriptor.getName());
// super(variableDescriptor.getContainingDeclaration(), Collections.<Annotation>emptyList(), variableDescriptor.getName());
super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName());
// super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName());
this.variableDescriptor = variableDescriptor;
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import java.util.List;
@@ -15,7 +16,7 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
public VariableDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
@Nullable JetType inType,
@Nullable JetType outType) {
@@ -0,0 +1,10 @@
package org.jetbrains.jet.lang.descriptors.annotations;
import java.util.List;
/**
* @author abreslav
*/
public interface Annotated {
List<AnnotationDescriptor> getAnnotations();
}
@@ -0,0 +1,19 @@
package org.jetbrains.jet.lang.descriptors.annotations;
import java.util.List;
/**
* @author abreslav
*/
public abstract class AnnotatedImpl implements Annotated {
private final List<AnnotationDescriptor> annotations;
public AnnotatedImpl(List<AnnotationDescriptor> annotations) {
this.annotations = annotations;
}
@Override
public List<AnnotationDescriptor> getAnnotations() {
return annotations;
}
}
@@ -0,0 +1,29 @@
package org.jetbrains.jet.lang.descriptors.annotations;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.constants.*;
/**
* @author abreslav
*/
public interface AnnotationArgumentVisitor<R, D> {
R visitLongValue(@NotNull LongValue value, D data);
R visitIntValue(IntValue value, D data);
R visitErrorValue(ErrorValue value, D data);
R visitShortValue(ShortValue value, D data);
R visitByteValue(ByteValue value, D data);
R visitDoubleValue(DoubleValue value, D data);
R visitBooleanValue(BooleanValue value, D data);
R visitCharValue(CharValue value, D data);
R visitStringValue(StringValue value, D data);
R visitNullValue(NullValue value, D data);
}
@@ -0,0 +1,33 @@
package org.jetbrains.jet.lang.descriptors.annotations;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
import java.util.List;
/**
* @author abreslav
*/
public class AnnotationDescriptor {
private JetType annotationType;
private List<CompileTimeConstant<?>> valueArguments;
@NotNull
public JetType getType() {
return annotationType;
}
@NotNull
public List<CompileTimeConstant<?>> getValueArguments() {
return valueArguments;
}
public void setAnnotationType(@NotNull JetType annotationType) {
this.annotationType = annotationType;
}
public void setValueArguments(@NotNull List<CompileTimeConstant<?>> valueArguments) {
this.valueArguments = valueArguments;
}
}
@@ -19,7 +19,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
private static final TokenSet WHEN_CONDITION_RECOVERY_SET_WITH_DOUBLE_ARROW = TokenSet.create(RBRACE, IN_KEYWORD, NOT_IN, IS_KEYWORD, NOT_IS, ELSE_KEYWORD, DOUBLE_ARROW, DOT);
private static final TokenSet TYPE_ARGUMENT_LIST_STOPPERS = TokenSet.create(
INTEGER_LITERAL, LONG_LITERAL, FLOAT_LITERAL, CHARACTER_LITERAL, OPEN_QUOTE, RAW_STRING_LITERAL,
INTEGER_LITERAL, FLOAT_LITERAL, CHARACTER_LITERAL, OPEN_QUOTE, RAW_STRING_LITERAL,
NAMESPACE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, THIS_KEYWORD, VAL_KEYWORD, VAR_KEYWORD,
FUN_KEYWORD, FOR_KEYWORD, NULL_KEYWORD,
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD,
@@ -41,7 +41,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
// literal constant
TRUE_KEYWORD, FALSE_KEYWORD,
OPEN_QUOTE, RAW_STRING_LITERAL,
INTEGER_LITERAL, LONG_LITERAL, CHARACTER_LITERAL, FLOAT_LITERAL,
INTEGER_LITERAL, CHARACTER_LITERAL, FLOAT_LITERAL,
NULL_KEYWORD,
LBRACE, // functionLiteral
@@ -317,7 +317,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
* : typeArguments? valueArguments (getEntryPoint? functionLiteral)
* : typeArguments (getEntryPoint? functionLiteral)
* : arrayAccess
* : memberAccessOperation postfixUnaryOperation // TODO: Review
* : memberAccessOperation postfixUnaryExpression // TODO: Review
* ;
*/
private void parsePostfixExpression() {
@@ -637,14 +637,11 @@ public class JetExpressionParsing extends AbstractJetParsing {
parseOneTokenExpression(BOOLEAN_CONSTANT);
}
else if (at(RAW_STRING_LITERAL)) {
parseOneTokenExpression(STRING_CONSTANT);
parseOneTokenExpression(RAW_STRING_CONSTANT);
}
else if (at(INTEGER_LITERAL)) {
parseOneTokenExpression(INTEGER_CONSTANT);
}
else if (at(LONG_LITERAL)) {
parseOneTokenExpression(LONG_CONSTANT);
}
else if (at(CHARACTER_LITERAL)) {
parseOneTokenExpression(CHARACTER_CONSTANT);
}
@@ -16,7 +16,7 @@ public class JetAnnotation extends JetElement {
@Override
public void accept(JetVisitor visitor) {
visitor.visitAttributeAnnotation(this);
visitor.visitAnnotation(this);
}
public List<JetAnnotationEntry> getEntries() {
@@ -11,14 +11,14 @@ import java.util.List;
/**
* @author max
*/
public class JetAnnotationEntry extends JetElement {
public class JetAnnotationEntry extends JetElement implements JetCall {
public JetAnnotationEntry(@NotNull ASTNode node) {
super(node);
}
@Override
public void accept(JetVisitor visitor) {
visitor.visitAttribute(this);
visitor.visitAnnotationEntry(this);
}
@Nullable @IfNotParsed
@@ -26,15 +26,41 @@ public class JetAnnotationEntry extends JetElement {
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
}
@Nullable
public JetArgumentList getArgumentList() {
return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
@Override
public JetValueArgumentList getValueArgumentList() {
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
}
@NotNull
public List<JetArgument> getArguments() {
JetArgumentList list = getArgumentList();
return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
@Override
public List<JetValueArgument> getValueArguments() {
JetValueArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
}
@NotNull
@Override
public List<JetExpression> getFunctionLiteralArguments() {
return Collections.emptyList();
}
@NotNull
@Override
public List<JetTypeProjection> getTypeArguments() {
JetTypeReference typeReference = getTypeReference();
if (typeReference != null) {
JetTypeElement typeElement = typeReference.getTypeElement();
if (typeElement instanceof JetUserType) {
JetUserType userType = (JetUserType) typeElement;
return userType.getTypeArguments();
}
}
return Collections.emptyList();
}
@NotNull
@Override
public JetElement asElement() {
return this;
}
}
@@ -11,10 +11,10 @@ import java.util.List;
*/
public interface JetCall extends PsiElement {
@Nullable
JetArgumentList getValueArgumentList();
JetValueArgumentList getValueArgumentList();
@NotNull
List<JetArgument> getValueArguments();
List<JetValueArgument> getValueArguments();
@NotNull
List<JetExpression> getFunctionLiteralArguments();
@@ -28,8 +28,8 @@ public class JetCallExpression extends JetExpression implements JetCall {
@Override
@Nullable
public JetArgumentList getValueArgumentList() {
return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
public JetValueArgumentList getValueArgumentList() {
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
}
@Nullable
@@ -51,9 +51,9 @@ public class JetCallExpression extends JetExpression implements JetCall {
@Override
@NotNull
public List<JetArgument> getValueArguments() {
JetArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
public List<JetValueArgument> getValueArguments() {
JetValueArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
}
@NotNull
@@ -1,9 +1,7 @@
package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetNodeTypes;
/**
* @author max
@@ -17,78 +15,4 @@ public class JetConstantExpression extends JetExpression {
public void accept(JetVisitor visitor) {
visitor.visitConstantExpression(this);
}
public Object getValue() {
IElementType elementType = getNode().getElementType();
String nodeText = getNode().getText();
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
try {
if (nodeText.startsWith("0x") || nodeText.startsWith("0X")) {
String hexString = nodeText.substring(2);
int length = hexString.length();
if (length > 8) {
return Long.parseLong(hexString);
}
return getRangedValue(Long.parseLong(hexString, 16));
}
if (nodeText.startsWith("0b") || nodeText.startsWith("0B")) {
return getRangedValue(Long.parseLong(nodeText.substring(2), 2));
}
return getRangedValue(Long.parseLong(nodeText));
}
catch (NumberFormatException e) {
return null;
}
}
else if (elementType == JetNodeTypes.LONG_CONSTANT) {
if (nodeText.endsWith("l") || nodeText.endsWith("L")) {
return Long.parseLong(nodeText.substring(0, nodeText.length() - 1));
}
return Long.parseLong(nodeText);
}
else if (elementType == JetNodeTypes.FLOAT_CONSTANT) {
assert nodeText.length() > 0;
char lastChar = nodeText.charAt(nodeText.length() - 1);
if (lastChar == 'f' || lastChar == 'F') {
return Float.parseFloat(nodeText.substring(0, nodeText.length() - 1));
}
else if (lastChar == 'd' || lastChar == 'D') {
return Double.parseDouble(nodeText.substring(0, nodeText.length() - 1));
}
else {
return Double.parseDouble(nodeText);
}
}
else if (elementType == JetNodeTypes.BOOLEAN_CONSTANT) {
return Boolean.parseBoolean(nodeText);
}
else if (elementType == JetNodeTypes.CHARACTER_CONSTANT) {
return nodeText.charAt(1);
}
else if (elementType == JetNodeTypes.STRING_CONSTANT) {
int tail = nodeText.length();
if (nodeText.endsWith("\"")) tail--;
return nodeText.substring(1, tail);
}
else if (elementType == JetNodeTypes.NULL) {
return null;
}
else {
throw new IllegalArgumentException("Unsupported constant: " + this);
}
}
private Object getRangedValue(long longValue) {
if (Byte.MIN_VALUE <= longValue && longValue <= Byte.MAX_VALUE) {
return (byte) longValue;
}
if (Short.MIN_VALUE <= longValue && longValue <= Short.MAX_VALUE) {
return (short) longValue;
}
if (Integer.MIN_VALUE <= longValue && longValue <= Integer.MAX_VALUE) {
return (int) longValue;
}
return longValue;
}
}
@@ -22,14 +22,14 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J
}
@Nullable
public JetArgumentList getValueArgumentList() {
return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
public JetValueArgumentList getValueArgumentList() {
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
}
@NotNull
public List<JetArgument> getValueArguments() {
JetArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
public List<JetValueArgument> getValueArguments() {
JetValueArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
}
@NotNull
@@ -23,14 +23,14 @@ public class JetDelegatorToThisCall extends JetDelegationSpecifier implements Je
}
@Nullable
public JetArgumentList getValueArgumentList() {
return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
public JetValueArgumentList getValueArgumentList() {
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
}
@NotNull
public List<JetArgument> getValueArguments() {
JetArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
public List<JetValueArgument> getValueArguments() {
JetValueArgumentList list = getValueArgumentList();
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
}
@NotNull
@@ -24,13 +24,13 @@ public class JetModifierList extends JetElement {
}
@NotNull
public List<JetAnnotation> getAttributeAnnotations() {
public List<JetAnnotation> getAnnotations() {
return findChildrenByType(JetNodeTypes.ANNOTATION);
}
public List<JetAnnotationEntry> getAttributes() {
public List<JetAnnotationEntry> getAnnotationEntries() {
List<JetAnnotationEntry> answer = null;
for (JetAnnotation annotation : getAttributeAnnotations()) {
for (JetAnnotation annotation : getAnnotations()) {
if (answer == null) answer = new ArrayList<JetAnnotationEntry>();
answer.addAll(annotation.getEntries());
}
@@ -7,7 +7,7 @@ import org.jetbrains.jet.lexer.JetTokens;
/**
* @author max
*/
public class JetNamedArgumentImpl extends JetArgument {
public class JetNamedArgumentImpl extends JetValueArgument {
public JetNamedArgumentImpl(@NotNull ASTNode node) {
super(node);
}
@@ -20,15 +20,15 @@ package org.jetbrains.jet.lang.psi;
//
// @Override
// @Nullable
// public JetArgumentList getValueArgumentList() {
// return (JetArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
// public JetValueArgumentList getValueArgumentList() {
// return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
// }
//
// @Override
// @NotNull
// public List<JetArgument> getValueArguments() {
// JetArgumentList list = getValueArgumentList();
// return list != null ? list.getArguments() : Collections.<JetArgument>emptyList();
// public List<JetValueArgument> getValueArguments() {
// JetValueArgumentList list = getValueArgumentList();
// return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
// }
//
// @Override
@@ -31,7 +31,7 @@ public class JetTypeReference extends JetElement {
return findChildByClass(JetTypeElement.class);
}
public List<JetAnnotationEntry> getAttributes() {
public List<JetAnnotationEntry> getAnnotations() {
List<JetAnnotationEntry> answer = null;
for (JetAnnotation annotation : getAttributeAnnotations()) {
if (answer == null) answer = new ArrayList<JetAnnotationEntry>();
@@ -9,8 +9,8 @@ import org.jetbrains.jet.lexer.JetTokens;
/**
* @author max
*/
public class JetArgument extends JetElement implements ValueArgumentPsi {
public JetArgument(@NotNull ASTNode node) {
public class JetValueArgument extends JetElement implements ValueArgumentPsi {
public JetValueArgument(@NotNull ASTNode node) {
super(node);
}
@@ -9,17 +9,17 @@ import java.util.List;
/**
* @author max
*/
public class JetArgumentList extends JetElement {
public JetArgumentList(@NotNull ASTNode node) {
public class JetValueArgumentList extends JetElement {
public JetValueArgumentList(@NotNull ASTNode node) {
super(node);
}
@Override
public void accept(JetVisitor visitor) {
visitor.visitArgumentList(this);
visitor.visitValueArgumentList(this);
}
public List<JetArgument> getArguments() {
public List<JetValueArgument> getArguments() {
return findChildrenByType(JetNodeTypes.VALUE_ARGUMENT);
}
}
@@ -62,11 +62,11 @@ public class JetVisitor extends PsiElementVisitor {
visitJetElement(list);
}
public void visitAttributeAnnotation(JetAnnotation annotation) {
public void visitAnnotation(JetAnnotation annotation) {
visitJetElement(annotation);
}
public void visitAttribute(JetAnnotationEntry annotationEntry) {
public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) {
visitJetElement(annotationEntry);
}
@@ -118,11 +118,11 @@ public class JetVisitor extends PsiElementVisitor {
visitJetElement(typeReference);
}
public void visitArgumentList(JetArgumentList list) {
public void visitValueArgumentList(JetValueArgumentList list) {
visitJetElement(list);
}
public void visitArgument(JetArgument argument) {
public void visitArgument(JetValueArgument argument) {
visitJetElement(argument);
}
@@ -139,4 +139,4 @@ public class AnalyzingUtils {
}
});
}
}
}
@@ -1,10 +1,15 @@
package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collections;
import java.util.List;
@@ -13,23 +18,85 @@ import java.util.List;
* @author abreslav
*/
public class AnnotationResolver {
public static final AnnotationResolver INSTANCE = new AnnotationResolver();
private AnnotationResolver() {}
private final BindingTrace trace;
@NotNull
public List<Annotation> resolveAnnotations(@NotNull List<JetAnnotationEntry> annotationEntryElements) {
return Collections.emptyList(); // TODO
// if (annotationEntryElements.isEmpty()) {
// }
// throw new UnsupportedOperationException(); // TODO
public AnnotationResolver(JetSemanticServices semanticServices, BindingTrace trace) {
this.trace = trace;
}
@NotNull
public List<Annotation> resolveAnnotations(@Nullable JetModifierList modifierList) {
public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @NotNull List<JetAnnotationEntry> annotationEntryElements) {
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
List<AnnotationDescriptor> result = Lists.newArrayList();
// for (JetAnnotationEntry entryElement : annotationEntryElements) {
// JetType jetType = typeInferrer.checkTypeInitializerCall(scope, entryElement.getTypeReference(), entryElement);
// AnnotationDescriptor descriptor = new AnnotationDescriptor();
// descriptor.setAnnotationType(jetType);
// result.add(descriptor);
// }
return result;
}
@NotNull
public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @Nullable JetModifierList modifierList) {
if (modifierList == null) {
return Collections.emptyList();
}
return resolveAnnotations(modifierList.getAttributes());
return resolveAnnotations(scope, modifierList.getAnnotationEntries());
}
}
public CompileTimeConstant<?> resolveAnnotationArgument(@NotNull JetExpression expression, @NotNull JetType expectedType) {
final CompileTimeConstant<?>[] result = new CompileTimeConstant<?>[1];
// expression.accept(new JetVisitor() {
// @Override
// public void visitConstantExpression(JetConstantExpression expression) {
// JetType type = typeInferrer.getType(JetScope.EMPTY, expression, false, expectedType);
// if (type != null) {
// Object value = expression.getValue();
//
// }
// }
//
// @Override
// public void visitAnnotation(JetAnnotation annotation) {
// super.visitAnnotation(annotation); // TODO
// }
//
// @Override
// public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) {
// super.visitAnnotationEntry(annotationEntry); // TODO
// }
//
// @Override
// public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
// expression.getExpression().accept(this);
// }
//
// @Override
// public void visitJetElement(JetElement element) {
// trace.getErrorHandler().genericError(element.getNode(), "Not allowed as an annotation argument");
// }
// });
return result[0];
}
@NotNull
public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations) {
List<AnnotationDescriptor> result = Lists.newArrayList();
for (JetAnnotationEntry annotation : annotations) {
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
result.add(annotationDescriptor);
trace.recordAnnotationResolution(annotation, annotationDescriptor);
}
return result;
}
@NotNull
public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList) {
if (modifierList == null) {
return Collections.emptyList();
}
return createAnnotationStubs(modifierList.getAnnotationEntries());
}
}
@@ -5,7 +5,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetDiagnostic;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
@@ -22,6 +24,10 @@ public interface BindingContext {
TypeParameterDescriptor getTypeParameterDescriptor(JetTypeParameter declaration);
FunctionDescriptor getFunctionDescriptor(JetNamedFunction declaration);
ConstructorDescriptor getConstructorDescriptor(JetElement declaration);
AnnotationDescriptor getAnnotationDescriptor(JetAnnotationEntry annotationEntry);
@Nullable
CompileTimeConstant<?> getCompileTimeValue(JetExpression expression);
VariableDescriptor getVariableDescriptor(JetProperty declaration);
VariableDescriptor getVariableDescriptor(JetParameter declaration);
@@ -5,7 +5,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
/**
@@ -25,6 +27,10 @@ public interface BindingTrace {
void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type);
void recordAnnotationResolution(@NotNull JetAnnotationEntry annotationEntry, @NotNull AnnotationDescriptor annotationDescriptor);
void recordCompileTimeValue(@NotNull JetExpression expression, @NotNull CompileTimeConstant<?> value);
void recordBlock(JetFunctionLiteralExpression expression);
void recordStatement(@NotNull JetElement statement);
@@ -5,7 +5,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
/**
@@ -48,6 +50,16 @@ public class BindingTraceAdapter implements BindingTrace {
originalTrace.recordTypeResolution(typeReference, type);
}
@Override
public void recordAnnotationResolution(@NotNull JetAnnotationEntry annotationEntry, @NotNull AnnotationDescriptor annotationDescriptor) {
originalTrace.recordAnnotationResolution(annotationEntry, annotationDescriptor);
}
@Override
public void recordCompileTimeValue(@NotNull JetExpression expression, @NotNull CompileTimeConstant<?> value) {
originalTrace.recordCompileTimeValue(expression, value);
}
public void recordBlock(JetFunctionLiteralExpression expression) {
originalTrace.recordBlock(expression);
}
@@ -10,7 +10,9 @@ import org.jetbrains.jet.lang.CollectingErrorHandler;
import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
import org.jetbrains.jet.lang.JetDiagnostic;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
import java.util.*;
@@ -41,6 +43,8 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
private final List<JetDiagnostic> diagnostics = Lists.newArrayList();
private final ErrorHandlerWithRegions errorHandler = new ErrorHandlerWithRegions(new CollectingErrorHandler(diagnostics));
private Map<JetAnnotationEntry, AnnotationDescriptor> annotationDescriptos = Maps.newHashMap();
private Map<JetExpression, CompileTimeConstant<?>> compileTimeValues = Maps.newHashMap();
public BindingTraceContext() {
}
@@ -108,6 +112,16 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
safePut(types, typeReference, type);
}
@Override
public void recordAnnotationResolution(@NotNull JetAnnotationEntry annotationEntry, @NotNull AnnotationDescriptor annotationDescriptor) {
safePut(annotationDescriptos, annotationEntry, annotationDescriptor);
}
@Override
public void recordCompileTimeValue(@NotNull JetExpression expression, @NotNull CompileTimeConstant<?> value) {
safePut(compileTimeValues, expression, value);
}
@Override
public void recordDeclarationResolution(@NotNull PsiElement declaration, @NotNull DeclarationDescriptor descriptor) {
safePut(descriptorToDeclarations, getOriginal(descriptor), declaration);
@@ -234,6 +248,16 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
return constructorDeclarationsToDescriptors.get(declaration);
}
@Override
public AnnotationDescriptor getAnnotationDescriptor(JetAnnotationEntry annotationEntry) {
return annotationDescriptos.get(annotationEntry);
}
@Override
public CompileTimeConstant<?> getCompileTimeValue(JetExpression expression) {
return compileTimeValues.get(expression);
}
@Override
public JetType resolveTypeReference(JetTypeReference typeReference) {
return types.get(typeReference);
@@ -14,6 +14,7 @@ import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.cfg.LoopInfo;
import org.jetbrains.jet.lang.cfg.pseudocode.*;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lexer.JetTokens;
@@ -32,6 +33,7 @@ public class ClassDescriptorResolver {
private final TypeResolver typeResolverNotCheckingBounds;
private final BindingTrace trace;
private final JetControlFlowDataTraceFactory flowDataTraceFactory;
private final AnnotationResolver annotationResolver;
public ClassDescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace, JetControlFlowDataTraceFactory flowDataTraceFactory) {
this.semanticServices = semanticServices;
@@ -39,13 +41,14 @@ public class ClassDescriptorResolver {
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
this.trace = trace;
this.flowDataTraceFactory = flowDataTraceFactory;
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
}
@Nullable
public ClassDescriptor resolveClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement) {
final ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
scope.getContainingDeclaration(),
AnnotationResolver.INSTANCE.resolveAnnotations(classElement.getModifierList()),
annotationResolver.resolveAnnotations(scope, classElement.getModifierList()),
JetPsiUtil.safeName(classElement.getName()));
trace.recordDeclarationResolution(classElement, classDescriptor);
@@ -126,7 +129,7 @@ public class ClassDescriptorResolver {
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
descriptor,
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()),
index
@@ -172,7 +175,7 @@ public class ClassDescriptorResolver {
public FunctionDescriptorImpl resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) {
final FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
containingDescriptor,
AnnotationResolver.INSTANCE.resolveAnnotations(function.getModifierList()),
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
JetPsiUtil.safeName(function.getName())
);
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler()).setDebugName("Function descriptor header scope");
@@ -260,7 +263,7 @@ public class ClassDescriptorResolver {
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
declarationDescriptor,
index,
AnnotationResolver.INSTANCE.resolveAnnotations(valueParameter.getModifierList()),
annotationResolver.createAnnotationStubs(valueParameter.getModifierList()),
JetPsiUtil.safeName(valueParameter.getName()),
valueParameter.isMutable() ? type : null,
type,
@@ -289,7 +292,7 @@ public class ClassDescriptorResolver {
// : typeResolver.resolveType(extensibleScope, extendsBound);
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
containingDescriptor,
AnnotationResolver.INSTANCE.resolveAnnotations(typeParameter.getModifierList()),
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()),
index
@@ -423,7 +426,7 @@ public class ClassDescriptorResolver {
public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetParameter parameter, @NotNull JetType type) {
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
containingDeclaration,
AnnotationResolver.INSTANCE.resolveAnnotations(parameter.getModifierList()),
annotationResolver.createAnnotationStubs(parameter.getModifierList()),
JetPsiUtil.safeName(parameter.getName()),
type,
parameter.isMutable());
@@ -442,7 +445,7 @@ public class ClassDescriptorResolver {
public VariableDescriptor resolveLocalVariableDescriptorWithType(DeclarationDescriptor containingDeclaration, JetProperty property, JetType type) {
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
containingDeclaration,
AnnotationResolver.INSTANCE.resolveAnnotations(property.getModifierList()),
annotationResolver.createAnnotationStubs(property.getModifierList()),
JetPsiUtil.safeName(property.getName()),
type,
property.isVar());
@@ -454,7 +457,7 @@ public class ClassDescriptorResolver {
JetModifierList modifierList = objectDeclaration.getModifierList();
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
containingDeclaration,
AnnotationResolver.INSTANCE.resolveAnnotations(modifierList),
annotationResolver.createAnnotationStubs(modifierList),
resolveModifiers(modifierList, DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
false,
null,
@@ -504,7 +507,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
containingDeclaration,
AnnotationResolver.INSTANCE.resolveAnnotations(modifierList),
annotationResolver.resolveAnnotations(scope, modifierList),
resolveModifiers(modifierList, DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
isVar,
receiverType,
@@ -571,7 +574,7 @@ public class ClassDescriptorResolver {
}
PropertySetterDescriptor setterDescriptor = null;
if (setter != null) {
List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(setter.getModifierList());
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList());
JetParameter parameter = setter.getParameter();
setterDescriptor = new PropertySetterDescriptor(
@@ -619,7 +622,7 @@ public class ClassDescriptorResolver {
PropertyGetterDescriptor getterDescriptor = null;
JetPropertyAccessor getter = property.getGetter();
if (getter != null) {
List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(getter.getModifierList());
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList());
JetType returnType = null;
JetTypeReference returnTypeReference = getter.getReturnTypeReference();
@@ -650,7 +653,7 @@ public class ClassDescriptorResolver {
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
classDescriptor,
AnnotationResolver.INSTANCE.resolveAnnotations(modifierList),
annotationResolver.resolveAnnotations(scope, modifierList),
isPrimary
);
trace.recordDeclarationResolution(declarationToTrace, constructorDescriptor);
@@ -693,7 +696,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
classDescriptor,
AnnotationResolver.INSTANCE.resolveAnnotations(modifierList),
annotationResolver.resolveAnnotations(scope, modifierList),
resolveModifiers(modifierList, DEFAULT_MODIFIERS),
isMutable,
null,
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetStandardClasses;
@@ -149,7 +150,7 @@ public class TopDownAnalyzer {
if (namespaceDescriptor == null) {
namespaceDescriptor = new NamespaceDescriptorImpl(
owner.getOriginal(),
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
name
);
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler()).setDebugName("Namespace member scope"));
@@ -226,7 +227,7 @@ public class TopDownAnalyzer {
}
private void createPrimaryConstructor(MutableClassDescriptor mutableClassDescriptor) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.<Annotation>emptyList(), true);
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.<AnnotationDescriptor>emptyList(), true);
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList());
// TODO : make the constructor private?
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor);
@@ -482,6 +483,7 @@ public class TopDownAnalyzer {
private void resolveBehaviorDeclarationBodies() {
resolveDelegationSpecifierLists();
resolveClassAnnotations();
resolveAnonymousInitializers();
resolvePropertyDeclarationBodies();
@@ -585,7 +587,7 @@ public class TopDownAnalyzer {
typeInferrer.checkTypeInitializerCall(scopeForConstructor, typeReference, call);
}
else {
JetArgumentList valueArgumentList = call.getValueArgumentList();
JetValueArgumentList valueArgumentList = call.getValueArgumentList();
assert valueArgumentList != null;
trace.getErrorHandler().genericError(valueArgumentList.getNode(),
"Class " + JetPsiUtil.safeName(jetClass.getName()) + " must have a constructor in order to be able to initialize supertypes");
@@ -624,6 +626,10 @@ public class TopDownAnalyzer {
}
}
private void resolveClassAnnotations() {
}
private void resolveAnonymousInitializers() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
resolveAnonymousInitializers(entry.getKey(), entry.getValue());
@@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.*;
@@ -19,11 +20,13 @@ public class TypeResolver {
private final JetSemanticServices semanticServices;
private final BindingTrace trace;
private final boolean checkBounds;
private final AnnotationResolver annotationResolver;
public TypeResolver(JetSemanticServices semanticServices, BindingTrace trace, boolean checkBounds) {
this.semanticServices = semanticServices;
this.trace = trace;
this.checkBounds = checkBounds;
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
}
@NotNull
@@ -31,7 +34,7 @@ public class TypeResolver {
JetType cachedType = trace.getBindingContext().resolveTypeReference(typeReference);
if (cachedType != null) return cachedType;
final List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(typeReference.getAttributes());
final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations());
JetTypeElement typeElement = typeReference.getTypeElement();
JetType type = resolveTypeElement(scope, annotations, typeElement, false);
@@ -40,7 +43,7 @@ public class TypeResolver {
}
@NotNull
private JetType resolveTypeElement(final JetScope scope, final List<Annotation> annotations, JetTypeElement typeElement, final boolean nullable) {
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations, JetTypeElement typeElement, final boolean nullable) {
final JetType[] result = new JetType[1];
if (typeElement != null) {
typeElement.accept(new JetVisitor() {
@@ -0,0 +1,43 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class BooleanValue implements CompileTimeConstant<Boolean> {
public static final BooleanValue FALSE = new BooleanValue(false);
public static final BooleanValue TRUE = new BooleanValue(true);
private final boolean value;
private BooleanValue(boolean value) {
this.value = value;
}
@Override
public Boolean getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getBooleanType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitBooleanValue(this, data);
}
@Override
public String toString() {
return String.valueOf(value);
}
}
@@ -0,0 +1,48 @@
package org.jetbrains.jet.lang.resolve.constants;
import com.google.common.base.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class ByteValue implements CompileTimeConstant<Byte> {
public static final Function<Long, ByteValue> CREATE = new Function<Long, ByteValue>() {
@Override
public ByteValue apply(@Nullable Long input) {
assert input != null;
return new ByteValue(input.byteValue());
}
};
private final byte value;
public ByteValue(byte value) {
this.value = value;
}
@Override
public Byte getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getByteType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitByteValue(this, data);
}
@Override
public String toString() {
return value + ".byt";
}
}
@@ -0,0 +1,39 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class CharValue implements CompileTimeConstant<Character> {
private final char value;
public CharValue(char value) {
this.value = value;
}
@Override
public Character getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getCharType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitCharValue(this, data);
}
@Override
public String toString() {
return "#" + ((int) value) + "(" + value + ")";
}
}
@@ -0,0 +1,18 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public interface CompileTimeConstant<T> {
T getValue();
@NotNull
JetType getType(@NotNull JetStandardLibrary standardLibrary);
<R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data);
}
@@ -0,0 +1,266 @@
package org.jetbrains.jet.lang.resolve.constants;
import com.google.common.base.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.psi.JetEscapeStringTemplateEntry;
import org.jetbrains.jet.lang.psi.JetLiteralStringTemplateEntry;
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
import org.jetbrains.jet.lang.psi.JetVisitor;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.types.*;
import java.util.List;
/**
* @author abreslav
*/
public class CompileTimeConstantResolver {
public static final ErrorValue OUT_OF_RANGE = new ErrorValue("The value is out of range");
private final JetSemanticServices semanticServices;
private final BindingTrace trace;
public CompileTimeConstantResolver(@NotNull JetSemanticServices semanticServices, @NotNull BindingTrace trace) {
this.semanticServices = semanticServices;
this.trace = trace;
}
@NotNull
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
if (noExpectedType(expectedType)) {
Long value = parseLongValue(text);
if (value == null) {
return OUT_OF_RANGE;
}
if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
return new IntValue(value.intValue());
}
return new LongValue(value);
}
Function<Long, ? extends CompileTimeConstant<?>> create;
long lowerBound;
long upperBound;
TypeConstructor constructor = expectedType.getConstructor();
if (constructor == standardLibrary.getInt().getTypeConstructor()) {
create = IntValue.CREATE;
lowerBound = Integer.MIN_VALUE;
upperBound = Integer.MAX_VALUE;
}
else if (constructor == standardLibrary.getLong().getTypeConstructor()) {
create = LongValue.CREATE;
lowerBound = Long.MIN_VALUE;
upperBound = Long.MAX_VALUE;
}
else if (constructor == standardLibrary.getShort().getTypeConstructor()) {
create = ShortValue.CREATE;
lowerBound = Short.MIN_VALUE;
upperBound = Short.MAX_VALUE;
}
else if (constructor == standardLibrary.getByte().getTypeConstructor()) {
create = ByteValue.CREATE;
lowerBound = Byte.MIN_VALUE;
upperBound = Byte.MAX_VALUE;
}
else {
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
JetType intType = standardLibrary.getIntType();
JetType longType = standardLibrary.getLongType();
if (typeChecker.isSubtypeOf(intType, expectedType)) {
return getIntegerValue(text, intType);
}
else if (typeChecker.isSubtypeOf(longType, expectedType)) {
return getIntegerValue(text, longType);
}
else {
return new ErrorValue("An integer literal does not conform to the expected type " + expectedType);
}
}
Long value = parseLongValue(text);
if (value != null && lowerBound <= value && value <= upperBound) {
return create.apply(value);
}
return new ErrorValue("An integer literal does not conform to the expected type " + expectedType);
}
@Nullable
private static Long parseLongValue(String text) {
try {
long value;
if (text.startsWith("0x") || text.startsWith("0X")) {
String hexString = text.substring(2);
value = Long.parseLong(hexString, 16);
}
else if (text.startsWith("0b") || text.startsWith("0B")) {
String binString = text.substring(2);
value = Long.parseLong(binString, 2);
}
else {
value = Long.parseLong(text);
}
return value;
}
catch (NumberFormatException e) {
return null;
}
}
@NotNull
public CompileTimeConstant<?> getFloatValue(@NotNull String text, @NotNull JetType expectedType) {
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
if (noExpectedType(expectedType)
|| semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getDoubleType(), expectedType)) {
try {
return new DoubleValue(Double.parseDouble(text));
}
catch (NumberFormatException e) {
return OUT_OF_RANGE;
}
}
else if (semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getFloatType(), expectedType)) {
try {
return new DoubleValue(Float.parseFloat(text));
}
catch (NumberFormatException e) {
return OUT_OF_RANGE;
}
}
else {
return new ErrorValue("A floating-point literal does not conform to the expected type " + expectedType);
}
}
@Nullable
private CompileTimeConstant<?> checkNativeType(String text, JetType expectedType, String title, JetType nativeType) {
if (!noExpectedType(expectedType)
&& !semanticServices.getTypeChecker().isSubtypeOf(nativeType, expectedType)) {
return new ErrorValue("A " + title + " literal " + text + " does not conform to the expected type " + expectedType);
}
return null;
}
@NotNull
public CompileTimeConstant<?> getBooleanValue(@NotNull String text, @NotNull JetType expectedType) {
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "boolean", semanticServices.getStandardLibrary().getBooleanType());
if (error != null) {
return error;
}
if ("true".equals(text)) {
return BooleanValue.TRUE;
}
else if ("false".equals(text)) {
return BooleanValue.FALSE;
}
throw new IllegalStateException("Must not happen. A boolean literal has text: " + text);
}
@NotNull
public CompileTimeConstant<?> getCharValue(@NotNull String text, @NotNull JetType expectedType) {
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "character", semanticServices.getStandardLibrary().getCharType());
if (error != null) {
return error;
}
assert text.charAt(0) == '\'' && text.charAt(text.length() - 1) == '\'';
text = text.substring(1, text.length() - 1);
assert text.length() < 3 && text.length() > 0;
if (text.length() == 2) {
assert text.charAt(0) == '\\';
Character escaped = translateEscape(text.charAt(1));
if (escaped == null) {
return new ErrorValue("Illegal escape: " + text);
}
return new CharValue(escaped);
}
assert text.length() == 1;
return new CharValue(text.charAt(0));
}
@Nullable
public static Character translateEscape(char c) {
switch (c) {
case 't':
return '\t';
case 'b':
return '\b';
case 'n':
return '\n';
case 'r':
return '\r';
case '\'':
return '\'';
case '\"':
return '\"';
case '\\':
return '\\';
case '$':
return '$';
}
return null;
}
@NotNull
public CompileTimeConstant<?> getRawStringValue(@NotNull String unescapedText, @NotNull JetType expectedType) {
CompileTimeConstant<?> error = checkNativeType("\"\"\"...\"\"\"", expectedType, "string", semanticServices.getStandardLibrary().getStringType());
if (error != null) {
return error;
}
return new StringValue(unescapedText);
}
@NotNull
public CompileTimeConstant<?> getEscapedStringValue(@NotNull List<JetStringTemplateEntry> entries, @NotNull JetType expectedType) {
CompileTimeConstant<?> error = checkNativeType("\"...\"", expectedType, "string", semanticServices.getStandardLibrary().getStringType());
if (error != null) {
return error;
}
final StringBuilder builder = new StringBuilder();
final CompileTimeConstant<?>[] result = new CompileTimeConstant<?>[1];
for (JetStringTemplateEntry entry : entries) {
entry.accept(new JetVisitor() {
@Override
public void visitStringTemplateEntry(JetStringTemplateEntry entry) {
result[0] = new ErrorValue("String templates are not allowed in compile-time constants");
}
@Override
public void visitLiteralStringTemplateEntry(JetLiteralStringTemplateEntry entry) {
builder.append(entry.getText());
}
@Override
public void visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry) {
String text = entry.getText();
assert text.length() == 2 && text.charAt(0) == '\\';
Character character = translateEscape(text.charAt(1));
if (character != null) {
builder.append(character);
}
}
});
if (result[0] != null) {
return result[0];
}
}
return new StringValue(builder.toString());
}
@NotNull
public CompileTimeConstant<?> getNullValue(@NotNull JetType expectedType) {
if (noExpectedType(expectedType) || expectedType.isNullable()) {
return NullValue.NULL;
}
return new ErrorValue("Null can not be a value of a non-null type " + expectedType);
}
private boolean noExpectedType(JetType expectedType) {
return expectedType == JetTypeInferrer.NO_EXPECTED_TYPE || JetStandardClasses.isUnit(expectedType);
}
}
@@ -0,0 +1,38 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class DoubleValue implements CompileTimeConstant<Double> {
private final double value;
public DoubleValue(double value) {
this.value = value;
}
@Override
public Double getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getDoubleType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitDoubleValue(this, data);
}
@Override
public String toString() {
return value + ".dbl";
}
}
@@ -0,0 +1,40 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class ErrorValue implements CompileTimeConstant<Void> {
private final String message;
public ErrorValue(@NotNull String message) {
this.message = message;
}
@Override
@Deprecated // Should not be called, for this is not a real value, but a indication of an error
public Void getValue() {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return ErrorUtils.createErrorType(message);
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitErrorValue(this, data);
}
@NotNull
public String getMessage() {
return message;
}
}
@@ -0,0 +1,48 @@
package org.jetbrains.jet.lang.resolve.constants;
import com.google.common.base.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class IntValue implements CompileTimeConstant<Integer> {
public static final Function<Long, IntValue> CREATE = new Function<Long, IntValue>() {
@Override
public IntValue apply(@Nullable Long input) {
assert input != null;
return new IntValue(input.intValue());
}
};
private final int value;
public IntValue(int value) {
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getIntType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitIntValue(this, data);
}
@Override
public String toString() {
return value + ".int";
}
}
@@ -0,0 +1,47 @@
package org.jetbrains.jet.lang.resolve.constants;
import com.google.common.base.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class LongValue implements CompileTimeConstant<Long> {
public static final Function<Long, LongValue> CREATE = new Function<Long, LongValue>() {
@Override
public LongValue apply(@Nullable Long input) {
return new LongValue(input);
}
};
private final long value;
public LongValue(long value) {
this.value = value;
}
@Override
public Long getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getLongType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitLongValue(this, data);
}
@Override
public String toString() {
return value + ".lng";
}
}
@@ -0,0 +1,39 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class NullValue implements CompileTimeConstant<Void> {
public static final NullValue NULL = new NullValue();
private NullValue() {
}
@Override
public Void getValue() {
return null;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return JetStandardClasses.getNullableNothingType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitNullValue(this, data);
}
@Override
public String toString() {
return "null";
}
}
@@ -0,0 +1,49 @@
package org.jetbrains.jet.lang.resolve.constants;
import com.google.common.base.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class ShortValue implements CompileTimeConstant<Short> {
public static final Function<Long, ShortValue> CREATE = new Function<Long, ShortValue>() {
@Override
public ShortValue apply(@Nullable Long input) {
assert input != null;
return new ShortValue(input.shortValue());
}
};
private final short value;
public ShortValue(short value) {
this.value = value;
}
@Override
public Short getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getShortType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitShortValue(this, data);
}
@Override
public String toString() {
return value + ".sht";
}
}
@@ -0,0 +1,39 @@
package org.jetbrains.jet.lang.resolve.constants;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.jet.lang.types.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType;
/**
* @author abreslav
*/
public class StringValue implements CompileTimeConstant<String> {
private final String value;
public StringValue(String value) {
this.value = value;
}
@Override
public String getValue() {
return value;
}
@NotNull
@Override
public JetType getType(@NotNull JetStandardLibrary standardLibrary) {
return standardLibrary.getStringType();
}
@Override
public <R, D> R accept(AnnotationArgumentVisitor<R, D> visitor, D data) {
return visitor.visitStringValue(this, data);
}
@Override
public String toString() {
return "\"" + value + "\"";
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.SubstitutingScope;
import org.jetbrains.jet.lang.types.*;
@@ -36,7 +37,7 @@ public class JavaClassDescriptor extends MutableDeclarationDescriptor implements
classObjectType = new JetTypeImpl(
new TypeConstructorImpl(
JavaDescriptorResolver.JAVA_CLASS_OBJECT,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
true,
"Class object emulation for " + getName(),
Collections.<TypeParameterDescriptor>emptyList(),
@@ -81,7 +81,7 @@ public class JavaClassMembersScope implements JetScope {
if (method.hasModifierProperty(PsiModifier.STATIC) != staticMembers) {
continue;
}
FunctionDescriptor functionDescriptor = semanticServices.getDescriptorResolver().resolveMethodToFunctionDescriptor(psiClass, substitutorForGenericSupertypes, method);
FunctionDescriptor functionDescriptor = semanticServices.getDescriptorResolver().resolveMethodToFunctionDescriptor(containingDeclaration, psiClass, substitutorForGenericSupertypes, method);
if (functionDescriptor != null) {
allDescriptors.add(functionDescriptor);
}
@@ -132,6 +132,7 @@ public class JavaClassMembersScope implements JetScope {
FunctionGroup functionGroup = functionGroups.get(name);
if (functionGroup == null) {
functionGroup = semanticServices.getDescriptorResolver().resolveFunctionGroup(
containingDeclaration,
psiClass,
staticMembers ? null : (ClassDescriptor) containingDeclaration,
name,
@@ -8,6 +8,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.*;
import java.util.*;
@@ -17,7 +18,7 @@ import java.util.*;
*/
public class JavaDescriptorResolver {
/*package*/ static final DeclarationDescriptor JAVA_ROOT = new DeclarationDescriptorImpl(null, Collections.<Annotation>emptyList(), "<java_root>") {
/*package*/ static final DeclarationDescriptor JAVA_ROOT = new DeclarationDescriptorImpl(null, Collections.<AnnotationDescriptor>emptyList(), "<java_root>") {
@NotNull
@Override
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
@@ -30,7 +31,7 @@ public class JavaDescriptorResolver {
}
};
/*package*/ static final DeclarationDescriptor JAVA_CLASS_OBJECT = new DeclarationDescriptorImpl(null, Collections.<Annotation>emptyList(), "<java_class_object_emulation>") {
/*package*/ static final DeclarationDescriptor JAVA_CLASS_OBJECT = new DeclarationDescriptorImpl(null, Collections.<AnnotationDescriptor>emptyList(), "<java_class_object_emulation>") {
@NotNull
@Override
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
@@ -96,7 +97,7 @@ public class JavaDescriptorResolver {
List<TypeParameterDescriptor> typeParameters = resolveTypeParameters(classDescriptor, psiClass.getTypeParameters());
classDescriptor.setTypeConstructor(new TypeConstructorImpl(
classDescriptor,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
// TODO
psiClass.hasModifierProperty(PsiModifier.FINAL),
name,
@@ -116,7 +117,7 @@ public class JavaDescriptorResolver {
if (!psiClass.hasModifierProperty(PsiModifier.ABSTRACT) && !psiClass.isInterface()) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
classDescriptor,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
false);
constructorDescriptor.initialize(typeParameters, Collections.<ValueParameterDescriptor>emptyList());
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
@@ -128,7 +129,7 @@ public class JavaDescriptorResolver {
for (PsiMethod constructor : psiConstructors) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
classDescriptor,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
false);
constructorDescriptor.initialize(typeParameters, resolveParameterDescriptors(constructorDescriptor, constructor.getParameterList().getParameters()));
constructorDescriptor.setReturnType(classDescriptor.getDefaultType());
@@ -154,7 +155,7 @@ public class JavaDescriptorResolver {
private TypeParameterDescriptor createJavaTypeParameterDescriptor(@NotNull DeclarationDescriptor owner, @NotNull PsiTypeParameter typeParameter) {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
owner,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
Variance.INVARIANT,
typeParameter.getName(),
typeParameter.getIndex()
@@ -225,7 +226,7 @@ public class JavaDescriptorResolver {
private NamespaceDescriptor createJavaNamespaceDescriptor(PsiPackage psiPackage) {
JavaNamespaceDescriptor namespaceDescriptor = new JavaNamespaceDescriptor(
JAVA_ROOT,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
psiPackage.getName()
);
namespaceDescriptor.setMemberScope(new JavaPackageScope(psiPackage.getQualifiedName(), namespaceDescriptor, semanticServices));
@@ -236,7 +237,7 @@ public class JavaDescriptorResolver {
private NamespaceDescriptor createJavaNamespaceDescriptor(@NotNull final PsiClass psiClass) {
JavaNamespaceDescriptor namespaceDescriptor = new JavaNamespaceDescriptor(
JAVA_ROOT,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
psiClass.getName()
);
namespaceDescriptor.setMemberScope(new JavaClassMembersScope(namespaceDescriptor, psiClass, semanticServices, true));
@@ -252,7 +253,7 @@ public class JavaDescriptorResolver {
result.add(new ValueParameterDescriptorImpl(
containingDeclaration,
i,
Collections.<Annotation>emptyList(), // TODO
Collections.<AnnotationDescriptor>emptyList(), // TODO
name == null ? "p" + i : name,
null, // TODO : review
semanticServices.getTypeTransformer().transformToType(parameter.getType()),
@@ -272,7 +273,7 @@ public class JavaDescriptorResolver {
boolean isFinal = field.hasModifierProperty(PsiModifier.FINAL);
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
containingDeclaration,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
new MemberModifiers(false, false, false),
!isFinal,
null,
@@ -285,7 +286,7 @@ public class JavaDescriptorResolver {
}
@NotNull
public FunctionGroup resolveFunctionGroup(@NotNull PsiClass psiClass, @Nullable ClassDescriptor classDescriptor, @NotNull String methodName, boolean staticMembers) {
public FunctionGroup resolveFunctionGroup(@NotNull DeclarationDescriptor owner, @NotNull PsiClass psiClass, @Nullable ClassDescriptor classDescriptor, @NotNull String methodName, boolean staticMembers) {
WritableFunctionGroup writableFunctionGroup = new WritableFunctionGroup(methodName);
final Collection<HierarchicalMethodSignature> signatures = psiClass.getVisibleSignatures();
TypeSubstitutor typeSubstitutor = createSubstitutorForGenericSupertypes(classDescriptor);
@@ -298,7 +299,7 @@ public class JavaDescriptorResolver {
continue;
}
FunctionDescriptor substitutedFunctionDescriptor = resolveMethodToFunctionDescriptor(psiClass, typeSubstitutor, method);
FunctionDescriptor substitutedFunctionDescriptor = resolveMethodToFunctionDescriptor(owner, psiClass, typeSubstitutor, method);
if (substitutedFunctionDescriptor != null) {
writableFunctionGroup.addFunction(substitutedFunctionDescriptor);
}
@@ -318,7 +319,7 @@ public class JavaDescriptorResolver {
}
@Nullable
public FunctionDescriptor resolveMethodToFunctionDescriptor(PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod method) {
public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod method) {
PsiType returnType = method.getReturnType();
if (returnType == null) {
return null;
@@ -332,8 +333,8 @@ public class JavaDescriptorResolver {
}
PsiParameter[] parameters = method.getParameterList().getParameters();
FunctionDescriptorImpl functionDescriptorImpl = new FunctionDescriptorImpl(
JavaDescriptorResolver.JAVA_ROOT,
Collections.<Annotation>emptyList(), // TODO
owner,
Collections.<AnnotationDescriptor>emptyList(), // TODO
method.getName()
);
methodDescriptorCache.put(method, functionDescriptorImpl);
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.AbstractNamespaceDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
@@ -14,7 +14,7 @@ import java.util.List;
public class JavaNamespaceDescriptor extends AbstractNamespaceDescriptorImpl {
private JetScope memberScope;
public JavaNamespaceDescriptor(DeclarationDescriptor containingDeclaration, List<Annotation> annotations, String name) {
public JavaNamespaceDescriptor(DeclarationDescriptor containingDeclaration, List<AnnotationDescriptor> annotations, String name) {
super(containingDeclaration, annotations, name);
}
@@ -3,7 +3,7 @@ package org.jetbrains.jet.lang.resolve.java;
import com.google.common.collect.Lists;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.types.*;
@@ -96,7 +96,7 @@ public class JavaTypeTransformer {
}
}
return new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
descriptor.getTypeConstructor(),
true,
arguments,
@@ -1,7 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import java.util.List;
@@ -48,7 +48,7 @@ public class DeferredType implements JetType {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
return getActualType().getAnnotations();
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.OverloadResolutionResult;
@@ -97,14 +98,14 @@ public class ErrorUtils {
}
};
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<Annotation>emptyList(), "<ERROR CLASS>") {
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<AnnotationDescriptor>emptyList(), "<ERROR CLASS>") {
@NotNull
@Override
public FunctionGroup getConstructors() {
return ERROR_FUNCTION_GROUP;
}
};
private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<Annotation>emptyList(), true);
private static final ConstructorDescriptor ERROR_CONSTRUCTOR = new ConstructorDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), true);
static {
ERROR_CLASS.initialize(
true, Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(), getErrorScope(), ERROR_FUNCTION_GROUP, ERROR_CONSTRUCTOR);
@@ -117,7 +118,7 @@ public class ErrorUtils {
private static final JetType ERROR_PROPERTY_TYPE = createErrorType("<ERROR PROPERTY TYPE>");
private static final VariableDescriptor ERROR_PROPERTY = new PropertyDescriptor(
ERROR_CLASS,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
new MemberModifiers(false, false, false),
true,
null,
@@ -125,7 +126,7 @@ public class ErrorUtils {
ERROR_PROPERTY_TYPE, ERROR_PROPERTY_TYPE);
private static FunctionDescriptor createErrorFunction(List<TypeParameterDescriptor> typeParameters, List<JetType> positionedValueArgumentTypes) {
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(ERROR_CLASS, Collections.<Annotation>emptyList(), "<ERROR FUNCTION>");
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>");
return functionDescriptor.initialize(
null,
typeParameters,
@@ -135,7 +136,7 @@ public class ErrorUtils {
}
public static FunctionDescriptor createErrorFunction(int typeParameterCount, List<JetType> positionedValueParameterTypes) {
return new FunctionDescriptorImpl(ERROR_CLASS, Collections.<Annotation>emptyList(), "<ERROR FUNCTION>").initialize(
return new FunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>").initialize(
null,
Collections.<TypeParameterDescriptor>emptyList(), // TODO
Collections.<ValueParameterDescriptor>emptyList(), // TODO
@@ -150,7 +151,7 @@ public class ErrorUtils {
result.add(new ValueParameterDescriptorImpl(
functionDescriptor,
i,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"<ERROR PARAMETER>",
ERROR_PARAMETER_TYPE,
ERROR_PARAMETER_TYPE,
@@ -166,7 +167,7 @@ public class ErrorUtils {
}
private static JetType createErrorType(String debugMessage, JetScope memberScope) {
return new ErrorTypeImpl(new TypeConstructorImpl(ERROR_CLASS, Collections.<Annotation>emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope);
return new ErrorTypeImpl(new TypeConstructorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), false, "[ERROR : " + debugMessage + "]", Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(JetStandardClasses.getAnyType())), memberScope);
}
public static JetType createWrongVarianceErrorType(TypeProjection value) {
@@ -182,9 +183,10 @@ public class ErrorUtils {
}
public static boolean isErrorType(@NotNull JetType type) {
return (type instanceof DeferredType && ((DeferredType) type).getActualType() == null) ||
type instanceof ErrorTypeImpl ||
isError(type.getConstructor());
return type != JetTypeInferrer.NO_EXPECTED_TYPE &&(
(type instanceof DeferredType && ((DeferredType) type).getActualType() == null) ||
type instanceof ErrorTypeImpl ||
isError(type.getConstructor()));
}
private static class ErrorTypeImpl implements JetType {
@@ -221,7 +223,7 @@ public class ErrorUtils {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
return Collections.emptyList();
}
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
import org.jetbrains.jet.lang.resolve.WritableScope;
@@ -25,11 +26,11 @@ public class JetStandardClasses {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*package*/ static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl(null, Collections.<Annotation>emptyList(), "jet");
/*package*/ static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl(null, Collections.<AnnotationDescriptor>emptyList(), "jet");
private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"Nothing"
).initialize(
true,
@@ -57,7 +58,7 @@ public class JetStandardClasses {
private static final JetType NOTHING_TYPE = new JetTypeImpl(getNothing());
private static final JetType NULLABLE_NOTHING_TYPE = new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
getNothing().getTypeConstructor(),
true,
Collections.<TypeProjection>emptyList(),
@@ -67,7 +68,7 @@ public class JetStandardClasses {
private static final ClassDescriptor ANY = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"Any").initialize(
false,
Collections.<TypeParameterDescriptor>emptyList(),
@@ -110,12 +111,12 @@ public class JetStandardClasses {
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"Tuple" + i);
for (int j = 0; j < i; j++) {
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
classDescriptor,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
Variance.OUT_VARIANCE, "T" + j, j));
}
TUPLE[i] = classDescriptor.initialize(
@@ -142,7 +143,7 @@ public class JetStandardClasses {
for (int i = 0; i < FUNCTION_COUNT; i++) {
ClassDescriptorImpl function = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"Function" + i);
FUNCTION[i] = function.initialize(
false,
@@ -152,12 +153,12 @@ public class JetStandardClasses {
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
STANDARD_CLASSES_NAMESPACE,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
"ExtensionFunction" + i);
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
receiverFunction,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
Variance.IN_VARIANCE, "T", 0));
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
false,
@@ -172,12 +173,12 @@ public class JetStandardClasses {
for (int j = 0; j < parameterCount; j++) {
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
Variance.IN_VARIANCE, "P" + j, j + 1));
}
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function,
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
Variance.OUT_VARIANCE, "R", parameterCount + 1));
return parameters;
}
@@ -286,7 +287,7 @@ public class JetStandardClasses {
type.getConstructor() == UNIT_TYPE.getConstructor();
}
public static JetType getTupleType(List<Annotation> annotations, List<JetType> arguments) {
public static JetType getTupleType(List<AnnotationDescriptor> annotations, List<JetType> arguments) {
if (annotations.isEmpty() && arguments.isEmpty()) {
return getUnitType();
}
@@ -294,21 +295,21 @@ public class JetStandardClasses {
}
public static JetType getTupleType(List<JetType> arguments) {
return getTupleType(Collections.<Annotation>emptyList(), arguments);
return getTupleType(Collections.<AnnotationDescriptor>emptyList(), arguments);
}
public static JetType getTupleType(JetType... arguments) {
return getTupleType(Collections.<Annotation>emptyList(), Arrays.asList(arguments));
return getTupleType(Collections.<AnnotationDescriptor>emptyList(), Arrays.asList(arguments));
}
public static JetType getLabeledTupleType(List<Annotation> annotations, List<ValueParameterDescriptor> arguments) {
public static JetType getLabeledTupleType(List<AnnotationDescriptor> annotations, List<ValueParameterDescriptor> arguments) {
// TODO
return getTupleType(annotations, toTypes(arguments));
}
public static JetType getLabeledTupleType(List<ValueParameterDescriptor> arguments) {
// TODO
return getLabeledTupleType(Collections.<Annotation>emptyList(), arguments);
return getLabeledTupleType(Collections.<AnnotationDescriptor>emptyList(), arguments);
}
private static List<TypeProjection> toProjections(List<JetType> arguments) {
@@ -328,7 +329,7 @@ public class JetStandardClasses {
}
// TODO : labeled version?
public static JetType getFunctionType(List<Annotation> annotations, @Nullable JetType receiverType, @NotNull List<JetType> parameterTypes, @NotNull JetType returnType) {
public static JetType getFunctionType(List<AnnotationDescriptor> annotations, @Nullable JetType receiverType, @NotNull List<JetType> parameterTypes, @NotNull JetType returnType) {
List<TypeProjection> arguments = new ArrayList<TypeProjection>();
if (receiverType != null) {
arguments.add(defaultProjection(receiverType));
@@ -368,7 +369,7 @@ public class JetStandardClasses {
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
for (int i = first; i <= last; i++) {
JetType parameterType = arguments.get(i).getType();
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(functionDescriptor, i, Collections.<Annotation>emptyList(), "p" + i, null, parameterType, false, false);
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(functionDescriptor, i, Collections.<AnnotationDescriptor>emptyList(), "p" + i, null, parameterType, false, false);
valueParameters.add(valueParameterDescriptor);
}
return valueParameters;
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.plugin.JetFileType;
@@ -192,7 +193,7 @@ public class JetStandardLibrary {
public JetType getTypeInfoType(@NotNull JetType type) {
TypeProjection typeProjection = new TypeProjection(type);
List<TypeProjection> arguments = Collections.singletonList(typeProjection);
return new JetTypeImpl(Collections.<Annotation>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
return new JetTypeImpl(Collections.<AnnotationDescriptor>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
}
@NotNull
@@ -250,7 +251,7 @@ public class JetStandardLibrary {
public JetType getArrayType(@NotNull Variance variance, @NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(variance, argument));
return new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
getArray().getTypeConstructor(),
false,
types,
@@ -262,7 +263,7 @@ public class JetStandardLibrary {
public JetType getIterableType(@NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(Variance.INVARIANT, argument));
return new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
getIterable().getTypeConstructor(),
false,
types,
@@ -1,7 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.Annotated;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.resolve.JetScope;
import java.util.List;
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import java.util.*;
@@ -138,7 +138,7 @@ public class JetTypeChecker {
}
// TODO : attributes?
return new JetTypeImpl(Collections.<Annotation>emptyList(), constructor, nullable, newProjections, JetStandardClasses.STUB); // TODO : scope
return new JetTypeImpl(Collections.<AnnotationDescriptor>emptyList(), constructor, nullable, newProjections, JetStandardClasses.STUB); // TODO : scope
}
@NotNull
@@ -419,4 +419,4 @@ public class JetTypeChecker {
return true;
}
}
}
@@ -3,8 +3,8 @@ package org.jetbrains.jet.lang.types;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
@@ -24,7 +24,7 @@ public final class JetTypeImpl extends AnnotatedImpl implements JetType {
private final boolean nullable;
private JetScope memberScope;
public JetTypeImpl(List<Annotation> annotations, TypeConstructor constructor, boolean nullable, List<TypeProjection> arguments, JetScope memberScope) {
public JetTypeImpl(List<AnnotationDescriptor> annotations, TypeConstructor constructor, boolean nullable, List<TypeProjection> arguments, JetScope memberScope) {
super(annotations);
this.constructor = constructor;
this.nullable = nullable;
@@ -33,11 +33,11 @@ public final class JetTypeImpl extends AnnotatedImpl implements JetType {
}
public JetTypeImpl(TypeConstructor constructor, JetScope memberScope) {
this(Collections.<Annotation>emptyList(), constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
this(Collections.<AnnotationDescriptor>emptyList(), constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
}
public JetTypeImpl(@NotNull ClassDescriptor classDescriptor) {
this(Collections.<Annotation>emptyList(),
this(Collections.<AnnotationDescriptor>emptyList(),
classDescriptor.getTypeConstructor(),
false,
Collections.<TypeProjection>emptyList(),
@@ -14,10 +14,15 @@ import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.resolve.DescriptorRenderer;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import java.util.*;
@@ -51,7 +56,7 @@ public class JetTypeInferrer {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
throw new UnsupportedOperationException(); // TODO
}
};
@@ -80,7 +85,7 @@ public class JetTypeInferrer {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
throw new UnsupportedOperationException(); // TODO
}
};
@@ -140,11 +145,15 @@ public class JetTypeInferrer {
private final BindingTrace trace;
private final ClassDescriptorResolver classDescriptorResolver;
private final TypeResolver typeResolver;
private final CompileTimeConstantResolver compileTimeConstantResolver;
private final AnnotationResolver annotationResolver;
private Services(BindingTrace trace) {
this.trace = trace;
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
this.typeResolver = new TypeResolver(semanticServices, trace, true);
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
this.compileTimeConstantResolver = new CompileTimeConstantResolver(semanticServices, trace);
}
@NotNull
@@ -522,10 +531,10 @@ public class JetTypeInferrer {
}
private JetType resolveCallWithTypeArguments(JetScope scope, OverloadDomain overloadDomain, JetCall call, List<JetType> typeArguments) {
final List<JetArgument> valueArguments = call.getValueArguments();
final List<JetValueArgument> valueArguments = call.getValueArguments();
boolean someNamed = false;
for (JetArgument argument : valueArguments) {
for (JetValueArgument argument : valueArguments) {
if (argument.isNamed()) {
someNamed = true;
break;
@@ -543,7 +552,7 @@ public class JetTypeInferrer {
} else {
List<JetExpression> positionedValueArguments = new ArrayList<JetExpression>();
for (JetArgument argument : valueArguments) {
for (JetValueArgument argument : valueArguments) {
JetExpression argumentExpression = argument.getArgumentExpression();
if (argumentExpression != null) {
positionedValueArguments.add(argumentExpression);
@@ -680,7 +689,7 @@ public class JetTypeInferrer {
assert declarationDescriptor != null;
trace.recordReferenceResolution(referenceExpression, declarationDescriptor);
// TODO : more helpful message
JetArgumentList argumentList = call.getValueArgumentList();
JetValueArgumentList argumentList = call.getValueArgumentList();
final String errorMessage = "Cannot find a constructor overload for class " + classDescriptor.getName() + " with these arguments";
if (argumentList != null) {
trace.getErrorHandler().genericError(argumentList.getNode(), errorMessage);
@@ -962,7 +971,7 @@ public class JetTypeInferrer {
}
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
context.scope.getContainingDeclaration(), Collections.<Annotation>emptyList(), "<anonymous>");
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>");
List<JetType> parameterTypes = new ArrayList<JetType>();
List<ValueParameterDescriptor> valueParameterDescriptors = Lists.newArrayList();
@@ -1003,7 +1012,7 @@ public class JetTypeInferrer {
functionDescriptor.setReturnType(safeReturnType);
result = JetStandardClasses.getFunctionType(Collections.<Annotation>emptyList(), effectiveReceiverType, parameterTypes, safeReturnType);
result = JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), effectiveReceiverType, parameterTypes, safeReturnType);
}
@Override
@@ -1016,50 +1025,42 @@ public class JetTypeInferrer {
@Override
public void visitConstantExpression(JetConstantExpression expression) {
IElementType elementType = expression.getNode().getElementType();
ASTNode node = expression.getNode();
IElementType elementType = node.getElementType();
String text = node.getText();
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
CompileTimeConstantResolver compileTimeConstantResolver = services.compileTimeConstantResolver;
CompileTimeConstant<?> value;
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
Object value = expression.getValue();
if (value == null) {
context.trace.getErrorHandler().genericError(expression.getNode(), "Number is of range for Long");
}
else if (value instanceof Long) {
result = standardLibrary.getLongType();
}
else {
result = standardLibrary.getIntType();
}
// TODO : other ranges
}
else if (elementType == JetNodeTypes.LONG_CONSTANT) {
result = standardLibrary.getLongType();
value = compileTimeConstantResolver.getIntegerValue(text, context.expectedType);
}
else if (elementType == JetNodeTypes.FLOAT_CONSTANT) {
String text = expression.getText();
assert text.length() > 0;
char lastChar = text.charAt(text.length() - 1);
if (lastChar == 'f' || lastChar == 'F') {
result = standardLibrary.getFloatType();
}
else {
result = standardLibrary.getDoubleType();
}
value = compileTimeConstantResolver.getFloatValue(text, context.expectedType);
}
else if (elementType == JetNodeTypes.BOOLEAN_CONSTANT) {
result = standardLibrary.getBooleanType();
value = compileTimeConstantResolver.getBooleanValue(text, context.expectedType);
}
else if (elementType == JetNodeTypes.CHARACTER_CONSTANT) {
result = standardLibrary.getCharType();
value = compileTimeConstantResolver.getCharValue(text, context.expectedType);
}
else if (elementType == JetNodeTypes.STRING_CONSTANT) {
result = standardLibrary.getStringType();
else if (elementType == JetNodeTypes.RAW_STRING_CONSTANT) {
value = compileTimeConstantResolver.getRawStringValue(text, context.expectedType);
}
else if (elementType == JetNodeTypes.NULL) {
result = JetStandardClasses.getNullableNothingType();
value = compileTimeConstantResolver.getNullValue(context.expectedType);
}
else {
throw new IllegalArgumentException("Unsupported constant: " + expression);
}
if (value instanceof ErrorValue) {
ErrorValue errorValue = (ErrorValue) value;
context.trace.getErrorHandler().genericError(node, errorValue.getMessage());
}
else {
context.trace.recordCompileTimeValue(expression, value);
result = value.getType(standardLibrary);
}
}
@Override
@@ -2436,6 +2437,8 @@ public class JetTypeInferrer {
@Override
public void visitStringTemplateExpression(JetStringTemplateExpression expression) {
final StringBuilder builder = new StringBuilder();
final CompileTimeConstant<?>[] value = new CompileTimeConstant<?>[1];
for (JetStringTemplateEntry entry : expression.getEntries()) {
entry.accept(new JetVisitor() {
@@ -2445,26 +2448,35 @@ public class JetTypeInferrer {
if (entryExpression != null) {
getType(context.scope, entryExpression, true);
}
value[0] = CompileTimeConstantResolver.OUT_OF_RANGE;
}
@Override
public void visitLiteralStringTemplateEntry(JetLiteralStringTemplateEntry entry) {
// Nothing
builder.append(entry.getText());
}
@Override
public void visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry) {
// TODO : Check escape
String text = entry.getText();
assert text.length() == 2;
assert text.length() == 2 && text.charAt(0) == '\\';
char escaped = text.charAt(1);
Character[] legal = {'n', 'r', 't', 'b', 'f', '$', '\"', '$', '\\'};
if (!Sets.newHashSet(legal).contains(escaped)) {
Character character = CompileTimeConstantResolver.translateEscape(escaped);
if (character == null) {
context.trace.getErrorHandler().genericError(entry.getNode(), "Illegal escape sequence");
value[0] = CompileTimeConstantResolver.OUT_OF_RANGE;
}
else {
builder.append(character);
}
}
});
}
if (value[0] != CompileTimeConstantResolver.OUT_OF_RANGE) {
context.trace.recordCompileTimeValue(expression, new StringValue(builder.toString()));
}
result = semanticServices.getStandardLibrary().getStringType();
}
@@ -1,7 +1,7 @@
package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.JetScope;
import java.util.List;
@@ -52,7 +52,7 @@ public class NamespaceType implements JetType {
}
@Override
public List<Annotation> getAnnotations() {
public List<AnnotationDescriptor> getAnnotations() {
throwException();
return null;
}
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Annotated;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
@@ -2,8 +2,8 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
@@ -25,7 +25,7 @@ public class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructo
public TypeConstructorImpl(
@Nullable DeclarationDescriptor declarationDescriptor,
@NotNull List<Annotation> annotations,
@NotNull List<AnnotationDescriptor> annotations,
boolean sealed,
@NotNull String debugName,
@NotNull List<TypeParameterDescriptor> parameters,
@@ -5,7 +5,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.Annotation;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.resolve.ChainedScope;
@@ -72,7 +72,7 @@ public class TypeUtils {
}
}
List<Annotation> noAnnotations = Collections.<Annotation>emptyList();
List<AnnotationDescriptor> noAnnotations = Collections.<AnnotationDescriptor>emptyList();
TypeConstructor constructor = new TypeConstructorImpl(
null,
noAnnotations,
@@ -181,7 +181,7 @@ public class TypeUtils {
public static JetType makeUnsubstitutedType(ClassDescriptor classDescriptor, JetScope unsubstitutedMemberScope) {
List<TypeProjection> arguments = getDefaultTypeProjections(classDescriptor.getTypeConstructor().getParameters());
return new JetTypeImpl(
Collections.<Annotation>emptyList(),
Collections.<AnnotationDescriptor>emptyList(),
classDescriptor.getTypeConstructor(),
false,
arguments,
@@ -73,7 +73,6 @@ INTEGER_LITERAL={DECIMAL_INTEGER_LITERAL}|{HEX_INTEGER_LITERAL}|{BIN_INTEGER_LIT
DECIMAL_INTEGER_LITERAL=(0|([1-9]({DIGIT})*))
HEX_INTEGER_LITERAL=0[Xx]({HEX_DIGIT})*
BIN_INTEGER_LITERAL=0[Bb]({DIGIT})*
LONG_LITERAL=({INTEGER_LITERAL})[Ll]
//FLOAT_LITERAL=(({FLOATING_POINT_LITERAL1})[Ff])|(({FLOATING_POINT_LITERAL2})[Ff])|(({FLOATING_POINT_LITERAL3})[Ff])|(({FLOATING_POINT_LITERAL4})[Ff])
//DOUBLE_LITERAL=(({FLOATING_POINT_LITERAL1})[Dd]?)|(({FLOATING_POINT_LITERAL2})[Dd]?)|(({FLOATING_POINT_LITERAL3})[Dd]?)|(({FLOATING_POINT_LITERAL4})[Dd])
@@ -148,10 +147,7 @@ LONG_TEMPLATE_ENTRY_END=\}
{INTEGER_LITERAL}\.\. { yypushback(2); return JetTokens.INTEGER_LITERAL; }
{INTEGER_LITERAL} { return JetTokens.INTEGER_LITERAL; }
//{LONG_LITERAL} { return JetTokens.LONG_LITERAL; }
//{FLOAT_LITERAL} { return JetTokens.FLOAT_LITERAL; }
//{HEX_FLOAT_LITERAL} { return JetTokens.FLOAT_LITERAL; }
{DOUBLE_LITERAL} { return JetTokens.FLOAT_LITERAL; }
{HEX_DOUBLE_LITERAL} { return JetTokens.FLOAT_LITERAL; }
@@ -17,10 +17,8 @@ public interface JetTokens {
IElementType WHITE_SPACE = TokenType.WHITE_SPACE;
JetToken INTEGER_LITERAL = new JetToken("INTEGER_LITERAL");
JetToken LONG_LITERAL = new JetToken("LONG_LITERAL");
JetToken FLOAT_LITERAL = new JetToken("FLOAT_CONSTANT");
JetToken CHARACTER_LITERAL = new JetToken("CHARACTER_LITERAL");
// JetToken STRING_LITERAL = new JetToken("STRING_LITERAL");
JetToken CLOSING_QUOTE = new JetToken("CLOSING_QUOTE");
JetToken OPEN_QUOTE = new JetToken("OPEN_QUOTE");
@@ -118,7 +118,6 @@ public class JetHighlighter extends SyntaxHighlighterBase {
keys1.put(JetTokens.ATAT, JET_LABEL_IDENTIFIER);
keys1.put(JetTokens.FIELD_IDENTIFIER, JET_FIELD_IDENTIFIER);
keys1.put(JetTokens.INTEGER_LITERAL, JET_NUMBER);
keys1.put(JetTokens.LONG_LITERAL, JET_NUMBER);
keys1.put(JetTokens.FLOAT_LITERAL, JET_NUMBER);
keys1.put(JetTokens.OPEN_QUOTE, JET_STRING);
@@ -16,7 +16,7 @@ fun bbb() {
fun foo(expr: StringBuilder): Int {
val c = 'a'
when(c) {
'\0' => throw Exception("zero")
0.chr => throw Exception("zero")
else => throw Exception("nonzero" + c)
}
}
@@ -1,5 +1,5 @@
fun StringBuilder.takeFirst(): Char {
if (this.length() == 0) return '\0'
if (this.length() == 0) return 0.chr
val c = this.charAt(0)
this.deleteCharAt(0)
return c
@@ -8,7 +8,7 @@ fun StringBuilder.takeFirst(): Char {
fun foo(expr: StringBuilder): Int {
val c = expr.takeFirst()
when(c) {
'\0' => throw Exception("zero")
0.chr => throw Exception("zero")
else => throw Exception("nonzero" + c)
}
}
@@ -6,10 +6,12 @@ import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
import org.jetbrains.jet.lang.JetDiagnostic;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
@@ -45,6 +47,16 @@ public class JetTestUtils {
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
}
@Override
public void recordAnnotationResolution(@NotNull JetAnnotationEntry annotationEntry, @NotNull AnnotationDescriptor annotationDescriptor) {
}
@Override
public void recordCompileTimeValue(@NotNull JetExpression expression, @NotNull CompileTimeConstant<?> value) {
}
@Override
public void recordBlock(JetFunctionLiteralExpression expression) {
}
@@ -130,6 +142,16 @@ public class JetTestUtils {
throw new UnsupportedOperationException(); // TODO
}
@Override
public AnnotationDescriptor getAnnotationDescriptor(JetAnnotationEntry annotationEntry) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public CompileTimeConstant<?> getCompileTimeValue(JetExpression expression) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public VariableDescriptor getVariableDescriptor(JetProperty declaration) {
throw new UnsupportedOperationException(); // TODO