diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 7bf0fd0534d..cfa646579a2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -30,8 +30,7 @@ public interface JetNodeTypes { IElementType CLASS = JetStubElementTypes.CLASS; IElementType FUN = JetStubElementTypes.FUNCTION; - - JetNodeType PROPERTY = new JetNodeType("PROPERTY", JetProperty.class); + IElementType PROPERTY = JetStubElementTypes.PROPERTY; JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class); JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index 8a918e918ed..38e9bec57be 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -836,11 +836,11 @@ public class JetParsing extends AbstractJetParsing { * (getter? setter? | setter? getter?) SEMI? * ; */ - private JetNodeType parseProperty() { + private IElementType parseProperty() { return parseProperty(false); } - JetNodeType parseProperty(boolean local) { + IElementType parseProperty(boolean local) { if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) { advance(); // VAL_KEYWORD or VAR_KEYWORD } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java index 0ced9c4f227..79653fd8dd4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFunction.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Nikolay Krasko */ -public interface JetFunction extends JetTypeParameterListOwner, JetDeclarationWithBody, JetModifierListOwner { +public interface JetFunction extends JetTypeParameterListOwner, JetDeclarationWithBody { @Nullable JetParameterList getValueParameterList(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java index 4edec5aeb9d..5c13f319867 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetProperty.java @@ -20,12 +20,15 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.search.LocalSearchScope; import com.intellij.psi.search.SearchScope; +import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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 java.util.List; @@ -36,11 +39,15 @@ import static org.jetbrains.jet.lexer.JetTokens.*; /** * @author max */ -public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements JetModifierListOwner { +public class JetProperty extends JetTypeParameterListOwnerStub { public JetProperty(@NotNull ASTNode node) { super(node); } + public JetProperty(@NotNull PsiJetPropertyStub stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + @Override public void accept(@NotNull JetVisitorVoid visitor) { visitor.visitProperty(this); @@ -51,11 +58,27 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements return visitor.visitProperty(this, data); } + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.PROPERTY; + } + public boolean isVar() { + PsiJetPropertyStub stub = getStub(); + if (stub != null) { + return stub.isVar(); + } + return getNode().findChildByType(JetTokens.VAR_KEYWORD) != null; } public boolean isLocal() { + PsiJetPropertyStub stub = getStub(); + if (stub != null) { + return stub.isLocal(); + } + PsiElement parent = getParent(); return !(parent instanceof JetFile || parent instanceof JetClassBody || parent instanceof JetNamespaceBody); } @@ -64,7 +87,7 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements @Override public SearchScope getUseScope() { 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(); else return new LocalSearchScope(block); } else return super.getUseScope(); @@ -135,11 +158,8 @@ public class JetProperty extends JetTypeParameterListOwnerNotStubbed implements @NotNull public ASTNode getValOrVarNode() { - return getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD)); - } - - @Nullable - public ASTNode getEqualsSign() { - return getNode().findChildByType(TokenSet.create(EQ)); + ASTNode node = getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD)); + assert node != null : "Val or var should always exist for property"; + return node; } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetPropertyStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetPropertyStub.java new file mode 100644 index 00000000000..8a0ba8919b6 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetPropertyStub.java @@ -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 { + boolean isVar(); + boolean isLocal(); + String getTypeText(); + String getInferenceBodyText(); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java index fa97579497e..5be6bb2b270 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java @@ -38,7 +38,7 @@ import java.io.IOException; * @author Nikolay Krasko */ public class JetFileElementType extends IStubFileElementType { - public static final int STUB_VERSION = 8; + public static final int STUB_VERSION = 9; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); @@ -71,6 +71,7 @@ public class JetFileElementType extends IStubFileElementType { return new PsiJetFileStubImpl(null, packName); } + @Override protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull final PsiElement psi) { final Project project = psi.getProject(); Language languageForParser = getLanguageForParser(psi); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetPropertyElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetPropertyElementType.java new file mode 100644 index 00000000000..c4574016fa7 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetPropertyElementType.java @@ -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 { + 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 + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java index edf994cbc6f..8298393510f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java @@ -24,6 +24,7 @@ public interface JetStubElementTypes { JetClassElementType CLASS = new JetClassElementType("CLASS"); JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN"); + JetPropertyElementType PROPERTY = new JetPropertyElementType("PROPERTY"); JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER"); JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetPropertyStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetPropertyStubImpl.java new file mode 100644 index 00000000000..e5f14ae4449 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetPropertyStubImpl.java @@ -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 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); + } +}