Merge remote branch 'origin/master'
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -54,4 +53,8 @@ public class CodegenUtil {
|
||||
}
|
||||
return (ClassDescriptor) outerDescriptor;
|
||||
}
|
||||
|
||||
public static Type arrayElementType(Type type) {
|
||||
return Type.getType(type.getDescriptor().substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,8 +378,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
gen(expression.getLoopRange(), loopRangeType); // array
|
||||
v.load(myIndexVar, Type.INT_TYPE);
|
||||
v.aload(loopRangeType.getElementType());
|
||||
StackValue.onStack(loopRangeType.getElementType()).put(asmParamType, v);
|
||||
v.aload(CodegenUtil.arrayElementType(loopRangeType));
|
||||
StackValue.onStack(CodegenUtil.arrayElementType(loopRangeType)).put(asmParamType, v);
|
||||
v.store(lookupLocal(parameterDescriptor), asmParamType);
|
||||
}
|
||||
|
||||
@@ -1683,12 +1683,23 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
private void generateNewArray(JetCallExpression expression, Type type) {
|
||||
JetType arrayType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
|
||||
List<? extends ValueArgument> args = expression.getValueArguments();
|
||||
if (args.size() != 1) {
|
||||
throw new CompilationException("array constructor requires one value argument");
|
||||
}
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
v.newarray(type.getElementType());
|
||||
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/typeinfo/TypeInfo", "newArray", "(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;");
|
||||
v.checkcast(type);
|
||||
}
|
||||
else {
|
||||
v.newarray(CodegenUtil.arrayElementType(type));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1698,7 +1709,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
gen(array, arrayType);
|
||||
generateArrayIndex(expression);
|
||||
if (arrayType.getSort() == Type.ARRAY) {
|
||||
final Type elementType = arrayType.getElementType();
|
||||
final Type elementType = CodegenUtil.arrayElementType(arrayType);
|
||||
return StackValue.arrayElement(elementType);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -670,4 +670,20 @@ public class JetTypeMapper {
|
||||
public String isKnownTypeInfo(JetType jetType) {
|
||||
return knowTypes.get(jetType);
|
||||
}
|
||||
|
||||
public boolean isGenericsArray(JetType type) {
|
||||
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if(declarationDescriptor instanceof TypeParameterDescriptor)
|
||||
return true;
|
||||
|
||||
if(standardLibrary.getArray().equals(declarationDescriptor))
|
||||
return isGenericsArray(type.getArguments().get(0).getType());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public JetType getGenericsElementType(JetType arrayType) {
|
||||
JetType type = arrayType.getArguments().get(0).getType();
|
||||
return isGenericsArray(type) ? type : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class NamespaceCodegen {
|
||||
v.aconst(jvmType);
|
||||
v.iconst(jetType.isNullable() ? 1 : 0);
|
||||
List<TypeProjection> arguments = jetType.getArguments();
|
||||
if (arguments.size() > 0) {
|
||||
if (arguments.size() > 0 && !(jvmType.getSort() == Type.ARRAY && jvmType.getElementType().getSort() != Type.OBJECT)) {
|
||||
v.iconst(arguments.size());
|
||||
v.newarray(JetTypeMapper.TYPE_TYPEINFOPROJECTION);
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public abstract class StackValue {
|
||||
else
|
||||
v.iconst(0);
|
||||
}
|
||||
else if (type.getSort() == Type.OBJECT && this.type.equals(JetTypeMapper.TYPE_OBJECT)) {
|
||||
else if (type.getSort() == Type.OBJECT && this.type.equals(JetTypeMapper.TYPE_OBJECT) || type.getSort() == Type.ARRAY) {
|
||||
v.checkcast(type);
|
||||
}
|
||||
else if (type.getSort() == Type.OBJECT) {
|
||||
@@ -431,6 +431,7 @@ public abstract class StackValue {
|
||||
@Override
|
||||
public void put(Type type, InstructionAdapter v) {
|
||||
v.aload(type); // assumes array and index are on the stack
|
||||
coerce(type, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.jetbrains.jet.lang.diagnostics;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
|
||||
@@ -9,6 +9,6 @@ import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
*/
|
||||
public interface DiagnosticParameters {
|
||||
DiagnosticParameter<JetKeywordToken> MODIFIER = new DiagnosticParameterImpl<JetKeywordToken>("MODIFIER");
|
||||
DiagnosticParameter<JetModifierListOwner> CLASS = new DiagnosticParameterImpl<JetModifierListOwner>("CLASS");
|
||||
DiagnosticParameter<JetClass> CLASS = new DiagnosticParameterImpl<JetClass>("CLASS");
|
||||
DiagnosticParameter<JetType> TYPE = new DiagnosticParameterImpl<JetType>("TYPE");
|
||||
}
|
||||
|
||||
+4
-4
@@ -7,14 +7,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class DiagnosticWithParametersFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
|
||||
public static <T extends PsiElement, A> DiagnosticWithParametersFactory<T, A> create(Severity severity, String messageStub, DiagnosticParameter<A> diagnosticParameter) {
|
||||
return new DiagnosticWithParametersFactory<T, A>(severity, messageStub, diagnosticParameter);
|
||||
public class DiagnosticWithParameterFactory<T extends PsiElement, A> extends PsiElementOnlyDiagnosticFactory1<T, A> {
|
||||
public static <T extends PsiElement, A> DiagnosticWithParameterFactory<T, A> create(Severity severity, String messageStub, DiagnosticParameter<A> diagnosticParameter) {
|
||||
return new DiagnosticWithParameterFactory<T, A>(severity, messageStub, diagnosticParameter);
|
||||
}
|
||||
|
||||
private final DiagnosticParameter<A> diagnosticParameter;
|
||||
|
||||
protected DiagnosticWithParametersFactory(Severity severity, String message, DiagnosticParameter<A> diagnosticParameter) {
|
||||
protected DiagnosticWithParameterFactory(Severity severity, String message, DiagnosticParameter<A> diagnosticParameter) {
|
||||
super(severity, message);
|
||||
this.diagnosticParameter = diagnosticParameter;
|
||||
}
|
||||
@@ -88,25 +88,25 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory FUNCTION_WITH_NO_TYPE_NO_BODY = SimpleDiagnosticFactory.create(ERROR, "This function must either declare a return type or have a body element");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "This property cannot be declared abstract");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_NOT_IN_CLASS = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "A property may be abstract only when defined in a class or trait");
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParametersFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParametersFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParametersFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParameterFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE);
|
||||
SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field");
|
||||
SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "Property must be initialized");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
|
||||
DiagnosticWithParametersFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParametersFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetProperty, JetType> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed in traits", DiagnosticParameters.TYPE);
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field");
|
||||
SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present");
|
||||
DiagnosticWithParameterFactory<JetProperty, JetClass> PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = DiagnosticWithParameterFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present", DiagnosticParameters.CLASS);
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
|
||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetModifierListOwner> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetModifierListOwner>(ERROR, "Abstract property {0} in non-abstract class {1}") {
|
||||
PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetModifierListOwner, String, ClassDescriptor, JetClass>(ERROR, "Abstract property {0} in non-abstract class {1}") {
|
||||
@NotNull
|
||||
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetModifierListOwner aClass) {
|
||||
protected DiagnosticWithPsiElement<JetModifierListOwner> on(@NotNull JetModifierListOwner elementToBlame, @NotNull TextRange textRangeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass aClass) {
|
||||
return super.on(elementToBlame, textRangeToMark, s, classDescriptor, aClass).add(DiagnosticParameters.CLASS, aClass);
|
||||
}
|
||||
};
|
||||
PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetModifierListOwner> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetModifierListOwner>(ERROR, "Abstract function {0} in non-abstract class {1}") {
|
||||
PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetClass>(ERROR, "Abstract function {0} in non-abstract class {1}") {
|
||||
@NotNull
|
||||
public DiagnosticWithPsiElement<JetFunctionOrPropertyAccessor> on(@NotNull JetFunctionOrPropertyAccessor elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetModifierListOwner modifierListOwner) {
|
||||
public DiagnosticWithPsiElement<JetFunctionOrPropertyAccessor> on(@NotNull JetFunctionOrPropertyAccessor elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass modifierListOwner) {
|
||||
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
|
||||
}
|
||||
};
|
||||
@@ -125,7 +125,7 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required");
|
||||
SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
|
||||
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT);
|
||||
ParameterizedDiagnosticFactory1<PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = ParameterizedDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field");
|
||||
PsiElementOnlyDiagnosticFactory1<JetClass, PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field");
|
||||
ParameterizedDiagnosticFactory1<JetClassOrObject> PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1<JetClassOrObject>(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") {
|
||||
@Override
|
||||
protected String makeMessageFor(@NotNull JetClassOrObject argument) {
|
||||
@@ -162,8 +162,8 @@ public interface Errors {
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST_STATIC_ASSERT_IS_FINE = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed, use ':' instead");
|
||||
SimplePsiElementOnlyDiagnosticFactory<JetBinaryExpressionWithTypeRHS> USELESS_CAST = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "No cast needed");
|
||||
SimpleDiagnosticFactory CAST_NEVER_SUCCEEDS = SimpleDiagnosticFactory.create(WARNING, "This cast can never succeed");
|
||||
DiagnosticWithParametersFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParametersFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParametersFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParametersFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_SETTER_PARAMETER_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Setter parameter type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
DiagnosticWithParameterFactory<JetPropertyAccessor, JetType> WRONG_GETTER_RETURN_TYPE = DiagnosticWithParameterFactory.create(ERROR, "Getter return type must be equal to the type of the property, i.e. {0}", DiagnosticParameters.TYPE);
|
||||
ParameterizedDiagnosticFactory1<ClassifierDescriptor> NO_CLASS_OBJECT = ParameterizedDiagnosticFactory1.create(ERROR, "Classifier {0} does not have a class object", NAME);
|
||||
SimpleDiagnosticFactory NO_GENERICS_IN_SUPERTYPE_SPECIFIER = SimpleDiagnosticFactory.create(ERROR, "Generic arguments of the base type must be specified");
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
@@ -24,9 +25,10 @@ public class JetPsiFactory {
|
||||
return property.getPropertyTypeRef();
|
||||
}
|
||||
|
||||
public static PsiElement[] createColon(Project project) {
|
||||
//the pair contains the first and the last elements of a range
|
||||
public static Pair<PsiElement, PsiElement> createColon(Project project) {
|
||||
JetProperty property = createProperty(project, "val x : Int");
|
||||
return new PsiElement[] { property.findElementAt(5), property.findElementAt(6), property.findElementAt(7) };
|
||||
return Pair.create(property.findElementAt(5), property.findElementAt(7));
|
||||
}
|
||||
|
||||
public static PsiElement createWhiteSpace(Project project) {
|
||||
@@ -38,11 +40,6 @@ public class JetPsiFactory {
|
||||
return property.findElementAt(3);
|
||||
}
|
||||
|
||||
// public static PsiElement createEndOfLine(Project project) {
|
||||
// JetNamedFunction function = createFunction(project, "fun f { \n }");
|
||||
// return function.findElementAt(8);
|
||||
// }
|
||||
|
||||
public static JetClass createClass(Project project, String text) {
|
||||
return createDeclaration(project, text, JetClass.class);
|
||||
}
|
||||
@@ -99,4 +96,9 @@ public class JetPsiFactory {
|
||||
JetNamespace namespace = createNamespace(project, "import " + classPath);
|
||||
return namespace.getImportDirectives().iterator().next();
|
||||
}
|
||||
|
||||
public static PsiElement createPrimaryConstructor(Project project) {
|
||||
JetClass aClass = createClass(project, "class A()");
|
||||
return aClass.findElementAt(7).getParent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class BodyResolver {
|
||||
if (nameIdentifier != null) {
|
||||
// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(),
|
||||
// "This class must have a primary constructor, because property " + propertyDescriptor.getName() + " has a backing field");
|
||||
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY.on(nameIdentifier, propertyDescriptor));
|
||||
context.getTrace().report(PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY.on(jetClass, nameIdentifier, propertyDescriptor));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -526,6 +526,9 @@ public class BodyResolver {
|
||||
|
||||
if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
|
||||
JetType returnType = propertyDescriptor.getReturnType();
|
||||
if (returnType instanceof DeferredType) {
|
||||
returnType = ((DeferredType) returnType).getActualType();
|
||||
}
|
||||
|
||||
JetExpression initializer = property.getInitializer();
|
||||
if (initializer != null) {
|
||||
@@ -575,7 +578,11 @@ public class BodyResolver {
|
||||
}
|
||||
if (inTrait) {
|
||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed in traits");
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(property, initializer, propertyDescriptor.getReturnType()));
|
||||
JetType returnType = propertyDescriptor.getReturnType();
|
||||
if (returnType instanceof DeferredType) {
|
||||
returnType = ((DeferredType) returnType).getActualType();
|
||||
}
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_IN_TRAIT.on(property, initializer, returnType));
|
||||
}
|
||||
else if (!backingFieldRequired) {
|
||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no backing field");
|
||||
@@ -583,7 +590,10 @@ public class BodyResolver {
|
||||
}
|
||||
else if (classDescriptor != null && classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
|
||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR.on(initializer));
|
||||
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
|
||||
assert classElement instanceof JetClass;
|
||||
|
||||
context.getTrace().report(PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR.on(property, initializer, (JetClass) classElement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,10 +700,10 @@ public class BodyResolver {
|
||||
boolean inTrait = classDescriptor.getKind() == ClassKind.TRAIT;
|
||||
boolean inEnum = classDescriptor.getKind() == ClassKind.ENUM_CLASS;
|
||||
boolean inAbstractClass = classDescriptor.getModality() == Modality.ABSTRACT;
|
||||
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
|
||||
assert classElement instanceof JetModifierListOwner;
|
||||
if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) {
|
||||
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(functionOrPropertyAccessor, abstractNode, functionDescriptor.getName(), classDescriptor, (JetModifierListOwner) classElement));
|
||||
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
|
||||
assert classElement instanceof JetClass;
|
||||
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(functionOrPropertyAccessor, abstractNode, functionDescriptor.getName(), classDescriptor, (JetClass) classElement));
|
||||
}
|
||||
if (hasAbstractModifier && inTrait && !isPropertyAccessor) {
|
||||
context.getTrace().report(REDUNDANT_ABSTRACT.on(functionOrPropertyAccessor, abstractNode));
|
||||
|
||||
@@ -177,7 +177,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
public static boolean isError(@NotNull DeclarationDescriptor candidate) {
|
||||
return candidate.getContainingDeclaration() == getErrorClass();
|
||||
return candidate.getContainingDeclaration() == getErrorClass() || candidate == ERROR_MODULE;
|
||||
}
|
||||
|
||||
private static class ErrorTypeImpl implements JetType {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.resolve.java.JavaClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -61,7 +62,7 @@ public class JetPluginUtil {
|
||||
JetScope libraryScope = standardLibrary.getLibraryScope();
|
||||
|
||||
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
||||
if (declaration instanceof JavaClassDescriptor) {
|
||||
if (declaration instanceof JavaClassDescriptor || ErrorUtils.isError(declaration)) {
|
||||
return false;
|
||||
}
|
||||
while (!(declaration instanceof NamespaceDescriptor)) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class AddPrimaryConstructorFix extends JetIntentionAction<JetClass> {
|
||||
|
||||
public AddPrimaryConstructorFix(@NotNull JetClass element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Add primary constructor to " + element.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return "Add primary constructor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetClass newClass = (JetClass) element.copy();
|
||||
assert !newClass.hasPrimaryConstructor();
|
||||
PsiElement primaryConstructor = JetPsiFactory.createPrimaryConstructor(project);
|
||||
newClass.addAfter(primaryConstructor, newClass.getNameIdentifier());
|
||||
element.replace(newClass);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory<JetClass> createFactory() {
|
||||
return new JetIntentionActionFactory<JetClass>() {
|
||||
@Override
|
||||
public JetIntentionAction<JetClass> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetClass;
|
||||
return new AddPrimaryConstructorFix((JetClass) diagnostic.getPsiElement());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,6 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
|
||||
assert returnTypeReference != null;
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), returnTypeReference.getNode(), newTypeReference.getNode());
|
||||
element.replace(newElement);
|
||||
}
|
||||
else {
|
||||
JetParameter parameter = newElement.getParameter();
|
||||
@@ -56,8 +55,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
JetTypeReference typeReference = parameter.getTypeReference();
|
||||
assert typeReference != null;
|
||||
CodeEditUtil.replaceChild(parameter.getNode(), typeReference.getNode(), newTypeReference.getNode());
|
||||
element.replace(newElement);
|
||||
}
|
||||
ImportClassHelper.perform(type, element, newElement);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory<JetPropertyAccessor> createFactory() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
|
||||
@@ -21,7 +22,7 @@ public class ImportClassHelper {
|
||||
JetNamespace namespace = (JetNamespace) parent;
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
if (JetPluginUtil.checkTypeIsStandard(type, element.getProject())) {
|
||||
if (JetPluginUtil.checkTypeIsStandard(type, element.getProject()) || ErrorUtils.isError(type.getMemberScope().getContainingDeclaration())) {
|
||||
element.replace(newElement);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElementImpl;
|
||||
public class QuickFixUtil {
|
||||
private QuickFixUtil() {}
|
||||
|
||||
public static <T extends PsiElement> JetIntentionActionFactory<T> createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<T> parameter) {
|
||||
return new JetIntentionActionFactory<T>() {
|
||||
public static <T extends PsiElement, P extends T> JetIntentionActionFactory<PsiElement> createFactoryRedirectingAdditionalInfoToAnotherFactory(final JetIntentionActionFactory<T> factory, final DiagnosticParameter<P> parameter) {
|
||||
return new JetIntentionActionFactory<PsiElement>() {
|
||||
@Override
|
||||
public JetIntentionAction<T> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
public JetIntentionAction<PsiElement> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
|
||||
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, parameter);
|
||||
T element = diagnosticWithParameters.getParameter(parameter);
|
||||
return factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
|
||||
return (JetIntentionAction<PsiElement>) factory.createAction(new DiagnosticWithPsiElementImpl<T>(diagnostic.getFactory(), diagnostic.getSeverity(), diagnostic.getMessage(), element));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionOrPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
@@ -53,7 +50,7 @@ public class QuickFixes {
|
||||
add(Errors.MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
|
||||
add(Errors.REDUNDANT_ABSTRACT, removeAbstractModifierFactory);
|
||||
|
||||
JetIntentionActionFactory<JetModifierListOwner> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.CLASS);
|
||||
JetIntentionActionFactory<PsiElement> addAbstractToClassFactory = QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.CLASS);
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
|
||||
|
||||
@@ -89,6 +86,12 @@ public class QuickFixes {
|
||||
add(Errors.UNNECESSARY_SAFE_CALL, ReplaceSafeCallToDotCall.createFactory());
|
||||
|
||||
add(Errors.REDUNDANT_MODIFIER, RemoveRedundantModifierFix.createFactory());
|
||||
|
||||
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
|
||||
|
||||
JetIntentionActionFactory<JetClass> addPrimaryConstructorFactory = AddPrimaryConstructorFix.createFactory();
|
||||
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addPrimaryConstructorFactory, DiagnosticParameters.CLASS));
|
||||
add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
@@ -18,39 +19,46 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
*/
|
||||
public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty> {
|
||||
private final JetType type;
|
||||
private final String partsToRemove;
|
||||
private final boolean removeInitializer;
|
||||
private final boolean removeGetter;
|
||||
private final boolean removeSetter;
|
||||
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, JetType type) {
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, @Nullable JetType type, boolean removeInitializer, boolean removeGetter, boolean removeSetter) {
|
||||
super(element);
|
||||
if (type instanceof DeferredType) {
|
||||
this.type = ((DeferredType) type).getActualType();
|
||||
}
|
||||
else {
|
||||
this.type = type;
|
||||
}
|
||||
partsToRemove = partsToRemove(element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
||||
element.getSetter() != null && element.getSetter().getBodyExpression() != null,
|
||||
element.getInitializer() != null);
|
||||
this.type = type;
|
||||
this.removeInitializer = removeInitializer;
|
||||
this.removeGetter = removeGetter;
|
||||
this.removeSetter = removeSetter;
|
||||
}
|
||||
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, @Nullable JetType type) {
|
||||
this(element, type, element.getInitializer() != null,
|
||||
element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
||||
element.getSetter() != null && element.getSetter().getBodyExpression() != null);
|
||||
}
|
||||
|
||||
private static String partsToRemove(boolean hasGetter, boolean hasSetter, boolean hasInitializer) {
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, boolean removeInitializer, boolean removeGetter, boolean removeSetter) {
|
||||
this(element, null, removeInitializer, removeGetter, removeSetter);
|
||||
}
|
||||
|
||||
private static String partsToRemove(boolean getter, boolean setter, boolean initializer) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (hasGetter) {
|
||||
if (getter) {
|
||||
sb.append("getter");
|
||||
if (hasSetter && hasInitializer) {
|
||||
if (setter && initializer) {
|
||||
sb.append(", ");
|
||||
}
|
||||
else if (hasSetter || hasInitializer) {
|
||||
else if (setter || initializer) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
}
|
||||
if (hasSetter) {
|
||||
if (setter) {
|
||||
sb.append("setter");
|
||||
if (hasInitializer) {
|
||||
if (initializer) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
}
|
||||
if (hasInitializer) {
|
||||
if (initializer) {
|
||||
sb.append("initializer");
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -59,7 +67,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Remove " + partsToRemove + " from property";
|
||||
return "Remove " + partsToRemove(removeGetter, removeSetter, removeInitializer) + " from property";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -77,23 +85,23 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetProperty newElement = (JetProperty) element.copy();
|
||||
JetPropertyAccessor getter = newElement.getGetter();
|
||||
if (getter != null) {
|
||||
if (removeGetter && getter != null) {
|
||||
newElement.deleteChildInternal(getter.getNode());
|
||||
}
|
||||
JetPropertyAccessor setter = newElement.getSetter();
|
||||
if (setter != null) {
|
||||
if (removeSetter && setter != null) {
|
||||
newElement.deleteChildInternal(setter.getNode());
|
||||
}
|
||||
JetExpression initializer = newElement.getInitializer();
|
||||
boolean needImport = false;
|
||||
if (initializer != null) {
|
||||
if (removeInitializer && initializer != null) {
|
||||
PsiElement nameIdentifier = newElement.getNameIdentifier();
|
||||
assert nameIdentifier != null;
|
||||
PsiElement nextSibling = nameIdentifier.getNextSibling();
|
||||
assert nextSibling != null;
|
||||
newElement.deleteChildRange(nextSibling, initializer);
|
||||
|
||||
if (newElement.getPropertyTypeRef() == null) {
|
||||
if (newElement.getPropertyTypeRef() == null && type != null) {
|
||||
newElement = addPropertyType(project, newElement, type);
|
||||
needImport = true;
|
||||
}
|
||||
@@ -108,13 +116,11 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
public static JetProperty addPropertyType(Project project, JetProperty property, JetType type) {
|
||||
JetProperty newProperty = (JetProperty) property.copy();
|
||||
JetTypeReference typeReference = JetPsiFactory.createType(project, type.toString());
|
||||
PsiElement[] colon = JetPsiFactory.createColon(project);
|
||||
Pair<PsiElement, PsiElement> colon = JetPsiFactory.createColon(project);
|
||||
PsiElement nameIdentifier = newProperty.getNameIdentifier();
|
||||
assert nameIdentifier != null;
|
||||
newProperty.addAfter(typeReference, nameIdentifier);
|
||||
for (int i = colon.length - 1; i >= 0; i--) {
|
||||
newProperty.addAfter(colon[i], nameIdentifier);
|
||||
}
|
||||
newProperty.addRangeAfter(colon.getFirst(), colon.getSecond(), nameIdentifier);
|
||||
return newProperty;
|
||||
}
|
||||
|
||||
@@ -129,4 +135,14 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory<JetProperty> createRemoveInitializerFactory() {
|
||||
return new JetIntentionActionFactory<JetProperty>() {
|
||||
@Override
|
||||
public JetIntentionAction<JetProperty> createAction(DiagnosticWithPsiElement diagnostic) {
|
||||
assert diagnostic.getPsiElement() instanceof JetProperty;
|
||||
return new RemovePartsFromPropertyFix((JetProperty) diagnostic.getPsiElement(), true, false, false);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ public class ReplaceSafeCallToDotCall extends JetIntentionAction<JetElement> {
|
||||
JetSafeQualifiedExpression safeQualifiedExpression = (JetSafeQualifiedExpression) element;
|
||||
JetDotQualifiedExpression newElement = (JetDotQualifiedExpression) JetPsiFactory.createExpression(project, "x.foo");
|
||||
|
||||
//TODO check for null
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode());
|
||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode());
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace test
|
||||
|
||||
class List<T>() {
|
||||
val a : Array<T> = Array<T>(1)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = List<String>()
|
||||
a.a[0] = "1"
|
||||
println(a.a[0])
|
||||
|
||||
val b = List<Int?>()
|
||||
b.a[0] = 10
|
||||
println(b.a[0])
|
||||
|
||||
val c = List<Array<Int>>()
|
||||
c.a[0] = Array<Int>(4)
|
||||
println(c.a[0].size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun println(s : Any?) {
|
||||
System.out?.println(s);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add primary constructor to A" "true"
|
||||
namespace a
|
||||
|
||||
class A() {
|
||||
var i : Int = <caret>1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add primary constructor to A" "true"
|
||||
namespace a
|
||||
|
||||
class A<caret>() {
|
||||
var i : Int = 1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add primary constructor to A" "true"
|
||||
namespace a
|
||||
|
||||
class A {
|
||||
var i : Int = <caret>1
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Add primary constructor to A" "true"
|
||||
namespace a
|
||||
|
||||
class A<caret> {
|
||||
var i : Int = 1
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
namespace b {
|
||||
|
||||
import java.util.List
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
val l : <caret>List<Int>?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val e : <caret>Exception
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val i : <caret>Int
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
import java.util.List
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val l : <caret>List<Int>?
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
namespace b {
|
||||
|
||||
import java.util.List
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val l : <caret>List<Int>?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
namespace b {
|
||||
|
||||
import java.util.List
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
val l = <caret>Collections.emptyList<Int>()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val e = <caret>Exception("")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val i = <caret>10
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val l = <caret>Collections.emptyList<Int>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Remove initializer from property" "true"
|
||||
namespace a
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
namespace b {
|
||||
|
||||
class M {
|
||||
trait A {
|
||||
abstract val l = <caret>Collections.emptyList<Int>()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ArrayGenTest extends CodegenTestCase {
|
||||
public void testKt238 () throws Exception {
|
||||
blackBoxFile("regressions/kt238.jet");
|
||||
}
|
||||
|
||||
public void testKt326 () throws Exception {
|
||||
blackBoxFile("regressions/kt326.jet");
|
||||
}
|
||||
|
||||
public void testCreateMultiInt () throws Exception {
|
||||
loadText("fun foo() = Array<Array<Int>> (5)");
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof int[][]);
|
||||
}
|
||||
|
||||
public void testCreateMultiString () throws Exception {
|
||||
loadText("fun foo() = Array<Array<String>> (5)");
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof String[][]);
|
||||
}
|
||||
|
||||
public void testCreateMultiGenerics () throws Exception {
|
||||
/*
|
||||
loadText("class L<T>() { val a = Array<T>(5) } fun foo() = L<Int>.a");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof Integer[]);
|
||||
*/
|
||||
}
|
||||
|
||||
public void testIntGenerics () throws Exception {
|
||||
loadText("class L<T>(var a : T) {} fun foo() = L<Int>(5).a");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
Object invoke = foo.invoke(null);
|
||||
System.out.println(invoke.getClass());
|
||||
assertTrue(invoke instanceof Integer);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
public class ArrayGenTestCase extends CodegenTestCase {
|
||||
public void testKt238 () throws Exception {
|
||||
blackBoxFile("regressions/kt238.jet");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class AddPrimaryConstructorTest extends LightQuickFixTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/quickfix/addPrimaryConstructor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JetTestCaseBase.getTestDataPathBase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.jetbrains.jet.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ClassImportTests extends LightQuickFixTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/quickfix/classImport";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JetTestCaseBase.getTestDataPathBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JetTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package jet.typeinfo;
|
||||
import jet.JetObject;
|
||||
import jet.Tuple0;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.*;
|
||||
@@ -37,6 +38,10 @@ public abstract class TypeInfo<T> implements JetObject {
|
||||
public static final TypeInfo<Double> NULLABLE_DOUBLE_TYPE_INFO = getTypeInfo(Double.class, true);
|
||||
public static final TypeInfo<String> NULLABLE_STRING_TYPE_INFO = getTypeInfo(String.class, true);
|
||||
public static final TypeInfo<Tuple0> NULLABLE_TUPLE0_TYPE_INFO = getTypeInfo(Tuple0.class, true);
|
||||
|
||||
public static Object [] newArray(int length, TypeInfo typeInfo) {
|
||||
return (Object[]) Array.newInstance(((TypeInfoImpl) typeInfo).signature.klazz, length);
|
||||
}
|
||||
|
||||
public static <T> TypeInfoProjection invariantProjection(final TypeInfo<T> typeInfo) {
|
||||
return (TypeInfoProjection) typeInfo;
|
||||
|
||||
Reference in New Issue
Block a user