Stub for JetProperty
This commit is contained in:
@@ -30,8 +30,7 @@ public interface JetNodeTypes {
|
|||||||
|
|
||||||
IElementType CLASS = JetStubElementTypes.CLASS;
|
IElementType CLASS = JetStubElementTypes.CLASS;
|
||||||
IElementType FUN = JetStubElementTypes.FUNCTION;
|
IElementType FUN = JetStubElementTypes.FUNCTION;
|
||||||
|
IElementType PROPERTY = JetStubElementTypes.PROPERTY;
|
||||||
JetNodeType PROPERTY = new JetNodeType("PROPERTY", JetProperty.class);
|
|
||||||
|
|
||||||
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
||||||
JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class);
|
JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class);
|
||||||
|
|||||||
@@ -836,11 +836,11 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
* (getter? setter? | setter? getter?) SEMI?
|
* (getter? setter? | setter? getter?) SEMI?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
private JetNodeType parseProperty() {
|
private IElementType parseProperty() {
|
||||||
return parseProperty(false);
|
return parseProperty(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetNodeType parseProperty(boolean local) {
|
IElementType parseProperty(boolean local) {
|
||||||
if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) {
|
if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) {
|
||||||
advance(); // VAL_KEYWORD or VAR_KEYWORD
|
advance(); // VAL_KEYWORD or VAR_KEYWORD
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
/**
|
/**
|
||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
*/
|
*/
|
||||||
public interface JetFunction extends JetTypeParameterListOwner, JetDeclarationWithBody, JetModifierListOwner {
|
public interface JetFunction extends JetTypeParameterListOwner, JetDeclarationWithBody {
|
||||||
@Nullable
|
@Nullable
|
||||||
JetParameterList getValueParameterList();
|
JetParameterList getValueParameterList();
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,15 @@ import com.intellij.lang.ASTNode;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.search.LocalSearchScope;
|
import com.intellij.psi.search.LocalSearchScope;
|
||||||
import com.intellij.psi.search.SearchScope;
|
import com.intellij.psi.search.SearchScope;
|
||||||
|
import com.intellij.psi.stubs.IStubElementType;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
import com.intellij.psi.tree.TokenSet;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -36,11 +39,15 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
|||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements JetModifierListOwner {
|
public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStub> {
|
||||||
public JetProperty(@NotNull ASTNode node) {
|
public JetProperty(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JetProperty(@NotNull PsiJetPropertyStub stub, @NotNull IStubElementType nodeType) {
|
||||||
|
super(stub, nodeType);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(@NotNull JetVisitorVoid visitor) {
|
public void accept(@NotNull JetVisitorVoid visitor) {
|
||||||
visitor.visitProperty(this);
|
visitor.visitProperty(this);
|
||||||
@@ -51,11 +58,27 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements
|
|||||||
return visitor.visitProperty(this, data);
|
return visitor.visitProperty(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public IStubElementType getElementType() {
|
||||||
|
return JetStubElementTypes.PROPERTY;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVar() {
|
public boolean isVar() {
|
||||||
|
PsiJetPropertyStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
return stub.isVar();
|
||||||
|
}
|
||||||
|
|
||||||
return getNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
|
return getNode().findChildByType(JetTokens.VAR_KEYWORD) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLocal() {
|
public boolean isLocal() {
|
||||||
|
PsiJetPropertyStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
return stub.isLocal();
|
||||||
|
}
|
||||||
|
|
||||||
PsiElement parent = getParent();
|
PsiElement parent = getParent();
|
||||||
return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody);
|
return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody);
|
||||||
}
|
}
|
||||||
@@ -64,7 +87,7 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements
|
|||||||
@Override
|
@Override
|
||||||
public SearchScope getUseScope() {
|
public SearchScope getUseScope() {
|
||||||
if (isLocal()) {
|
if (isLocal()) {
|
||||||
PsiElement block = PsiTreeUtil.getParentOfType(this, JetBlockExpression.class, JetClassInitializer.class);
|
@SuppressWarnings("unchecked") PsiElement block = PsiTreeUtil.getParentOfType(this, JetBlockExpression.class, JetClassInitializer.class);
|
||||||
if (block == null) return super.getUseScope();
|
if (block == null) return super.getUseScope();
|
||||||
else return new LocalSearchScope(block);
|
else return new LocalSearchScope(block);
|
||||||
} else return super.getUseScope();
|
} else return super.getUseScope();
|
||||||
@@ -135,11 +158,8 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ASTNode getValOrVarNode() {
|
public ASTNode getValOrVarNode() {
|
||||||
return getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
|
ASTNode node = getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
|
||||||
}
|
assert node != null : "Val or var should always exist for property";
|
||||||
|
return node;
|
||||||
@Nullable
|
|
||||||
public ASTNode getEqualsSign() {
|
|
||||||
return getNode().findChildByType(TokenSet.create(EQ));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.NamedStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface PsiJetPropertyStub extends NamedStub<JetProperty> {
|
||||||
|
boolean isVar();
|
||||||
|
boolean isLocal();
|
||||||
|
String getTypeText();
|
||||||
|
String getInferenceBodyText();
|
||||||
|
}
|
||||||
+2
-1
@@ -38,7 +38,7 @@ import java.io.IOException;
|
|||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
*/
|
*/
|
||||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||||
public static final int STUB_VERSION = 8;
|
public static final int STUB_VERSION = 9;
|
||||||
|
|
||||||
public JetFileElementType() {
|
public JetFileElementType() {
|
||||||
super("jet.FILE", JetLanguage.INSTANCE);
|
super("jet.FILE", JetLanguage.INSTANCE);
|
||||||
@@ -71,6 +71,7 @@ public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
|||||||
return new PsiJetFileStubImpl(null, packName);
|
return new PsiJetFileStubImpl(null, packName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi) {
|
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi) {
|
||||||
final Project project = psi.getProject();
|
final Project project = psi.getProject();
|
||||||
Language languageForParser = getLanguageForParser(psi);
|
Language languageForParser = getLanguageForParser(psi);
|
||||||
|
|||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.lang.ASTNode;
|
||||||
|
import com.intellij.lang.LighterAST;
|
||||||
|
import com.intellij.lang.LighterASTNode;
|
||||||
|
import com.intellij.psi.stubs.IndexSink;
|
||||||
|
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.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStub, JetProperty> {
|
||||||
|
public JetPropertyElementType(@NotNull @NonNls String debugName) {
|
||||||
|
super(debugName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetProperty createPsiFromAst(@NotNull ASTNode node) {
|
||||||
|
return new JetProperty(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetPropertyStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetProperty createPsi(@NotNull PsiJetPropertyStub stub) {
|
||||||
|
return new JetProperty(stub, JetStubElementTypes.PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetPropertyStub createStub(@NotNull JetProperty psi, StubElement parentStub) {
|
||||||
|
JetTypeReference typeRef = psi.getPropertyTypeRef();
|
||||||
|
JetExpression expression = psi.getInitializer();
|
||||||
|
|
||||||
|
return new PsiJetPropertyStubImpl(JetStubElementTypes.PROPERTY, parentStub,
|
||||||
|
psi.getName(), psi.isVar(), psi.isLocal(),
|
||||||
|
typeRef != null ? typeRef.getText() : null,
|
||||||
|
expression != null ? expression.getText() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(PsiJetPropertyStub stub, StubOutputStream dataStream) throws IOException {
|
||||||
|
dataStream.writeName(stub.getName());
|
||||||
|
dataStream.writeBoolean(stub.isVar());
|
||||||
|
dataStream.writeBoolean(stub.isLocal());
|
||||||
|
dataStream.writeName(stub.getTypeText());
|
||||||
|
dataStream.writeName(stub.getInferenceBodyText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetPropertyStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||||
|
StringRef name = dataStream.readName();
|
||||||
|
boolean isVar = dataStream.readBoolean();
|
||||||
|
boolean isLocal = dataStream.readBoolean();
|
||||||
|
StringRef typeText = dataStream.readName();
|
||||||
|
StringRef inferenceBodyText = dataStream.readName();
|
||||||
|
|
||||||
|
return new PsiJetPropertyStubImpl(JetStubElementTypes.PROPERTY, parentStub,
|
||||||
|
name, isVar, isLocal, typeText, inferenceBodyText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void indexStub(PsiJetPropertyStub stub, IndexSink sink) {
|
||||||
|
// No index
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -24,6 +24,7 @@ public interface JetStubElementTypes {
|
|||||||
|
|
||||||
JetClassElementType CLASS = new JetClassElementType("CLASS");
|
JetClassElementType CLASS = new JetClassElementType("CLASS");
|
||||||
JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN");
|
JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN");
|
||||||
|
JetPropertyElementType PROPERTY = new JetPropertyElementType("PROPERTY");
|
||||||
|
|
||||||
JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER");
|
JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER");
|
||||||
JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST");
|
JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST");
|
||||||
|
|||||||
+78
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.IStubElementType;
|
||||||
|
import com.intellij.psi.stubs.StubBase;
|
||||||
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import com.intellij.util.io.StringRef;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class PsiJetPropertyStubImpl extends StubBase<JetProperty> implements PsiJetPropertyStub {
|
||||||
|
private final StringRef name;
|
||||||
|
private final boolean isVar;
|
||||||
|
private final boolean isLocal;
|
||||||
|
private final StringRef typeText;
|
||||||
|
private final StringRef inferenceBodyText;
|
||||||
|
|
||||||
|
public PsiJetPropertyStubImpl(IStubElementType elementType, StubElement parent, StringRef name,
|
||||||
|
boolean isVar, boolean isLocal, StringRef typeText, StringRef inferenceBodyText) {
|
||||||
|
super(parent, elementType);
|
||||||
|
this.name = name;
|
||||||
|
this.isVar = isVar;
|
||||||
|
this.isLocal = isLocal;
|
||||||
|
this.typeText = typeText;
|
||||||
|
this.inferenceBodyText = inferenceBodyText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PsiJetPropertyStubImpl(IStubElementType elementType, StubElement parent, String name,
|
||||||
|
boolean isVal, boolean isLocal,
|
||||||
|
String typeText, String inferenceBodyText
|
||||||
|
) {
|
||||||
|
this(elementType, parent, StringRef.fromString(name),
|
||||||
|
isVal, isLocal, StringRef.fromString(typeText), StringRef.fromString(inferenceBodyText));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVar() {
|
||||||
|
return isVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLocal() {
|
||||||
|
return isLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeText() {
|
||||||
|
return StringRef.toString(typeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInferenceBodyText() {
|
||||||
|
return StringRef.toString(inferenceBodyText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return StringRef.toString(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user