Added JetModifierListOwner interface

This commit is contained in:
svtk
2011-09-15 17:19:32 +04:00
parent dd43c3cf08
commit 205e23c866
9 changed files with 34 additions and 23 deletions
@@ -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<JetDeclaration> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
SimplePsiElementOnlyDiagnosticFactory<JetModifierListOwner> REDUNDANT_ABSTRACT = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "Abstract modifier is redundant in traits");
ParameterizedDiagnosticFactory2<String, ClassDescriptor> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract property {0} in non-abstract class {1}");
ParameterizedDiagnosticFactory2<String, ClassDescriptor> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = ParameterizedDiagnosticFactory2.create(ERROR, "Abstract function {0} in non-abstract class {1}");
ParameterizedDiagnosticFactory1<FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = ParameterizedDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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");
@@ -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;
@@ -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<JetDeclaration> {
public RemoveAbstractModifierFix(JetDeclaration declaration) {
super(declaration);
public class RemoveAbstractModifierFix extends QuickFixes.IntentionActionForPsiElement<JetModifierListOwner> {
public RemoveAbstractModifierFix(JetModifierListOwner element) {
super(element);
}
@NotNull
@@ -56,12 +57,12 @@ public class RemoveAbstractModifierFix extends QuickFixes.IntentionActionForPsiE
return true;
}
public static QuickFixes.IntentionActionFactory<JetDeclaration> factory =
new QuickFixes.IntentionActionFactory<JetDeclaration>() {
public static QuickFixes.IntentionActionFactory<JetModifierListOwner> factory =
new QuickFixes.IntentionActionFactory<JetModifierListOwner>() {
@Override
public QuickFixes.IntentionActionForPsiElement<JetDeclaration> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetDeclaration;
return new RemoveAbstractModifierFix((JetDeclaration) diagnostic.getPsiElement());
public QuickFixes.IntentionActionForPsiElement<JetModifierListOwner> createAction(DiagnosticWithPsiElement diagnostic) {
assert diagnostic.getPsiElement() instanceof JetModifierListOwner;
return new RemoveAbstractModifierFix((JetModifierListOwner) diagnostic.getPsiElement());
}
};
}