Reverting pull request 240
This commit is contained in:
+1
-46
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
@@ -48,9 +49,6 @@ public class FunctionDescriptorUtil {
|
||||
}
|
||||
});
|
||||
|
||||
private FunctionDescriptorUtil() {
|
||||
}
|
||||
|
||||
public static Map<TypeConstructor, TypeProjection> createSubstitutionContext(@NotNull FunctionDescriptor functionDescriptor, List<JetType> typeArguments) {
|
||||
if (functionDescriptor.getTypeParameters().isEmpty()) return Collections.emptyMap();
|
||||
|
||||
@@ -139,47 +137,4 @@ public class FunctionDescriptorUtil {
|
||||
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
||||
return (D) candidate.substitute(MAKE_TYPE_PARAMETERS_FRESH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns function's copy with new parameter list. Note that parameters may belong to other methods or have incorrect "index" property
|
||||
* -- it will be fixed by this function.
|
||||
*/
|
||||
@NotNull
|
||||
public static FunctionDescriptor replaceFunctionParameters(
|
||||
@NotNull FunctionDescriptor function,
|
||||
@NotNull List<ValueParameterDescriptor> newParameters
|
||||
) {
|
||||
FunctionDescriptorImpl descriptor = new SimpleFunctionDescriptorImpl(
|
||||
function.getContainingDeclaration(),
|
||||
function.getAnnotations(),
|
||||
function.getName(),
|
||||
function.getKind());
|
||||
List<ValueParameterDescriptor> parameters = new ArrayList<ValueParameterDescriptor>(newParameters.size());
|
||||
int idx = 0;
|
||||
for (ValueParameterDescriptor parameter : newParameters) {
|
||||
JetType returnType = parameter.getReturnType();
|
||||
assert returnType != null;
|
||||
|
||||
parameters.add(new ValueParameterDescriptorImpl(
|
||||
descriptor,
|
||||
idx,
|
||||
parameter.getAnnotations(),
|
||||
parameter.getName(),
|
||||
returnType,
|
||||
parameter.declaresDefaultValue(),
|
||||
parameter.getVarargElementType())
|
||||
);
|
||||
idx++;
|
||||
}
|
||||
ReceiverParameterDescriptor receiver = function.getReceiverParameter();
|
||||
descriptor.initialize(
|
||||
receiver == null ? null : receiver.getType(),
|
||||
function.getExpectedThisObject(),
|
||||
function.getTypeParameters(),
|
||||
parameters,
|
||||
function.getReturnType(),
|
||||
function.getModality(),
|
||||
function.getVisibility());
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,12 +240,24 @@ public class OverrideResolver {
|
||||
) {
|
||||
Queue<CallableMemberDescriptor> fromSuperQueue = new LinkedList<CallableMemberDescriptor>(notOverridden);
|
||||
while (!fromSuperQueue.isEmpty()) {
|
||||
CallableMemberDescriptor notOverriddenFromSuper = VisibilityUtil.findMemberWithMaxVisibility(fromSuperQueue);
|
||||
CallableMemberDescriptor notOverriddenFromSuper = findMemberWithMaxVisibility(fromSuperQueue);
|
||||
Collection<CallableMemberDescriptor> overridables = extractMembersOverridableBy(notOverriddenFromSuper, fromSuperQueue, sink);
|
||||
createAndBindFakeOverride(notOverriddenFromSuper, overridables, current, sink);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CallableMemberDescriptor findMemberWithMaxVisibility(@NotNull Queue<CallableMemberDescriptor> descriptors) {
|
||||
CallableMemberDescriptor descriptor = descriptors.element();
|
||||
for (CallableMemberDescriptor candidate : descriptors) {
|
||||
Integer result = Visibilities.compare(descriptor.getVisibility(), candidate.getVisibility());
|
||||
if (result != null && result < 0) {
|
||||
descriptor = candidate;
|
||||
}
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverride(
|
||||
@NotNull CallableMemberDescriptor notOverriddenFromSuper,
|
||||
@NotNull Collection<CallableMemberDescriptor> overridables,
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public class VisibilityUtil {
|
||||
@NotNull
|
||||
public static CallableMemberDescriptor findMemberWithMaxVisibility(@NotNull Queue<CallableMemberDescriptor> descriptors) {
|
||||
CallableMemberDescriptor descriptor = descriptors.element();
|
||||
for (CallableMemberDescriptor candidate : descriptors) {
|
||||
Integer result = Visibilities.compare(descriptor.getVisibility(), candidate.getVisibility());
|
||||
if (result != null && result < 0) {
|
||||
descriptor = candidate;
|
||||
}
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.renderer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
@@ -26,20 +27,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
DescriptorRenderer COMPACT_WITH_MODIFIERS = new DescriptorRendererBuilder().setWithDefinedIn(false).build();
|
||||
|
||||
DescriptorRenderer SOURCE_CODE = new DescriptorRendererBuilder()
|
||||
.setNormalizedVisibilities(true)
|
||||
.setWithDefinedIn(false)
|
||||
.setShortNames(false)
|
||||
.setShowInternalKeyword(false)
|
||||
.setUnitReturnType(false).build();
|
||||
|
||||
DescriptorRenderer SOURCE_CODE_SHORT_NAMES_IN_TYPES = new DescriptorRendererBuilder()
|
||||
.setNormalizedVisibilities(true)
|
||||
.setWithDefinedIn(false)
|
||||
.setShortNames(true)
|
||||
.setShowInternalKeyword(false)
|
||||
.setUnitReturnType(false).build();
|
||||
|
||||
DescriptorRenderer COMPACT = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setModifiers(false).build();
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class DescriptorRendererBuilder {
|
||||
private boolean shortNames = false;
|
||||
@@ -30,9 +31,6 @@ public class DescriptorRendererBuilder {
|
||||
private boolean debugMode = false;
|
||||
private boolean classWithPrimaryConstructor = false;
|
||||
private boolean verbose = false;
|
||||
private boolean unitReturnType = true;
|
||||
private boolean normalizedVisibilities = false;
|
||||
private boolean showInternalKeyword = true;
|
||||
@NotNull
|
||||
private DescriptorRenderer.ValueParametersHandler valueParametersHandler = new DescriptorRenderer.DefaultValueParameterHandler();
|
||||
@NotNull
|
||||
@@ -78,21 +76,6 @@ public class DescriptorRendererBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setUnitReturnType(boolean unitReturnType) {
|
||||
this.unitReturnType = unitReturnType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setNormalizedVisibilities(boolean normalizedVisibilities) {
|
||||
this.normalizedVisibilities = normalizedVisibilities;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setShowInternalKeyword(boolean showInternalKeyword) {
|
||||
this.showInternalKeyword = showInternalKeyword;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setValueParametersHandler(@NotNull DescriptorRenderer.ValueParametersHandler valueParametersHandler) {
|
||||
this.valueParametersHandler = valueParametersHandler;
|
||||
return this;
|
||||
@@ -110,7 +93,6 @@ public class DescriptorRendererBuilder {
|
||||
|
||||
public DescriptorRenderer build() {
|
||||
return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
|
||||
verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, valueParametersHandler,
|
||||
textFormat, excludedAnnotationClasses);
|
||||
verbose, valueParametersHandler, textFormat, excludedAnnotationClasses);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
private final boolean debugMode;
|
||||
private final boolean classWithPrimaryConstructor;
|
||||
private final boolean verbose;
|
||||
private final boolean unitReturnType;
|
||||
private final boolean normalizedVisibilities;
|
||||
private final boolean showInternalKeyword;
|
||||
@NotNull
|
||||
private final ValueParametersHandler handler;
|
||||
@NotNull
|
||||
@@ -73,9 +70,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
boolean debugMode,
|
||||
boolean classWithPrimaryConstructor,
|
||||
boolean verbose,
|
||||
boolean unitReturnType,
|
||||
boolean normalizedVisibilities,
|
||||
boolean showInternalKeyword,
|
||||
@NotNull ValueParametersHandler handler,
|
||||
@NotNull TextFormat textFormat,
|
||||
@NotNull Collection<FqName> excludedAnnotationClasses
|
||||
@@ -87,9 +81,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
this.handler = handler;
|
||||
this.classWithPrimaryConstructor = classWithPrimaryConstructor;
|
||||
this.verbose = verbose;
|
||||
this.unitReturnType = unitReturnType;
|
||||
this.normalizedVisibilities = normalizedVisibilities;
|
||||
this.showInternalKeyword = showInternalKeyword;
|
||||
this.debugMode = debugMode;
|
||||
this.textFormat = textFormat;
|
||||
this.excludedAnnotationClasses = Sets.newHashSet(excludedAnnotationClasses);
|
||||
@@ -316,10 +307,6 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
|
||||
private void renderVisibility(@NotNull Visibility visibility, @NotNull StringBuilder builder) {
|
||||
if (!modifiers) return;
|
||||
if (normalizedVisibilities) {
|
||||
visibility = visibility.normalize();
|
||||
}
|
||||
if (!showInternalKeyword && visibility == Visibilities.INTERNAL) return;
|
||||
builder.append(renderKeyword(visibility.toString())).append(" ");
|
||||
}
|
||||
|
||||
@@ -338,24 +325,18 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
|
||||
private void renderModalityForCallable(@NotNull CallableMemberDescriptor callable, @NotNull StringBuilder builder) {
|
||||
if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.getModality() != Modality.FINAL) {
|
||||
if (overridesSomething(callable) && callable.getModality() == Modality.OPEN) return;
|
||||
renderModality(callable.getModality(), builder);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean overridesSomething(CallableMemberDescriptor callable) {
|
||||
return !callable.getOverriddenDescriptors().isEmpty();
|
||||
}
|
||||
|
||||
private void renderOverrideAndMemberKind(@NotNull CallableMemberDescriptor callableMember, @NotNull StringBuilder builder) {
|
||||
if (overridesSomething(callableMember)) {
|
||||
builder.append("override ");
|
||||
if (verbose) {
|
||||
builder.append("/*").append(callableMember.getOverriddenDescriptors().size()).append("*/ ");
|
||||
if (verbose) {
|
||||
if (!callableMember.getOverriddenDescriptors().isEmpty()) {
|
||||
builder.append("override /*").append(callableMember.getOverriddenDescriptors().size()).append("*/ ");
|
||||
}
|
||||
if (callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
builder.append("/*").append(callableMember.getKind().name().toLowerCase()).append("*/ ");
|
||||
}
|
||||
}
|
||||
if (verbose && callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
builder.append("/*").append(callableMember.getKind().name().toLowerCase()).append("*/ ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +371,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
builder.append(renderKeyword(variance)).append(" ");
|
||||
}
|
||||
renderName(typeParameter, builder);
|
||||
if (typeParameter.getUpperBounds().size() >= 1) {
|
||||
if (typeParameter.getUpperBounds().size() == 1) {
|
||||
JetType upperBound = typeParameter.getUpperBounds().iterator().next();
|
||||
if (!KotlinBuiltIns.getInstance().getDefaultBound().equals(upperBound)) {
|
||||
builder.append(" : ").append(renderType(upperBound));
|
||||
@@ -462,9 +443,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
renderName(function, builder);
|
||||
renderValueParameters(function, builder);
|
||||
JetType returnType = function.getReturnType();
|
||||
if (unitReturnType || !KotlinBuiltIns.getInstance().isUnit(returnType)) {
|
||||
builder.append(": ").append(returnType == null ? "[NULL]" : escape(renderType(returnType)));
|
||||
}
|
||||
builder.append(" : ").append(returnType == null ? "[NULL]" : escape(renderType(returnType)));
|
||||
renderWhereSuffix(function.getTypeParameters(), builder);
|
||||
}
|
||||
|
||||
@@ -486,13 +465,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
|
||||
for (TypeParameterDescriptor typeParameter : typeParameters) {
|
||||
if (typeParameter.getUpperBounds().size() > 1) {
|
||||
boolean first = true;
|
||||
for (JetType upperBound : typeParameter.getUpperBounds()) {
|
||||
// first parameter is rendered by renderTypeParameter:
|
||||
if (!first) {
|
||||
upperBoundStrings.add(renderName(typeParameter.getName()) + " : " + escape(renderType(upperBound)));
|
||||
}
|
||||
first = false;
|
||||
upperBoundStrings.add(renderName(typeParameter.getName()) + " : " + escape(renderType(upperBound)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,7 +531,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
}
|
||||
|
||||
renderName(variable, builder);
|
||||
builder.append(": ").append(escape(renderType(typeToRender)));
|
||||
builder.append(" : ").append(escape(renderType(typeToRender)));
|
||||
|
||||
if (verbose && varargElementType != null) {
|
||||
builder.append(" /*").append(escape(renderType(realType))).append("*/");
|
||||
@@ -581,7 +555,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
builder.append(escape(renderType(receiver.getType()))).append(".");
|
||||
}
|
||||
renderName(property, builder);
|
||||
builder.append(": ").append(escape(renderType(property.getType())));
|
||||
builder.append(" : ").append(escape(renderType(property.getType())));
|
||||
|
||||
renderWhereSuffix(property.getTypeParameters(), builder);
|
||||
}
|
||||
|
||||
@@ -139,13 +139,9 @@ surround.with.function.template={ }
|
||||
surround.with.cannot.perform.action=Cannot perform Surround With action to the current contextsurround.with.function.template={ }
|
||||
remove.variable.family.name=Remove variable
|
||||
remove.variable.action=Remove variable ''{0}''
|
||||
|
||||
kotlin.code.transformations=Kotlin Code Transformations
|
||||
transform.if.statement.with.assignments.to.expression=Transform 'if' statement with assignments to expression
|
||||
transform.assignment.with.if.expression.to.statement=Transform assignment with 'if' expression to statement
|
||||
transform.if.statement.with.assignments.to.expression.family=Transform 'if' Statement with Assignments to Expression
|
||||
transform.assignment.with.if.expression.to.statement.family=Transform Assignment with 'if' Expression to Statement
|
||||
change.function.signature.action.single=Change function signature to ''{0}''
|
||||
change.function.signature.action.multiple=Change function signature...
|
||||
change.function.signature.family=Change function signature
|
||||
change.function.signature.chooser.title=Choose signature
|
||||
change.function.signature.action=Change function signature
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* 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.actions;
|
||||
|
||||
import com.intellij.codeInsight.hint.QuestionAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ReferenceToClassesShortening;
|
||||
import org.jetbrains.jet.plugin.quickfix.QuickFixUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Changes method signature to one of provided signatures.
|
||||
* Based on {@link JetAddImportAction}
|
||||
*/
|
||||
public class JetChangeFunctionSignatureAction implements QuestionAction {
|
||||
|
||||
private final Project project;
|
||||
private final Editor editor;
|
||||
private final JetNamedFunction element;
|
||||
private final List<FunctionDescriptor> signatures;
|
||||
|
||||
/**
|
||||
* @param project Project where action takes place.
|
||||
* @param editor Editor where modification should be done.
|
||||
* @param element Function element which signature should be changed.
|
||||
* @param signatures Variants for new function signature.
|
||||
*/
|
||||
public JetChangeFunctionSignatureAction(
|
||||
@NotNull Project project,
|
||||
@NotNull Editor editor,
|
||||
@NotNull JetNamedFunction element,
|
||||
@NotNull Collection<FunctionDescriptor> signatures
|
||||
) {
|
||||
this.project = project;
|
||||
this.editor = editor;
|
||||
this.element = element;
|
||||
this.signatures = new ArrayList<FunctionDescriptor>(signatures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
if (!element.isValid() || signatures.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signatures.size() == 1 || !editor.getComponent().isShowing()) {
|
||||
changeSignature(element, project, signatures.get(0));
|
||||
}
|
||||
else {
|
||||
chooseSignatureAndChange();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private BaseListPopupStep getSignaturePopup() {
|
||||
return new BaseListPopupStep<FunctionDescriptor>(
|
||||
JetBundle.message("change.function.signature.chooser.title"), signatures) {
|
||||
@Override
|
||||
public boolean isAutoSelectionEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PopupStep onChosen(FunctionDescriptor selectedValue, boolean finalChoice) {
|
||||
if (finalChoice) {
|
||||
changeSignature(element, project, selectedValue);
|
||||
}
|
||||
return FINAL_CHOICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIconFor(FunctionDescriptor aValue) {
|
||||
return PlatformIcons.FUNCTION_ICON;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTextFor(FunctionDescriptor aValue) {
|
||||
return QuickFixUtil.createFunctionSignatureStringFromDescriptor(
|
||||
aValue,
|
||||
/* shortTypeNames = */ true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static void changeSignature(final JetNamedFunction element, final Project project, FunctionDescriptor signature) {
|
||||
final String signatureString = QuickFixUtil.createFunctionSignatureStringFromDescriptor(
|
||||
signature,
|
||||
/* shortTypeNames = */ false);
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JetExpression bodyExpression = element.getBodyExpression();
|
||||
JetNamedFunction newElement;
|
||||
|
||||
if (bodyExpression != null) {
|
||||
if (element.hasBlockBody()) {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString + "{}");
|
||||
}
|
||||
else {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString + "= \"dummy\"");
|
||||
}
|
||||
JetExpression newBodyExpression = newElement.getBodyExpression();
|
||||
assert newBodyExpression != null;
|
||||
newBodyExpression.replace(bodyExpression);
|
||||
}
|
||||
else {
|
||||
newElement = JetPsiFactory.createFunction(project, signatureString);
|
||||
}
|
||||
newElement = (JetNamedFunction) element.replace(newElement);
|
||||
ReferenceToClassesShortening.compactReferenceToClasses(Collections.singletonList(newElement));
|
||||
}
|
||||
});
|
||||
}
|
||||
}, JetBundle.message("change.function.signature.action"), null);
|
||||
}
|
||||
|
||||
private void chooseSignatureAndChange() {
|
||||
JBPopupFactory.getInstance().createListPopup(getSignaturePopup()).showInBestPositionFor(editor);
|
||||
}
|
||||
}
|
||||
+95
-32
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -118,29 +119,29 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
for (DescriptorClassMember selectedElement : selectedElements) {
|
||||
DeclarationDescriptor descriptor = selectedElement.getDescriptor();
|
||||
if (descriptor instanceof SimpleFunctionDescriptor) {
|
||||
overridingMembers.add(overrideFunction(file.getProject(),
|
||||
(SimpleFunctionDescriptor) descriptor /* shortTypeNames = */
|
||||
));
|
||||
overridingMembers.add(overrideFunction(file.getProject(), (SimpleFunctionDescriptor) descriptor));
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
overridingMembers.add(
|
||||
overrideProperty(file.getProject(), (PropertyDescriptor) descriptor));
|
||||
overridingMembers.add(overrideProperty(file.getProject(), (PropertyDescriptor) descriptor));
|
||||
}
|
||||
}
|
||||
return overridingMembers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetElement overrideProperty(@NotNull Project project, @NotNull PropertyDescriptor descriptor) {
|
||||
PropertyDescriptor newDescriptor = (PropertyDescriptor) descriptor.copy(
|
||||
descriptor.getContainingDeclaration(),
|
||||
Modality.OPEN,
|
||||
descriptor.getVisibility(),
|
||||
descriptor.getKind(),
|
||||
/* copyOverrides = */ true);
|
||||
newDescriptor.addOverriddenDescriptor(descriptor);
|
||||
|
||||
private static JetElement overrideProperty(Project project, PropertyDescriptor descriptor) {
|
||||
StringBuilder bodyBuilder = new StringBuilder();
|
||||
bodyBuilder.append(displayableVisibility(descriptor)).append("override ");
|
||||
if (descriptor.isVar()) {
|
||||
bodyBuilder.append("var ");
|
||||
}
|
||||
else {
|
||||
bodyBuilder.append("val ");
|
||||
}
|
||||
|
||||
addReceiverParameter(descriptor, bodyBuilder);
|
||||
|
||||
bodyBuilder.append(descriptor.getName()).append(" : ").append(
|
||||
DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(descriptor.getType()));
|
||||
String initializer = CodeInsightUtils.defaultInitializer(descriptor.getType());
|
||||
if (initializer != null) {
|
||||
bodyBuilder.append(" = ").append(initializer);
|
||||
@@ -148,19 +149,53 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
else {
|
||||
bodyBuilder.append(" = ?");
|
||||
}
|
||||
return JetPsiFactory.createProperty(project, DescriptorRenderer.SOURCE_CODE.render(newDescriptor) + bodyBuilder.toString());
|
||||
return JetPsiFactory.createProperty(project, bodyBuilder.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetNamedFunction overrideFunction(@NotNull Project project, @NotNull FunctionDescriptor descriptor) {
|
||||
FunctionDescriptor newDescriptor = descriptor.copy(
|
||||
descriptor.getContainingDeclaration(),
|
||||
Modality.OPEN,
|
||||
descriptor.getVisibility(),
|
||||
descriptor.getKind(),
|
||||
/* copyOverrides = */ true);
|
||||
newDescriptor.addOverriddenDescriptor(descriptor);
|
||||
private static String renderType(JetType type) {
|
||||
return DescriptorRenderer.TEXT.renderType(type);
|
||||
}
|
||||
|
||||
private static JetElement overrideFunction(Project project, SimpleFunctionDescriptor descriptor) {
|
||||
StringBuilder bodyBuilder = new StringBuilder();
|
||||
bodyBuilder.append(displayableVisibility(descriptor));
|
||||
bodyBuilder.append("override fun ");
|
||||
|
||||
List<String> whereRestrictions = new ArrayList<String>();
|
||||
if (!descriptor.getTypeParameters().isEmpty()) {
|
||||
bodyBuilder.append("<");
|
||||
boolean first = true;
|
||||
for (TypeParameterDescriptor param : descriptor.getTypeParameters()) {
|
||||
if (!first) {
|
||||
bodyBuilder.append(", ");
|
||||
}
|
||||
|
||||
bodyBuilder.append(param.getName());
|
||||
Set<JetType> upperBounds = param.getUpperBounds();
|
||||
if (!upperBounds.isEmpty()) {
|
||||
boolean firstUpperBound = true;
|
||||
for (JetType upperBound : upperBounds) {
|
||||
String upperBoundText = " : " + renderType(upperBound);
|
||||
if (!KotlinBuiltIns.getInstance().getDefaultBound().equals(upperBound)) {
|
||||
if (firstUpperBound) {
|
||||
bodyBuilder.append(upperBoundText);
|
||||
}
|
||||
else {
|
||||
whereRestrictions.add(param.getName() + upperBoundText);
|
||||
}
|
||||
}
|
||||
firstUpperBound = false;
|
||||
}
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
bodyBuilder.append("> ");
|
||||
}
|
||||
|
||||
addReceiverParameter(descriptor, bodyBuilder);
|
||||
|
||||
bodyBuilder.append(descriptor.getName()).append("(");
|
||||
boolean isAbstractFun = descriptor.getModality() == Modality.ABSTRACT;
|
||||
StringBuilder delegationBuilder = new StringBuilder();
|
||||
if (isAbstractFun) {
|
||||
@@ -171,23 +206,51 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
delegationBuilder.append(">.").append(descriptor.getName()).append("(");
|
||||
}
|
||||
boolean first = true;
|
||||
if (!isAbstractFun) {
|
||||
for (ValueParameterDescriptor parameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (!first) {
|
||||
delegationBuilder.append(", ");
|
||||
for (ValueParameterDescriptor parameterDescriptor : descriptor.getValueParameters()) {
|
||||
if (!first) {
|
||||
bodyBuilder.append(",");
|
||||
if (!isAbstractFun) {
|
||||
delegationBuilder.append(",");
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
first = false;
|
||||
bodyBuilder.append(parameterDescriptor.getName());
|
||||
bodyBuilder.append(" : ");
|
||||
bodyBuilder.append(renderType(parameterDescriptor.getType()));
|
||||
|
||||
if (!isAbstractFun) {
|
||||
delegationBuilder.append(parameterDescriptor.getName());
|
||||
}
|
||||
}
|
||||
bodyBuilder.append(")");
|
||||
if (!isAbstractFun) {
|
||||
delegationBuilder.append(")");
|
||||
}
|
||||
JetType returnType = descriptor.getReturnType();
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
|
||||
boolean returnsNotUnit = returnType != null && !builtIns.getUnitType().equals(returnType);
|
||||
String body = "{" + (returnsNotUnit && !isAbstractFun ? "return " : "") + delegationBuilder.toString() + "}";
|
||||
if (returnsNotUnit) {
|
||||
bodyBuilder.append(" : ").append(renderType(returnType));
|
||||
}
|
||||
if (!whereRestrictions.isEmpty()) {
|
||||
bodyBuilder.append("\n").append("where ").append(StringUtil.join(whereRestrictions, ", "));
|
||||
}
|
||||
bodyBuilder.append("{").append(returnsNotUnit && !isAbstractFun ? "return " : "").append(delegationBuilder.toString()).append("}");
|
||||
|
||||
return JetPsiFactory.createFunction(project, DescriptorRenderer.SOURCE_CODE.render(newDescriptor) + body);
|
||||
return JetPsiFactory.createFunction(project, bodyBuilder.toString());
|
||||
}
|
||||
|
||||
private static void addReceiverParameter(CallableDescriptor descriptor, StringBuilder bodyBuilder) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
bodyBuilder.append(receiverParameter.getType()).append(".");
|
||||
}
|
||||
}
|
||||
|
||||
private static String displayableVisibility(MemberDescriptor descriptor) {
|
||||
Visibility visibility = descriptor.getVisibility().normalize();
|
||||
return visibility != Visibilities.INTERNAL ? visibility.toString() + " " : "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
/*
|
||||
* 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.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
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.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.VisibilityUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
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.actions.JetChangeFunctionSignatureAction;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManagerUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Fix that changes member function's signature to match one of super functions' signatures.
|
||||
*/
|
||||
public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunction> {
|
||||
private final List<FunctionDescriptor> possibleSignatures;
|
||||
|
||||
public ChangeMemberFunctionSignatureFix(@NotNull JetNamedFunction element) {
|
||||
super(element);
|
||||
this.possibleSignatures = computePossibleSignatures(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && !possibleSignatures.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
if (possibleSignatures.size() == 1)
|
||||
return JetBundle.message("change.function.signature.action.single",
|
||||
getFunctionSignatureString(
|
||||
possibleSignatures.get(0),
|
||||
/* shortTypeNames = */ true));
|
||||
else
|
||||
return JetBundle.message("change.function.signature.action.multiple");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getFunctionSignatureString(@NotNull FunctionDescriptor functionSignature, boolean shortTypeNames) {
|
||||
return QuickFixUtil.createFunctionSignatureStringFromDescriptor(
|
||||
functionSignature, shortTypeNames);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("change.function.signature.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, @NotNull final Editor editor, PsiFile file)
|
||||
throws IncorrectOperationException {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createAction(project, editor).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetChangeFunctionSignatureAction createAction(@NotNull Project project, @NotNull Editor editor) {
|
||||
return new JetChangeFunctionSignatureAction(project, editor, element, possibleSignatures);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes all the signatures a 'functionElement' could be changed to in order to remove NOTHING_TO_OVERRIDE error.
|
||||
*/
|
||||
@NotNull
|
||||
private List<FunctionDescriptor> computePossibleSignatures(JetNamedFunction functionElement) {
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsFromProject(functionElement).getBindingContext();
|
||||
FunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, functionElement);
|
||||
if (functionDescriptor == null) return Lists.newArrayList();
|
||||
List<FunctionDescriptor> superFunctions = getPossibleSuperFunctionsDescriptors(functionDescriptor);
|
||||
Map<String, FunctionDescriptor> possibleSignatures = Maps.newHashMap();
|
||||
for (FunctionDescriptor superFunction : superFunctions) {
|
||||
if (!superFunction.getKind().isReal()) continue;
|
||||
FunctionDescriptor signature = changeSignatureToMatch(functionDescriptor, superFunction);
|
||||
possibleSignatures.put(getFunctionSignatureString(signature, /* shortTypeNames = */ false), signature);
|
||||
}
|
||||
return Lists.newArrayList(possibleSignatures.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes function's signature to match superFunction's signature. Returns new descriptor.
|
||||
*/
|
||||
private static FunctionDescriptor changeSignatureToMatch(FunctionDescriptor function, FunctionDescriptor superFunction) {
|
||||
List<ValueParameterDescriptor> superParameters = superFunction.getValueParameters();
|
||||
List<ValueParameterDescriptor> parameters = function.getValueParameters();
|
||||
List<ValueParameterDescriptor> newParameters = Lists.newArrayList(superParameters);
|
||||
|
||||
// Parameters in superFunction, which are matched in new function signature:
|
||||
BitSet matched = new BitSet(superParameters.size());
|
||||
// Parameters in this function, which are used in new function signature:
|
||||
BitSet used = new BitSet(superParameters.size());
|
||||
|
||||
matchParameters(MATCH_NAMES, superParameters, parameters, newParameters, matched, used);
|
||||
matchParameters(MATCH_TYPES, superParameters, parameters, newParameters, matched, used);
|
||||
|
||||
FunctionDescriptor newFunction = FunctionDescriptorUtil.replaceFunctionParameters(
|
||||
superFunction.copy(
|
||||
function.getContainingDeclaration(),
|
||||
Modality.OPEN,
|
||||
getVisibility(function, superFunction),
|
||||
CallableMemberDescriptor.Kind.DELEGATION,
|
||||
/* copyOverrides = */ true),
|
||||
newParameters);
|
||||
newFunction.addOverriddenDescriptor(superFunction);
|
||||
return newFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new visibility for 'function' modified to override 'superFunction'.
|
||||
*/
|
||||
private static Visibility getVisibility(FunctionDescriptor function, FunctionDescriptor superFunction) {
|
||||
ArrayDeque<CallableMemberDescriptor> descriptors =
|
||||
Queues.<CallableMemberDescriptor>newArrayDeque(Arrays.asList(superFunction, function));
|
||||
return VisibilityUtil.findMemberWithMaxVisibility(descriptors).getVisibility();
|
||||
}
|
||||
|
||||
/** Helper interface for matchParameters(..) method. */
|
||||
private interface ParameterChooser {
|
||||
/**
|
||||
* Checks if 'parameter' may be used to match 'superParameter'.
|
||||
* If so, returns (possibly modified) descriptor to be used as the new parameter.
|
||||
* If not, returns null.
|
||||
*/
|
||||
@Nullable
|
||||
ValueParameterDescriptor choose(@NotNull ValueParameterDescriptor parameter, @NotNull ValueParameterDescriptor superParameter);
|
||||
}
|
||||
|
||||
private static final ParameterChooser MATCH_NAMES = new ParameterChooser() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ValueParameterDescriptor choose(
|
||||
@NotNull ValueParameterDescriptor parameter,
|
||||
@NotNull ValueParameterDescriptor superParameter
|
||||
) {
|
||||
return parameter.getName().equals(superParameter.getName()) ? superParameter : null;
|
||||
}
|
||||
};
|
||||
|
||||
private static final ParameterChooser MATCH_TYPES = new ParameterChooser() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ValueParameterDescriptor choose(
|
||||
@NotNull ValueParameterDescriptor parameter,
|
||||
@NotNull ValueParameterDescriptor superParameter
|
||||
) {
|
||||
return JetTypeChecker.INSTANCE.equalTypes(parameter.getType(), superParameter.getType()) ? parameter : null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Match function's parameters with super function's parameters using parameterChooser.
|
||||
* Doesn't have to preserve ordering, parameter names or types.
|
||||
* @param superParameters - super function's parameters
|
||||
* @param parameters - function's parameters
|
||||
* @param newParameters - new parameters (may be modified by this function)
|
||||
* @param matched - true iff this parameter in super function is matched by some parameter in function (may be modified by this function)
|
||||
* @param used - true iff this parameter in function is used to match some parameter in super function (may be modified by this function)
|
||||
*/
|
||||
private static void matchParameters(
|
||||
@NotNull ParameterChooser parameterChooser,
|
||||
@NotNull List<ValueParameterDescriptor> superParameters,
|
||||
@NotNull List<ValueParameterDescriptor> parameters,
|
||||
@NotNull List<ValueParameterDescriptor> newParameters,
|
||||
@NotNull BitSet matched,
|
||||
@NotNull BitSet used
|
||||
) {
|
||||
for (ValueParameterDescriptor superParameter : superParameters) {
|
||||
if (!matched.get(superParameter.getIndex())) {
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
ValueParameterDescriptor choice = parameterChooser.choose(parameter, superParameter);
|
||||
if (!used.get(parameter.getIndex()) && choice != null) {
|
||||
used.set(parameter.getIndex(), true);
|
||||
matched.set(superParameter.getIndex(), true);
|
||||
newParameters.set(superParameter.getIndex(), choice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all open functions in superclasses which have the same name as 'functionDescriptor' (but possibly
|
||||
* different parameters/return type).
|
||||
*/
|
||||
@NotNull
|
||||
private static List<FunctionDescriptor> getPossibleSuperFunctionsDescriptors(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
||||
List<FunctionDescriptor> superFunctions = Lists.newArrayList();
|
||||
if (!(containingDeclaration instanceof ClassDescriptor)) return superFunctions;
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
|
||||
Name name = functionDescriptor.getName();
|
||||
for (ClassDescriptor superclass : DescriptorUtils.getSuperclassDescriptors(classDescriptor)) {
|
||||
JetType type = superclass.getDefaultType();
|
||||
JetScope scope = type.getMemberScope();
|
||||
for (FunctionDescriptor function : scope.getFunctions(name)) {
|
||||
if (!function.getKind().isReal()) continue;
|
||||
if (function.getModality().isOverridable())
|
||||
superFunctions.add(function);
|
||||
}
|
||||
}
|
||||
return superFunctions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
|
||||
return function == null ? null : new ChangeMemberFunctionSignatureFix(function);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showHint(@NotNull Editor editor) {
|
||||
if (possibleSignatures.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Project project = editor.getProject();
|
||||
if (project == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -36,7 +35,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class QuickFixUtil {
|
||||
private QuickFixUtil() {
|
||||
@@ -95,13 +93,4 @@ public class QuickFixUtil {
|
||||
public static boolean canModifyElement(@NotNull PsiElement element) {
|
||||
return element.isWritable() && !BuiltInsReferenceResolver.isFromBuiltIns(element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String createFunctionSignatureStringFromDescriptor(
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
boolean shortTypeNames
|
||||
) {
|
||||
DescriptorRenderer renderer = shortTypeNames ? DescriptorRenderer.SOURCE_CODE_SHORT_NAMES_IN_TYPES : DescriptorRenderer.SOURCE_CODE;
|
||||
return renderer.render(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ public class QuickFixes {
|
||||
factories.put(NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
factories.put(NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OVERRIDE_KEYWORD));
|
||||
factories.put(NOTHING_TO_OVERRIDE, ChangeMemberFunctionSignatureFix.createFactory());
|
||||
factories.put(VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(OVERRIDE_KEYWORD));
|
||||
|
||||
factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
|
||||
|
||||
@@ -4,7 +4,8 @@ trait Trait {
|
||||
|
||||
class TraitImpl : Trait {
|
||||
|
||||
override fun <A, B: Runnable, E: Map.Entry<A, B>> foo() where B: Cloneable, B: Comparable<B> {
|
||||
override fun <A, B: Runnable, E: Map.Entry<A, B>> foo()
|
||||
where B: Cloneable, B: Comparable<B> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@ fun some() {
|
||||
tes<caret>
|
||||
}
|
||||
|
||||
// EXIST: test@test(a: jet.Int)
|
||||
// EXIST: test@test(a : jet.Int)
|
||||
@@ -9,20 +9,20 @@ T</b>
|
||||
<td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;">
|
||||
<b>
|
||||
fun</b>
|
||||
<T, E : java.lang.Cloneable>
|
||||
<T, E>
|
||||
writeToMyList</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
l: MyList<in T>,</td>
|
||||
l : MyList<in T>,</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
t: T</td>
|
||||
t : T</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
: jet.Unit <b>
|
||||
: jet.Unit <b>
|
||||
where</b>
|
||||
E : java.io.Closeable</td>
|
||||
E : java.lang.Cloneable, E : java.io.Closeable</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="8" style="white-space:nowrap;">
|
||||
|
||||
@@ -14,9 +14,9 @@ constructor</b>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
l: MyList<in T>,</td>
|
||||
l : MyList<in T>,</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
t: T</td>
|
||||
t : T</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
|
||||
@@ -12,11 +12,11 @@ fun</b>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
a: A<T, R></td>
|
||||
a : A<T, R></td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
: A<T, R></td>
|
||||
: A<T, R></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="7" style="white-space:nowrap;">
|
||||
|
||||
@@ -12,11 +12,11 @@ fun</b>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
a: A<T, R></td>
|
||||
a : A<T, R></td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
: A<T, R></td>
|
||||
: A<T, R></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="7" style="white-space:nowrap;">
|
||||
|
||||
@@ -12,11 +12,11 @@ fun</b>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
a: A<T, R></td>
|
||||
a : A<T, R></td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
: A<T, R></td>
|
||||
: A<T, R></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="7" style="white-space:nowrap;">
|
||||
|
||||
@@ -14,13 +14,13 @@ fun</b>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
(</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
r: R,</td>
|
||||
r : R,</td>
|
||||
<td align="right" style="white-space:nowrap;font-weight:bold;">
|
||||
list: T</td>
|
||||
list : T</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
)</td>
|
||||
<td style="white-space:nowrap;font-weight:bold;">
|
||||
: jet.Unit</td>
|
||||
: jet.Unit</td>
|
||||
</tr>
|
||||
</table>
|
||||
is not satisfied: inferred type <font color=red>
|
||||
|
||||
@@ -3,7 +3,7 @@ fun test() {
|
||||
MyClass().<warning descr="'fun test2()' is deprecated. Use A instead">test2</warning>()
|
||||
MyClass.<warning descr="'fun test3()' is deprecated. Use A instead">test3</warning>()
|
||||
|
||||
<warning descr="'fun test4(x: jet.Int, y: jet.Int)' is deprecated. Use A instead">test4</warning>(1, 2)
|
||||
<warning descr="'fun test4(x : jet.Int, y : jet.Int)' is deprecated. Use A instead">test4</warning>(1, 2)
|
||||
}
|
||||
|
||||
deprecated("Use A instead") fun test1() { }
|
||||
|
||||
@@ -6,5 +6,5 @@ fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
<warning descr="'fun get(i: MyClass)' is deprecated. Use A instead">x1[x2]</warning>
|
||||
<warning descr="'fun get(i : MyClass)' is deprecated. Use A instead">x1[x2]</warning>
|
||||
}
|
||||
@@ -20,19 +20,19 @@ fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
x1 <warning descr="'fun minus(i: MyClass)' is deprecated. Use A instead">-</warning> x2
|
||||
x1 <warning descr="'fun div(i: MyClass)' is deprecated. Use A instead">/</warning> x2
|
||||
x1 <warning descr="'fun times(i: MyClass)' is deprecated. Use A instead">*</warning> x2
|
||||
x1 <warning descr="'fun minus(i : MyClass)' is deprecated. Use A instead">-</warning> x2
|
||||
x1 <warning descr="'fun div(i : MyClass)' is deprecated. Use A instead">/</warning> x2
|
||||
x1 <warning descr="'fun times(i : MyClass)' is deprecated. Use A instead">*</warning> x2
|
||||
|
||||
<warning descr="'fun not()' is deprecated. Use A instead">!</warning>x1
|
||||
<warning descr="'fun plus()' is deprecated. Use A instead">+</warning>x1
|
||||
|
||||
x1 <warning descr="'fun contains(i: MyClass)' is deprecated. Use A instead">in</warning> x2
|
||||
x1 <warning descr="'fun contains(i: MyClass)' is deprecated. Use A instead">!in</warning> x2
|
||||
x1 <warning descr="'fun contains(i : MyClass)' is deprecated. Use A instead">in</warning> x2
|
||||
x1 <warning descr="'fun contains(i : MyClass)' is deprecated. Use A instead">!in</warning> x2
|
||||
|
||||
x1 <warning descr="'fun plusAssign(i: MyClass)' is deprecated. Use A instead">+=</warning> x2
|
||||
x1 <warning descr="'fun plusAssign(i : MyClass)' is deprecated. Use A instead">+=</warning> x2
|
||||
|
||||
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">==</warning> x2
|
||||
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">!=</warning> x2
|
||||
x1 <warning descr="'fun compareTo(i: MyClass)' is deprecated. Use A instead">></warning> x2
|
||||
x1 <warning descr="'fun equals(i : jet.Any?)' is deprecated. Use A instead">==</warning> x2
|
||||
x1 <warning descr="'fun equals(i : jet.Any?)' is deprecated. Use A instead">!=</warning> x2
|
||||
x1 <warning descr="'fun compareTo(i : MyClass)' is deprecated. Use A instead">></warning> x2
|
||||
}
|
||||
@@ -11,7 +11,7 @@ fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
for (i in x1<warning descr="'fun rangeTo(i: MyClass)' is deprecated. Use A instead">..</warning>x2) {
|
||||
for (i in x1<warning descr="'fun rangeTo(i : MyClass)' is deprecated. Use A instead">..</warning>x2) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
package testData.libraries
|
||||
|
||||
[[public abstract class ClassWithAbstractAndOpenMembers() {
|
||||
[public abstract val abstractVal: jet.String]
|
||||
[public abstract val abstractVal : jet.String]
|
||||
|
||||
[public abstract var abstractVar: jet.String]
|
||||
[public abstract var abstractVar : jet.String]
|
||||
|
||||
[public open val openVal: jet.String] /* compiled code */
|
||||
[public open val openVal : jet.String] /* compiled code */
|
||||
|
||||
[public open val openValWithGetter: jet.String] /* compiled code */
|
||||
[public open val openValWithGetter : jet.String] /* compiled code */
|
||||
|
||||
[public open var openVar: jet.String] /* compiled code */
|
||||
[public open var openVar : jet.String] /* compiled code */
|
||||
|
||||
[public open var openVarWithGetter: jet.String] /* compiled code */
|
||||
[public open var openVarWithGetter : jet.String] /* compiled code */
|
||||
|
||||
[public abstract fun abstractFun(): jet.Unit]
|
||||
[public abstract fun abstractFun() : jet.Unit]
|
||||
|
||||
[public open fun openFun(): jet.Unit { /* compiled code */ }]
|
||||
}]]
|
||||
[public open fun openFun() : jet.Unit { /* compiled code */ }]
|
||||
}]]
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
[[public final class ClassWithConstructor(a: jet.String, b: jet.Any) {
|
||||
[internal final val a: jet.String] /* compiled code */
|
||||
}]]
|
||||
[[public final class ClassWithConstructor(a : jet.String, b : jet.Any) {
|
||||
[internal final val a : jet.String] /* compiled code */
|
||||
}]]
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
[[public final enum class Color(rgb: jet.Int) : jet.Enum<testData.libraries.Color> {
|
||||
[[public final enum class Color(rgb : jet.Int) : jet.Enum<testData.libraries.Color> {
|
||||
public class object {
|
||||
[public final val BLUE: testData.libraries.Color] /* compiled code */
|
||||
[public final val BLUE : testData.libraries.Color] /* compiled code */
|
||||
|
||||
[public final val GREEN: testData.libraries.Color] /* compiled code */
|
||||
[public final val GREEN : testData.libraries.Color] /* compiled code */
|
||||
|
||||
[public final val RED: testData.libraries.Color] /* compiled code */
|
||||
[public final val RED : testData.libraries.Color] /* compiled code */
|
||||
|
||||
public final fun valueOf(value: jet.String): testData.libraries.Color { /* compiled code */ }
|
||||
public final fun valueOf(value : jet.String) : testData.libraries.Color { /* compiled code */ }
|
||||
|
||||
public final fun values(): jet.Array<testData.libraries.Color> { /* compiled code */ }
|
||||
public final fun values() : jet.Array<testData.libraries.Color> { /* compiled code */ }
|
||||
}
|
||||
|
||||
[internal final val rgb: jet.Int] /* compiled code */
|
||||
}]]
|
||||
[internal final val rgb : jet.Int] /* compiled code */
|
||||
}]]
|
||||
|
||||
@@ -3,34 +3,34 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
[public val globalVal: testData.libraries.Pair<jet.Int, jet.String>] /* compiled code */
|
||||
[public val globalVal : testData.libraries.Pair<jet.Int, jet.String>] /* compiled code */
|
||||
|
||||
[public val globalValWithGetter: jet.Long] /* compiled code */
|
||||
[public val globalValWithGetter : jet.Long] /* compiled code */
|
||||
|
||||
[public val jet.Int.exProp: jet.Int] /* compiled code */
|
||||
[public val jet.Int.exProp : jet.Int] /* compiled code */
|
||||
|
||||
[public val jet.String.exProp: jet.String] /* compiled code */
|
||||
[public val jet.String.exProp : jet.String] /* compiled code */
|
||||
|
||||
[public val <T> testData.libraries.Pair<T, T>.exProp: jet.String] /* compiled code */
|
||||
[public val <T> testData.libraries.Pair<T, T>.exProp : jet.String] /* compiled code */
|
||||
|
||||
[public fun <T : jet.CharSequence> funWithTypeParam(t: T): jet.Unit { /* compiled code */ }]
|
||||
[public fun <T : jet.CharSequence> funWithTypeParam(t : T) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun <T : jet.Number> funWithTypeParam(t: T): jet.Unit { /* compiled code */ }]
|
||||
[public fun <T : jet.Number> funWithTypeParam(t : T) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun func(): jet.Unit { /* compiled code */ }]
|
||||
[public fun func() : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun func(cs: jet.CharSequence): jet.Unit { /* compiled code */ }]
|
||||
[public fun func(cs : jet.CharSequence) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun func(a: jet.Int, b: jet.Int): jet.Unit { /* compiled code */ }]
|
||||
[public fun func(a : jet.Int, b : jet.Int) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun func(a: jet.Int, b: jet.String = /* compiled code */): jet.Unit { /* compiled code */ }]
|
||||
[public fun func(a : jet.Int, b : jet.String = /* compiled code */) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun func(str: jet.String): jet.Unit { /* compiled code */ }]
|
||||
[public fun func(str : jet.String) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun main(args: jet.Array<jet.String>): jet.Unit { /* compiled code */ }]
|
||||
[public fun main(args : jet.Array<jet.String>) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun processDouble(d: jet.Double): jet.Unit { /* compiled code */ }]
|
||||
[public fun processDouble(d : jet.Double) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun processDouble(d: testData.libraries.Double): jet.Unit { /* compiled code */ }]
|
||||
[public fun processDouble(d : testData.libraries.Double) : jet.Unit { /* compiled code */ }]
|
||||
|
||||
[public fun <T> T.filter(predicate: (T) -> jet.Boolean): T? { /* compiled code */ }]
|
||||
[public fun <T> T.filter(predicate : (T) -> jet.Boolean) : T? { /* compiled code */ }]
|
||||
@@ -4,5 +4,5 @@
|
||||
package testData.libraries
|
||||
|
||||
[[public object NamedObject {
|
||||
[public final val objectMember: jet.Int] /* compiled code */
|
||||
[public final val objectMember : jet.Int] /* compiled code */
|
||||
}]]
|
||||
@@ -5,12 +5,12 @@ package testData.libraries
|
||||
|
||||
[[public final class WithInnerAndObject() {
|
||||
public class object {
|
||||
[internal final fun foo(): jet.Unit { /* compiled code */ }]
|
||||
[internal final fun foo() : jet.Unit { /* compiled code */ }]
|
||||
}
|
||||
|
||||
[[internal final class MyInner() {
|
||||
[internal trait MyInnerInner {
|
||||
[internal abstract fun innerInnerMethod(): jet.Unit]
|
||||
[internal abstract fun innerInnerMethod() : jet.Unit]
|
||||
}]
|
||||
}]]
|
||||
}]]
|
||||
}]]
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// "Change function signature..." "true"
|
||||
// ERROR: <html>Class 'B' must be declared abstract or implement abstract member<br/><b>internal</b> <b>abstract</b> <b>fun</b> f(a: jet.String): jet.Unit <i>defined in</i> A</html>
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
fun f(a: String)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'public override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
public <caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
abstract class A {
|
||||
abstract fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
trait B : A {
|
||||
<caret>override fun f(a: Int)
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(x: Int, t: String, z: Double)'" "true"
|
||||
open class A {
|
||||
open fun f(x: Int, y: String, z: Double) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(x: Int, t: String, z: Double) {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(y: Int, x: String)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int, b: String) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(y: Int, x: String) {}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
open class A {
|
||||
open fun f() {}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
open override fun f() {}
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int): Int'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int): Int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: Int): Int = 7
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int): Int'" "true"
|
||||
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Int</td></tr><tr><td>Found:</td><td>jet.String</td></tr></table></html>
|
||||
open class A {
|
||||
open fun f(a: Int): Int = 0
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
// Note that when parameter types match, RETURN_TYPE_MISMATCH_ON_OVERRIDE error is reported
|
||||
// and "Change function signature" quickfix is not present.
|
||||
<caret>override fun f(a: Int): Int = "FOO"
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "false"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ACTION: Remove 'override' modifier
|
||||
open class A {
|
||||
open fun foo() {}
|
||||
fun f(a: Int) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// "Change function signature to 'protected override fun next(p0: Int): Int'" "true"
|
||||
import java.util.Random
|
||||
|
||||
class MyRandom : Random() {
|
||||
<caret>protected override fun next(p0: Int): Int = 4
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
trait A {
|
||||
fun f()
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
trait A {
|
||||
fun f()
|
||||
}
|
||||
trait B {
|
||||
fun f()
|
||||
}
|
||||
|
||||
class C : A, B {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// "Change function signature..." "true"
|
||||
// ERROR: <html>Class 'B' must be declared abstract or implement abstract member<br/><b>internal</b> <b>abstract</b> <b>fun</b> f(a: jet.String): jet.Unit <i>defined in</i> A</html>
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
fun f(a: String)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'public override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
public <caret>override fun f() {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
abstract class A {
|
||||
abstract fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
trait B : A {
|
||||
<caret>override fun f(a: String)
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(x: Int, t: String, z: Double)'" "true"
|
||||
open class A {
|
||||
open fun f(x: Int, y: String, z: Double) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(z: String, x: String, t: String) {}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(y: Int, x: String)'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int, b: String) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(x: String, y: Int) {}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
open class A {
|
||||
open fun f() {}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
open override fun f() {}
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
<caret>override fun f(a : Int) {}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int): Int'" "true"
|
||||
open class A {
|
||||
open fun f(a: Int): Int {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: String): Int = 7
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "true"
|
||||
trait A {
|
||||
fun f(a: Int)
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int): Int'" "true"
|
||||
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Int</td></tr><tr><td>Found:</td><td>jet.String</td></tr></table></html>
|
||||
open class A {
|
||||
open fun f(a: Int): Int = 0
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
// Note that when parameter types match, RETURN_TYPE_MISMATCH_ON_OVERRIDE error is reported
|
||||
// and "Change function signature" quickfix is not present.
|
||||
<caret>override fun f(a : String): String = "FOO"
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: Int)'" "false"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ACTION: Remove 'override' modifier
|
||||
open class A {
|
||||
open fun foo() {}
|
||||
fun f(a: Int) {}
|
||||
}
|
||||
|
||||
class B : A(){
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
// "Change function signature to 'protected override fun next(p0: Int): Int'" "true"
|
||||
import java.util.Random
|
||||
|
||||
class MyRandom : Random() {
|
||||
<caret>override fun next(): Int = 4
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
trait A {
|
||||
fun f()
|
||||
}
|
||||
|
||||
class B : A {
|
||||
<caret>override fun f(a: Int) {}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// "Change function signature to 'override fun f()'" "true"
|
||||
trait A {
|
||||
fun f()
|
||||
}
|
||||
trait B {
|
||||
fun f()
|
||||
}
|
||||
|
||||
class C : A, B {
|
||||
<caret>override fun f(a: String) {}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: A)'" "true"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ERROR: 'f' overrides nothing
|
||||
import a.B
|
||||
import a.A
|
||||
|
||||
class BB : B() {
|
||||
<caret>override fun f(a: A) {}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: A)'" "true"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ERROR: 'f' overrides nothing
|
||||
import a.B
|
||||
class BB : B() {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package a
|
||||
class A {}
|
||||
open class B {
|
||||
override fun f(a: A) {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: A)'" "true"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ERROR: 'f' overrides nothing
|
||||
import a.B
|
||||
class A {}
|
||||
class BB : B() {
|
||||
<caret>override fun f(a: a.A) {}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Change function signature to 'override fun f(a: A)'" "true"
|
||||
// ERROR: 'f' overrides nothing
|
||||
// ERROR: 'f' overrides nothing
|
||||
import a.B
|
||||
class A {}
|
||||
class BB : B() {
|
||||
<caret>override fun f() {}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package a
|
||||
class A {}
|
||||
open class B {
|
||||
override fun f(a: A) {}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// "Change 'B.foo' function return type to 'Int'" "false"
|
||||
// "Change 'B.foo' function return type to 'Long'" "false"
|
||||
// "Remove explicitly specified return type in 'B.foo' function" "false"
|
||||
// ERROR: <html>Return type is 'jet.String', 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>
|
||||
// ERROR: <html>Return type is 'jet.String', 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>
|
||||
abstract class A {
|
||||
abstract fun foo() : Int;
|
||||
}
|
||||
|
||||
@@ -193,34 +193,15 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override")
|
||||
@InnerTestClasses({Override.NothingToOverride.class})
|
||||
@InnerTestClasses({})
|
||||
public static class Override extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInOverride() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override/nothingToOverride")
|
||||
public static class NothingToOverride extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInNothingToOverride() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override/nothingToOverride"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("import.before.Main.kt")
|
||||
public void testImport() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/override/nothingToOverride/import.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("twoPackages.before.Main.kt")
|
||||
public void testTwoPackages() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/override/nothingToOverride/twoPackages.before.Main.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Override");
|
||||
suite.addTestSuite(Override.class);
|
||||
suite.addTestSuite(NothingToOverride.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@@ -712,7 +715,7 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override")
|
||||
@InnerTestClasses({Override.NothingToOverride.class, Override.TypeMismatchOnOverride.class})
|
||||
@InnerTestClasses({Override.TypeMismatchOnOverride.class})
|
||||
public static class Override extends AbstractQuickFixTest {
|
||||
public void testAllFilesPresentInOverride() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||
@@ -723,6 +726,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/override/beforeChangeToInvocation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeNothingToOverride.kt")
|
||||
public void testNothingToOverride() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/beforeNothingToOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeOverriddingMultipleFinalMethods.kt")
|
||||
public void testOverriddingMultipleFinalMethods() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/beforeOverriddingMultipleFinalMethods.kt");
|
||||
@@ -768,99 +776,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/override/beforeVirtualMethodHidden.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override/nothingToOverride")
|
||||
public static class NothingToOverride extends AbstractQuickFixTest {
|
||||
@TestMetadata("beforeAddParameter.kt")
|
||||
public void testAddParameter() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeAddParameterMultiple.kt")
|
||||
public void testAddParameterMultiple() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterMultiple.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeAddParameterPreserveVisibility.kt")
|
||||
public void testAddParameterPreserveVisibility() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeAddParameterPreserveVisibility.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNothingToOverride() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override/nothingToOverride"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterType.kt")
|
||||
public void testChangeParameterType() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeAbstractSuperclass.kt")
|
||||
public void testChangeParameterTypeAbstractSuperclass() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeAbstractSuperclass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeInTrait.kt")
|
||||
public void testChangeParameterTypeInTrait() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeInTrait.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeMatchNames.kt")
|
||||
public void testChangeParameterTypeMatchNames() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeMatchNames.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeModifyOrder.kt")
|
||||
public void testChangeParameterTypeModifyOrder() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeModifyOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeOpenOverride.kt")
|
||||
public void testChangeParameterTypeOpenOverride() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeOpenOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeSingleExpressionFunction.kt")
|
||||
public void testChangeParameterTypeSingleExpressionFunction() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeSingleExpressionFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeParameterTypeSuperTrait.kt")
|
||||
public void testChangeParameterTypeSuperTrait() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeParameterTypeSuperTrait.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeChangeReturnType.kt")
|
||||
public void testChangeReturnType() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeChangeReturnType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeNoOpenSuperFunction.kt")
|
||||
public void testNoOpenSuperFunction() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeNoOpenSuperFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeOverrideJavaMethod.kt")
|
||||
public void testOverrideJavaMethod() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeOverrideJavaMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeRemoveOverride.kt")
|
||||
public void testRemoveOverride() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeRemoveOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeRemoveParameter.kt")
|
||||
public void testRemoveParameter() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeRemoveParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeRemoveParameterTwoTraits.kt")
|
||||
public void testRemoveParameterTwoTraits() throws Exception {
|
||||
doTest("idea/testData/quickfix/override/nothingToOverride/beforeRemoveParameterTwoTraits.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/override/typeMismatchOnOverride")
|
||||
public static class TypeMismatchOnOverride extends AbstractQuickFixTest {
|
||||
public void testAllFilesPresentInTypeMismatchOnOverride() throws Exception {
|
||||
@@ -907,7 +822,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Override");
|
||||
suite.addTestSuite(Override.class);
|
||||
suite.addTestSuite(NothingToOverride.class);
|
||||
suite.addTestSuite(TypeMismatchOnOverride.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user