Changes after forbidding modality modifiers in accessors

This commit is contained in:
svtk
2011-10-03 17:47:26 +04:00
parent 6bfaac9c34
commit 50418698db
30 changed files with 345 additions and 316 deletions
@@ -59,7 +59,7 @@ public interface Errors {
return sb.toString(); return sb.toString();
} }
}; };
ParameterizedDiagnosticFactory1<JetKeywordToken> ILLEGAL_MODIFIER = ParameterizedDiagnosticFactory1.create(ERROR, "Illegal modifier ''{0}''"); DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> ILLEGAL_MODIFIER = DiagnosticWithParameterFactory.create(ERROR, "Illegal modifier ''{0}''", DiagnosticParameters.MODIFIER);
PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = new PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken>(Severity.WARNING, "Modifier {0} is redundant because {1} is present") { PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken> REDUNDANT_MODIFIER = new PsiElementOnlyDiagnosticFactory2<JetModifierList, JetKeywordToken, JetKeywordToken>(Severity.WARNING, "Modifier {0} is redundant because {1} is present") {
@NotNull @NotNull
@@ -69,6 +69,7 @@ public interface Errors {
} }
}; };
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> REDUNDANT_MODIFIER_IN_TRAIT = DiagnosticWithParameterFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", DiagnosticParameters.MODIFIER); DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> REDUNDANT_MODIFIER_IN_TRAIT = DiagnosticWithParameterFactory.create(WARNING, "Modifier ''{0}'' is redundant in trait", DiagnosticParameters.MODIFIER);
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticWithParameterFactory.create(WARNING, "Visibility modifiers are redundant in getter", DiagnosticParameters.MODIFIER);
SimplePsiElementOnlyDiagnosticFactory<JetClass> TRAIT_CAN_NOT_BE_FINAL = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Trait can not be final"); SimplePsiElementOnlyDiagnosticFactory<JetClass> TRAIT_CAN_NOT_BE_FINAL = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Trait can not be final");
SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces"); SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces");
SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem"); // TODO: message SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem"); // TODO: message
@@ -94,6 +95,8 @@ public interface Errors {
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParameterFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_INITIALIZER = DiagnosticWithParameterFactory.create(ERROR, "Property with initializer cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_GETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with getter implementation cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE); DiagnosticWithParameterFactory<JetProperty, JetType> ABSTRACT_PROPERTY_WITH_SETTER = DiagnosticWithParameterFactory.create(ERROR, "Property with setter implementation cannot be abstract", DiagnosticParameters.TYPE);
DiagnosticWithParameterFactory<JetModifierList, JetKeywordToken> GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = DiagnosticWithParameterFactory.create(ERROR, "Getter visibility must be the same as property visibility", DiagnosticParameters.MODIFIER);
SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field"); SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property in a trait cannot have a backing field");
SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "Property must be initialized"); SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "Property must be initialized");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract"); SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "Property must be initialized or be abstract");
@@ -106,22 +109,19 @@ public interface Errors {
return super.on(elementToBlame, textRangeToMark, s, classDescriptor, aClass).add(DiagnosticParameters.CLASS, aClass); return super.on(elementToBlame, textRangeToMark, s, classDescriptor, aClass).add(DiagnosticParameters.CLASS, aClass);
} }
}; };
PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunctionOrPropertyAccessor, String, ClassDescriptor, JetClass>(ERROR, "Abstract function {0} in non-abstract class {1}") { PsiElementOnlyDiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = new PsiElementOnlyDiagnosticFactory3<JetFunction, String, ClassDescriptor, JetClass>(ERROR, "Abstract function {0} in non-abstract class {1}") {
@NotNull @NotNull
public DiagnosticWithPsiElement<JetFunctionOrPropertyAccessor> on(@NotNull JetFunctionOrPropertyAccessor elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass modifierListOwner) { public DiagnosticWithPsiElement<JetFunction> on(@NotNull JetFunction elementToBlame, @NotNull ASTNode nodeToMark, @NotNull String s, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass modifierListOwner) {
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner); return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
} }
}; };
PsiElementOnlyDiagnosticFactory1<JetFunctionOrPropertyAccessor, FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
PsiElementOnlyDiagnosticFactory1<JetFunctionOrPropertyAccessor, FunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract"); PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract");
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, FunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract"); PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, FunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> NON_MEMBER_ABSTRACT_ACCESSOR = SimplePsiElementOnlyDiagnosticFactory.create(ERROR, "This property is not a class or trait member and thus cannot have abstract accessors"); // TODO : Better message
PsiElementOnlyDiagnosticFactory1<JetFunctionOrPropertyAccessor, FunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body"); PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body");
DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS); DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS);
DiagnosticWithParameterFactory<JetPropertyAccessor, JetProperty> NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY = DiagnosticWithParameterFactory.create(ERROR, "Non final accessor of a final property", DiagnosticParameters.PROPERTY);
DiagnosticWithParameterFactory<JetPropertyAccessor, JetProperty> ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY = DiagnosticWithParameterFactory.create(ERROR, "Abstract accessor of a final property", DiagnosticParameters.PROPERTY);
SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, "Projections are not allowed on type arguments of functions and properties"); // TODO : better positioning
SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here"); SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, "This type has a constructor, and thus must be initialized here");
@@ -130,7 +130,7 @@ public interface Errors {
SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors"); SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "'by'-clause is only supported for primary constructors");
SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required"); SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR, "Constructor arguments required");
SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed"); SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR, "Only one call to 'this(...)' is allowed");
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT); PsiElementOnlyDiagnosticFactory1<JetModifierList, CallableMemberDescriptor> NOTHING_TO_OVERRIDE = PsiElementOnlyDiagnosticFactory1.create(ERROR, "{0} overrides nothing", DescriptorRenderer.TEXT);
PsiElementOnlyDiagnosticFactory1<JetClass, PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field"); PsiElementOnlyDiagnosticFactory1<JetClass, PropertyDescriptor> PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "This class must have a primary constructor, because property {0} has a backing field");
ParameterizedDiagnosticFactory1<JetClassOrObject> PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1<JetClassOrObject>(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") { ParameterizedDiagnosticFactory1<JetClassOrObject> PRIMARY_CONSTRUCTOR_MISSING_SUPER_CONSTRUCTOR_CALL = new ParameterizedDiagnosticFactory1<JetClassOrObject>(ERROR, "Class {0} must have a constructor in order to be able to initialize supertypes") {
@Override @Override
@@ -14,7 +14,7 @@ import java.util.List;
/** /**
* @author abreslav * @author abreslav
*/ */
abstract public class JetFunction extends JetTypeParameterListOwner implements JetFunctionOrPropertyAccessor { abstract public class JetFunction extends JetTypeParameterListOwner implements JetDeclarationWithBody, JetModifierListOwner {
public JetFunction(@NotNull ASTNode node) { public JetFunction(@NotNull ASTNode node) {
super(node); super(node);
} }
@@ -1,7 +0,0 @@
package org.jetbrains.jet.lang.psi;
/**
* @author svtk
*/
public interface JetFunctionOrPropertyAccessor extends JetDeclarationWithBody, JetModifierListOwner {
}
@@ -13,7 +13,7 @@ import java.util.List;
/** /**
* @author max * @author max
*/ */
public class JetPropertyAccessor extends JetDeclaration implements JetFunctionOrPropertyAccessor { public class JetPropertyAccessor extends JetDeclaration implements JetDeclarationWithBody, JetModifierListOwner {
public JetPropertyAccessor(@NotNull ASTNode node) { public JetPropertyAccessor(@NotNull ASTNode node) {
super(node); super(node);
} }
@@ -1,6 +1,7 @@
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Pair;
@@ -10,7 +11,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.DeferredType; import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetKeywordToken; import org.jetbrains.jet.lexer.JetKeywordToken;
@@ -20,7 +20,6 @@ import org.jetbrains.jet.lexer.JetTokens;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
@@ -114,7 +113,7 @@ public class DeclarationsChecker {
private void checkObject(JetObjectDeclaration objectDeclaration, MutableClassDescriptor classDescriptor) { private void checkObject(JetObjectDeclaration objectDeclaration, MutableClassDescriptor classDescriptor) {
checkIllegalInThisContextModifiers(objectDeclaration.getModifierList(), JetTokens.ABSTRACT_KEYWORD, JetTokens.OPEN_KEYWORD, JetTokens.OVERRIDE_KEYWORD); checkIllegalInThisContextModifiers(objectDeclaration.getModifierList(), Sets.newHashSet(JetTokens.ABSTRACT_KEYWORD, JetTokens.OPEN_KEYWORD, JetTokens.OVERRIDE_KEYWORD));
} }
private void checkOpenMembers(JetClass aClass, MutableClassDescriptor classDescriptor) { private void checkOpenMembers(JetClass aClass, MutableClassDescriptor classDescriptor) {
@@ -122,7 +121,9 @@ public class DeclarationsChecker {
JetNamedDeclaration member = (JetNamedDeclaration) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, memberDescriptor); JetNamedDeclaration member = (JetNamedDeclaration) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, memberDescriptor);
if (member != null && classDescriptor.getModality() == Modality.FINAL && member.hasModifier(JetTokens.OPEN_KEYWORD)) { if (member != null && classDescriptor.getModality() == Modality.FINAL && member.hasModifier(JetTokens.OPEN_KEYWORD)) {
ASTNode openModifierNode = member.getModifierList().getModifierNode(JetTokens.OPEN_KEYWORD); JetModifierList modifierList = member.getModifierList();
assert modifierList != null;
ASTNode openModifierNode = modifierList.getModifierNode(JetTokens.OPEN_KEYWORD);
context.getTrace().report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member, openModifierNode, aClass)); context.getTrace().report(NON_FINAL_MEMBER_IN_FINAL_CLASS.on(member, openModifierNode, aClass));
} }
} }
@@ -225,22 +226,10 @@ public class DeclarationsChecker {
} }
} }
protected void checkFunction(JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) { protected void checkFunction(JetNamedFunction function, FunctionDescriptor functionDescriptor) {
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration(); DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
PsiElement nameIdentifier; PsiElement nameIdentifier = function.getNameIdentifier();
boolean isPropertyAccessor = false; JetModifierList modifierList = function.getModifierList();
if (function instanceof JetNamedFunction) {
nameIdentifier = ((JetNamedFunction) function).getNameIdentifier();
}
else if (function instanceof JetPropertyAccessor) {
isPropertyAccessor = true;
nameIdentifier = ((JetPropertyAccessor) function).getNamePlaceholder();
}
else {
throw new UnsupportedOperationException();
}
JetFunctionOrPropertyAccessor functionOrPropertyAccessor = (JetFunctionOrPropertyAccessor) function;
JetModifierList modifierList = functionOrPropertyAccessor.getModifierList();
ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null; ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null;
boolean hasAbstractModifier = abstractNode != null; boolean hasAbstractModifier = abstractNode != null;
if (containingDescriptor instanceof ClassDescriptor) { if (containingDescriptor instanceof ClassDescriptor) {
@@ -251,46 +240,45 @@ public class DeclarationsChecker {
if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) { if (hasAbstractModifier && !inAbstractClass && !inTrait && !inEnum) {
PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor); PsiElement classElement = context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor);
assert classElement instanceof JetClass; assert classElement instanceof JetClass;
context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(functionOrPropertyAccessor, abstractNode, functionDescriptor.getName(), classDescriptor, (JetClass) classElement)); context.getTrace().report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, abstractNode, functionDescriptor.getName(), classDescriptor, (JetClass) classElement));
} }
if (hasAbstractModifier && inTrait && !isPropertyAccessor) { if (hasAbstractModifier && inTrait) {
context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD)); context.getTrace().report(REDUNDANT_MODIFIER_IN_TRAIT.on(modifierList, abstractNode, JetTokens.ABSTRACT_KEYWORD));
} }
if (function.getBodyExpression() != null && hasAbstractModifier) { if (function.getBodyExpression() != null && hasAbstractModifier) {
context.getTrace().report(ABSTRACT_FUNCTION_WITH_BODY.on(functionOrPropertyAccessor, abstractNode, functionDescriptor)); context.getTrace().report(ABSTRACT_FUNCTION_WITH_BODY.on(function, abstractNode, functionDescriptor));
} }
if (function.getBodyExpression() == null && !hasAbstractModifier && !inTrait && nameIdentifier != null && !isPropertyAccessor) { if (function.getBodyExpression() == null && !hasAbstractModifier && !inTrait && nameIdentifier != null) {
context.getTrace().report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(functionOrPropertyAccessor, nameIdentifier, functionDescriptor)); context.getTrace().report(NON_ABSTRACT_FUNCTION_WITH_NO_BODY.on(function, nameIdentifier, functionDescriptor));
} }
return; return;
} }
if (hasAbstractModifier) { if (hasAbstractModifier) {
if (!isPropertyAccessor) { context.getTrace().report(NON_MEMBER_ABSTRACT_FUNCTION.on(function, abstractNode, functionDescriptor));
context.getTrace().report(NON_MEMBER_ABSTRACT_FUNCTION.on(functionOrPropertyAccessor, abstractNode, functionDescriptor));
}
else {
context.getTrace().report(NON_MEMBER_ABSTRACT_ACCESSOR.on(functionOrPropertyAccessor, abstractNode));
}
} }
if (function.getBodyExpression() == null && !hasAbstractModifier && nameIdentifier != null && !isPropertyAccessor) { if (function.getBodyExpression() == null && !hasAbstractModifier && nameIdentifier != null) {
context.getTrace().report(NON_MEMBER_FUNCTION_NO_BODY.on(functionOrPropertyAccessor, nameIdentifier, functionDescriptor)); context.getTrace().report(NON_MEMBER_FUNCTION_NO_BODY.on(function, nameIdentifier, functionDescriptor));
} }
} }
private void checkAccessors(JetProperty property, PropertyDescriptor propertyDescriptor) { private void checkAccessors(JetProperty property, PropertyDescriptor propertyDescriptor) {
for (JetPropertyAccessor accessor : property.getAccessors()) { for (JetPropertyAccessor accessor : property.getAccessors()) {
PropertyAccessorDescriptor accessorDescriptor = accessor.isGetter() checkIllegalInThisContextModifiers(accessor.getModifierList(), Sets.newHashSet(JetTokens.ABSTRACT_KEYWORD, JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD, JetTokens.OVERRIDE_KEYWORD));
? propertyDescriptor.getGetter() }
: propertyDescriptor.getSetter(); JetPropertyAccessor getter = property.getGetter();
checkFunction(accessor, accessorDescriptor); PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
checkModifiers(accessor.getModifierList()); JetModifierList getterModifierList = getter != null ? getter.getModifierList() : null;
if (propertyDescriptor.getModality() == Modality.FINAL && accessor.hasModifier(JetTokens.OPEN_KEYWORD)) { if (getterModifierList != null && getterDescriptor != null) {
ASTNode openModifierNode = accessor.getModifierList().getModifierNode(JetTokens.OPEN_KEYWORD); Map<JetKeywordToken, ASTNode> nodes = getNodesCorrespondingToModifiers(getterModifierList, Sets.newHashSet(JetTokens.PUBLIC_KEYWORD, JetTokens.PROTECTED_KEYWORD, JetTokens.PRIVATE_KEYWORD, JetTokens.INTERNAL_KEYWORD));
context.getTrace().report(NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY.on(accessor, openModifierNode, property)); if (getterDescriptor.getVisibility() != propertyDescriptor.getVisibility()) {
for (Map.Entry<JetKeywordToken, ASTNode> entry : nodes.entrySet()) {
context.getTrace().report(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.on(getterModifierList, entry.getValue(), entry.getKey()));
}
} }
if (propertyDescriptor.getModality() != Modality.ABSTRACT && accessor.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { else {
ASTNode abstractModifierNode = accessor.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD); for (Map.Entry<JetKeywordToken, ASTNode> entry : nodes.entrySet()) {
context.getTrace().report(ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY.on(accessor, abstractModifierNode, property)); context.getTrace().report(Errors.REDUNDANT_MODIFIER_IN_GETTER.on(getterModifierList, entry.getValue(), entry.getKey()));
}
} }
} }
} }
@@ -346,12 +334,23 @@ public class DeclarationsChecker {
} }
} }
private void checkIllegalInThisContextModifiers(@Nullable JetModifierList modifierList, JetKeywordToken... illegalModifiers) { private void checkIllegalInThisContextModifiers(@Nullable JetModifierList modifierList, Collection<JetKeywordToken> illegalModifiers) {
if (modifierList == null) return; if (modifierList == null) return;
for (JetKeywordToken modifier : illegalModifiers) { for (JetKeywordToken modifier : illegalModifiers) {
if (modifierList.hasModifier(modifier)) { if (modifierList.hasModifier(modifier)) {
context.getTrace().report(Errors.ILLEGAL_MODIFIER.on(modifierList.getModifierNode(modifier), modifier)); context.getTrace().report(Errors.ILLEGAL_MODIFIER.on(modifierList, modifierList.getModifierNode(modifier), modifier));
} }
} }
} }
@NotNull
public static Map<JetKeywordToken, ASTNode> getNodesCorrespondingToModifiers(@NotNull JetModifierList modifierList, Collection<JetKeywordToken> possibleModifiers) {
Map<JetKeywordToken, ASTNode> nodes = Maps.newHashMap();
for (JetKeywordToken modifier : possibleModifiers) {
if (modifierList.hasModifier(modifier)) {
nodes.put(modifier, modifierList.getModifierNode(modifier));
}
}
return nodes;
}
} }
@@ -253,7 +253,7 @@ public class OverrideResolver {
} }
if (hasOverrideModifier && declared.getOverriddenDescriptors().size() == 0) { if (hasOverrideModifier && declared.getOverriddenDescriptors().size() == 0) {
// context.getTrace().getErrorHandler().genericError(overrideNode, "Method " + declared.getName() + " overrides nothing"); // context.getTrace().getErrorHandler().genericError(overrideNode, "Method " + declared.getName() + " overrides nothing");
context.getTrace().report(NOTHING_TO_OVERRIDE.on(member, overrideNode, declared)); context.getTrace().report(NOTHING_TO_OVERRIDE.on(modifierList, overrideNode, declared));
} }
PsiElement nameIdentifier = member.getNameIdentifier(); PsiElement nameIdentifier = member.getNameIdentifier();
if (!hasOverrideModifier && declared.getOverriddenDescriptors().size() > 0 && nameIdentifier != null) { if (!hasOverrideModifier && declared.getOverriddenDescriptors().size() > 0 && nameIdentifier != null) {
@@ -12,8 +12,8 @@ import org.jetbrains.jet.lang.psi.*;
/** /**
* @author svtk * @author svtk
*/ */
public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> { public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
public AddFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) { public AddFunctionBodyFix(@NotNull JetFunction element) {
super(element); super(element);
} }
@@ -37,7 +37,7 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrProperty
@Override @Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetFunctionOrPropertyAccessor newElement = (JetFunctionOrPropertyAccessor) element.copy(); JetFunction newElement = (JetFunction) element.copy();
JetExpression bodyExpression = newElement.getBodyExpression(); JetExpression bodyExpression = newElement.getBodyExpression();
if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) { if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) {
newElement.add(JetPsiFactory.createWhiteSpace(project)); newElement.add(JetPsiFactory.createWhiteSpace(project));
@@ -48,12 +48,12 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunctionOrProperty
element.replace(newElement); element.replace(newElement);
} }
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() { public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() { return new JetIntentionActionFactory<JetFunction>() {
@Override @Override
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) { public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor; assert diagnostic.getPsiElement() instanceof JetFunction;
return new AddFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement()); return new AddFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
} }
}; };
} }
@@ -4,11 +4,13 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetModifierList; import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lang.psi.JetModifierListOwner; import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lexer.JetKeywordToken; import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetToken; import org.jetbrains.jet.lexer.JetToken;
@@ -17,19 +19,39 @@ import org.jetbrains.jet.lexer.JetTokens;
/** /**
* @author svtk * @author svtk
*/ */
public class AddModifierFix extends ModifierFix { public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
private final JetKeywordToken modifier;
private final JetToken[] modifiersThanCanBeReplaced; private final JetToken[] modifiersThanCanBeReplaced;
private AddModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier, JetToken[] modifiersThanCanBeReplaced) { private AddModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier, JetToken[] modifiersThanCanBeReplaced) {
super(element, modifier); super(element);
this.modifier = modifier;
this.modifiersThanCanBeReplaced = modifiersThanCanBeReplaced; this.modifiersThanCanBeReplaced = modifiersThanCanBeReplaced;
} }
@NotNull
/*package*/ static String getElementName(JetModifierListOwner modifierListOwner) {
String name = null;
if (modifierListOwner instanceof PsiNameIdentifierOwner) {
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) modifierListOwner).getNameIdentifier();
if (nameIdentifier != null) {
name = nameIdentifier.getText();
}
}
else if (modifierListOwner instanceof JetPropertyAccessor) {
name = ((JetPropertyAccessor) modifierListOwner).getNamePlaceholder().getText();
}
if (name == null) {
name = modifierListOwner.getText();
}
return "'" + name + "'";
}
@NotNull @NotNull
@Override @Override
public String getText() { public String getText() {
if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) { if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
return "Make " + getElementName() + " " + modifier.getValue(); return "Make " + getElementName(element) + " " + modifier.getValue();
} }
return "Add '" + modifier.getValue() + "' modifier"; return "Add '" + modifier.getValue() + "' modifier";
} }
@@ -1,38 +0,0 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.jet.lexer.JetKeywordToken;
/**
* @author svtk
*/
public abstract class ModifierFix extends JetIntentionAction<JetModifierListOwner> {
protected final JetKeywordToken modifier;
protected ModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier) {
super(element);
this.modifier = modifier;
}
@NotNull
protected String getElementName() {
String name = null;
if (element instanceof PsiNameIdentifierOwner) {
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) element).getNameIdentifier();
if (nameIdentifier != null) {
name = nameIdentifier.getText();
}
}
else if (element instanceof JetPropertyAccessor) {
name = ((JetPropertyAccessor) element).getNamePlaceholder().getText();
}
if (name == null) {
name = element.getText();
}
return "'" + name + "'";
}
}
@@ -1,9 +1,11 @@
package org.jetbrains.jet.plugin.quickfix; package org.jetbrains.jet.plugin.quickfix;
import com.intellij.extapi.psi.ASTDelegatePsiElement;
import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter; import org.jetbrains.jet.lang.diagnostics.DiagnosticParameter;
@@ -69,4 +71,12 @@ public class QuickFixUtil {
} }
}; };
} }
public static boolean removePossiblyWhiteSpace(ASTDelegatePsiElement element, PsiElement possiblyWhiteSpace) {
if (possiblyWhiteSpace instanceof PsiWhiteSpace) {
element.deleteChildInternal(possiblyWhiteSpace.getNode());
return true;
}
return false;
}
} }
@@ -29,7 +29,7 @@ public class QuickFixes {
} }
static { static {
JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD); JetIntentionActionFactory<JetModifierListOwner> removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.ABSTRACT_KEYWORD);
JetIntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD}); JetIntentionActionFactory<JetModifierListOwner> addAbstractModifierFactory = AddModifierFix.createFactory(JetTokens.ABSTRACT_KEYWORD, new JetToken[]{JetTokens.OPEN_KEYWORD, JetTokens.FINAL_KEYWORD});
add(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory); add(Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
@@ -53,22 +53,21 @@ public class QuickFixes {
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory); add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory); add(Errors.ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory(); JetIntentionActionFactory<JetFunction> removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory); add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory); add(Errors.ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeAbstractModifierFactory); add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeAbstractModifierFactory);
add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeFunctionBodyFactory); add(Errors.ABSTRACT_FUNCTION_WITH_BODY, removeFunctionBodyFactory);
JetIntentionActionFactory<JetFunctionOrPropertyAccessor> addFunctionBodyFactory = AddFunctionBodyFix.createFactory(); JetIntentionActionFactory<JetFunction> addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory); add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory); add(Errors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
add(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory); add(Errors.NON_MEMBER_ABSTRACT_FUNCTION, removeAbstractModifierFactory);
add(Errors.NON_MEMBER_ABSTRACT_ACCESSOR, removeAbstractModifierFactory);
add(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory); add(Errors.NON_MEMBER_FUNCTION_NO_BODY, addFunctionBodyFactory);
add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD)); add(Errors.NOTHING_TO_OVERRIDE, RemoveModifierFix.createRemoveModifierFromListFactory(JetTokens.OVERRIDE_KEYWORD));
add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD})); add(Errors.VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(JetTokens.OVERRIDE_KEYWORD, new JetToken[] {JetTokens.OPEN_KEYWORD}));
add(Errors.VAL_WITH_SETTER, ChangeVariableMutabilityFix.createFactory()); add(Errors.VAL_WITH_SETTER, ChangeVariableMutabilityFix.createFactory());
@@ -84,10 +83,10 @@ public class QuickFixes {
add(Errors.UNNECESSARY_SAFE_CALL, ReplaceSafeCallToDotCall.createFactory()); add(Errors.UNNECESSARY_SAFE_CALL, ReplaceSafeCallToDotCall.createFactory());
JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveRedundantModifierFix.createFactory(); JetIntentionActionFactory<JetModifierList> removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory(true);
add(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory); add(Errors.REDUNDANT_MODIFIER, removeRedundantModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory); add(Errors.REDUNDANT_MODIFIER_IN_TRAIT, removeRedundantModifierFactory);
add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createFactory(JetTokens.FINAL_KEYWORD)); add(Errors.TRAIT_CAN_NOT_BE_FINAL, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.FINAL_KEYWORD));
add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory()); add(Errors.PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR, RemovePartsFromPropertyFix.createRemoveInitializerFactory());
@@ -96,14 +95,13 @@ public class QuickFixes {
add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory); add(Errors.PRIMARY_CONSTRUCTOR_MISSING_STATEFUL_PROPERTY, addPrimaryConstructorFactory);
JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD}); JetIntentionActionFactory<JetModifierListOwner> addOpenModifierFactory = AddModifierFix.createFactory(JetTokens.OPEN_KEYWORD, new JetToken[]{JetTokens.FINAL_KEYWORD});
JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createFactory(JetTokens.OPEN_KEYWORD); JetIntentionActionFactory<JetModifierListOwner> removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(JetTokens.OPEN_KEYWORD);
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS)); add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.CLASS));
add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory); add(Errors.NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
add(Errors.NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addOpenModifierFactory, DiagnosticParameters.PROPERTY));
add(Errors.NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY, removeOpenModifierFactory);
add(Errors.ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY, QuickFixUtil.createFactoryRedirectingAdditionalInfoToAnotherFactory(addAbstractModifierFactory, DiagnosticParameters.PROPERTY)); JetIntentionActionFactory<JetModifierList> removeModifierFactory = RemoveModifierFix.createRemoveModifierFromListFactory();
add(Errors.ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY, removeAbstractModifierFactory); add(Errors.GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
add(Errors.REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
add(Errors.ILLEGAL_MODIFIER, removeModifierFactory);
} }
} }
@@ -4,18 +4,22 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lexer.JetTokens;
/** /**
* @author svtk * @author svtk
*/ */
public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunctionOrPropertyAccessor> { public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunction> {
public RemoveFunctionBodyFix(@NotNull JetFunctionOrPropertyAccessor element) { public RemoveFunctionBodyFix(@NotNull JetFunction element) {
super(element); super(element);
} }
@@ -39,25 +43,41 @@ public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunctionOrPrope
@Override @Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetFunctionOrPropertyAccessor newElement = (JetFunctionOrPropertyAccessor) element.copy(); JetFunction function = (JetFunction) element.copy();
JetExpression bodyExpression = newElement.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
if (bodyExpression != null) { assert bodyExpression != null;
PsiElement prevSibling = bodyExpression.getPrevSibling(); if (function.hasBlockBody()) {
if (prevSibling instanceof PsiWhiteSpace) { PsiElement prevElement = bodyExpression.getPrevSibling();
((JetElement)newElement).deleteChildInternal(prevSibling.getNode()); QuickFixUtil.removePossiblyWhiteSpace(function, prevElement);
} function.deleteChildInternal(bodyExpression.getNode());
((JetElement)newElement).deleteChildInternal(bodyExpression.getNode());
} }
element.replace(newElement); else {
PsiElement prevElement = bodyExpression.getPrevSibling();
PsiElement prevPrevElement = prevElement.getPrevSibling();
QuickFixUtil.removePossiblyWhiteSpace(function, prevElement);
removePossiblyEquationSign(function, prevElement);
removePossiblyEquationSign(function, prevPrevElement);
function.deleteChildInternal(bodyExpression.getNode());
}
element.replace(function);
} }
public static JetIntentionActionFactory<JetFunctionOrPropertyAccessor> createFactory() { private static boolean removePossiblyEquationSign(@NotNull JetElement element, @Nullable PsiElement possiblyEq) {
return new JetIntentionActionFactory<JetFunctionOrPropertyAccessor>() { if (possiblyEq instanceof LeafPsiElement && ((LeafPsiElement)possiblyEq).getElementType() == JetTokens.EQ) {
QuickFixUtil.removePossiblyWhiteSpace(element, possiblyEq.getNextSibling());
element.deleteChildInternal(possiblyEq.getNode());
return true;
}
return false;
}
public static JetIntentionActionFactory<JetFunction> createFactory() {
return new JetIntentionActionFactory<JetFunction>() {
@Override @Override
public JetIntentionAction<JetFunctionOrPropertyAccessor> createAction(DiagnosticWithPsiElement diagnostic) { public JetIntentionAction<JetFunction> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetFunctionOrPropertyAccessor; assert diagnostic.getPsiElement() instanceof JetFunction;
return new RemoveFunctionBodyFix((JetFunctionOrPropertyAccessor) diagnostic.getPsiElement()); return new RemoveFunctionBodyFix((JetFunction) diagnostic.getPsiElement());
} }
}; };
} }
} }
@@ -1,14 +1,15 @@
package org.jetbrains.jet.plugin.quickfix; package org.jetbrains.jet.plugin.quickfix;
import com.intellij.extapi.psi.ASTDelegatePsiElement;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.psi.JetModifierList; import org.jetbrains.jet.lang.psi.JetModifierList;
@@ -20,35 +21,31 @@ import org.jetbrains.jet.lexer.JetTokens;
/** /**
* @author svtk * @author svtk
*/ */
public class RemoveModifierFix extends ModifierFix { public class RemoveModifierFix {
private final JetKeywordToken modifier;
private final boolean isRedundant;
public RemoveModifierFix(@NotNull JetModifierListOwner element, JetKeywordToken modifier) { public RemoveModifierFix(JetKeywordToken modifier, boolean isRedundant) {
super(element, modifier); this.modifier = modifier;
this.isRedundant = isRedundant;
} }
@NotNull private static String makeText(@Nullable JetModifierListOwner element, JetKeywordToken modifier, boolean isRedundant) {
@Override if (isRedundant) {
public String getText() { return "Remove redundant '" + modifier.getValue() + "' modifier";
if (modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) { }
return "Make " + getElementName() + " not " + modifier.getValue(); if (element != null && modifier == JetTokens.ABSTRACT_KEYWORD || modifier == JetTokens.OPEN_KEYWORD) {
return "Make " + AddModifierFix.getElementName(element) + " not " + modifier.getValue();
} }
return "Remove '" + modifier.getValue() + "' modifier"; return "Remove '" + modifier.getValue() + "' modifier";
} }
@NotNull private static String getFamilyName() {
@Override return "Remove modifier fix";
public String getFamilyName() {
return "Remove modifier";
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
} }
@NotNull @NotNull
/*package*/ static <T extends JetModifierListOwner> T removeModifier(T element, JetToken modifier) { private static <T extends JetModifierListOwner> T removeModifier(T element, JetToken modifier) {
JetModifierList modifierList = element.getModifierList(); JetModifierList modifierList = element.getModifierList();
assert modifierList != null; assert modifierList != null;
removeModifierFromList(modifierList, modifier); removeModifierFromList(modifierList, modifier);
@@ -56,38 +53,128 @@ public class RemoveModifierFix extends ModifierFix {
PsiElement whiteSpace = modifierList.getNextSibling(); PsiElement whiteSpace = modifierList.getNextSibling();
assert element instanceof JetElement; assert element instanceof JetElement;
((JetElement) element).deleteChildInternal(modifierList.getNode()); ((JetElement) element).deleteChildInternal(modifierList.getNode());
removeWhiteSpace((JetElement) element, whiteSpace); QuickFixUtil.removePossiblyWhiteSpace((JetElement) element, whiteSpace);
} }
return element; return element;
} }
/*package*/ static JetModifierList removeModifierFromList(@NotNull JetModifierList modifierList, JetToken modifier) { @NotNull
private static JetModifierList removeModifierFromList(@NotNull JetModifierList modifierList, JetToken modifier) {
assert modifierList.hasModifier(modifier); assert modifierList.hasModifier(modifier);
ASTNode modifierNode = modifierList.getModifierNode(modifier); ASTNode modifierNode = modifierList.getModifierNode(modifier);
PsiElement whiteSpace = modifierNode.getPsi().getNextSibling(); PsiElement whiteSpace = modifierNode.getPsi().getNextSibling();
boolean wsRemoved = removeWhiteSpace(modifierList, whiteSpace); boolean wsRemoved = QuickFixUtil.removePossiblyWhiteSpace(modifierList, whiteSpace);
modifierList.deleteChildInternal(modifierNode); modifierList.deleteChildInternal(modifierNode);
if (!wsRemoved) { if (!wsRemoved) {
removeWhiteSpace(modifierList, modifierList.getLastChild()); QuickFixUtil.removePossiblyWhiteSpace(modifierList, modifierList.getLastChild());
} }
return modifierList; return modifierList;
} }
private static boolean removeWhiteSpace(ASTDelegatePsiElement element, PsiElement subElement) { private class RemoveModifierFromListOwner extends JetIntentionAction<JetModifierListOwner> {
if (subElement instanceof PsiWhiteSpace) { public RemoveModifierFromListOwner(@NotNull JetModifierListOwner element) {
element.deleteChildInternal(subElement.getNode()); super(element);
return true; }
@NotNull
@Override
public String getText() {
return makeText(element, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierListOwner newElement = (JetModifierListOwner) element.copy();
element.replace(removeModifier(newElement, modifier));
} }
return false;
} }
public static JetIntentionActionFactory<JetModifierListOwner> createFactory(final JetKeywordToken modifier) { private class RemoveModifierFromList extends JetIntentionAction<JetModifierList> {
public RemoveModifierFromList(@NotNull JetModifierList element) {
super(element);
}
@NotNull
@Override
public String getText() {
return makeText(null, modifier, isRedundant);
}
@NotNull
@Override
public String getFamilyName() {
return RemoveModifierFix.getFamilyName();
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierList newElement = (JetModifierList) element.copy();
element.replace(RemoveModifierFix.removeModifierFromList(newElement, modifier));
}
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() { return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override @Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) { public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner; assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return new RemoveModifierFix((JetModifierListOwner) diagnostic.getPsiElement(), modifier); return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
} }
}; };
} }
}
private static RemoveModifierFix createRemoveModifierFixFromDiagnostic(DiagnosticWithPsiElement diagnostic, boolean isRedundant) {
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = JetIntentionAction.assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
return new RemoveModifierFix(modifier, isRedundant);
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierListOwner>() {
@Override
public JetIntentionAction<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromListOwner((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return createRemoveModifierFixFromDiagnostic(diagnostic, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier, final boolean isRedundant) {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
return new RemoveModifierFix(modifier, isRedundant).new RemoveModifierFromList((JetModifierList) diagnostic.getPsiElement());
}
};
}
public static JetIntentionActionFactory<JetModifierListOwner> createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListOwnerFactory(modifier, false);
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory() {
return createRemoveModifierFromListFactory(false);
}
public static JetIntentionActionFactory<JetModifierList> createRemoveModifierFromListFactory(final JetKeywordToken modifier) {
return createRemoveModifierFromListFactory(modifier, false);
}
}
@@ -1,54 +0,0 @@
package org.jetbrains.jet.plugin.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.DiagnosticParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters;
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement;
import org.jetbrains.jet.lang.psi.JetModifierList;
import org.jetbrains.jet.lexer.JetKeywordToken;
/**
* @author svtk
*/
public class RemoveRedundantModifierFix extends JetIntentionAction<JetModifierList> {
private JetKeywordToken redundantModifier;
public RemoveRedundantModifierFix(@NotNull JetModifierList element, @NotNull JetKeywordToken redundantModifier) {
super(element);
this.redundantModifier = redundantModifier;
}
@NotNull
@Override
public String getText() {
return "Remove redundant '" + redundantModifier + "' modifier";
}
@NotNull
@Override
public String getFamilyName() {
return "Remove redundant modifier";
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
JetModifierList newElement = (JetModifierList) element.copy();
element.replace(RemoveModifierFix.removeModifierFromList(newElement, redundantModifier));
}
public static JetIntentionActionFactory<JetModifierList> createFactory() {
return new JetIntentionActionFactory<JetModifierList>() {
@Override
public JetIntentionAction<JetModifierList> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierList;
DiagnosticWithParameters<PsiElement> diagnosticWithParameters = assertAndCastToDiagnosticWithParameters(diagnostic, DiagnosticParameters.MODIFIER);
JetKeywordToken modifier = diagnosticWithParameters.getParameter(DiagnosticParameters.MODIFIER);
return new RemoveRedundantModifierFix((JetModifierList) diagnostic.getPsiElement(), modifier);
}
};
}
}
@@ -35,8 +35,6 @@
var <error>v5</error> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x} var <error>v5</error> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x}
var <error>v6</error> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){} var <error>v6</error> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){}
<info>abstract</info> val v7 : Int <info>abstract</info> <info>get</info>
<info>abstract</info> var v8 : Int <info>abstract</info> <info>get</info> <info>abstract</info> <info>set</info>
var <error>v9</error> : Int <info>set</info> var <error>v9</error> : Int <info>set</info>
var <error>v10</error> : Int <info>get</info> var <error>v10</error> : Int <info>get</info>
+1 -1
View File
@@ -1,4 +1,4 @@
abstract class XXX { abstract class XXX {
abstract val a : Int abstract get abstract val a : Int get
} }
@@ -29,19 +29,19 @@ class MyClass() {
<!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {} <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors //property accessors
var i: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {} var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
} }
abstract class MyAbstractClass() { abstract class MyAbstractClass() {
@@ -73,19 +73,19 @@ abstract class MyAbstractClass() {
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {} <!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors //property accessors
var i: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j1: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {} var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
} }
trait MyTrait { trait MyTrait {
@@ -117,19 +117,19 @@ trait MyTrait {
<!REDUNDANT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {} <!REDUNDANT_MODIFIER_IN_TRAIT, ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors //property accessors
var i: Int abstract get abstract set var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var k: Int abstract set var k: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var k1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int abstract get abstract set var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l1: Int = <!PROPERTY_INITIALIZER_IN_TRAIT!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {} var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
} }
enum class MyEnum() { enum class MyEnum() {
@@ -161,19 +161,19 @@ enum class MyEnum() {
<!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {} <!ABSTRACT_FUNCTION_WITH_BODY!>abstract<!> fun j() {}
//property accessors //property accessors
var i: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!ABSTRACT_FUNCTION_WITH_BODY, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {} var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
} }
abstract enum class MyAbstractEnum() {} abstract enum class MyAbstractEnum() {}
@@ -207,19 +207,19 @@ namespace MyNamespace {
<!NON_MEMBER_ABSTRACT_FUNCTION!>abstract<!> fun j() {} <!NON_MEMBER_ABSTRACT_FUNCTION!>abstract<!> fun j() {}
//property accessors //property accessors
var i: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var i1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var j: Int get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j: Int get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var j1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; get() = i; <!ILLEGAL_MODIFIER!>abstract<!> set
var <!MUST_BE_INITIALIZED!>k<!>: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var <!MUST_BE_INITIALIZED!>k<!>: Int <!ILLEGAL_MODIFIER!>abstract<!> set
var k1: Int = 0; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var k1: Int = 0; <!ILLEGAL_MODIFIER!>abstract<!> set
var l: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var l1: Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>0<!>; <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
var n: Int <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get <!NON_MEMBER_ABSTRACT_ACCESSOR, ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set(v: Int) {} var n: Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set(v: Int) {}
} }
//creating an instance //creating an instance
@@ -7,7 +7,7 @@ abstract class A() {
open var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>r<!>: String open var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>r<!>: String
get get
<!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> protected set <!ILLEGAL_MODIFIER!>abstract<!> protected set
} }
<!TRAIT_CAN_NOT_BE_FINAL!>final<!> trait T {} <!TRAIT_CAN_NOT_BE_FINAL!>final<!> trait T {}
@@ -15,7 +15,7 @@ abstract class A() {
class FinalClass() { class FinalClass() {
<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> fun foo() {} <!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> fun foo() {}
val i: Int = 1 val i: Int = 1
<!NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY!>open<!> get(): Int = $i <!ILLEGAL_MODIFIER!>open<!> get(): Int = $i
var j: Int = 1 var j: Int = 1
<!NON_FINAL_ACCESSOR_OF_FINAL_PROPERTY!>open<!> set(v: Int) {} <!ILLEGAL_MODIFIER!>open<!> set(v: Int) {}
} }
@@ -35,10 +35,12 @@ abstract class Test() {
var <!MUST_BE_INITIALIZED!>v5<!> : Int get() = 1; set(x){$v5 = x} var <!MUST_BE_INITIALIZED!>v5<!> : Int get() = 1; set(x){$v5 = x}
var <!MUST_BE_INITIALIZED!>v6<!> : Int get() = $v6 + 1; set(x){} var <!MUST_BE_INITIALIZED!>v6<!> : Int get() = $v6 + 1; set(x){}
abstract val v7 : Int abstract get abstract val v7 : Int get
abstract var v8 : Int abstract get abstract set abstract var v8 : Int get set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v9<!> : Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> set var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v9<!> : Int set
var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v10<!> : Int <!ABSTRACT_ACCESSOR_OF_NON_ABSTRACT_PROPERTY!>abstract<!> get var <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>v10<!> : Int get
abstract val v11 : Int <!ILLEGAL_MODIFIER!>abstract<!> get
abstract var v12 : Int <!ILLEGAL_MODIFIER!>abstract<!> get <!ILLEGAL_MODIFIER!>abstract<!> set
} }
@@ -1,4 +1,4 @@
abstract class XXX { abstract class XXX {
abstract val a : Int abstract get abstract val a : Int get
} }
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any
}
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any
}
@@ -1,2 +0,0 @@
// "Make 'get' not abstract" "true"
val i : Int = 0; <caret>get
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any { return "a" }
}
@@ -0,0 +1,4 @@
// "Remove function body" "true"
abstract class A() {
<caret>abstract fun foo() : Any = 1
}
@@ -1,2 +0,0 @@
// "Make 'get' not abstract" "true"
val i : Int = 0; <caret>abstract get
@@ -1,5 +0,0 @@
// "Make 'i' open" "true"
open class A() {
open val i: Int = 1
<caret>open get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'get' not open" "true"
open class A() {
val i: Int = 1
<caret>get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'i' open" "true"
open class A() {
val i: Int = 1
<caret>open get(): Int = $i
}
@@ -1,5 +0,0 @@
// "Make 'get' not open" "true"
open class A() {
val i: Int = 1
<caret>open get(): Int = $i
}