Tests for import class action added
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -22,12 +21,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
|
||||
private RemovePartsFromPropertyFix(@NotNull JetProperty element, JetType type) {
|
||||
super(element);
|
||||
if (type instanceof DeferredType) {
|
||||
this.type = ((DeferredType) type).getActualType();
|
||||
}
|
||||
else {
|
||||
this.type = type;
|
||||
}
|
||||
this.type = type;
|
||||
partsToRemove = partsToRemove(element.getGetter() != null && element.getGetter().getBodyExpression() != null,
|
||||
element.getSetter() != null && element.getSetter().getBodyExpression() != null,
|
||||
element.getInitializer() != null);
|
||||
|
||||
@@ -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,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