diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 3d3dfdbae9b..ff28ecd1f33 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -53,7 +53,7 @@ public interface Errors { SimpleDiagnosticFactory PROPERTY_INITIALIZER_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed in traits"); SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR, "Initializer is not allowed here because this property has no backing field"); SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_PRIMARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "Property initializers are not allowed when no primary constructor is present"); - SimplePsiElementOnlyDiagnosticFactory REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits"); + SimplePsiElementOnlyDiagnosticFactory REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits"); ParameterizedDiagnosticFactory2 ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract property {0} in non-abstract class {1}"); ParameterizedDiagnosticFactory2 ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract function {0} in non-abstract class {1}"); ParameterizedDiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java index bc4af407c63..433b26aa2af 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclaration.java @@ -9,7 +9,7 @@ import org.jetbrains.jet.lexer.JetToken; /** * @author max */ -public abstract class JetDeclaration extends JetExpression { +public abstract class JetDeclaration extends JetExpression implements JetModifierListOwner { public JetDeclaration(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java index 10f03300dca..52c987ea24f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java @@ -14,7 +14,7 @@ import java.util.List; /** * @author abreslav */ -abstract public class JetFunction extends JetTypeParameterListOwner implements JetDeclarationWithBody { +abstract public class JetFunction extends JetTypeParameterListOwner implements JetDeclarationWithBody, JetModifierListOwner { public JetFunction(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java new file mode 100644 index 00000000000..b56e9bea2ac --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java @@ -0,0 +1,15 @@ +package org.jetbrains.jet.lang.psi; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lexer.JetToken; + +/** + * @author svtk + */ +public interface JetModifierListOwner extends PsiElement { + @Nullable + JetModifierList getModifierList(); + + boolean hasModifier(JetToken modifier); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java index a7d1af61ef4..679b6a2adb1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java @@ -14,7 +14,7 @@ import java.util.List; /** * @author max */ -public class JetProperty extends JetTypeParameterListOwner { +public class JetProperty extends JetTypeParameterListOwner implements JetModifierListOwner { public JetProperty(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java index 7b209efca3c..291c381e2d1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java @@ -12,7 +12,7 @@ import java.util.List; /** * @author max */ -public class JetPropertyAccessor extends JetDeclaration implements JetDeclarationWithBody { +public class JetPropertyAccessor extends JetDeclaration implements JetDeclarationWithBody, JetModifierListOwner { public JetPropertyAccessor(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 8e5ce72a814..2d36d49885c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -769,22 +769,19 @@ public class BodyResolver { protected void checkFunction(JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) { DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration(); PsiElement nameIdentifier; - JetModifierList modifierList; boolean isPropertyAccessor = false; if (function instanceof JetNamedFunction) { - JetNamedFunction namedFunction = (JetNamedFunction) function; - nameIdentifier = namedFunction.getNameIdentifier(); - modifierList = namedFunction.getModifierList(); + nameIdentifier = ((JetNamedFunction) function).getNameIdentifier(); } else if (function instanceof JetPropertyAccessor) { isPropertyAccessor = true; - JetPropertyAccessor propertyAccessor = (JetPropertyAccessor) function; - nameIdentifier = propertyAccessor.getNamePlaceholder(); - modifierList = propertyAccessor.getModifierList(); + nameIdentifier = ((JetPropertyAccessor) function).getNamePlaceholder(); } else { throw new UnsupportedOperationException(); } + JetModifierListOwner modifierListOwner = (JetModifierListOwner) function; + JetModifierList modifierList = modifierListOwner.getModifierList(); ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null; boolean hasAbstractModifier = abstractNode != null; if (containingDescriptor instanceof ClassDescriptor) { @@ -799,7 +796,7 @@ public class BodyResolver { } if (hasAbstractModifier && inTrait && !isPropertyAccessor) { // context.getTrace().getErrorHandler().genericWarning(abstractNode, "Abstract modifier is redundant in trait"); - context.getTrace().report(REDUNDANT_ABSTRACT.on((JetDeclaration)function, abstractNode)); //TODO + context.getTrace().report(REDUNDANT_ABSTRACT.on(modifierListOwner, abstractNode)); } if (function.getBodyExpression() != null && hasAbstractModifier) { // context.getTrace().getErrorHandler().genericError(abstractNode, "Method " + methodName + "with body cannot be abstract"); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index a0541b40ba1..5808ef7ee6a 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -3,8 +3,6 @@ package org.jetbrains.jet.plugin.quickfix; import com.google.common.collect.Maps; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.psi.PsiElement; -import org.jetbrains.jet.lang.diagnostics.Diagnostic; -import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.PsiElementOnlyDiagnosticFactory; diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveAbstractModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveAbstractModifierFix.java index d86be2b1baf..aee9cf8238c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveAbstractModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveAbstractModifierFix.java @@ -9,14 +9,15 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.psi.JetDeclaration; +import org.jetbrains.jet.lang.psi.JetModifierListOwner; import org.jetbrains.jet.lexer.JetTokens; /** * @author svtk */ -public class RemoveAbstractModifierFix extends QuickFixes.IntentionActionForPsiElement { - public RemoveAbstractModifierFix(JetDeclaration declaration) { - super(declaration); +public class RemoveAbstractModifierFix extends QuickFixes.IntentionActionForPsiElement { + public RemoveAbstractModifierFix(JetModifierListOwner element) { + super(element); } @NotNull @@ -56,12 +57,12 @@ public class RemoveAbstractModifierFix extends QuickFixes.IntentionActionForPsiE return true; } - public static QuickFixes.IntentionActionFactory factory = - new QuickFixes.IntentionActionFactory() { + public static QuickFixes.IntentionActionFactory factory = + new QuickFixes.IntentionActionFactory() { @Override - public QuickFixes.IntentionActionForPsiElement createAction(DiagnosticWithPsiElement diagnostic) { - assert diagnostic.getPsiElement() instanceof JetDeclaration; - return new RemoveAbstractModifierFix((JetDeclaration) diagnostic.getPsiElement()); + public QuickFixes.IntentionActionForPsiElement createAction(DiagnosticWithPsiElement diagnostic) { + assert diagnostic.getPsiElement() instanceof JetModifierListOwner; + return new RemoveAbstractModifierFix((JetModifierListOwner) diagnostic.getPsiElement()); } }; }