Merge branch 'master' into idea13

Conflicts:
	idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionToSupertypeFix.java
	idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java
	libraries/stdlib/src/kotlin/properties/Properties.kt
	libraries/stdlib/test/properties/delegation/DelegationTest.kt
	libraries/stdlib/test/properties/delegation/MapDelegationTest.kt
	libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt
	update_dependencies.xml
This commit is contained in:
Natalia.Ukhorskaya
2013-06-04 11:26:36 +04:00
198 changed files with 3212 additions and 550 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<root id="archive" name="instrumentation.jar">
<element id="module-output" name="instrumentation" />
<element id="extracted-dir" path="$PROJECT_DIR$/ideaSDK/lib/guava-12.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/ideaSDK/lib/asm4-all.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/ideaSDK/lib/jetbrains-asm-debug-all-4.0.jar" path-in-jar="/" />
</root>
</artifact>
</component>
+3
View File
@@ -539,12 +539,15 @@
</jar>
</target>
<!-- builds redistributables from sources -->
<target name="dist"
depends="clean,init,prepareDist,compileGenerators,invokeGenerators,preloader,compiler,compilerSources,antTools,jdkAnnotations,annotationsExt,runtime,jslib,j2kConverter"/>
<!-- builds everything, but classes are reused from project out dir, doesn't run proguard and javadoc -->
<target name="dist_quick"
depends="clean,init,prepareDist,preloader,compiler_quick,antTools,jdkAnnotations,annotationsExt,runtime,jslib,j2kConverter"/>
<!-- builds compiler jar from project out dir -->
<target name="dist_quick_compiler_only"
depends="init,prepareDist,preloader,compiler_quick"/>
@@ -17,9 +17,11 @@
package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.HierarchicalMethodSignature;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiSubstitutorImpl;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,7 +40,11 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.intellij.psi.util.TypeConversionUtil.erasure;
// This class contains heuristics for processing corner cases in propagation
class PropagationHeuristics {
@@ -122,8 +128,7 @@ class PropagationHeuristics {
@NotNull
static List<PsiMethod> getSuperMethods(@NotNull PsiMethod method) {
List<PsiMethod> superMethods = Lists.newArrayList();
for (HierarchicalMethodSignature superSignature : method.getHierarchicalMethodSignature().getSuperSignatures()) {
PsiMethod superMethod = superSignature.getMethod();
for (PsiMethod superMethod : new SuperMethodCollector(method).collect()) {
CallableMemberDescriptor.Kind kindFromFlags =
DescriptorKindUtils.flagsToKind(new PsiMethodWrapper(superMethod).getJetMethodAnnotation().kind());
if (kindFromFlags == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
@@ -141,4 +146,110 @@ class PropagationHeuristics {
private PropagationHeuristics() {
}
private static class SuperMethodCollector {
private final PsiMethod initialMethod;
private final String initialMethodName;
private final List<PsiType> initialParametersErasure;
private final List<PsiClass> visitedSuperclasses = Lists.newArrayList();
private final List<PsiMethod> collectedMethods = Lists.newArrayList();
private SuperMethodCollector(@NotNull PsiMethod initialMethod) {
this.initialMethod = initialMethod;
initialMethodName = initialMethod.getName();
PsiParameterList parameterList = initialMethod.getParameterList();
initialParametersErasure = Lists.newArrayListWithExpectedSize(parameterList.getParametersCount());
for (PsiParameter parameter : parameterList.getParameters()) {
initialParametersErasure.add(erasureNoEllipsis(parameter.getType()));
}
}
public List<PsiMethod> collect() {
if (!canHaveSuperMethod(initialMethod)) {
return Collections.emptyList();
}
PsiClass containingClass = initialMethod.getContainingClass();
assert containingClass != null : " containing class is null for " + initialMethod;
for (PsiClassType superType : containingClass.getSuperTypes()) {
collectFromSupertype(superType);
}
return collectedMethods;
}
private void collectFromSupertype(PsiClassType type) {
PsiClass klass = type.resolve();
if (klass == null) {
return;
}
if (!visitedSuperclasses.add(klass)) {
return;
}
PsiSubstitutor supertypeSubstitutor = getErasedSubstitutor(type);
for (PsiMethod methodFromSuper : klass.getMethods()) {
if (isSubMethodOf(methodFromSuper, supertypeSubstitutor)) {
collectedMethods.add(methodFromSuper);
return;
}
}
for (PsiType superType : type.getSuperTypes()) {
assert superType instanceof PsiClassType : "supertype is not a PsiClassType for " + type + ": " + superType;
collectFromSupertype((PsiClassType) superType);
}
}
private boolean isSubMethodOf(@NotNull PsiMethod methodFromSuper, @NotNull PsiSubstitutor supertypeSubstitutor) {
if (!methodFromSuper.getName().equals(initialMethodName)) {
return false;
}
PsiParameterList fromSuperParameterList = methodFromSuper.getParameterList();
if (fromSuperParameterList.getParametersCount() != initialParametersErasure.size()) {
return false;
}
for (int i = 0; i < initialParametersErasure.size(); i++) {
PsiType originalType = initialParametersErasure.get(i);
PsiType typeFromSuper = fromSuperParameterList.getParameters()[i].getType();
PsiType typeFromSuperErased = erasureNoEllipsis(supertypeSubstitutor.substitute(typeFromSuper));
if (!Comparing.equal(originalType, typeFromSuperErased)) {
return false;
}
}
return true;
}
private static PsiType erasureNoEllipsis(PsiType type) {
if (type instanceof PsiEllipsisType) {
return erasureNoEllipsis(((PsiEllipsisType) type).toArrayType());
}
return erasure(type);
}
private static PsiSubstitutor getErasedSubstitutor(PsiClassType type) {
Map<PsiTypeParameter, PsiType> unerasedMap = type.resolveGenerics().getSubstitutor().getSubstitutionMap();
Map<PsiTypeParameter, PsiType> erasedMap = Maps.newHashMapWithExpectedSize(unerasedMap.size());
for (Map.Entry<PsiTypeParameter, PsiType> entry : unerasedMap.entrySet()) {
erasedMap.put(entry.getKey(), erasure(entry.getValue()));
}
return PsiSubstitutorImpl.createSubstitutor(erasedMap);
}
private static boolean canHaveSuperMethod(PsiMethod method) {
if (method.isConstructor()) return false;
if (method.hasModifierProperty(PsiModifier.STATIC)) return false;
if (method.hasModifierProperty(PsiModifier.PRIVATE)) return false;
PsiClass containingClass = method.getContainingClass();
return containingClass != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName());
}
}
}
@@ -18,17 +18,20 @@ package org.jetbrains.jet.lang.resolve.calls.autocasts;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
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.JetModuleUtil;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
public class DataFlowValueFactory {
public static final DataFlowValueFactory INSTANCE = new DataFlowValueFactory();
@@ -42,8 +45,8 @@ public class DataFlowValueFactory {
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
}
if (TypeUtils.equalTypes(type, KotlinBuiltIns.getInstance().getNullableNothingType())) return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
Pair<Object, Boolean> result = getIdForStableIdentifier(expression, bindingContext, false);
return new DataFlowValue(result.first == null ? expression : result.first, type, result.second, getImmanentNullability(type));
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext);
return new DataFlowValue(result.id == null ? expression : result.id, type, result.isStable, getImmanentNullability(type));
}
@NotNull
@@ -104,55 +107,154 @@ public class DataFlowValueFactory {
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
}
private static class IdentifierInfo {
public final Object id;
public final boolean isStable;
public final boolean isNamespace;
private IdentifierInfo(Object id, boolean isStable, boolean isNamespace) {
this.id = id;
this.isStable = isStable;
this.isNamespace = isNamespace;
}
}
private static final IdentifierInfo ERROR_IDENTIFIER_INFO = new IdentifierInfo(null, false, false);
@NotNull
private static Pair<Object, Boolean> getIdForStableIdentifier(@NotNull JetExpression expression, @NotNull BindingContext bindingContext, boolean allowNamespaces) {
private static IdentifierInfo createInfo(Object id, boolean isStable) {
return new IdentifierInfo(id, isStable, false);
}
@NotNull
private static IdentifierInfo createNamespaceInfo(Object id) {
return new IdentifierInfo(id, true, true);
}
@NotNull
private static IdentifierInfo combineInfo(@Nullable IdentifierInfo receiverInfo, @NotNull IdentifierInfo selectorInfo) {
if (receiverInfo == null || receiverInfo == ERROR_IDENTIFIER_INFO || receiverInfo.isNamespace) {
return selectorInfo;
}
return createInfo(Pair.create(receiverInfo.id, selectorInfo.id), receiverInfo.isStable && selectorInfo.isStable);
}
@NotNull
private static IdentifierInfo getIdForStableIdentifier(
@Nullable JetExpression expression,
@NotNull BindingContext bindingContext
) {
if (expression instanceof JetParenthesizedExpression) {
JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) expression;
JetExpression innerExpression = parenthesizedExpression.getExpression();
if (innerExpression == null) {
return Pair.create(null, false);
}
return getIdForStableIdentifier(innerExpression, bindingContext, allowNamespaces);
return getIdForStableIdentifier(innerExpression, bindingContext);
}
else if (expression instanceof JetQualifiedExpression) {
JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) expression;
JetExpression receiverExpression = qualifiedExpression.getReceiverExpression();
JetExpression selectorExpression = qualifiedExpression.getSelectorExpression();
if (selectorExpression == null) {
return Pair.create(null, false);
}
Pair<Object, Boolean> receiverId = getIdForStableIdentifier(qualifiedExpression.getReceiverExpression(), bindingContext, true);
Pair<Object, Boolean> selectorId = getIdForStableIdentifier(selectorExpression, bindingContext, allowNamespaces);
return receiverId.second ? selectorId : Pair.create(receiverId.first, false);
IdentifierInfo receiverId = getIdForStableIdentifier(receiverExpression, bindingContext);
IdentifierInfo selectorId = getIdForStableIdentifier(selectorExpression, bindingContext);
return combineInfo(receiverId, selectorId);
}
if (expression instanceof JetSimpleNameExpression) {
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
if (declarationDescriptor instanceof VariableDescriptor) {
return Pair.create((Object) declarationDescriptor, isStableVariable((VariableDescriptor) declarationDescriptor));
}
if (declarationDescriptor instanceof NamespaceDescriptor) {
return Pair.create((Object) declarationDescriptor, allowNamespaces);
}
if (declarationDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
return Pair.create((Object) classDescriptor, classDescriptor.isClassObjectAValue());
}
return getIdForSimpleNameExpression((JetSimpleNameExpression) expression, bindingContext);
}
else if (expression instanceof JetThisExpression) {
JetThisExpression thisExpression = (JetThisExpression) expression;
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, thisExpression.getInstanceReference());
if (declarationDescriptor instanceof CallableDescriptor) {
return Pair.create((Object) ((CallableDescriptor) declarationDescriptor).getReceiverParameter().getValue(), true);
}
if (declarationDescriptor instanceof ClassDescriptor) {
return Pair.create((Object) ((ClassDescriptor) declarationDescriptor).getThisAsReceiverParameter().getValue(), true);
}
return Pair.create(null, true);
return getIdForThisReceiver(declarationDescriptor);
}
else if (expression instanceof JetRootNamespaceExpression) {
return Pair.create((Object) JetModuleUtil.getRootNamespaceType(expression), allowNamespaces);
return createNamespaceInfo(JetModuleUtil.getRootNamespaceType(expression));
}
return Pair.create(null, false);
return ERROR_IDENTIFIER_INFO;
}
@NotNull
private static IdentifierInfo getIdForSimpleNameExpression(
@NotNull JetSimpleNameExpression simpleNameExpression,
@NotNull BindingContext bindingContext
) {
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
if (declarationDescriptor instanceof VariableDescriptor) {
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, simpleNameExpression);
// todo return assert
// for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes
// assert resolvedCall != null : "Cannot create right identifier info if the resolved call is not known yet for " + declarationDescriptor;
IdentifierInfo receiverInfo = resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null;
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor)));
}
if (declarationDescriptor instanceof NamespaceDescriptor) {
return createNamespaceInfo(declarationDescriptor);
}
if (declarationDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
return createInfo(classDescriptor, classDescriptor.isClassObjectAValue());
}
return ERROR_IDENTIFIER_INFO;
}
@Nullable
private static IdentifierInfo getIdForImplicitReceiver(@NotNull ReceiverValue receiverValue, @Nullable final JetExpression expression) {
return receiverValue.accept(new ReceiverValueVisitor<IdentifierInfo, Void>() {
@Override
public IdentifierInfo visitNoReceiver(ReceiverValue noReceiver, Void data) {
return null;
}
@Override
public IdentifierInfo visitTransientReceiver(TransientReceiver receiver, Void data) {
assert false: "Transient receiver is implicit for an explicit expression: " + expression + ". Receiver: " + receiver;
return null;
}
@Override
public IdentifierInfo visitExtensionReceiver(ExtensionReceiver receiver, Void data) {
return getIdForThisReceiver(receiver);
}
@Override
public IdentifierInfo visitExpressionReceiver(ExpressionReceiver receiver, Void data) {
// there is an explicit "this" expression and it was analyzed earlier
return null;
}
@Override
public IdentifierInfo visitClassReceiver(ClassReceiver receiver, Void data) {
return getIdForThisReceiver(receiver);
}
@Override
public IdentifierInfo visitScriptReceiver(ScriptReceiver receiver, Void data) {
return getIdForThisReceiver(receiver);
}
}, null);
}
@NotNull
private static IdentifierInfo getIdForThisReceiver(@NotNull ThisReceiver thisReceiver) {
return getIdForThisReceiver(thisReceiver.getDeclarationDescriptor());
}
@NotNull
private static IdentifierInfo getIdForThisReceiver(@Nullable DeclarationDescriptor descriptorOfThisReceiver) {
if (descriptorOfThisReceiver instanceof CallableDescriptor) {
ReceiverParameterDescriptor receiverParameter = ((CallableDescriptor) descriptorOfThisReceiver).getReceiverParameter();
assert receiverParameter != null : "'This' refers to the callable member without a receiver parameter: " + descriptorOfThisReceiver;
return createInfo(receiverParameter.getValue(), true);
}
if (descriptorOfThisReceiver instanceof ClassDescriptor) {
return createInfo(((ClassDescriptor) descriptorOfThisReceiver).getThisAsReceiverParameter().getValue(), true);
}
return ERROR_IDENTIFIER_INFO;
}
public static boolean isStableVariable(@NotNull VariableDescriptor variableDescriptor) {
@@ -16,28 +16,16 @@
package org.jetbrains.jet.lang.resolve.scopes.receivers;
public class ReceiverValueVisitor<R, D> {
public R visitNoReceiver(ReceiverValue noReceiver, D data) {
return null;
}
public interface ReceiverValueVisitor<R, D> {
R visitNoReceiver(ReceiverValue noReceiver, D data);
public R visitTransientReceiver(TransientReceiver receiver, D data) {
return null;
}
R visitTransientReceiver(TransientReceiver receiver, D data);
public R visitExtensionReceiver(ExtensionReceiver receiver, D data) {
return null;
}
R visitExtensionReceiver(ExtensionReceiver receiver, D data);
public R visitExpressionReceiver(ExpressionReceiver receiver, D data) {
return null;
}
R visitExpressionReceiver(ExpressionReceiver receiver, D data);
public R visitClassReceiver(ClassReceiver receiver, D data) {
return null;
}
R visitClassReceiver(ClassReceiver receiver, D data);
public R visitScriptReceiver(ScriptReceiver receiver, D data) {
return null;
}
R visitScriptReceiver(ScriptReceiver receiver, D data);
}
+1 -1
View File
@@ -27,7 +27,7 @@ This is determined by the ```src/META-INF/services/org.jetbrains.jet.preloading.
Preloader loads the **first** instrumenter service found on the class path.
Services are provided through the [standard JDK mechanism](http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html).
Every preloaded class is run through the instrumenter. Before exiting the program instrumenter's dupm() method is called.
Every preloaded class is run through the instrumenter. Before exiting the program instrumenter's dump() method is called.
**Note** JDK classes and everything in the Preloader's own class path are not preloaded, thus not instrumented.
The ```instrumentation``` module provides a convenient way to define useful instrumenters:
@@ -0,0 +1,23 @@
package bar
class Test {
val foo: Int? = null
fun foo(o: Test) = foo == null && o.foo == null // ERROR warning: o.test == null is always true
fun bar(a: Test, b: Test) {
if (a.foo != null) {
useInt(<!TYPE_MISMATCH!>b.foo<!>)
}
if (a.foo != null) {
useInt(<!TYPE_MISMATCH!>foo<!>)
}
if (this.foo != null) {
useInt(foo)
}
if (foo != null) {
useInt(this.foo)
}
}
fun useInt(i: Int) = i
}
@@ -0,0 +1,25 @@
//FILE: bar.kt
package bar
val i: Int? = 2
//FILE: foo.kt
package foo
val i: Int? = 1
class A(val i: Int?) {
fun testUseFromClass() {
if (foo.i != null) {
useInt(<!TYPE_MISMATCH!>i<!>)
}
}
}
fun testUseFromOtherPackage() {
if (bar.i != null) {
useInt(<!TYPE_MISMATCH!>i<!>)
}
}
fun useInt(i: Int) = i
@@ -0,0 +1,36 @@
package foo
class A(val i: Int?) {
fun test1() {
if (this@A.i != null) {
useInt(this.i)
useInt(i)
}
}
inner class B {
fun test2() {
if (i != null) {
useInt(this@A.i)
}
}
}
}
fun A.foo() {
if (this@foo.i != null) {
useInt(this.i)
useInt(i)
}
}
fun test3() {
useFunction {
if(i != null) {
useInt(this.i)
}
}
}
fun useInt(i: Int) = i
fun useFunction(f: A.() -> Unit) = f
@@ -0,0 +1,39 @@
package foo
class C(val i: Int?) {}
class A(val c: C) {
fun test1() {
if (this@A.c.i != null) {
useInt(this.c.i)
useInt(c.i)
}
}
inner class B {
fun test2() {
if (c.i != null) {
useInt(this@A.c.i)
}
}
}
}
fun A.foo() {
if (this@foo.c.i != null) {
useInt(this.c.i)
useInt(c.i)
}
}
fun test3() {
useFunction {
if(c.i != null) {
useInt(this.c.i)
}
}
}
fun useInt(i: Int) = i
fun useFunction(f: A.() -> Unit) = f
@@ -4722,6 +4722,26 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");
}
@TestMetadata("kt2422.kt")
public void testKt2422() throws Exception {
doTest("compiler/testData/diagnostics/tests/smartCasts/kt2422.kt");
}
@TestMetadata("noErrorCheckForPackageLevelVal.kt")
public void testNoErrorCheckForPackageLevelVal() throws Exception {
doTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
}
@TestMetadata("thisWithLabel.kt")
public void testThisWithLabel() throws Exception {
doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.kt");
}
@TestMetadata("thisWithLabelAsReceiverPart.kt")
public void testThisWithLabelAsReceiverPart() throws Exception {
doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabelAsReceiverPart.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/substitutions")
@@ -59,9 +59,12 @@ add.semicolon.after.invocation=Add semicolon after invocation of ''{0}''
add.semicolon.family=Add Semicolon
change.function.return.type=Change ''{0}'' function return type to ''{1}''
change.no.name.function.return.type=Change function return type to ''{0}''
change.function.literal.return.type=Change function literal return type to ''{0}''
remove.function.return.type=Remove explicitly specified return type in ''{0}'' function
remove.no.name.function.return.type=Remove explicitly specified function return type
change.element.type=Change ''{0}'' type to ''{1}''
change.function.parameter.type=Change parameter ''{0}'' type of function ''{1}'' to ''{2}''
change.primary.constructor.parameter.type=Change parameter ''{0}'' type of primary constructor of class ''{1}'' to ''{2}''
change.type=Change type from ''{0}'' to ''{1}''
change.type.family=Change Type
add.parameters.to.function=Add parameter{0} to function ''{1}''
@@ -43,12 +43,12 @@ class ConvertedCode implements TextBlockTransferableData {
@Override
public int getOffsets(int[] offsets, int index) {
return 0;
return index;
}
@Override
public int setOffsets(int[] offsets, int index) {
return 0;
return index;
}
public String getData() {
@@ -43,9 +43,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory;
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionsFactory;
import org.jetbrains.jet.plugin.quickfix.QuickFixes;
import org.jetbrains.jet.utils.ExceptionUtils;
import java.util.Collection;
import java.util.List;
@@ -217,14 +216,12 @@ public class JetPsiChecker implements Annotator {
return null;
}
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.getActionFactories(diagnostic.getFactory());
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
IntentionAction action = null;
if (intentionActionFactory != null) {
action = intentionActionFactory.createAction(diagnostic);
}
if (action != null) {
annotation.registerFix(action);
Collection<JetIntentionActionsFactory> intentionActionsFactories = QuickFixes.getActionsFactories(diagnostic.getFactory());
for (JetIntentionActionsFactory intentionActionsFactory : intentionActionsFactories) {
if (intentionActionsFactory != null) {
for (IntentionAction action: intentionActionsFactory.createActions(diagnostic)) {
annotation.registerFix(action);
}
}
}
@@ -67,8 +67,8 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
element.replace(newElement);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
@@ -158,8 +158,8 @@ public class AddFunctionToSupertypeFix extends JetHintAction<JetNamedFunction> {
return new JetAddFunctionToClassifierAction(project, editor, bindingContext, functionsToAdd);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetIntentionActionsFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -164,8 +164,8 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
return true;
}
public static <T extends JetModifierListOwner> JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class<T> modifierOwnerClass) {
return new JetIntentionActionFactory() {
public static <T extends JetModifierListOwner> JetSingleIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class<T> modifierOwnerClass) {
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, modifierOwnerClass);
@@ -175,7 +175,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
};
}
public static JetIntentionActionFactory createFactory(JetKeywordToken modifier) {
public static JetSingleIntentionActionFactory createFactory(JetKeywordToken modifier) {
return createFactory(modifier, JetModifierListOwner.class);
}
@@ -183,8 +183,8 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
return JetBundle.message("add.name.to.argument.family");
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetIntentionActionsFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -81,8 +81,8 @@ public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction<Jet
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -61,8 +61,8 @@ public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction<JetCall
editor.getCaretModel().moveToOffset(caretOffset + 1);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
@@ -68,8 +68,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
return true;
}
public static JetIntentionActionFactory createFactoryForIsExpression() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForIsExpression() {
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.NO_TYPE_ARGUMENTS_ON_RHS_OF_IS_EXPRESSION;
@@ -84,8 +84,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
};
}
public static JetIntentionActionFactory createFactoryForJavaClass() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForJavaClass() {
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
@@ -74,8 +74,8 @@ public class AddWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
editor.getCaretModel().moveToOffset(textRange.getStartOffset() + indexOfOpenBrace + 1);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
@@ -289,8 +289,8 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
}
@Nullable
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetSimpleNameExpression> createAction(@NotNull Diagnostic diagnostic) {
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -33,19 +32,22 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class CastExpressionFix extends JetIntentionAction<JetExpression> {
private final JetType type;
private final String renderedType;
public CastExpressionFix(@NotNull JetExpression element, @NotNull JetType type) {
super(element);
this.type = type;
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
}
@NotNull
@Override
public String getText() {
return JetBundle.message("cast.expression.to.type", element.getText(), type.toString());
return JetBundle.message("cast.expression.to.type", element.getText(), renderedType);
}
@NotNull
@@ -64,9 +66,9 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetBinaryExpressionWithTypeRHS castedExpression =
(JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, "(" + element.getText() + ") as " + type.toString());
(JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, "(" + element.getText() + ") as " + renderedType);
if (JetPsiUtil.areParenthesesUseless((JetParenthesizedExpression) castedExpression.getLeft())) {
castedExpression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, element.getText() + " as " + type.toString());
castedExpression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, element.getText() + " as " + renderedType);
}
JetParenthesizedExpression castedExpressionInParentheses =
@@ -78,8 +80,8 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
}
@NotNull
public static JetIntentionActionFactory createFactoryForAutoCastImpossible() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForAutoCastImpossible() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -91,32 +93,4 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
}
};
}
@NotNull
public static JetIntentionActionFactory createFactoryForTypeMismatch() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
JetExpression expression = diagnosticWithParameters.getPsiElement();
// we don't want to cast a cast:
if (expression instanceof JetBinaryExpressionWithTypeRHS) {
return null;
}
// 'x: Int' - TYPE_MISMATCH might be reported on 'x', and we don't want this quickfix to be available:
JetBinaryExpressionWithTypeRHS parentExpressionWithTypeRHS =
PsiTreeUtil.getParentOfType(expression, JetBinaryExpressionWithTypeRHS.class, true);
if (parentExpressionWithTypeRHS != null && parentExpressionWithTypeRHS.getLeft() == expression) {
return null;
}
return new CastExpressionFix(expression, diagnosticWithParameters.getA());
}
};
}
}
@@ -23,38 +23,38 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
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.JetBundle;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccessor> {
private String renderedType;
public ChangeAccessorTypeFix(@NotNull JetPropertyAccessor element) {
super(element);
}
@Nullable
private JetType getPropertyType() {
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
if (property == null) return null;
return QuickFixUtil.getDeclarationReturnType(property);
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
JetType type = getPropertyType();
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
if (property == null) return false;
JetType type = QuickFixUtil.getDeclarationReturnType(property);
if (super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type)) {
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
return true;
}
return false;
}
@NotNull
@Override
public String getText() {
JetType type = getPropertyType();
return element.isGetter()
? JetBundle.message("change.getter.type", type)
: JetBundle.message("change.setter.type", type);
? JetBundle.message("change.getter.type", renderedType)
: JetBundle.message("change.setter.type", renderedType);
}
@NotNull
@@ -65,10 +65,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetType type = getPropertyType();
if (type == null) return;
JetPropertyAccessor newElement = (JetPropertyAccessor) element.copy();
JetTypeReference newTypeReference = JetPsiFactory.createType(project, type.toString());
JetTypeReference newTypeReference = JetPsiFactory.createType(project, renderedType);
if (element.isGetter()) {
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
@@ -85,8 +83,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
element.replace(newElement);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetPropertyAccessor> createAction(Diagnostic diagnostic) {
JetPropertyAccessor accessor = QuickFixUtil.getParentElementOfType(diagnostic, JetPropertyAccessor.class);
@@ -0,0 +1,140 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.LinkedList;
import java.util.List;
public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFunctionLiteralExpression> {
private final String renderedType;
private final JetTypeReference functionLiteralReturnTypeRef;
private IntentionAction appropriateQuickFix = null;
public ChangeFunctionLiteralReturnTypeFix(@NotNull JetFunctionLiteralExpression element, @NotNull JetType type) {
super(element);
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
functionLiteralReturnTypeRef = element.getFunctionLiteral().getReturnTypeRef();
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, element);
assert functionLiteralType != null : "Type of function literal not available in binding context";
ClassDescriptor functionClass = KotlinBuiltIns.getInstance().getFunction(functionLiteralType.getArguments().size() - 1);
List<JetType> functionClassTypeParameters = new LinkedList<JetType>();
for (TypeProjection typeProjection: functionLiteralType.getArguments()) {
functionClassTypeParameters.add(typeProjection.getType());
}
// Replacing return type:
functionClassTypeParameters.remove(functionClassTypeParameters.size() - 1);
functionClassTypeParameters.add(type);
JetType eventualFunctionLiteralType = TypeUtils.substituteParameters(functionClass, functionClassTypeParameters);
JetProperty correspondingProperty = PsiTreeUtil.getParentOfType(element, JetProperty.class);
if (correspondingProperty != null && QuickFixUtil.canEvaluateTo(correspondingProperty.getInitializer(), element)) {
JetTypeReference correspondingPropertyTypeRef = correspondingProperty.getTypeRef();
JetType propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef);
if (propertyType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, propertyType)) {
appropriateQuickFix = new ChangeVariableTypeFix(correspondingProperty, eventualFunctionLiteralType);
}
return;
}
JetParameter correspondingParameter = QuickFixUtil.getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(element);
if (correspondingParameter != null) {
JetTypeReference correspondingParameterTypeRef = correspondingParameter.getTypeReference();
JetType parameterType = context.get(BindingContext.TYPE, correspondingParameterTypeRef);
if (parameterType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, parameterType)) {
appropriateQuickFix = new ChangeParameterTypeFix(correspondingParameter, eventualFunctionLiteralType);
}
return;
}
JetFunction parentFunction = PsiTreeUtil.getParentOfType(element, JetFunction.class, true);
if (parentFunction != null && QuickFixUtil.canFunctionOrGetterReturnExpression(parentFunction, element)) {
JetTypeReference parentFunctionReturnTypeRef = parentFunction.getReturnTypeRef();
JetType parentFunctionReturnType = context.get(BindingContext.TYPE, parentFunctionReturnTypeRef);
if (parentFunctionReturnType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, parentFunctionReturnType)) {
appropriateQuickFix = new ChangeFunctionReturnTypeFix(parentFunction, eventualFunctionLiteralType);
}
}
}
@NotNull
@Override
public String getText() {
if (appropriateQuickFix != null) {
return appropriateQuickFix.getText();
}
return JetBundle.message("change.function.literal.return.type", renderedType);
}
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("change.type.family");
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return super.isAvailable(project, editor, file) &&
(functionLiteralReturnTypeRef != null || (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)));
}
@Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
if (functionLiteralReturnTypeRef != null) {
functionLiteralReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
}
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)) {
appropriateQuickFix.invoke(project, editor, file);
}
}
@NotNull
public static JetSingleIntentionActionFactory createFactoryForExpectedOrAssignmentTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetFunctionLiteralExpression functionLiteralExpression = QuickFixUtil.getParentElementOfType(diagnostic, JetFunctionLiteralExpression.class);
assert functionLiteralExpression != null : "ASSIGNMENT/EXPECTED_TYPE_MISMATCH reported outside any function literal";
return new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, KotlinBuiltIns.getInstance().getUnitType());
}
};
}
}
@@ -23,11 +23,13 @@ import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters3;
import org.jetbrains.jet.lang.psi.*;
@@ -37,24 +39,45 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManagerUtil;
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunction> {
import java.util.LinkedList;
import java.util.List;
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
private final JetType type;
private final String renderedType;
private final ChangeFunctionLiteralReturnTypeFix changeFunctionLiteralReturnTypeFix;
public ChangeFunctionReturnTypeFix(@NotNull JetNamedFunction element, @NotNull JetType type) {
public ChangeFunctionReturnTypeFix(@NotNull JetFunction element, @NotNull JetType type) {
super(element);
this.type = type;
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
if (element instanceof JetFunctionLiteral) {
JetFunctionLiteralExpression functionLiteralExpression = PsiTreeUtil.getParentOfType(element, JetFunctionLiteralExpression.class);
assert functionLiteralExpression != null : "FunctionLiteral outside any FunctionLiteralExpression";
changeFunctionLiteralReturnTypeFix = new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, type);
}
else {
changeFunctionLiteralReturnTypeFix = null;
}
}
@NotNull
@Override
public String getText() {
if (changeFunctionLiteralReturnTypeFix != null) {
return changeFunctionLiteralReturnTypeFix.getText();
}
String functionName = element.getName();
FqName fqName = JetPsiUtil.getFQName(element);
if (fqName != null) functionName = fqName.asString();
@@ -65,8 +88,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
JetBundle.message("remove.function.return.type", functionName);
}
return functionName == null ?
JetBundle.message("change.no.name.function.return.type", type.toString()) :
JetBundle.message("change.function.return.type", functionName, type.toString());
JetBundle.message("change.no.name.function.return.type", renderedType) :
JetBundle.message("change.function.return.type", functionName, renderedType);
}
@NotNull
@@ -76,10 +99,20 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
}
@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) throws IncorrectOperationException {
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
addReturnTypeAnnotation(project, element, type.toString());
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) {
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
}
@Override
public void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable JetFile file) throws IncorrectOperationException {
if (changeFunctionLiteralReturnTypeFix != null) {
changeFunctionLiteralReturnTypeFix.invoke(project, editor, file);
}
else {
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
addReturnTypeAnnotation(project, element, renderedType);
}
}
}
@@ -97,6 +130,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
@NotNull
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
String componentName = ((DiagnosticWithParameters3<JetExpression, Name, JetType, JetType>) diagnostic).getA().asString();
int componentIndex = Integer.valueOf(componentName.substring(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX.length()));
JetMultiDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, JetMultiDeclaration.class);
@@ -105,8 +139,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
}
@NotNull
public static JetIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -114,7 +148,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) entry.getContainingFile().getContainingFile()).getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null;
JetNamedFunction componentFunction = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeRef());
if (componentFunction != null && expectedType != null) {
return new ChangeFunctionReturnTypeFix(componentFunction, expectedType);
@@ -125,8 +159,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
}
@NotNull
public static JetIntentionActionFactory createFactoryForHasNextFunctionTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForHasNextFunctionTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -135,7 +169,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
if (resolvedCall == null) return null;
JetNamedFunction hasNextFunction = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
if (hasNextFunction != null) {
return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType());
}
@@ -145,67 +179,75 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
}
@NotNull
public static JetIntentionActionFactory createFactoryForCompareToTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForCompareToTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression";
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext();
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL,
expression.getOperationReference());
if (resolvedCall == null) return null;
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
if (!(compareTo instanceof JetNamedFunction)) return null;
return new ChangeFunctionReturnTypeFix((JetNamedFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
if (!(compareTo instanceof JetFunction)) return null;
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
}
};
}
@NotNull
public static JetIntentionActionFactory createFactoryForReturnTypeMismatchOnOverride() {
return new JetIntentionActionFactory() {
@Nullable
public static JetIntentionActionsFactory createFactoryForReturnTypeMismatchOnOverride() {
return new JetIntentionActionsFactory() {
@NotNull
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
if (function == null) return null;
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(function);
JetType matchingReturnType = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, function);
return matchingReturnType == null ? null : new ChangeFunctionReturnTypeFix(function, matchingReturnType);
public List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> actions = new LinkedList<IntentionAction>();
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
if (function != null) {
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(function);
JetType matchingReturnType = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, function);
if (matchingReturnType != null) {
actions.add(new ChangeFunctionReturnTypeFix(function, matchingReturnType));
}
SimpleFunctionDescriptor descriptor = context.get(BindingContext.FUNCTION, function);
if (descriptor == null) return actions;
JetType functionType = descriptor.getReturnType();
if (functionType == null) return actions;
List<FunctionDescriptor> overriddenMismatchingFunctions = new LinkedList<FunctionDescriptor>();
for (FunctionDescriptor overriddenFunction: descriptor.getOverriddenDescriptors()) {
JetType overriddenFunctionType = overriddenFunction.getReturnType();
if (overriddenFunctionType == null) continue;
if (!JetTypeChecker.INSTANCE.isSubtypeOf(functionType, overriddenFunctionType)) {
overriddenMismatchingFunctions.add(overriddenFunction);
}
}
if (overriddenMismatchingFunctions.size() == 1) {
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingFunctions.get(0));
if (overriddenFunction instanceof JetFunction) {
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) overriddenFunction, functionType));
}
}
}
return actions;
}
};
}
@NotNull
public static JetIntentionActionFactory createFactoryForChangingReturnTypeToUnit() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForChangingReturnTypeToUnit() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
return function == null ? null : new ChangeFunctionReturnTypeFix(function, KotlinBuiltIns.getInstance().getUnitType());
}
};
}
@NotNull
public static JetIntentionActionFactory createFactoryForTypeMismatch() {
return new JetIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetExpression expression = (JetExpression) diagnostic.getPsiElement();
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
if (function != null && (function.getInitializer() == expression || expression.getParent() instanceof JetReturnExpression)) {
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) diagnostic.getPsiFile()).getBindingContext();
JetType type = context.get(BindingContext.EXPRESSION_TYPE, expression);
assert type != null : "Expression type mismatch, but expression has no type";
return new ChangeFunctionReturnTypeFix(function, type);
}
return null;
}
};
}
}
@@ -124,8 +124,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
});
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class);
@@ -140,8 +140,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
};
}
public static JetIntentionActionFactory createFactoryForParametersNumberMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForParametersNumberMismatch() {
return new JetSingleIntentionActionFactory() {
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
@@ -159,8 +159,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
};
}
public static JetIntentionActionFactory createFactoryForUnusedParameter() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForUnusedParameter() {
return new JetSingleIntentionActionFactory() {
@Override
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
@SuppressWarnings("unchecked")
@@ -253,8 +253,8 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -0,0 +1,70 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
private final String renderedType;
private final String containingDeclarationName;
private final boolean isPrimaryConstructorParameter;
public ChangeParameterTypeFix(@NotNull JetParameter element, @NotNull JetType type) {
super(element);
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
JetNamedDeclaration declaration = PsiTreeUtil.getParentOfType(element, JetNamedDeclaration.class);
isPrimaryConstructorParameter = declaration instanceof JetClass;
FqName declarationFQName = declaration == null ? null : JetPsiUtil.getFQName(declaration);
containingDeclarationName = declarationFQName == null ? null : declarationFQName.asString();
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return super.isAvailable(project, editor, file) && containingDeclarationName != null;
}
@NotNull
@Override
public String getText() {
return isPrimaryConstructorParameter ?
JetBundle.message("change.primary.constructor.parameter.type", element.getName(), containingDeclarationName, renderedType) :
JetBundle.message("change.function.parameter.type", element.getName(), containingDeclarationName, renderedType);
}
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("change.type.family");
}
@Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
JetTypeReference typeReference = element.getTypeReference();
assert typeReference != null : "Parameter without type annotation cannot cause type mismatch";
typeReference.replace(JetPsiFactory.createType(project, renderedType));
}
}
@@ -49,8 +49,8 @@ public class ChangeToBackingFieldFix extends JetIntentionAction<JetSimpleNameExp
element.replace(backingField);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetSimpleNameExpression> createAction(Diagnostic diagnostic) {
JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class);
@@ -84,8 +84,8 @@ public class ChangeToConstructorInvocationFix extends JetIntentionAction<JetDele
element.replace(specifier);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetDelegatorToSuperClass> createAction(Diagnostic diagnostic) {
if (diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass) {
@@ -50,8 +50,8 @@ public class ChangeToFunctionInvocationFix extends JetIntentionAction<JetExpress
element.replace(JetPsiFactory.createExpression(project, reference.getText() + "()"));
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetExpression> createAction(Diagnostic diagnostic) {
if (diagnostic.getPsiElement() instanceof JetExpression) {
@@ -58,8 +58,8 @@ public class ChangeToPropertyNameFix extends JetIntentionAction<JetSimpleNameExp
element.replace(propertyName);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetSimpleNameExpression> createAction(Diagnostic diagnostic) {
JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class);
@@ -54,8 +54,8 @@ public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement
}
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
@@ -19,31 +19,32 @@ package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
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.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.psi.JetTypeReference;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.renderer.DescriptorRenderer;
public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
private final JetType type;
private final String renderedType;
public ChangeTypeFix(@NotNull JetTypeReference element, JetType type) {
super(element);
this.type = type;
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
}
@NotNull
@Override
public String getText() {
return JetBundle.message("change.type", element.getText(), type);
return JetBundle.message("change.type", element.getText(), renderedType);
}
@NotNull
@@ -53,13 +54,13 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
element.replace(JetPsiFactory.createType(project, type.toString()));
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
element.replace(JetPsiFactory.createType(project, renderedType));
}
@NotNull
public static JetIntentionActionFactory createFactoryForExpectedParameterTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForExpectedParameterTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -74,8 +75,8 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
}
@NotNull
public static JetIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -26,29 +26,43 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.plugin.JetBundle;
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManagerUtil;
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.LinkedList;
import java.util.List;
public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclaration> {
private final String renderedType;
private final JetType type;
public ChangeVariableTypeFix(@NotNull JetVariableDeclaration element, @NotNull JetType type) {
super(element);
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
this.type = type;
}
@NotNull
@Override
public String getText() {
return JetBundle.message("change.element.type", element.getName(), type);
String propertyName = element.getName();
FqName fqName = JetPsiUtil.getFQName(element);
if (fqName != null) propertyName = fqName.asString();
return JetBundle.message("change.element.type", propertyName, renderedType);
}
@NotNull
@@ -58,17 +72,37 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
}
@Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
PsiElement nameIdentifier = element.getNameIdentifier();
assert nameIdentifier != null : "ChangeVariableTypeFix applied to variable without name";
Pair<PsiElement, PsiElement> typeWhiteSpaceAndColon = JetPsiFactory.createTypeWhiteSpaceAndColon(project, type.toString());
Pair<PsiElement, PsiElement> typeWhiteSpaceAndColon = JetPsiFactory.createTypeWhiteSpaceAndColon(project, renderedType);
element.addRangeAfter(typeWhiteSpaceAndColon.first, typeWhiteSpaceAndColon.second, nameIdentifier);
if (element instanceof JetProperty) {
JetPropertyAccessor getter = ((JetProperty) element).getGetter();
JetTypeReference getterReturnTypeRef = getter == null ? null : getter.getReturnTypeReference();
if (getterReturnTypeRef != null) {
getterReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
}
JetPropertyAccessor setter = ((JetProperty) element).getSetter();
JetParameter setterParameter = setter == null ? null : setter.getParameter();
JetTypeReference setterParameterTypeRef = setterParameter == null ? null : setterParameter.getTypeReference();
if (setterParameterTypeRef != null) {
setterParameterTypeRef.replace(JetPsiFactory.createType(project, renderedType));
}
}
}
@NotNull
public static JetIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -85,16 +119,53 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
}
@NotNull
public static JetIntentionActionFactory createFactoryForPropertyOrReturnTypeMismatchOnOverride() {
return new JetIntentionActionFactory() {
@Nullable
public static JetIntentionActionsFactory createFactoryForPropertyOrReturnTypeMismatchOnOverride() {
return new JetIntentionActionsFactory() {
@NotNull
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
public List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> actions = new LinkedList<IntentionAction>();
JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
if (property == null) return null;
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(property);
JetType type = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
return type == null ? null : new ChangeVariableTypeFix(property, type);
if (property != null) {
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(property);
JetType lowerBoundOfOverriddenPropertiesTypes = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
PropertyDescriptor descriptor = (PropertyDescriptor) context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
assert descriptor != null : "Descriptor of property not available in binding context";
JetType propertyType = descriptor.getReturnType();
assert propertyType != null : "Property type cannot be null if it mismatch something";
List<PropertyDescriptor> overriddenMismatchingProperties = new LinkedList<PropertyDescriptor>();
boolean canChangeOverriddenPropertyType = true;
for (PropertyDescriptor overriddenProperty: descriptor.getOverriddenDescriptors()) {
JetType overriddenPropertyType = overriddenProperty.getReturnType();
if (overriddenPropertyType != null) {
if (!JetTypeChecker.INSTANCE.isSubtypeOf(propertyType, overriddenPropertyType)) {
overriddenMismatchingProperties.add(overriddenProperty);
}
else if (overriddenProperty.isVar() && !JetTypeChecker.INSTANCE.equalTypes(overriddenPropertyType, propertyType)) {
canChangeOverriddenPropertyType = false;
}
if (overriddenProperty.isVar() && lowerBoundOfOverriddenPropertiesTypes != null &&
!JetTypeChecker.INSTANCE.equalTypes(lowerBoundOfOverriddenPropertiesTypes, overriddenPropertyType)) {
lowerBoundOfOverriddenPropertiesTypes = null;
}
}
}
if (lowerBoundOfOverriddenPropertiesTypes != null) {
actions.add(new ChangeVariableTypeFix(property, lowerBoundOfOverriddenPropertiesTypes));
}
if (overriddenMismatchingProperties.size() == 1 && canChangeOverriddenPropertyType) {
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingProperties.get(0));
if (overriddenProperty instanceof JetProperty) {
actions.add(new ChangeVariableTypeFix((JetProperty) overriddenProperty, propertyType));
}
}
}
return actions;
}
};
}
@@ -103,8 +103,8 @@ public class ChangeVisibilityModifierFix extends JetIntentionAction<JetModifierL
return JetRefactoringUtil.getVisibilityToken(maxVisibility);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
@@ -17,12 +17,13 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
public interface JetIntentionActionFactory {
import java.util.List;
@Nullable
IntentionAction createAction(Diagnostic diagnostic);
public interface JetIntentionActionsFactory {
@NotNull
List<IntentionAction> createActions(Diagnostic diagnostic);
}
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import java.util.LinkedList;
import java.util.List;
public abstract class JetSingleIntentionActionFactory implements JetIntentionActionsFactory {
@Nullable
public abstract IntentionAction createAction(Diagnostic diagnostic);
@NotNull
@Override
public final List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> intentionActionList = new LinkedList<IntentionAction>();
IntentionAction intentionAction = createAction(diagnostic);
if (intentionAction != null) {
intentionActionList.add(intentionAction);
}
return intentionActionList;
}
}
@@ -90,8 +90,8 @@ public class MakeClassAnAnnotationClassFix extends JetIntentionAction<JetAnnotat
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -110,8 +110,8 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction<JetDeclarati
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -183,8 +183,8 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
return typeExpr;
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -135,8 +135,8 @@ public class MigrateSureInProjectFix extends JetIntentionAction<PsiElement> {
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
@@ -78,8 +78,8 @@ public class MoveWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
editor.getCaretModel().moveToOffset(insertedWhenEntry.getTextOffset() + cursorOffset);
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
@@ -0,0 +1,135 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import java.util.LinkedList;
import java.util.List;
public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory {
@NotNull
@Override
public List<IntentionAction> createActions(Diagnostic diagnostic) {
List<IntentionAction> actions = new LinkedList<IntentionAction>();
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH;
@SuppressWarnings("unchecked")
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
JetExpression expression = diagnosticWithParameters.getPsiElement();
JetType expectedType = diagnosticWithParameters.getA();
JetType expressionType = diagnosticWithParameters.getB();
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) diagnostic.getPsiFile()).getBindingContext();
// We don't want to cast a cast or type-asserted expression:
if (!(expression instanceof JetBinaryExpressionWithTypeRHS) && !(expression.getParent() instanceof JetBinaryExpressionWithTypeRHS)) {
actions.add(new CastExpressionFix(expression, expectedType));
}
// Property initializer type mismatch property type:
JetProperty property = PsiTreeUtil.getParentOfType(expression, JetProperty.class);
if (property != null) {
JetPropertyAccessor getter = property.getGetter();
if (QuickFixUtil.canEvaluateTo(property.getInitializer(), expression) ||
(getter != null && QuickFixUtil.canFunctionOrGetterReturnExpression(property.getGetter(), expression))) {
actions.add(new ChangeVariableTypeFix(property, expressionType));
}
}
// Mismatch in returned expression:
JetFunction function = PsiTreeUtil.getParentOfType(expression, JetFunction.class, true);
if (function != null && QuickFixUtil.canFunctionOrGetterReturnExpression(function, expression)) {
actions.add(new ChangeFunctionReturnTypeFix(function, expressionType));
}
// Fixing overloaded operators:
if (expression instanceof JetOperationExpression) {
ResolvedCall<? extends CallableDescriptor> resolvedCall =
context.get(BindingContext.RESOLVED_CALL, ((JetOperationExpression) expression).getOperationReference());
if (resolvedCall != null) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
if (declaration instanceof JetFunction) {
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
}
}
}
if (expression.getParent() instanceof JetBinaryExpression) {
JetBinaryExpression parentBinary = (JetBinaryExpression) expression.getParent();
if (parentBinary.getRight() == expression) {
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, parentBinary.getOperationReference());
if (resolvedCall != null) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
if (declaration instanceof JetFunction) {
JetParameter binaryOperatorParameter = ((JetFunction) declaration).getValueParameterList().getParameters().get(0);
actions.add(new ChangeParameterTypeFix(binaryOperatorParameter, expressionType));
}
}
}
}
// Change function return type when TYPE_MISMATCH is reported on call expression:
if (expression instanceof JetCallExpression) {
ResolvedCall<? extends CallableDescriptor> resolvedCall =
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
if (resolvedCall != null) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
if (declaration instanceof JetFunction) {
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
}
}
}
// Change type of a function parameter in case TYPE_MISMATCH is reported on expression passed as value argument of call.
// 1) When an argument is a dangling function literal:
JetFunctionLiteralExpression functionLiteralExpression =
QuickFixUtil.getParentElementOfType(diagnostic, JetFunctionLiteralExpression.class);
if (functionLiteralExpression != null && functionLiteralExpression.getBodyExpression() == expression) {
JetParameter correspondingParameter =
QuickFixUtil.getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(functionLiteralExpression);
JetType functionLiteralExpressionType = context.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression);
if (correspondingParameter != null && functionLiteralExpressionType != null) {
actions.add(new ChangeParameterTypeFix(correspondingParameter, functionLiteralExpressionType));
}
}
// 2) When an argument is passed inside value argument list:
else {
JetValueArgument valueArgument = QuickFixUtil.getParentElementOfType(diagnostic, JetValueArgument.class);
if (valueArgument != null && QuickFixUtil.canEvaluateTo(valueArgument.getArgumentExpression(), expression)) {
JetParameter correspondingParameter = QuickFixUtil.getParameterCorrespondingToValueArgumentPassedInCall(valueArgument);
JetType valueArgumentType = context.get(BindingContext.EXPRESSION_TYPE, valueArgument.getArgumentExpression());
if (correspondingParameter != null && valueArgumentType != null) {
actions.add(new ChangeParameterTypeFix(correspondingParameter, valueArgumentType));
}
}
}
return actions;
}
}
@@ -26,10 +26,10 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
@@ -93,4 +93,103 @@ public class QuickFixUtil {
public static boolean canModifyElement(@NotNull PsiElement element) {
return element.isWritable() && !BuiltInsReferenceResolver.isFromBuiltIns(element);
}
@Nullable
public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) {
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) callExpression.getContainingFile()).getBindingContext();
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
if (resolvedCall == null) return null;
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
if (declaration instanceof JetFunction) {
return ((JetFunction) declaration).getValueParameterList();
}
if (declaration instanceof JetClass) {
return ((JetClass) declaration).getPrimaryConstructorParameterList();
}
return null;
}
@Nullable
public static JetParameter getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(@NotNull JetFunctionLiteralExpression functionLiteralExpression) {
if (!(functionLiteralExpression.getParent() instanceof JetCallExpression)) {
return null;
}
JetCallExpression callExpression = (JetCallExpression) functionLiteralExpression.getParent();
JetParameterList parameterList = getParameterListOfCallee(callExpression);
if (parameterList == null) return null;
return parameterList.getParameters().get(parameterList.getParameters().size() - 1);
}
@Nullable
public static JetParameter getParameterCorrespondingToValueArgumentPassedInCall(@NotNull JetValueArgument valueArgument) {
if (!(valueArgument.getParent() instanceof JetValueArgumentList)) {
return null;
}
JetValueArgumentList valueArgumentList = (JetValueArgumentList) valueArgument.getParent();
if (!(valueArgumentList.getParent() instanceof JetCallExpression)) {
return null;
}
JetCallExpression callExpression = (JetCallExpression) valueArgumentList.getParent();
JetParameterList parameterList = getParameterListOfCallee(callExpression);
if (parameterList == null) return null;
int position = valueArgumentList.getArguments().indexOf(valueArgument);
if (position == -1) return null;
if (valueArgument.isNamed()) {
JetValueArgumentName valueArgumentName = valueArgument.getArgumentName();
JetSimpleNameExpression referenceExpression = valueArgumentName == null ? null : valueArgumentName.getReferenceExpression();
String valueArgumentNameAsString = referenceExpression == null ? null : referenceExpression.getReferencedName();
if (valueArgumentNameAsString == null) return null;
for (JetParameter parameter: parameterList.getParameters()) {
if (valueArgumentNameAsString.equals(parameter.getName())) {
return parameter;
}
}
return null;
}
else {
return parameterList.getParameters().get(position);
}
}
private static boolean equalOrLastInThenOrElse(JetExpression thenOrElse, JetExpression expression) {
if (thenOrElse == expression) return true;
return thenOrElse instanceof JetBlockExpression && expression.getParent() == thenOrElse &&
PsiTreeUtil.getNextSiblingOfType(expression, JetExpression.class) == null;
}
public static boolean canEvaluateTo(JetExpression parent, JetExpression child) {
if (parent == null || child == null) {
return false;
}
while (parent != child) {
if (child.getParent() instanceof JetParenthesizedExpression) {
child = (JetExpression) child.getParent();
continue;
}
JetIfExpression jetIfExpression = PsiTreeUtil.getParentOfType(child, JetIfExpression.class, true);
if (jetIfExpression == null) return false;
if (!equalOrLastInThenOrElse(jetIfExpression.getThen(), child) && !equalOrLastInThenOrElse(jetIfExpression.getElse(), child)) {
return false;
}
child = jetIfExpression;
}
return true;
}
public static boolean canFunctionOrGetterReturnExpression(@NotNull JetDeclaration functionOrGetter, @NotNull JetExpression expression) {
if (functionOrGetter instanceof JetFunctionLiteral) {
JetBlockExpression functionLiteralBody = ((JetFunctionLiteral) functionOrGetter).getBodyExpression();
PsiElement returnedElement = functionLiteralBody == null ? null : functionLiteralBody.getLastChild();
return returnedElement instanceof JetExpression && canEvaluateTo((JetExpression) returnedElement, expression);
}
else {
if (functionOrGetter instanceof JetWithExpressionInitializer && canEvaluateTo(((JetWithExpressionInitializer) functionOrGetter).getInitializer(), expression)) {
return true;
}
JetReturnExpression returnExpression = PsiTreeUtil.getParentOfType(expression, JetReturnExpression.class);
return returnExpression != null && canEvaluateTo(returnExpression.getReturnedExpression(), expression);
}
}
}
@@ -30,10 +30,10 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
public class QuickFixes {
private static final Multimap<AbstractDiagnosticFactory, JetIntentionActionFactory> factories = HashMultimap.create();
private static final Multimap<AbstractDiagnosticFactory, JetIntentionActionsFactory> factories = HashMultimap.create();
private static final Multimap<AbstractDiagnosticFactory, IntentionAction> actions = HashMultimap.create();
public static Collection<JetIntentionActionFactory> getActionFactories(AbstractDiagnosticFactory diagnosticFactory) {
public static Collection<JetIntentionActionsFactory> getActionsFactories(AbstractDiagnosticFactory diagnosticFactory) {
return factories.get(diagnosticFactory);
}
@@ -44,12 +44,12 @@ public class QuickFixes {
private QuickFixes() {}
static {
JetIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD);
JetIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD);
JetSingleIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD);
JetSingleIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD);
factories.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
JetIntentionActionFactory removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
JetSingleIntentionActionFactory removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
factories.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, removeAbstractModifierFactory);
factories.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, removePartsFromPropertyFactory);
@@ -63,13 +63,13 @@ public class QuickFixes {
factories.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
JetIntentionActionFactory removeFinalModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD);
JetSingleIntentionActionFactory removeFinalModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD);
JetIntentionActionFactory addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, JetClass.class);
JetSingleIntentionActionFactory addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, JetClass.class);
factories.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
factories.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
JetIntentionActionFactory removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
JetSingleIntentionActionFactory removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
factories.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
factories.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
@@ -79,7 +79,7 @@ public class QuickFixes {
factories.put(FINAL_PROPERTY_IN_TRAIT, removeFinalModifierFactory);
factories.put(FINAL_FUNCTION_WITH_NO_BODY, removeFinalModifierFactory);
JetIntentionActionFactory addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
JetSingleIntentionActionFactory addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
@@ -97,13 +97,13 @@ public class QuickFixes {
factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
factories.put(USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
JetIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
JetSingleIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
factories.put(WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
factories.put(WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
factories.put(USELESS_ELVIS, RemoveRightPartOfBinaryExpressionFix.createRemoveElvisOperatorFactory());
JetIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
JetSingleIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
factories.put(REDUNDANT_MODIFIER, removeRedundantModifierFactory);
factories.put(ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD, true));
factories.put(OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD, true));
@@ -112,28 +112,28 @@ public class QuickFixes {
factories.put(INCOMPATIBLE_MODIFIERS, RemoveModifierFix.createRemoveModifierFactory(false));
factories.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, RemoveModifierFix.createRemoveVarianceFactory());
JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD);
JetSingleIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD);
factories.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, AddModifierFix.createFactory(OPEN_KEYWORD, JetClass.class));
factories.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
JetIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
JetSingleIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
factories.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
factories.put(REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
factories.put(ILLEGAL_MODIFIER, removeModifierFactory);
JetIntentionActionFactory changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
JetSingleIntentionActionFactory changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
factories.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, changeToBackingFieldFactory);
factories.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, changeToBackingFieldFactory);
JetIntentionActionFactory changeToPropertyNameFactory = ChangeToPropertyNameFix.createFactory();
JetSingleIntentionActionFactory changeToPropertyNameFactory = ChangeToPropertyNameFix.createFactory();
factories.put(NO_BACKING_FIELD_ABSTRACT_PROPERTY, changeToPropertyNameFactory);
factories.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS, changeToPropertyNameFactory);
factories.put(INACCESSIBLE_BACKING_FIELD, changeToPropertyNameFactory);
JetIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.createFactory();
JetSingleIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.createFactory();
factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
JetIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
JetSingleIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
factories.put(USELESS_SIMPLE_IMPORT, removeImportFixFactory);
factories.put(USELESS_HIDDEN_IMPORT, removeImportFixFactory);
@@ -173,7 +173,7 @@ public class QuickFixes {
actions.put(UNNECESSARY_NOT_NULL_ASSERTION, ExclExclCallFix.removeExclExclCall());
factories.put(UNSAFE_INFIX_CALL, ReplaceInfixCallFix.createFactory());
JetIntentionActionFactory removeProtectedModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(PROTECTED_KEYWORD);
JetSingleIntentionActionFactory removeProtectedModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(PROTECTED_KEYWORD);
factories.put(PACKAGE_MEMBER_CANNOT_BE_PROTECTED, removeProtectedModifierFactory);
actions.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, new SpecifyTypeExplicitlyFix());
@@ -187,13 +187,13 @@ public class QuickFixes {
factories.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, RemovePsiElementSimpleFix.createRemoveTypeArgumentsFactory());
JetIntentionActionFactory changeToStarProjectionFactory = ChangeToStarProjectionFix.createFactory();
JetSingleIntentionActionFactory changeToStarProjectionFactory = ChangeToStarProjectionFix.createFactory();
factories.put(UNCHECKED_CAST, changeToStarProjectionFactory);
factories.put(CANNOT_CHECK_FOR_ERASED, changeToStarProjectionFactory);
factories.put(INACCESSIBLE_OUTER_CLASS_EXPRESSION, AddModifierFix.createFactory(INNER_KEYWORD, JetClass.class));
JetIntentionActionFactory addOpenModifierToClassDeclarationFix = AddOpenModifierToClassDeclarationFix.createFactory();
JetSingleIntentionActionFactory addOpenModifierToClassDeclarationFix = AddOpenModifierToClassDeclarationFix.createFactory();
factories.put(FINAL_SUPERTYPE, addOpenModifierToClassDeclarationFix);
factories.put(FINAL_UPPER_BOUND, addOpenModifierToClassDeclarationFix);
@@ -214,19 +214,18 @@ public class QuickFixes {
factories.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, AddSemicolonAfterFunctionCallFix.createFactory());
JetIntentionActionFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
JetIntentionActionsFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeVariableTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
JetIntentionActionFactory changeFunctionReturnTypeFix = ChangeFunctionReturnTypeFix.createFactoryForChangingReturnTypeToUnit();
JetSingleIntentionActionFactory changeFunctionReturnTypeFix = ChangeFunctionReturnTypeFix.createFactoryForChangingReturnTypeToUnit();
factories.put(RETURN_TYPE_MISMATCH, changeFunctionReturnTypeFix);
factories.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, changeFunctionReturnTypeFix);
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, ChangeFunctionReturnTypeFix.createFactoryForReturnTypeMismatchOnOverride());
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
factories.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForHasNextFunctionTypeMismatch());
factories.put(COMPARE_TO_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForCompareToTypeMismatch());
factories.put(TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForTypeMismatch());
factories.put(TOO_MANY_ARGUMENTS, ChangeFunctionSignatureFix.createFactory());
factories.put(NO_VALUE_FOR_PARAMETER, ChangeFunctionSignatureFix.createFactory());
@@ -235,9 +234,14 @@ public class QuickFixes {
factories.put(EXPECTED_PARAMETER_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedParameterTypeMismatch());
factories.put(EXPECTED_RETURN_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedReturnTypeMismatch());
JetSingleIntentionActionFactory changeFunctionLiteralReturnTypeFix = ChangeFunctionLiteralReturnTypeFix.createFactoryForExpectedOrAssignmentTypeMismatch();
factories.put(EXPECTED_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix);
factories.put(ASSIGNMENT_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix);
factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError());
factories.put(AUTOCAST_IMPOSSIBLE, CastExpressionFix.createFactoryForAutoCastImpossible());
factories.put(TYPE_MISMATCH, CastExpressionFix.createFactoryForTypeMismatch());
factories.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, MapPlatformClassToKotlinFix.createFactory());
@@ -87,8 +87,8 @@ public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunction> {
return false;
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetFunction> createAction(Diagnostic diagnostic) {
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
@@ -103,12 +103,12 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
}
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(JetKeywordToken modifier) {
public static JetSingleIntentionActionFactory createRemoveModifierFromListOwnerFactory(JetKeywordToken modifier) {
return createRemoveModifierFromListOwnerFactory(modifier, false);
}
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
@@ -119,12 +119,12 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
};
}
public static JetIntentionActionFactory createRemoveModifierFactory() {
public static JetSingleIntentionActionFactory createRemoveModifierFactory() {
return createRemoveModifierFactory(false);
}
public static JetIntentionActionFactory createRemoveModifierFactory(final boolean isRedundant) {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveModifierFactory(final boolean isRedundant) {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
@@ -139,8 +139,8 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
};
}
public static JetIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
@@ -156,8 +156,8 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
};
}
public static JetIntentionActionFactory createRemoveVarianceFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveVarianceFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
@@ -62,8 +62,8 @@ public class RemoveNullableFix extends JetIntentionAction<JetNullableType> {
super.element.replace(type);
}
public static JetIntentionActionFactory createFactory(final NullableKind typeOfError) {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory(final NullableKind typeOfError) {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetNullableType> createAction(Diagnostic diagnostic) {
JetNullableType nullType = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
@@ -121,8 +121,8 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
}
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetProperty> createAction(Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
@@ -60,8 +60,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
element.delete();
}
public static JetIntentionActionFactory createRemoveImportFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveImportFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
JetImportDirective directive = QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class);
@@ -79,8 +79,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
};
}
public static JetIntentionActionFactory createRemoveSpreadFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveSpreadFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
PsiElement element = diagnostic.getPsiElement();
@@ -92,8 +92,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
};
}
public static JetIntentionActionFactory createRemoveTypeArgumentsFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveTypeArgumentsFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
JetTypeArgumentList element = QuickFixUtil.getParentElementOfType(diagnostic, JetTypeArgumentList.class);
@@ -104,8 +104,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
};
}
public static JetIntentionActionFactory createRemoveVariableFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveVariableFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
final JetProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
@@ -57,8 +57,8 @@ public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> exten
}
}
public static JetIntentionActionFactory createRemoveCastFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveCastFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
@@ -68,8 +68,8 @@ public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> exten
};
}
public static JetIntentionActionFactory createRemoveElvisOperatorFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createRemoveElvisOperatorFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpression> createAction(Diagnostic diagnostic) {
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
@@ -63,8 +63,8 @@ public class RemoveSupertypeFix extends JetIntentionAction<JetDelegationSpecifie
superClass.delete();
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetDelegationSpecifier> createAction(Diagnostic diagnostic) {
JetDelegationSpecifier superClass = QuickFixUtil.getParentElementOfType(diagnostic, JetDelegationSpecifier.class);
@@ -82,8 +82,8 @@ public class RenameParameterToMatchOverriddenMethodFix extends JetIntentionActio
}
@NotNull
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
@@ -59,8 +59,8 @@ public class ReplaceInfixCallFix extends JetIntentionAction<JetBinaryExpression>
return true;
}
public static JetIntentionActionFactory createFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
@@ -18,7 +18,6 @@ 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;
@@ -55,8 +54,8 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
}
}
public static JetIntentionActionFactory createChangeCastToStaticAssertFactory() {
return new JetIntentionActionFactory() {
public static JetSingleIntentionActionFactory createChangeCastToStaticAssertFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
@@ -0,0 +1,12 @@
// "Change 'B.x' type to '(Int) -> Int'" "true"
trait A {
val x: (Int) -> Int
}
trait B {
val x: (Int) -> Int
}
trait C : A, B {
override val x: (Int) -> Int<caret>
}
@@ -0,0 +1,12 @@
// "Change 'A.x' type to 'String'" "true"
trait A {
var x: String
}
trait B {
var x: String
}
trait C : A, B {
override var x: String<caret>
}
@@ -0,0 +1,7 @@
// "Change 'B.x' type to '(String) -> Int'" "true"
trait A {
var x: (String) -> Int
}
trait B : A {
override var x: (String) -> Int
}
@@ -0,0 +1,12 @@
// "Change 'A.foo' function return type to 'Long'" "true"
trait A {
fun foo(): Long
}
trait B {
fun foo(): Number
}
trait C : A, B {
override fun foo(): Long<caret>
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'A.x' type to 'Int'" "true"
trait X {
val x: Int
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'B.x' type to 'Int'" "true"
abstract class A {
abstract var x : Int
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'B.x' type to 'Int'" "true"
abstract class A {
abstract var x : Int
}
@@ -0,0 +1,14 @@
// "Change 'A.x' type to '(Int) -> Int'" "false"
// ACTION: Change 'C.x' type to '(String) -> Int'
// ERROR: <html>Return type is '(jet.Int) &rarr; jet.Int', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>val</b> x: (jet.String) &rarr; jet.Int <i>defined in</i> A</html>
trait A {
val x: (String) -> Int
}
trait B {
val x: (String) -> Any
}
trait C : A, B {
override val x: (Int) -> Int<caret>
}
@@ -0,0 +1,13 @@
// "Change 'A.x' type to 'String'" "false"
// ERROR: <html>Var-property type is 'jet.String', which is not a type of overridden<br/><b>internal</b> <b>abstract</b> <b>var</b> x: jet.Int <i>defined in</i> A</html>
trait A {
var x: Int
}
trait B {
var x: Any
}
trait C : A, B {
override var x: String<caret>
}
@@ -0,0 +1,13 @@
// "Change 'C.x' type to 'String'" "false"
// ERROR: <html>Var-property type is 'jet.Int', which is not a type of overridden<br/><b>internal</b> <b>abstract</b> <b>var</b> x: jet.String <i>defined in</i> A</html>
trait A {
var x: String
}
trait B {
var x: Any
}
trait C : A, B {
override var x: Int<caret>
}
@@ -0,0 +1,13 @@
// "Change 'A.foo' function return type to 'Long'" "false"
// ERROR: <html>Return type is 'jet.Long', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>fun</b> foo(): jet.Int <i>defined in</i> A</html>
trait A {
fun foo(): Int
}
trait B {
fun foo(): String
}
trait C : A, B {
override fun foo(): Long
}
@@ -0,0 +1,12 @@
// "Change 'B.x' type to '(Int) -> Int'" "true"
trait A {
val x: (Int) -> Int
}
trait B {
val x: (String) -> Any
}
trait C : A, B {
override val x: (Int) -> Int<caret>
}
@@ -0,0 +1,12 @@
// "Change 'A.x' type to 'String'" "true"
trait A {
var x: Int
}
trait B {
var x: String
}
trait C : A, B {
override var x: String<caret>
}
@@ -0,0 +1,7 @@
// "Change 'B.x' type to '(String) -> Int'" "true"
trait A {
var x: (String) -> Int
}
trait B : A {
override var x: (Int) -> String<caret>
}
@@ -0,0 +1,12 @@
// "Change 'A.foo' function return type to 'Long'" "true"
trait A {
fun foo(): Int
}
trait B {
fun foo(): Number
}
trait C : A, B {
override fun foo(): Long<caret>
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'A.x' type to 'Int'" "true"
trait X {
val x: Int
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'B.x' type to 'Int'" "true"
abstract class A {
abstract var x : Int
}
@@ -1,4 +1,4 @@
// "Change 'x' type to 'Int'" "true"
// "Change 'B.x' type to 'Int'" "true"
abstract class A {
abstract var x : Int
}
@@ -0,0 +1,5 @@
// "Change getter type to (String) -> Int" "true"
class A {
val x: (String) -> Int
get(): (String) -> Int<caret> = {42}
}
@@ -0,0 +1,5 @@
// "Change getter type to (String) -> Int" "true"
class A {
val x: (String) -> Int
get(): Int<caret> = {42}
}
@@ -0,0 +1,6 @@
// "Change type from 'String' to '(Int) -> String'" "true"
fun foo(f: ((Int) -> String) -> String) {
foo {
(f: (Int) -> String<caret>) -> f(42)
}
}
@@ -0,0 +1,3 @@
// "Change 'bar' function return type to 'String'" "true"
fun bar(): String = ""
fun foo(): String = bar(<caret>)
@@ -0,0 +1,4 @@
// "Change 'f' type to '(Long) -> Unit'" "true"
fun foo() {
var f: (Long) -> Unit = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
}
@@ -0,0 +1,6 @@
// "Change type from 'String' to '(Int) -> String'" "true"
fun foo(f: ((Int) -> String) -> String) {
foo {
(f: String<caret>) -> f(42)
}
}
@@ -0,0 +1,3 @@
// "Change 'bar' function return type to 'String'" "true"
fun bar(): Any = ""
fun foo(): String = bar(<caret>)
@@ -0,0 +1,10 @@
// "Change 'B.x' type to '(String) -> [ERROR : Ay]'" "false"
// ACTION: Change 'A.x' type to '(Int) -> Int'
// ERROR: <html>Return type is '(jet.Int) &rarr; jet.Int', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>val</b> x: (jet.String) &rarr; [ERROR : Ay] <i>defined in</i> A</html>
// ERROR: Unresolved reference: Ay
trait A {
val x: (String) -> Ay
}
trait B : A {
override val x: (Int) -> Int<caret>
}
@@ -0,0 +1,4 @@
// "Change 'f' type to '(Long) -> Unit'" "true"
fun foo() {
var f: Int = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
}
@@ -0,0 +1,4 @@
// "Cast expression 'x' to '() -> Int'" "true"
fun foo(x: Any): () -> Int {
return x as () -> Int<caret>
}
@@ -0,0 +1,4 @@
// "Cast expression 'x' to '() -> Int'" "true"
fun foo(x: Any): () -> Int {
return x<caret>
}
@@ -0,0 +1,7 @@
// "Change 'A.not' function return type to 'A'" "true"
trait A {
fun not(): A
fun times(a: A): A
}
fun foo(a: A): A = a * <caret>!(if (true) a else a)
@@ -0,0 +1,8 @@
// "Change 'A.plus' function return type to '() -> Int'" "true"
trait A {
fun plus(a: A): () -> Int
}
fun foo(a: A): () -> Int {
return a + a<caret>
}
@@ -0,0 +1,6 @@
// "Change parameter 'a' type of function 'A.times' to 'String'" "true"
trait A {
fun times(a: String): A
}
fun foo(a: A): A = a * <caret>""

Some files were not shown because too many files have changed in this diff Show More