From d566250b186cf443005bccd5abb884c3cf466471 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 12 Mar 2013 19:10:57 +0400 Subject: [PATCH] Introduce JetCallableReferenceExpression Reuse the obsolete hash qualified expression as a newly born callable reference expression: Foo::bar. It's not a qualified expression anymore, since the receiver part is now a JetTypeReference and it also can be empty ("::bar") #KT-1183 In Progress --- .../src/org/jetbrains/jet/JetNodeTypes.java | 1 + .../jet/lang/cfg/JetControlFlowProcessor.java | 1 - .../psi/JetCallableReferenceExpression.java | 59 +++++++++++++++++++ .../lang/psi/JetHashQualifiedExpression.java | 36 ----------- .../jetbrains/jet/lang/psi/JetVisitor.java | 4 +- .../jet/lang/psi/JetVisitorVoid.java | 4 +- .../BasicExpressionTypingVisitor.java | 2 +- 7 files changed, 65 insertions(+), 42 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallableReferenceExpression.java delete mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetHashQualifiedExpression.java diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 97f2aff95cb..04839a4ba85 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -131,6 +131,7 @@ public interface JetNodeTypes { JetNodeType ARRAY_ACCESS_EXPRESSION = new JetNodeType("ARRAY_ACCESS_EXPRESSION", JetArrayAccessExpression.class); JetNodeType INDICES = new JetNodeType("INDICES", JetContainerNode.class); JetNodeType DOT_QUALIFIED_EXPRESSION = new JetNodeType("DOT_QUALIFIED_EXPRESSION", JetDotQualifiedExpression.class); + JetNodeType CALLABLE_REFERENCE_EXPRESSION = new JetNodeType("CALLABLE_REFERENCE_EXPRESSION", JetCallableReferenceExpression.class); JetNodeType SAFE_ACCESS_EXPRESSION = new JetNodeType("SAFE_ACCESS_EXPRESSION", JetSafeQualifiedExpression.class); JetNodeType OBJECT_LITERAL = new JetNodeType("OBJECT_LITERAL", JetObjectLiteralExpression.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 05dddae0607..91e6937ba5b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -228,7 +228,6 @@ public class JetControlFlowProcessor { visitAssignToArrayAccess(expression, arrayAccessExpression); } else if (left instanceof JetQualifiedExpression) { - assert !(left instanceof JetHashQualifiedExpression) : left; // TODO JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) left; generateInstructions(qualifiedExpression.getReceiverExpression(), false); generateInstructions(expression.getOperationReference(), false); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallableReferenceExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallableReferenceExpression.java new file mode 100644 index 00000000000..0fe2faf4f4d --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetCallableReferenceExpression.java @@ -0,0 +1,59 @@ +/* + * 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 com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lexer.JetTokens; + +public class JetCallableReferenceExpression extends JetExpressionImpl { + public JetCallableReferenceExpression(@NotNull ASTNode node) { + super(node); + } + + @Nullable + public JetTypeReference getTypeReference() { + return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE); + } + + @NotNull + public JetSimpleNameExpression getCallableReference() { + ASTNode node = getNode().findChildByType(JetTokens.OPERATIONS /* TODO: COLONCOLON */); + while (node != null) { + PsiElement psi = node.getPsi(); + if (psi instanceof JetSimpleNameExpression) { + return (JetSimpleNameExpression) psi; + } + node = node.getTreeNext(); + } + + throw new IllegalStateException("Callable reference simple name shouldn't be parsed to null"); + } + + @Override + public void accept(@NotNull JetVisitorVoid visitor) { + visitor.visitCallableReferenceExpression(this); + } + + @Override + public R accept(@NotNull JetVisitor visitor, D data) { + return visitor.visitCallableReferenceExpression(this, data); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetHashQualifiedExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetHashQualifiedExpression.java deleted file mode 100644 index d97c3ac1915..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetHashQualifiedExpression.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 com.intellij.lang.ASTNode; -import org.jetbrains.annotations.NotNull; - -public class JetHashQualifiedExpression extends JetQualifiedExpression { - public JetHashQualifiedExpression(@NotNull ASTNode node) { - super(node); - } - - @Override - public void accept(@NotNull JetVisitorVoid visitor) { - visitor.visitHashQualifiedExpression(this); - } - - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitHashQualifiedExpression(this, data); - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java index b2dd04a8477..0780f0b985e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java @@ -245,8 +245,8 @@ public class JetVisitor extends PsiElementVisitor { return visitExpression(expression, data); } - public R visitHashQualifiedExpression(JetHashQualifiedExpression expression, D data) { - return visitQualifiedExpression(expression, data); + public R visitCallableReferenceExpression(JetCallableReferenceExpression expression, D data) { + return visitExpression(expression, data); } public R visitDotQualifiedExpression(JetDotQualifiedExpression expression, D data) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index e331a2b5d87..d25489bbb14 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -235,8 +235,8 @@ public class JetVisitorVoid extends PsiElementVisitor { visitExpression(expression); } - public void visitHashQualifiedExpression(JetHashQualifiedExpression expression) { - visitQualifiedExpression(expression); + public void visitCallableReferenceExpression(JetCallableReferenceExpression expression) { + visitExpression(expression); } public void visitDotQualifiedExpression(JetDotQualifiedExpression expression) { 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 d4e669f080c..a357ea22044 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 @@ -563,7 +563,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } @Override - public JetTypeInfo visitHashQualifiedExpression(JetHashQualifiedExpression expression, ExpressionTypingContext context) { + public JetTypeInfo visitCallableReferenceExpression(JetCallableReferenceExpression expression, ExpressionTypingContext context) { context.trace.report(UNSUPPORTED.on(expression, getClass().getCanonicalName())); return JetTypeInfo.create(null, context.dataFlowInfo); }