JetAnnotated interface extracted to unify declarations and annotated expressions
This commit is contained in:
@@ -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<JetAnnotation> getAnnotations();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
List<JetAnnotationEntry> getAnnotationEntries();
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JetAnnotatedExpression extends JetExpressionImpl {
|
public class JetAnnotatedExpression extends JetExpressionImpl implements JetAnnotated {
|
||||||
public JetAnnotatedExpression(@NotNull ASTNode node) {
|
public JetAnnotatedExpression(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
@@ -45,13 +45,17 @@ public class JetAnnotatedExpression extends JetExpressionImpl {
|
|||||||
return findChildByClass(JetExpression.class);
|
return findChildByClass(JetExpression.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JetAnnotation> getAttributeAnnotations() {
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<JetAnnotation> getAnnotations() {
|
||||||
return findChildrenByType(JetNodeTypes.ANNOTATION);
|
return findChildrenByType(JetNodeTypes.ANNOTATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JetAnnotationEntry> getAttributes() {
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<JetAnnotationEntry> getAnnotationEntries() {
|
||||||
List<JetAnnotationEntry> answer = null;
|
List<JetAnnotationEntry> answer = null;
|
||||||
for (JetAnnotation annotation : getAttributeAnnotations()) {
|
for (JetAnnotation annotation : getAnnotations()) {
|
||||||
if (answer == null) answer = new ArrayList<JetAnnotationEntry>();
|
if (answer == null) answer = new ArrayList<JetAnnotationEntry>();
|
||||||
answer.addAll(annotation.getEntries());
|
answer.addAll(annotation.getEntries());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclaration {
|
abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclaration {
|
||||||
public JetDeclarationImpl(@NotNull ASTNode node) {
|
public JetDeclarationImpl(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
@@ -38,4 +41,20 @@ abstract class JetDeclarationImpl extends JetExpressionImpl implements JetDeclar
|
|||||||
JetModifierList modifierList = getModifierList();
|
JetModifierList modifierList = getModifierList();
|
||||||
return modifierList != null && modifierList.hasModifier(modifier);
|
return modifierList != null && modifierList.hasModifier(modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotationEntry> getAnnotationEntries() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotationEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotation> getAnnotations() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
abstract class JetDeclarationStub<T extends StubElement> extends JetElementImplStub<T> implements JetDeclaration {
|
abstract class JetDeclarationStub<T extends StubElement> extends JetElementImplStub<T> implements JetDeclaration {
|
||||||
public JetDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
public JetDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) {
|
||||||
super(stub, nodeType);
|
super(stub, nodeType);
|
||||||
@@ -44,4 +47,20 @@ abstract class JetDeclarationStub<T extends StubElement> extends JetElementImplS
|
|||||||
JetModifierList modifierList = getModifierList();
|
JetModifierList modifierList = getModifierList();
|
||||||
return modifierList != null && modifierList.hasModifier(modifier);
|
return modifierList != null && modifierList.hasModifier(modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotationEntry> getAnnotationEntries() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotationEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotation> getAnnotations() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
|
|
||||||
public interface JetModifierListOwner extends PsiElement {
|
public interface JetModifierListOwner extends PsiElement, JetAnnotated {
|
||||||
@Nullable
|
@Nullable
|
||||||
JetModifierList getModifierList();
|
JetModifierList getModifierList();
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ import org.jetbrains.jet.JetNodeTypes;
|
|||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class JetTypeProjection extends JetElementImpl implements JetModifierListOwner {
|
public class JetTypeProjection extends JetElementImpl implements JetModifierListOwner {
|
||||||
public JetTypeProjection(@NotNull ASTNode node) {
|
public JetTypeProjection(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
@@ -87,4 +90,20 @@ public class JetTypeProjection extends JetElementImpl implements JetModifierList
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotationEntry> getAnnotationEntries() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotationEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetAnnotation> getAnnotations() {
|
||||||
|
JetModifierList modifierList = getModifierList();
|
||||||
|
if (modifierList == null) return Collections.emptyList();
|
||||||
|
return modifierList.getAnnotations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1170,7 +1170,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context) {
|
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context) {
|
||||||
context.expressionTypingServices.getAnnotationResolver().resolveAnnotationsWithArguments(
|
context.expressionTypingServices.getAnnotationResolver().resolveAnnotationsWithArguments(
|
||||||
context.scope, expression.getAttributes(), context.trace);
|
context.scope, expression.getAnnotationEntries(), context.trace);
|
||||||
|
|
||||||
JetExpression baseExpression = expression.getBaseExpression();
|
JetExpression baseExpression = expression.getBaseExpression();
|
||||||
if (baseExpression == null) {
|
if (baseExpression == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user