Stubs for JetNameReferenceExpression

This commit is contained in:
Pavel V. Talanov
2014-03-27 19:21:53 +04:00
parent 19a60dda3f
commit 0674d2495c
9 changed files with 221 additions and 26 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.jet;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.IFileElementType;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementType;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.plugin.JetLanguage;
@@ -114,7 +115,7 @@ public interface JetNodeTypes {
JetNodeType FUNCTION_LITERAL = new JetNodeType("FUNCTION_LITERAL", JetFunctionLiteral.class);
JetNodeType ANNOTATED_EXPRESSION = new JetNodeType("ANNOTATED_EXPRESSION", JetAnnotatedExpression.class);
JetNodeType REFERENCE_EXPRESSION = new JetNodeType("REFERENCE_EXPRESSION", JetNameReferenceExpression.class);
IElementType REFERENCE_EXPRESSION = JetStubElementTypes.REFERENCE_EXPRESSION;
JetNodeType OPERATION_REFERENCE = new JetNodeType("OPERATION_REFERENCE", JetOperationReferenceExpression.class);
JetNodeType LABEL = new JetNodeType("LABEL", JetLabelReferenceExpression.class);
@@ -17,5 +17,8 @@
package org.jetbrains.jet.lang.psi
import com.intellij.lang.ASTNode
import org.jetbrains.jet.lexer.JetTokens
public class JetLabelReferenceExpression(node: ASTNode) : JetSimpleNameExpressionImpl(node)
public class JetLabelReferenceExpression(node: ASTNode) : JetSimpleNameExpressionImpl(node) {
public override fun getReferencedNameElement() = findChildByType(JetTokens.LABEL_IDENTIFIER) ?: this
}
@@ -0,0 +1,82 @@
/*
* Copyright 2010-2014 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 com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.stubs.PsiJetNameReferenceExpressionStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lexer.JetTokens;
import static org.jetbrains.jet.lexer.JetTokens.*;
public class JetNameReferenceExpression extends JetElementImplStub<PsiJetNameReferenceExpressionStub> implements JetSimpleNameExpression {
private static final TokenSet NAME_REFERENCE_EXPRESSIONS = TokenSet.create(IDENTIFIER, FIELD_IDENTIFIER, THIS_KEYWORD, SUPER_KEYWORD);
public JetNameReferenceExpression(@NotNull ASTNode node) {
super(node);
}
public JetNameReferenceExpression(@NotNull PsiJetNameReferenceExpressionStub stub) {
super(stub, JetStubElementTypes.REFERENCE_EXPRESSION);
}
@Override
@NotNull
public String getReferencedName() {
return JetSimpleNameExpressionImpl.object$.getReferencedNameImpl(this);
}
@Override
@NotNull
public Name getReferencedNameAsName() {
return JetSimpleNameExpressionImpl.object$.getReferencedNameAsNameImpl(this);
}
@Override
@NotNull
public PsiElement getReferencedNameElement() {
PsiElement element = findChildByType(NAME_REFERENCE_EXPRESSIONS);
if (element == null) {
return this;
}
return element;
}
@Override
@Nullable
public PsiElement getIdentifier() {
return findChildByType(JetTokens.IDENTIFIER);
}
@NotNull
@Override
public IElementType getReferencedNameElementType() {
return JetSimpleNameExpressionImpl.object$.getReferencedNameElementTypeImpl(this);
}
@Override
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
return visitor.visitSimpleNameExpression(this, data);
}
}
@@ -17,5 +17,8 @@
package org.jetbrains.jet.lang.psi
import com.intellij.lang.ASTNode
import org.jetbrains.jet.lang.parsing.JetExpressionParsing
public class JetOperationReferenceExpression(node: ASTNode) : JetSimpleNameExpressionImpl(node)
public class JetOperationReferenceExpression(node: ASTNode) : JetSimpleNameExpressionImpl(node) {
override fun getReferencedNameElement() = findChildByType(JetExpressionParsing.ALL_OPERATIONS) ?: this
}
@@ -28,41 +28,46 @@ import org.jetbrains.jet.lexer.JetTokens.*
public trait JetSimpleNameExpression : JetReferenceExpression {
public fun getReferencedName(): String {
val text = getReferencedNameElement().getNode()!!.getText()
return JetPsiUtil.unquoteIdentifierOrFieldReference(text)
}
public fun getReferencedName(): String
public fun getReferencedNameAsName(): Name {
val name = getReferencedName()
return Name.identifierNoValidate(name)
}
public fun getReferencedNameAsName(): Name
public fun getReferencedNameElement(): PsiElement
public fun getIdentifier(): PsiElement?
public fun getReferencedNameElementType(): IElementType {
return getReferencedNameElement().getNode()!!.getElementType()!!
}
public fun getReferencedNameElementType(): IElementType
}
abstract class JetSimpleNameExpressionImpl(node: ASTNode) : JetExpressionImpl(node), JetSimpleNameExpression {
public override fun getIdentifier(): PsiElement? {
return findChildByType(JetTokens.IDENTIFIER)
}
override fun getIdentifier(): PsiElement? = findChildByType(JetTokens.IDENTIFIER)
override fun getReferencedNameElementType() = getReferencedNameElementTypeImpl()
override fun <R, D> accept(visitor: JetVisitor<R, D>, data: D?): R {
return visitor.visitSimpleNameExpression(this, data) as R
}
public override fun getReferencedNameElement(): PsiElement {
return findChildByType(REFERENCE_TOKENS) ?:
findChildByType(JetExpressionParsing.ALL_OPERATIONS) ?:
this
}
override fun getReferencedNameAsName() = getReferencedNameAsNameImpl()
override fun getReferencedName() = getReferencedNameImpl()
//NOTE: an unfortunate way to share an implementation between stubbed and not stubbed tree
class object {
public val REFERENCE_TOKENS: TokenSet = TokenSet.create(LABEL_IDENTIFIER, IDENTIFIER, FIELD_IDENTIFIER, THIS_KEYWORD, SUPER_KEYWORD)
fun JetSimpleNameExpression.getReferencedNameElementTypeImpl(): IElementType {
return this.getReferencedNameElement().getNode()!!.getElementType()!!
}
fun JetSimpleNameExpression.getReferencedNameAsNameImpl(): Name {
val name = this.getReferencedName()
return Name.identifierNoValidate(name)
}
fun JetSimpleNameExpression.getReferencedNameImpl(): String {
val text = this.getReferencedNameElement().getNode()!!.getText()
return JetPsiUtil.unquoteIdentifierOrFieldReference(text)
}
}
}
@@ -14,8 +14,14 @@
* limitations under the License.
*/
package org.jetbrains.jet.lang.psi
package org.jetbrains.jet.lang.psi.stubs;
import com.intellij.lang.ASTNode
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetNameReferenceExpression;
import org.jetbrains.jet.lang.resolve.name.Name;
public class JetNameReferenceExpression(node: ASTNode) : JetSimpleNameExpressionImpl(node)
public interface PsiJetNameReferenceExpressionStub extends StubElement<JetNameReferenceExpression> {
@NotNull
String getReferencedName();
}
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2014 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.stubs.elements;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream;
import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetNameReferenceExpression;
import org.jetbrains.jet.lang.psi.stubs.PsiJetNameReferenceExpressionStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetNameReferenceExpressionStubImpl;
import java.io.IOException;
public class JetNameReferenceExpressionElementType extends JetStubElementType<PsiJetNameReferenceExpressionStub, JetNameReferenceExpression> {
public JetNameReferenceExpressionElementType(@NotNull @NonNls String debugName) {
super(debugName, JetNameReferenceExpression.class, PsiJetNameReferenceExpressionStub.class);
}
@Override
public PsiJetNameReferenceExpressionStub createStub(@NotNull JetNameReferenceExpression psi, StubElement parentStub) {
return new PsiJetNameReferenceExpressionStubImpl(parentStub, StringRef.fromString(psi.getReferencedName()));
}
@Override
public void serialize(@NotNull PsiJetNameReferenceExpressionStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getReferencedName());
}
@NotNull
@Override
public PsiJetNameReferenceExpressionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef referencedName = dataStream.readName();
return new PsiJetNameReferenceExpressionStubImpl(parentStub, referencedName);
}
}
@@ -60,4 +60,6 @@ public interface JetStubElementTypes {
new JetPlaceHolderStubElementType<JetTypeReference>("TYPE_REFERENCE", JetTypeReference.class);;
JetUserTypeElementType USER_TYPE = new JetUserTypeElementType("USER_TYPE");
JetNameReferenceExpressionElementType REFERENCE_EXPRESSION = new JetNameReferenceExpressionElementType("REFERENCE_EXPRESSION");
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2014 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.stubs.impl;
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetNameReferenceExpression;
import org.jetbrains.jet.lang.psi.stubs.PsiJetNameReferenceExpressionStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
public class PsiJetNameReferenceExpressionStubImpl extends StubBase<JetNameReferenceExpression> implements PsiJetNameReferenceExpressionStub {
@NotNull
private final StringRef referencedName;
public PsiJetNameReferenceExpressionStubImpl(StubElement parent, @NotNull StringRef referencedName) {
super(parent, JetStubElementTypes.REFERENCE_EXPRESSION);
this.referencedName = referencedName;
}
@NotNull
@Override
public String getReferencedName() {
return referencedName.getString();
}
}