Tests for import class action added
This commit is contained in:
@@ -526,6 +526,9 @@ public class BodyResolver {
|
|||||||
|
|
||||||
if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
|
if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
|
||||||
JetType returnType = propertyDescriptor.getReturnType();
|
JetType returnType = propertyDescriptor.getReturnType();
|
||||||
|
if (returnType instanceof DeferredType) {
|
||||||
|
returnType = ((DeferredType) returnType).getActualType();
|
||||||
|
}
|
||||||
|
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
@@ -575,7 +578,11 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
if (inTrait) {
|
if (inTrait) {
|
||||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed in traits");
|
// 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) {
|
else if (!backingFieldRequired) {
|
||||||
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no backing field");
|
// context.getTrace().getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no backing field");
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ public class ErrorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isError(@NotNull DeclarationDescriptor candidate) {
|
public static boolean isError(@NotNull DeclarationDescriptor candidate) {
|
||||||
return candidate.getContainingDeclaration() == getErrorClass();
|
return candidate.getContainingDeclaration() == getErrorClass() || candidate == ERROR_MODULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ErrorTypeImpl implements JetType {
|
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.java.JavaDescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.DeferredType;
|
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.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ public class JetPluginUtil {
|
|||||||
JetScope libraryScope = standardLibrary.getLibraryScope();
|
JetScope libraryScope = standardLibrary.getLibraryScope();
|
||||||
|
|
||||||
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
||||||
if (declaration instanceof JavaClassDescriptor) {
|
if (declaration instanceof JavaClassDescriptor || ErrorUtils.isError(declaration)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (!(declaration instanceof NamespaceDescriptor)) {
|
while (!(declaration instanceof NamespaceDescriptor)) {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
|||||||
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
|
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
|
||||||
assert returnTypeReference != null;
|
assert returnTypeReference != null;
|
||||||
CodeEditUtil.replaceChild(newElement.getNode(), returnTypeReference.getNode(), newTypeReference.getNode());
|
CodeEditUtil.replaceChild(newElement.getNode(), returnTypeReference.getNode(), newTypeReference.getNode());
|
||||||
element.replace(newElement);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetParameter parameter = newElement.getParameter();
|
JetParameter parameter = newElement.getParameter();
|
||||||
@@ -56,8 +55,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
|||||||
JetTypeReference typeReference = parameter.getTypeReference();
|
JetTypeReference typeReference = parameter.getTypeReference();
|
||||||
assert typeReference != null;
|
assert typeReference != null;
|
||||||
CodeEditUtil.replaceChild(parameter.getNode(), typeReference.getNode(), newTypeReference.getNode());
|
CodeEditUtil.replaceChild(parameter.getNode(), typeReference.getNode(), newTypeReference.getNode());
|
||||||
element.replace(newElement);
|
|
||||||
}
|
}
|
||||||
|
ImportClassHelper.perform(type, element, newElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetIntentionActionFactory<JetPropertyAccessor> createFactory() {
|
public static JetIntentionActionFactory<JetPropertyAccessor> createFactory() {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.quickfix;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ public class ImportClassHelper {
|
|||||||
JetNamespace namespace = (JetNamespace) parent;
|
JetNamespace namespace = (JetNamespace) parent;
|
||||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
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);
|
element.replace(newElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.types.DeferredType;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,12 +21,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
|||||||
|
|
||||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, JetType type) {
|
private RemovePartsFromPropertyFix(@NotNull JetProperty element, JetType type) {
|
||||||
super(element);
|
super(element);
|
||||||
if (type instanceof DeferredType) {
|
this.type = type;
|
||||||
this.type = ((DeferredType) type).getActualType();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
partsToRemove = partsToRemove(element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
partsToRemove = partsToRemove(element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
||||||
element.getSetter() != null && element.getSetter().getBodyExpression() != null,
|
element.getSetter() != null && element.getSetter().getBodyExpression() != null,
|
||||||
element.getInitializer() != null);
|
element.getInitializer() != null);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public class ReplaceSafeCallToDotCall extends JetIntentionAction<JetElement> {
|
|||||||
JetSafeQualifiedExpression safeQualifiedExpression = (JetSafeQualifiedExpression) element;
|
JetSafeQualifiedExpression safeQualifiedExpression = (JetSafeQualifiedExpression) element;
|
||||||
JetDotQualifiedExpression newElement = (JetDotQualifiedExpression) JetPsiFactory.createExpression(project, "x.foo");
|
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.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode());
|
||||||
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode());
|
CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode());
|
||||||
|
|
||||||
|
|||||||
@@ -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,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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user