From 716718fb0df6bd1d92fddfeaf18f04900e0394be Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sun, 22 Sep 2013 21:49:10 +0400 Subject: [PATCH] JetAnnotated interface extracted to unify declarations and annotated expressions --- .../jetbrains/jet/lang/psi/JetAnnotated.java | 29 +++++++++++++++++++ .../jet/lang/psi/JetAnnotatedExpression.java | 12 +++++--- .../jet/lang/psi/JetDeclarationImpl.java | 19 ++++++++++++ .../jet/lang/psi/JetDeclarationStub.java | 19 ++++++++++++ .../jet/lang/psi/JetModifierListOwner.java | 2 +- .../jet/lang/psi/JetTypeProjection.java | 19 ++++++++++++ .../BasicExpressionTypingVisitor.java | 2 +- 7 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotated.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotated.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotated.java new file mode 100644 index 00000000000..ae04cbfd02e --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotated.java @@ -0,0 +1,29 @@ +/* + * 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.psi; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface JetAnnotated extends JetElement { + @NotNull + List getAnnotations(); + + @NotNull + List getAnnotationEntries(); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotatedExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotatedExpression.java index 6ef28bbf857..7e03ca3f864 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotatedExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetAnnotatedExpression.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class JetAnnotatedExpression extends JetExpressionImpl { +public class JetAnnotatedExpression extends JetExpressionImpl implements JetAnnotated { public JetAnnotatedExpression(@NotNull ASTNode node) { super(node); } @@ -45,13 +45,17 @@ public class JetAnnotatedExpression extends JetExpressionImpl { return findChildByClass(JetExpression.class); } - public List getAttributeAnnotations() { + @Override + @NotNull + public List getAnnotations() { return findChildrenByType(JetNodeTypes.ANNOTATION); } - public List getAttributes() { + @Override + @NotNull + public List getAnnotationEntries() { List answer = null; - for (JetAnnotation annotation : getAttributeAnnotations()) { + for (JetAnnotation annotation : getAnnotations()) { if (answer == null) answer = new ArrayList(); answer.addAll(annotation.getEntries()); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationImpl.java index 21df45325ab..cc6e6a5def4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationImpl.java @@ -22,6 +22,9 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lexer.JetToken; +import java.util.Collections; +import java.util.List; + abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclaration { public JetDeclarationImpl(@NotNull ASTNode node) { super(node); @@ -38,4 +41,20 @@ abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclar JetModifierList modifierList = getModifierList(); return modifierList != null && modifierList.hasModifier(modifier); } + + @NotNull + @Override + public List getAnnotationEntries() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotationEntries(); + } + + @NotNull + @Override + public List getAnnotations() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotations(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java index 5392ff425c0..c73dd0ae466 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java @@ -24,6 +24,9 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lexer.JetToken; +import java.util.Collections; +import java.util.List; + abstract class JetDeclarationStub extends JetElementImplStub implements JetDeclaration { public JetDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) { super(stub, nodeType); @@ -44,4 +47,20 @@ abstract class JetDeclarationStub extends JetElementImplS JetModifierList modifierList = getModifierList(); return modifierList != null && modifierList.hasModifier(modifier); } + + @NotNull + @Override + public List getAnnotationEntries() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotationEntries(); + } + + @NotNull + @Override + public List getAnnotations() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotations(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java index 5cc59b351c3..2005cbd9aea 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifierListOwner.java @@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lexer.JetToken; -public interface JetModifierListOwner extends PsiElement { +public interface JetModifierListOwner extends PsiElement, JetAnnotated { @Nullable JetModifierList getModifierList(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeProjection.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeProjection.java index 6bdd9c47c27..b3467437ced 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeProjection.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeProjection.java @@ -24,6 +24,9 @@ import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lexer.JetToken; import org.jetbrains.jet.lexer.JetTokens; +import java.util.Collections; +import java.util.List; + public class JetTypeProjection extends JetElementImpl implements JetModifierListOwner { public JetTypeProjection(@NotNull ASTNode node) { super(node); @@ -87,4 +90,20 @@ public class JetTypeProjection extends JetElementImpl implements JetModifierList return null; } + + @NotNull + @Override + public List getAnnotationEntries() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotationEntries(); + } + + @NotNull + @Override + public List getAnnotations() { + JetModifierList modifierList = getModifierList(); + if (modifierList == null) return Collections.emptyList(); + return modifierList.getAnnotations(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 6ab0aebef06..628af320b3b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1170,7 +1170,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { @Override public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context) { context.expressionTypingServices.getAnnotationResolver().resolveAnnotationsWithArguments( - context.scope, expression.getAttributes(), context.trace); + context.scope, expression.getAnnotationEntries(), context.trace); JetExpression baseExpression = expression.getBaseExpression(); if (baseExpression == null) {